Grassroots

This commit is contained in:
Alex Kerr 2015-01-07 16:13:22 +00:00
parent 204833227a
commit 3c370dafc6
17 changed files with 353 additions and 0 deletions

1
.gitignore vendored
View File

@ -17,3 +17,4 @@ nytprof.out
/pm_to_blib /pm_to_blib
*.o *.o
*.bs *.bs
*.swp

BIN
lib/OSRIC/.Character.pm.swp Normal file

Binary file not shown.

BIN
lib/OSRIC/.Classes.pm.swp Normal file

Binary file not shown.

11
lib/OSRIC/CGI.pm Normal file
View File

@ -0,0 +1,11 @@
package OSRIC::CGI;
use CGI;
sub new
{
my $class = shift;
my $q = CGI->new;
bless $q, $class;
}
1;

99
lib/OSRIC/Character.pm Normal file
View File

@ -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;

21
lib/OSRIC/Classes.pm Normal file
View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

10
lib/OSRIC/Util.pm Normal file
View File

@ -0,0 +1,10 @@
package OSRIC::Util;
# Rolls a dice of the specified number:
sub d
{
my $n = shift;
return int(rand($n));
}
1;

4
osric.pl Executable file
View File

@ -0,0 +1,4 @@
#!/usr/bin/perl -w -Ilib
use OSRIC::CGI;
use OSRIC::Character;
use strict;