Skip to content

Instantly share code, notes, and snippets.

@wmeister-old
Created October 12, 2011 01:53
Show Gist options
  • Save wmeister-old/1280005 to your computer and use it in GitHub Desktop.
Save wmeister-old/1280005 to your computer and use it in GitHub Desktop.
Microlite20 Character Generator
#!/usr/bin/perl -wT
use strict;
use YAML;
sub R($) { my ($m)=@_; (int rand ($m+1))+1 }
sub R0($) { my ($m)=@_; (R $m)-1; }
sub D6() { R 6; }
sub L { my ($a,$b)=@_; ($a < $b) ? $a : $b; }
sub STAT() { my ($a,$b,$c,$d)=(D6,D6,D6,D6); $a+$b+$c+$d - L(L(L($a,$b),$c),$d); }
sub RAE { my @a=@_; $a[R0 $#a]; }
sub RACE() { RAE(qw[Human Elf Dwarf Halfling]); }
sub CLASS() { RAE(qw[Fighter Rogue Magi Cleric]); }
sub GEN() { my %c=(Race => RACE, Class => CLASS, Stats => {STR => STAT, DEX => STAT, MIND => STAT}); ARB(\%c); \%c; }
sub SM { my ($s)=@_; return sub { $_[0]{Stats}{$s} += 2 }; }
sub ARB {
my ($c)=@_;
my %b = (Human => sub { $_[0]{'Racial Bonus'} = '+1 to all skill rolls'; },
Elf => SM('MIND'),
Dwarf => SM('STR'),
Halfling => SM('DEX'));
&{$b{$c->{Race}}}($c);
}
print YAML::Dump(GEN);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment