Added function to generate HP

This commit is contained in:
Alex Kerr 2015-02-10 16:07:42 +00:00
parent e22b88537e
commit 2b7010bb27
12 changed files with 120 additions and 3 deletions

View File

@ -20,7 +20,8 @@ use OSRIC::Class::Paladin;
use OSRIC::Class::Ranger; use OSRIC::Class::Ranger;
use OSRIC::Class::Thief; use OSRIC::Class::Thief;
use OSRIC::Util qw/d/; use OSRIC::Util qw/d con_mod/;
use POSIX qw/ceil/;
use JSON qw/to_json/; use JSON qw/to_json/;
# These functions are ordered in this file in the order they are to be # These functions are ordered in this file in the order they are to be
@ -42,7 +43,7 @@ sub new
xp => 0, xp => 0,
hp => 0, hp => 0,
ac => 0, ac => 0,
lvl => 0, lvl => 1,
age => 0, age => 0,
height => 0, height => 0,
weight => 0, weight => 0,
@ -218,6 +219,25 @@ sub generate_age
$self->{personal}->{age} /= @{$self->{personal}->{classes}}; $self->{personal}->{age} /= @{$self->{personal}->{classes}};
} }
# Generates the player's HP.
sub generate_hp
{
my $self = shift;
# Loop over each class and generate an HP value:
for my $class(@{$self->{personal}->{classes}})
{
$self->{personal}->{hp} += ("OSRIC::Class::$class"->get_hp +
con_mod($self->{stats}->{con}, $class));
}
# Divide by the number of classes:
$self->{personal}->{hp} /= @{$self->{personal}->{classes}};
# Round up if needed:
$self->{personal}->{hp} = ceil($self->{personal}->{hp});
}
# Encodes the character to JSON: # Encodes the character to JSON:
sub as_json sub as_json
{ {

View File

@ -9,6 +9,9 @@ my @CLASSES = qw/Assassin Cleric Druid Fighter Illusionist MagicUser Paladin
sub max_starting_gold { 0 } sub max_starting_gold { 0 }
sub get_gold { 0 } sub get_gold { 0 }
# The starting HP of the class:
sub get_hp { 0 }
# Minimum score requirements: # Minimum score requirements:
sub minimum_scores sub minimum_scores
{ {

View File

@ -7,6 +7,9 @@ use OSRIC::Util qw/d/;
sub max_starting_gold { 120 } sub max_starting_gold { 120 }
sub get_gold { (d(6, 2) * 10) } # 2d6 * 10 sub get_gold { (d(6, 2) * 10) } # 2d6 * 10
# The starting HP of the class:
sub get_hp { d(6) }
# Minimum score requirements: # Minimum score requirements:
sub minimum_scores sub minimum_scores
{ {

View File

@ -7,6 +7,9 @@ use OSRIC::Util qw/d/;
sub max_starting_gold { 180 } sub max_starting_gold { 180 }
sub get_gold { (d(6, 3) * 10) } # 3d6 * 10 sub get_gold { (d(6, 3) * 10) } # 3d6 * 10
# The starting HP of the class:
sub get_hp { d(8) }
# Minimum score requirements: # Minimum score requirements:
sub minimum_scores sub minimum_scores
{ {

View File

@ -7,6 +7,9 @@ use OSRIC::Util qw/d/;
sub max_starting_gold { 180 } sub max_starting_gold { 180 }
sub get_gold { (d(6, 3) * 10) } # 3d6 * 10 sub get_gold { (d(6, 3) * 10) } # 3d6 * 10
# The starting HP of the class:
sub get_hp { d(8) }
# Minimum score requirements: # Minimum score requirements:
sub minimum_scores sub minimum_scores
{ {

View File

@ -7,6 +7,9 @@ use OSRIC::Util qw/d/;
sub max_starting_gold { 200 } sub max_starting_gold { 200 }
sub get_gold { ((d(6, 3) + 2) * 10) } # (3d6 + 2) * 10 sub get_gold { ((d(6, 3) + 2) * 10) } # (3d6 + 2) * 10
# The starting HP of the class:
sub get_hp { d(10) }
# Minimum score requirements: # Minimum score requirements:
sub minimum_scores sub minimum_scores
{ {

View File

@ -7,6 +7,9 @@ use OSRIC::Util qw/d/;
sub max_starting_gold { 80 } sub max_starting_gold { 80 }
sub get_gold { (d(4, 2) * 10) } # 2d4 * 10 sub get_gold { (d(4, 2) * 10) } # 2d4 * 10
# The starting HP of the class:
sub get_hp { d(4) }
# Minimum score requirements: # Minimum score requirements:
sub minimum_scores sub minimum_scores
{ {

View File

@ -7,6 +7,9 @@ use OSRIC::Util qw/d/;
sub max_starting_gold { 80 } sub max_starting_gold { 80 }
sub get_gold { (d(4, 2) * 10) } # 2d4 * 10 sub get_gold { (d(4, 2) * 10) } # 2d4 * 10
# The starting HP of the class:
sub get_hp { d(4) }
# Minimum score requirements: # Minimum score requirements:
sub minimum_scores sub minimum_scores
{ {

View File

@ -7,6 +7,9 @@ use OSRIC::Util qw/d/;
sub max_starting_gold { 200 } sub max_starting_gold { 200 }
sub get_gold { ((d(6, 3) + 2) * 10) } # (3d6 + 2) * 10 sub get_gold { ((d(6, 3) + 2) * 10) } # (3d6 + 2) * 10
# The starting HP of the class:
sub get_hp { d(10) }
# Minimum score requirements: # Minimum score requirements:
sub minimum_scores sub minimum_scores
{ {

View File

@ -7,6 +7,9 @@ use OSRIC::Util qw/d/;
sub max_starting_gold { 200 } sub max_starting_gold { 200 }
sub get_gold { ((d(6, 3) + 2) * 10) } # (3d6 + 2) * 10 sub get_gold { ((d(6, 3) + 2) * 10) } # (3d6 + 2) * 10
# The starting HP of the class:
sub get_hp { d(8) }
# Minimum score requirements: # Minimum score requirements:
sub minimum_scores sub minimum_scores
{ {

View File

@ -7,6 +7,9 @@ use OSRIC::Util qw/d/;
sub max_starting_gold { 120 } sub max_starting_gold { 120 }
sub get_gold { (d(6, 2) * 10) } # 2d6 * 10 sub get_gold { (d(6, 2) * 10) } # 2d6 * 10
# The starting HP of the class:
sub get_hp { d(6) }
# Minimum score requirements: # Minimum score requirements:
sub minimum_scores sub minimum_scores
{ {

View File

@ -1,6 +1,6 @@
package OSRIC::Util; package OSRIC::Util;
use Exporter qw/import/; use Exporter qw/import/;
our @EXPORT = qw/d/; our @EXPORT = qw/d con_mod/;
# Rolls a dice of the specified number: # Rolls a dice of the specified number:
sub d sub d
@ -16,4 +16,71 @@ sub d
return $i; return $i;
} }
# Returns the constitution hp modifier (at level 1):
sub con_mod
{
my $con = shift;
my $class = shift;
# Get the constitution modifier:
my $mod;
if($con <= 3)
{
$mod = -2;
}
elsif(($con > 3) && ($con <= 6))
{
$mod = -1;
}
elsif(($con > 6) && ($con <= 14))
{
$mod = 0;
}
elsif(($con > 14) && ($con <= 15))
{
$mod = 1;
}
elsif(($con > 15) && ($con <= 16))
{
$mod = 2;
}
elsif(($con > 16) && ($con <= 17))
{
if(($class eq "Fighter") || ($class eq "Paladin")
|| ($class eq "Ranger"))
{
$mod = 3;
}
else
{
$mod = 2;
}
}
elsif(($con > 17) && ($con <= 18))
{
if(($class eq "Fighter") || ($class eq "Paladin")
|| ($class eq "Ranger"))
{
$mod = 4;
}
else
{
$mod = 2;
}
}
elsif(($con > 18) && ($con <= 19))
{
if(($class eq "Fighter") || ($class eq "Paladin")
|| ($class eq "Ranger"))
{
$mod = 5;
}
else
{
$mod = 2;
}
}
return $mod;
}
1; 1;