Cthulhu

With the hope of keeping this project organized I’m going to keep a log of things on this page. It will probably get pretty cluttered as I go along. My goal at this point is to translate some of the rule set into the base functions which will be used through the ‘game’.

Ability Modifiers

function ability_modifier($stat) {
if ($stat == 1) {
$modifier = -5;
}
else if ($stat >= 2 && $stat <= 3) {
$modifier = -4;
}
else if ($stat >= 4 && $stat <= 5) {
$modifier = -3;
}
else if ($stat >= 6 && $stat <= 7) {
$modifier = -2;
}
else if ($stat >= 8 && $stat <= 9) {
$modifier = -1;
}
else if ($stat >= 10 && $stat <= 11) {
$modifier = 0;
}
else if ($stat >= 12 && $stat <= 13) {
$modifier = 1;
}
else if ($stat >= 14 && $stat <= 15) {
$modifier = 2;
}
else if ($stat >= 16 && $stat <= 17) {
$modifier = 3;
}
else if ($stat >= 18 && $stat <= 19) {
$modifier = 4;
}
else if ($stat >= 20 && $stat <= 21) {
$modifier = 5;
}
return $modifier;
}

The code is very simple – call the function as ability_modifier(12) for example and it will it will store a value of 1 in the $modifier variable and return. It does need to be modified as ability scores can go higher the 21. But, for now 21 will be the max.

Hit Points

function base_hitpoints($con) {
$additional_hp = ability_modifier($con);

$starting_hitpoints = 6 + $additional_hp;

return $starting_hitpoints;
}

According to my ebook source every player character starts with 6 hit points plus the constitution modifier. Upon leveling the new hitpoints are determined with: hp = 1d6 + con modifier + hp

function levelup_hitpoints($hp, $con) {
$modifier = ability_modifier($con);

$1d6 = rand(1,6);

$hp = $hp + $1d6 + $modifier;

return $hp;
}

Experience

With the rules that I’m using for the base of this monstrosity it seems that experience isn’t handed out each time you kill a monster but, when you complete an overall task. For example: Survive an attack from a dozen Deep Ones. Their example is: 300 * average character level / number of players. But since I’m starting will only a single player it will be 300 * level.

function award_experience($level) {
$award = 300 * $level;

return $award;
}

Sanity

Being a Cthulhu based game we need to take character sanity into account.

function base_sanity($wis) {
$sanity = $wis * 5;

return $sanity;
}

Sanity is affected when a character encounters a horror. However, that may not be the case if the character encounters the same horror again. After a while if running into Deep Ones the character will get used to their existence.

function sanity_check($current_sanity, $successful_loss, $unsuccessful_loss, $loss_modifier) {
$check_roll = rand(1, 99);
if ($check_roll <= $current_sanity && $successful_loss != ‘1d6’ && $successful_loss != ‘1d3’) {
$loss = $successful_loss;
}
else if ($check_roll > $current_sanity) {
$loss = rand (1, $unsuccessful_loss) + $loss_modifier;
}
else if ($check_roll <= $current_sanity && $successful_loss == ‘1d6’) {
$loss = rand (1, 6);
}
else if ($check_roll <= $current_sanity && $successful_loss == ‘1d3’) {
$loss = rand (1, 3);
}
return $loss;
}

Because some of the horrors deal a random amount of loss to sanity I had to code in some a couple of extra ifs to account for that. They may not stay in though I may just modify the successful loss to be constant.

Mikey pointed out that I didn’t include any code for MaxSanity.  Hopefully, I’ll be able to get some more code work done once I get my highspeed internet back.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: