Added sub to generate available races

This commit is contained in:
Alex Kerr 2015-01-29 12:38:07 +00:00
parent f89ec1f6c2
commit d0d47c901f

View File

@ -1,5 +1,14 @@
package OSRIC::Character; package OSRIC::Character;
use OSRIC::Race;
use OSRIC::Race::Dwarf;
use OSRIC::Race::Elf;
use OSRIC::Race::Gnome;
use OSRIC::Race::HalfElf;
use OSRIC::Race::Halfling;
use OSRIC::Race::HalfOrc;
use OSRIC::Race::Human;
use OSRIC::Class; use OSRIC::Class;
use OSRIC::Class::Assassin; use OSRIC::Class::Assassin;
use OSRIC::Class::Cleric; use OSRIC::Class::Cleric;
@ -69,13 +78,44 @@ sub generate_stats
for my $stat(keys %{$self->{stats}}) for my $stat(keys %{$self->{stats}})
{ {
# TODO: # TODO:
# * Class specific boosts. # * A system where players can choose what number to allocate to what
# * Perhaps an alternate system where players can choose what number # stat.
# to allocate to what stat.
$self->{stats}->{$stat} = d(6, 3); $self->{stats}->{$stat} = d(6, 3);
} }
} }
# Return a list of available races based on the player's stats:
sub get_available_races
{
my $self = shift;
my @races = @OSRIC::Race::races;
# Loop over each race:
for my $race(@OSRIC::Race::races)
{
# Get the stat boosts and racial limitations of this race:
my $stats_boosts = "OSRIC::Race::$race"->stats_boosts;
my $racial_limitations = "OSRIC::Race::$race"->racial_limitations;
# Loop over each stat:
for my $stat(keys %{$self->{stats}})
{
# Add any class boosts:
my $real = $self->{stats}->{$stat} + $stats_boosts->{$stat};
# Check if this stat fits the range:
if(($real < $racial_limitations->{$stat}->{min}) ||
($real > $racial_limitations->{$stat}->{max}))
{
# If not, remove it from the list and move onto the next race:
@races = grep { $_ ne "$race" } @races;
last;
}
}
}
return @races;
}
# Gives the player a certain amount of starting gold (class-dependant): # Gives the player a certain amount of starting gold (class-dependant):
sub generate_gold sub generate_gold
{ {