From d0d47c901f0da262bf73a7d0b4c962c9bafe1a24 Mon Sep 17 00:00:00 2001 From: Alex Kerr Date: Thu, 29 Jan 2015 12:38:07 +0000 Subject: [PATCH] Added sub to generate available races --- lib/OSRIC/Character.pm | 46 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 3 deletions(-) diff --git a/lib/OSRIC/Character.pm b/lib/OSRIC/Character.pm index e8ccc26..7bef401 100644 --- a/lib/OSRIC/Character.pm +++ b/lib/OSRIC/Character.pm @@ -1,5 +1,14 @@ 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::Assassin; use OSRIC::Class::Cleric; @@ -69,13 +78,44 @@ sub generate_stats for my $stat(keys %{$self->{stats}}) { # TODO: - # * Class specific boosts. - # * Perhaps an alternate system where players can choose what number - # to allocate to what stat. + # * A system where players can choose what number to allocate to what + # stat. $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): sub generate_gold {