Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^2: Lady Aleena's first working module

by Lady_Aleena (Curate)
on Oct 14, 2009 at 21:42 UTC ( #801219=note: print w/replies, xml ) Need Help??


in reply to Re: Lady Aleena's first working module
in thread Lady Aleena's first working module

Herkum,

Thanks for simplifying my code. While I didn't do exactly what you did above, I did use the hash.

For Alignment.pm...

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{'lawf +ul_vs_chaotic'}}]; my $suffix = $alignment{'good_vs_evil'}[rand @{$alignment{'good_vs_e +vil'}}]; 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; }

For Effect.pm...

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'}}, @{$ef +fects{'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; }

If there are any further improvements you can think of, please let me know. Thanks again!

Have a nice day!
Lady Aleena

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://801219]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (2)
As of 2021-04-19 05:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?