diff --git a/.gitignore b/.gitignore index eaca02e..f0b63fb 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,4 @@ nytprof.out /pm_to_blib *.o *.bs +*.swp diff --git a/lib/OSRIC/.Character.pm.swp b/lib/OSRIC/.Character.pm.swp new file mode 100644 index 0000000..f76e185 Binary files /dev/null and b/lib/OSRIC/.Character.pm.swp differ diff --git a/lib/OSRIC/.Classes.pm.swp b/lib/OSRIC/.Classes.pm.swp new file mode 100644 index 0000000..f2ad1f3 Binary files /dev/null and b/lib/OSRIC/.Classes.pm.swp differ diff --git a/lib/OSRIC/CGI.pm b/lib/OSRIC/CGI.pm new file mode 100644 index 0000000..2387567 --- /dev/null +++ b/lib/OSRIC/CGI.pm @@ -0,0 +1,11 @@ +package OSRIC::CGI; +use CGI; + +sub new +{ + my $class = shift; + my $q = CGI->new; + bless $q, $class; +} + +1; diff --git a/lib/OSRIC/Character.pm b/lib/OSRIC/Character.pm new file mode 100644 index 0000000..ed50a70 --- /dev/null +++ b/lib/OSRIC/Character.pm @@ -0,0 +1,99 @@ +package OSRIC::Character; + +use OSRIC::Classes; +use OSRIC::Classes::Assassin; +use OSRIC::Classes::Cleric; +use OSRIC::Classes::Druid; +use OSRIC::Classes::Fighter; +use OSRIC::Classes::Illusionist; +use OSRIC::Classes::MagicUser; +use OSRIC::Classes::Paladin; +use OSRIC::Classes::Ranger; +use OSRIC::Classes::Thief; + +use OSRIC::Util qw/d/; +use JSON qw/encode_json/; + +# Generates a new character: +sub new +{ + my $class = shift; + my $character = + { + personal => + { + irc => "", # The player's irc nick, not found on the character sheet. + name => "", + classes => [ ], + alignment => "", + race => "", + xp => 0, + hp => 0, + ac => 0, + lvl => 0, + age => 0, + height => 0, + weight => 0, + sex => "M" + }, + stats => + { + str => 0, + dex => 0, + con => 0, + int => 0, + wis => 0, + cha => 0, + }, + equipment => + { + items => [ ], + weapons => [ ], + missiles => [ ], + armour => [ ], + }, + wealth => + { + coins => 0, + gems => [ ], + other => [ ], + }, + }; + bless $character, $class; +} + +# Generates the 6 major stats: +sub generate_stats +{ + my $self = shift; + 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. + $self->{stats}->{$stat} = (d(6) + d(6) + d(6)); + } +} + +# Gives the player a certain amount of starting gold (class-dependant): +sub generate_gold +{ + my $self = shift; + + # Get the classes and sort by the highest starting gold (see page 28): + my @classes = @{$self->{personal}->{classes}}; + sort { $a->max_starting_gold <=> $b->max_starting_gold } @classes; + + # Generate the starting gold: + $self->{wealth}->{coins} = $classes[0]->get_gold; +} + +# Encodes the character to JSON: +sub to_json +{ + my $self = shift; + my $json = encode_json $self; +} + +1; diff --git a/lib/OSRIC/Classes.pm b/lib/OSRIC/Classes.pm new file mode 100644 index 0000000..fe70e35 --- /dev/null +++ b/lib/OSRIC/Classes.pm @@ -0,0 +1,21 @@ +package OSRIC::Classes; + +# A sub to get the maximum amount of starting gold (for sorting) and one to get +# an actual amount of starting gold: +sub max_starting_gold { 0 } +sub get_gold { 0 } + +# Minimum score requirements: +sub minimum_scores +{ + { + str => 0, + dex => 0, + con => 0, + int => 0, + wis => 0, + cha => 0, + } +} + +1; diff --git a/lib/OSRIC/Classes/Assassin.pm b/lib/OSRIC/Classes/Assassin.pm new file mode 100644 index 0000000..f3d8ee4 --- /dev/null +++ b/lib/OSRIC/Classes/Assassin.pm @@ -0,0 +1,23 @@ +package OSRIC::Classes::Assassin; +use parent qw(Classes); +use OSRIC::Util qw/d/; + +# A sub to get the maximum amount of starting gold (for sorting) and one to get +# an actual amount of starting gold: +sub max_starting_gold { 120 } +sub get_gold { ((d(6) + d(6)) * 10) } # 2d6 * 10 + +# Minimum score requirements: +sub minimum_scores +{ + { + str => 12, + dex => 12, + con => 6, + int => 11, + wis => 6, + cha => 0, + } +} + +1; diff --git a/lib/OSRIC/Classes/Cleric.pm b/lib/OSRIC/Classes/Cleric.pm new file mode 100644 index 0000000..47b2816 --- /dev/null +++ b/lib/OSRIC/Classes/Cleric.pm @@ -0,0 +1,23 @@ +package OSRIC::Classes::Assassin; +use parent qw(Classes); +use OSRIC::Util qw/d/; + +# A sub to get the maximum amount of starting gold (for sorting) and one to get +# an actual amount of starting gold: +sub max_starting_gold { 180 } +sub get_gold { ((d(6) + d(6) + d(6)) * 10) } # 3d6 * 10 + +# Minimum score requirements: +sub minimum_scores +{ + { + str => 6, + dex => 3, + con => 6, + int => 6, + wis => 9, + cha => 6, + } +} + +1; diff --git a/lib/OSRIC/Classes/Druid.pm b/lib/OSRIC/Classes/Druid.pm new file mode 100644 index 0000000..03b9f68 --- /dev/null +++ b/lib/OSRIC/Classes/Druid.pm @@ -0,0 +1,23 @@ +package OSRIC::Classes::Assassin; +use parent qw(Classes); +use OSRIC::Util qw/d/; + +# A sub to get the maximum amount of starting gold (for sorting) and one to get +# an actual amount of starting gold: +sub max_starting_gold { 180 } +sub get_gold { ((d(6) + d(6) + d(6)) * 10) } # 3d6 * 10 + +# Minimum score requirements: +sub minimum_scores +{ + { + str => 6, + dex => 6, + con => 6, + int => 6, + wis => 12, + cha => 15, + } +} + +1; diff --git a/lib/OSRIC/Classes/Fighter.pm b/lib/OSRIC/Classes/Fighter.pm new file mode 100644 index 0000000..770e38c --- /dev/null +++ b/lib/OSRIC/Classes/Fighter.pm @@ -0,0 +1,23 @@ +package OSRIC::Classes::Assassin; +use parent qw(Classes); +use OSRIC::Util qw/d/; + +# A sub to get the maximum amount of starting gold (for sorting) and one to get +# an actual amount of starting gold: +sub max_starting_gold { 200 } +sub get_gold { (((d(6) + d(6) + d(6)) + 2) * 10) } # (3d6 + 2) * 10 + +# Minimum score requirements: +sub minimum_scores +{ + { + str => 9, + dex => 6, + con => 7, + int => 3, + wis => 6, + cha => 6, + } +} + +1; diff --git a/lib/OSRIC/Classes/Illusionist.pm b/lib/OSRIC/Classes/Illusionist.pm new file mode 100644 index 0000000..6ab5405 --- /dev/null +++ b/lib/OSRIC/Classes/Illusionist.pm @@ -0,0 +1,23 @@ +package OSRIC::Classes::Assassin; +use parent qw(Classes); +use OSRIC::Util qw/d/; + +# A sub to get the maximum amount of starting gold (for sorting) and one to get +# an actual amount of starting gold: +sub max_starting_gold { 80 } +sub get_gold { ((d(4) + d(4)) * 10) } # 2d4 * 10 + +# Minimum score requirements: +sub minimum_scores +{ + { + str => 6, + dex => 16, + con => 0, + int => 15, + wis => 6, + cha => 6, + } +} + +1; diff --git a/lib/OSRIC/Classes/MagicUser.pm b/lib/OSRIC/Classes/MagicUser.pm new file mode 100644 index 0000000..357aa02 --- /dev/null +++ b/lib/OSRIC/Classes/MagicUser.pm @@ -0,0 +1,23 @@ +package OSRIC::Classes::Assassin; +use parent qw(Classes); +use OSRIC::Util qw/d/; + +# A sub to get the maximum amount of starting gold (for sorting) and one to get +# an actual amount of starting gold: +sub max_starting_gold { 80 } +sub get_gold { ((d(4) + d(4)) * 10) } # 2d4 * 10 + +# Minimum score requirements: +sub minimum_scores +{ + { + str => 3, + dex => 6, + con => 6, + int => 9, + wis => 6, + cha => 6, + } +} + +1; diff --git a/lib/OSRIC/Classes/Paladin.pm b/lib/OSRIC/Classes/Paladin.pm new file mode 100644 index 0000000..6d13eb8 --- /dev/null +++ b/lib/OSRIC/Classes/Paladin.pm @@ -0,0 +1,23 @@ +package OSRIC::Classes::Assassin; +use parent qw(Classes); +use OSRIC::Util qw/d/; + +# A sub to get the maximum amount of starting gold (for sorting) and one to get +# an actual amount of starting gold: +sub max_starting_gold { 200 } +sub get_gold { (((d(6) + d(6) + d(6)) + 2) * 10) } # (3d6 + 2) * 10 + +# Minimum score requirements: +sub minimum_scores +{ + { + str => 12, + dex => 6, + con => 9, + int => 9, + wis => 13, + cha => 17, + } +} + +1; diff --git a/lib/OSRIC/Classes/Ranger.pm b/lib/OSRIC/Classes/Ranger.pm new file mode 100644 index 0000000..f036e88 --- /dev/null +++ b/lib/OSRIC/Classes/Ranger.pm @@ -0,0 +1,23 @@ +package OSRIC::Classes::Assassin; +use parent qw(Classes); +use OSRIC::Util qw/d/; + +# A sub to get the maximum amount of starting gold (for sorting) and one to get +# an actual amount of starting gold: +sub max_starting_gold { 200 } +sub get_gold { (((d(6) + d(6) + d(6)) + 2) * 10) } # (3d6 + 2) * 10 + +# Minimum score requirements: +sub minimum_scores +{ + { + str => 13, + dex => 6, + con => 14, + int => 13, + wis => 14, + cha => 6, + } +} + +1; diff --git a/lib/OSRIC/Classes/Thief.pm b/lib/OSRIC/Classes/Thief.pm new file mode 100644 index 0000000..2e791fe --- /dev/null +++ b/lib/OSRIC/Classes/Thief.pm @@ -0,0 +1,23 @@ +package OSRIC::Classes::Assassin; +use parent qw(Classes); +use OSRIC::Util qw/d/; + +# A sub to get the maximum amount of starting gold (for sorting) and one to get +# an actual amount of starting gold: +sub max_starting_gold { 120 } +sub get_gold { ((d(6) + d(6)) * 10) } # 2d6 * 10 + +# Minimum score requirements: +sub minimum_scores +{ + { + str => 6, + dex => 9, + con => 6, + int => 6, + wis => 0, + cha => 6, + } +} + +1; diff --git a/lib/OSRIC/Util.pm b/lib/OSRIC/Util.pm new file mode 100644 index 0000000..1a5c079 --- /dev/null +++ b/lib/OSRIC/Util.pm @@ -0,0 +1,10 @@ +package OSRIC::Util; + +# Rolls a dice of the specified number: +sub d +{ + my $n = shift; + return int(rand($n)); +} + +1; diff --git a/osric.pl b/osric.pl new file mode 100755 index 0000000..0e8f8f0 --- /dev/null +++ b/osric.pl @@ -0,0 +1,4 @@ +#!/usr/bin/perl -w -Ilib +use OSRIC::CGI; +use OSRIC::Character; +use strict;