my %alignment = ( parts => [qw(lawful chaotic good evil neutral)], good_vs_evil => [qw(good neutral evil)], lawful_vs_chaotic => [qw(lawful neutral chaotic)], ); $alignment{'evil'} = [map($_." evil",@{$alignment{'lawful_vs_chaotic'}})]; $alignment{'good'} = [map($_." good",@{$alignment{'lawful_vs_chaotic'}})]; $alignment{'chaotic'} = [map("chaotic ".$_,@{$alignment{'good_vs_evil'}})]; $alignment{'lawful'} = [map("lawful ".$_,@{$alignment{'good_vs_evil'}})]; $alignment{'neutral_lc'} = [map($_." neutral",grep {$_ ne "neutral"} @{$alignment{'lawful_vs_chaotic'}}), "true neutral"]; $alignment{'neutral_ge'} = [map("neutral ".$_,grep {$_ ne "neutral"} @{$alignment{'good_vs_evil'}}), "true neutral"]; sub full { my $prefix = $alignment{'lawful_vs_chaotic'}[rand @{$alignment{'lawful_vs_chaotic'}}]; my $suffix = $alignment{'good_vs_evil'}[rand @{$alignment{'good_vs_evil'}}]; if ($prefix eq $suffix) { return "true neutral"; } else { return $prefix." ".$suffix; } } sub random_alignment { my $type = shift; my $result; if (exists $alignment{$type}) { $result = $alignment{$type}[rand @{$alignment{$type}}]; } else { $result = &full; } return $result; } #### my %effects = ( part => [qw(acid cold electricity fire)], gaze => [qw(paralysis stone stun death)], range_part => [qw(gas sonic)], touch_part => [qw(poison energy_drain)], touch_special => [qw(befouls purifies nullifies_holy_water nullifies_unholy_water)], vocal => [qw(deafen fear terror flight)], ); $effects{'range'} = [@{$effects{'part'}}, @{$effects{'range_part'}}]; $effects{'touch'} = [@{$effects{'part'}}, @{$effects{'touch_part'}}]; $effects{'general'} = [@{$effects{'part'}}, @{$effects{'gaze'}}, @{$effects{'range_part'}}, @{$effects{'touch_part'}}, @{$effects{'vocal'}}]; sub random_effect { my $type = shift; my $result; if (exists $effects{$type}) { $result = $effects{$type}[rand @{$effects{$type}}]; } else { $result = $effects{'general'}[rand @{$effects{'general'}}]; } $result =~ tr/_/ /; return $result; }