Code:
use 5.012;
use warnings;
package NPC;
sub new {
my ( $class, %param ) = ( shift, @_ );
$param{_class} = 14;
return bless \%param, $class;
}
sub GetClass {
shift->{_class};
}
package main;
my $npc = NPC->new();
# array of playable class long names
use constant CLASS_L => qw(
Unknown Warrior Cleric Paladin Ranger Shadowknight Druid Monk Bard Rogue
Shaman Necromancer Wizard Magician Enchanter Beastlord Berserker
);
# hashref containing buffs offered depening on the class of the npc
my $buff = {
Enchanter => [
[ "Bind Affinity", 35, 10 ],
[ "Breeze", 697, 25 ],
[ "Clarity", 174, 50 ],
[ "Clarity II", 1693, 200 ],
[ "Alacrity", 170, 10 ],
[ "Augment", 1729, 30 ],
[ "Aanya's Quickening", 1708, 100 ],
[ "Rune I", 481, 5 ],
],
Necromancer => [ [ "Dead Men Floating", 1391, 10 ], ],
};
# this is what the client said (used to search available buffs)
my $text = "la";
# this is how we find out long name of the class the npc is
my $mclass = (CLASS_L)[ $npc->GetClass() ];
# this searches the array of available buffs and returns only those that match
foreach my $spell ( grep { ${$_}[0] =~ /$text/i } @{ $buff->{$mclass} } ) {
my ( $spellName, $spellID, $spellCost ) = @{$spell};
say "I can cast $spellName [$spellID] on you for $spellCost platinum.";
}
results:
Code:
I can cast Clarity [174] on you for 50 platinum.
I can cast Clarity II [1693] on you for 200 platinum.
I can cast Alacrity [170] on you for 10 platinum.