http://qs1969.pair.com?node_id=799163

Over the years I have been here, many of you have probably despaired that I would ever get anywhere. I was so afraid of making modules because they looked so complicated, and I complained bitterly about them. I finally made one however, and I wonder why I was so timid about them in the first place. This module is rather simplistic and only usable by a very very small fraction (maybe .01%) of the Perl programmers out there that I have not decided whether or not I will ever upload it to CPAN.

This module started when I finally decided to read and learn how to use both map and grep about 2 weeks ago. It was a long time in coming. I may not be too much farther along, but any progress is better than none, I hope. maping and grepping will save me a lot of time and energy in the future. I am happy with the results of this little module. Sorry it is not tidier.

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, chaot +ic, good, evil, or neutral. random_alignment("good_vs_evil") will generate good, neutral +, or evil. random_alignment("lawful_vs_chaotic") will generate lawful, neutr +al, 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 neutra +l, 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_ev +il), "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;

My second module is similar to the first, randomly generating more stuff. :)

package Games::Random::Effect; use warnings; use strict; use diagnostics; use base 'Exporter'; our @EXPORT_OK = qw(random_effect); =head1 Effect This module generates random effects for AD&D 2nd Edition. =head2 Author Lady Aleena =head2 Use To use this module, please enter the following. use Games::Random::Effect qw(random_effect); When you want to generate a random effect with this module, you can ch +oose from the following. random_effect("general") will generate any of the effects listed b +elow. random_effect("gaze") will generate paralysis, stone, stun, or +death. random_effect("range") will generate acid, cold, electricity, fi +re, gas, or sonic. random_effect("touch") will generate acid, cold, electricity, fi +re, poison, or energy drain. random_effect("vocal") will generate deafen, fear, terror, or fl +ight. =cut my @part = qw(acid cold electricity fire); my @gaze = qw(paralysis stone stun death); my @range_part = qw(gas sonic); my @range = (@part, @range_part); my @touch_part = qw(poison energy_drain); my @touch = (@part, @touch_part); my @touch_special = qw(befouls purifies nullifies_holy_water nullifies +_unholy_water); my @vocal = qw(deafen fear terror flight); my @general = (@part, @gaze, @range_part, @touch_part, @vocal); my $result; sub random_effect { my $type = shift; if ($type eq 'general') { $result = $general[rand @general]; } elsif ($type eq 'gaze') { $result = $gaze[rand @gaze]; } elsif ($type eq 'range') { $result = $range[rand @range]; } elsif ($type eq 'touch') { $result = $touch[rand @touch]; } elsif ($type eq 'vocal') { $result = $vocal[rand @vocal]; } else { $result = $general[rand @general]; } $result =~ tr/_/ /; return $result; } 1;

I have a third in the works right now, but I overcomplicated it, I think.

Have a nice day!
Lady Aleena