From 3c370dafc6cb14b7c16e6c919034d5ca80574d0c Mon Sep 17 00:00:00 2001 From: Alex Kerr Date: Wed, 7 Jan 2015 16:13:22 +0000 Subject: [PATCH] Grassroots --- .gitignore | 1 + lib/OSRIC/.Character.pm.swp | Bin 0 -> 12288 bytes lib/OSRIC/.Classes.pm.swp | Bin 0 -> 12288 bytes lib/OSRIC/CGI.pm | 11 ++++ lib/OSRIC/Character.pm | 99 +++++++++++++++++++++++++++++++ lib/OSRIC/Classes.pm | 21 +++++++ lib/OSRIC/Classes/Assassin.pm | 23 +++++++ lib/OSRIC/Classes/Cleric.pm | 23 +++++++ lib/OSRIC/Classes/Druid.pm | 23 +++++++ lib/OSRIC/Classes/Fighter.pm | 23 +++++++ lib/OSRIC/Classes/Illusionist.pm | 23 +++++++ lib/OSRIC/Classes/MagicUser.pm | 23 +++++++ lib/OSRIC/Classes/Paladin.pm | 23 +++++++ lib/OSRIC/Classes/Ranger.pm | 23 +++++++ lib/OSRIC/Classes/Thief.pm | 23 +++++++ lib/OSRIC/Util.pm | 10 ++++ osric.pl | 4 ++ 17 files changed, 353 insertions(+) create mode 100644 lib/OSRIC/.Character.pm.swp create mode 100644 lib/OSRIC/.Classes.pm.swp create mode 100644 lib/OSRIC/CGI.pm create mode 100644 lib/OSRIC/Character.pm create mode 100644 lib/OSRIC/Classes.pm create mode 100644 lib/OSRIC/Classes/Assassin.pm create mode 100644 lib/OSRIC/Classes/Cleric.pm create mode 100644 lib/OSRIC/Classes/Druid.pm create mode 100644 lib/OSRIC/Classes/Fighter.pm create mode 100644 lib/OSRIC/Classes/Illusionist.pm create mode 100644 lib/OSRIC/Classes/MagicUser.pm create mode 100644 lib/OSRIC/Classes/Paladin.pm create mode 100644 lib/OSRIC/Classes/Ranger.pm create mode 100644 lib/OSRIC/Classes/Thief.pm create mode 100644 lib/OSRIC/Util.pm create mode 100755 osric.pl 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 0000000000000000000000000000000000000000..f76e1855f7d76c2a93fc956305d634184ed7ef42 GIT binary patch literal 12288 zcmeI2L2MgE6o#j{z!uU3xPo{j1`-;_NvP7wAyH8hssJTbn^Z_u6phzo?=tGQvz4ny2N_K>#zV1Vn(y{mb#@9k1)Ks-0jGddz$xGqa0)mD4z~ijeuTY&6#B9>{Oo$4qOKx zfGc1f%z?*2AGmdlv2VdQ;5zsaTm`#8flaUmUIt5G2Al-9`x*NM+yGyIPr)_t9(WV% zfDLd7yaZ+ee!gURFbW<81E3H5^B`ltfuF!l@HO}nd=5SW?|>%IAOK~s3Kqc$Pyoll zAUFp4!R-g&5BvbW0w05G;C-+K3Sa>Ie3Y>t!S~=Mco$p&uYoG4fXBce9&!YqfVaR! zumUcCDex4?frr4~Sc|{FpTMrmA*?GGvQxk*;1qBQI0gPE3QSJUFxFyTtx37dDvoHD zMC9Xb#C7|WQzER)q-JvqvkGKI&#+yl8YR-P?Z<{`(T-B213`ZKrA653#S6=?6zv?= zS$=MJTkuc^E!_FBj8qFwbAHH`66(^#T7Ir7^m;W8%b0hV&WK1PTnp=1X`W~qRmqs) z)KhVyX_s<5KUd>B>utLoPS4HGQLfa>(xTJZglTT=Cq#03w;g6(BoKs$HqbP@Rx681 zr+KEW#G^9VNJ>rH9>{7Sl%{q#He4D}LQtJo1x=kAEfS(PqW4m@n&oWMfVOAkmPnPY zhrB5g;^d1&a~Tn@#f?Z)Tsb(I%`aaTbrF?$q({vX5c9CqUOPdArJ-KfJISnU1Qdw5Xx8NRYb? zUXhP3eh|k>q+X&%tt67n&Aic+R9*P8B7G{Mn^x%@E6WSZMds}?uM#I@#Y5a98=|S` z$1q*FVMR=_-{PAMcenKd^ zOSEPis-mX4pKZCDh6!Uv9$vZ?(A06l6RhYyFEy!@L;&5MFs>d)`}}08C2SP=kJb3ilqkzjq(h_wIMP?(ufC9X>Qc4FUzR6@hq=Oe^uRS>{1vul#C;(@YT_4;ulPf+-dYe n(vbKz=rwLW6nJUAx9xeQaF+Cr7}C_azhP>xtwH-sYli&`bvAM^ literal 0 HcmV?d00001 diff --git a/lib/OSRIC/.Classes.pm.swp b/lib/OSRIC/.Classes.pm.swp new file mode 100644 index 0000000000000000000000000000000000000000..f2ad1f326d1823f9ff198d695a5d3f87bbb9e7cc GIT binary patch literal 12288 zcmeI&!DJvzQWEU%^|S zqGv%+1RuZ$@B!-G2heYmO%Oq1kA?q`KQq~#`DXTa3)w;Q_0BFo+_+EDYDDY3lUMIA z)`%YvsYH*<%gfpml_!m-xjtAj@u(~qbZw*q>v9t|!q^0f83fN?zS!vo-9$O3-Nq6PC0mlZq$XLDT$22fwLc}NlJAmllCP34lFyP)lCu5>2^s_-009U<00Izz z00bZa0SG|gzXV#d)}dC1=#W@zS!Jw3U#NstY704{9rAo8msQ#B literal 0 HcmV?d00001 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;