package Games::Random::Alignment; use strict; use warnings; use diagnostics; use base 'Exporter'; our @EXPORT_OK = qw(random_alignment); =head1 Alignment This module generates random alignments for AD&D 2nd Edition. =head2 Authors Lady Aleena with lots of help from DrForr, whoppix, and rindolf in the #perlcafe on freenode. =head2 Use To use this module, please enter the following. use Games::Random::Alignment qw(random_alignment); When you want to generate a random alignment with this module, you can choose from any of the alignment axes. random_alignment("parts") will generate lawful, chaotic, good, evil, or neutral. random_alignment("good_vs_evil") will generate good, neutral, or evil. random_alignment("lawful_vs_chaotic") will generate lawful, neutral, or chaotic. random_alignment("evil") will generate lawful evil, neutral evil, or chaotic evil. random_alignment("good") will generate lawful good, neutral good, or chaotic good. random_alignment("chaotic") will generate chaotic good, chaotic neutral, or chaotic evil. random_alignment("lawful") will generate lawful good, lawful neutral, or lawful evil. random_alignment("neutral_lc") will generate lawful neutral, true neutral, or chaotic neutral. random_alignment("neutral_ge") will generate neutral good, true neutral, or neutral evil. random_alignment("any") will generate any two part alignment. =cut my @parts = qw(lawful chaotic good evil neutral); my @good_vs_evil = qw(good neutral evil); my @lawful_vs_chaotic = qw(lawful neutral chaotic); my @evil = map($_." evil",@lawful_vs_chaotic); my @good = map($_." good",@lawful_vs_chaotic); my @chaotic = map("chaotic ".$_,@good_vs_evil); my @lawful = map("lawful ".$_,@good_vs_evil); my @neutral_lc = (map($_." neutral",grep {$_ ne "neutral"} @lawful_vs_chaotic), "true neutral"); my @neutral_ge = (map("neutral ".$_,grep {$_ ne "neutral"} @good_vs_evil), "true neutral"); sub full { my $prefix = $lawful_vs_chaotic[rand @lawful_vs_chaotic]; my $suffix = $good_vs_evil[rand @good_vs_evil]; if ($prefix eq $suffix) { return "true neutral"; } else { return $prefix." ".$suffix; } } sub random_alignment { my $type = shift; if ($type eq 'parts') { return $parts[rand @parts]; } elsif ($type eq 'good_vs_evil') { return $good_vs_evil[rand @good_vs_evil]; } elsif ($type eq 'lawful_vs_chaotic') { return $lawful_vs_chaotic[rand @lawful_vs_chaotic]; } elsif ($type eq 'evil') { return $evil[rand @evil]; } elsif ($type eq 'good') { return $good[rand @good]; } elsif ($type eq 'chaotic') { return $chaotic[rand @chaotic]; } elsif ($type eq 'lawful') { return $lawful[rand @lawful]; } elsif ($type eq 'neutral_lc') { return $neutral_lc[rand @neutral_lc]; } elsif ($type eq 'neutral_ge') { return $neutral_ge[rand @neutral_ge]; } else { return full; } } 1;