here's something along the same line. it uses regular expressions to match the class passed (long form or abbreviation, case insensitive) and returns the type (hybrid, melee, caster, or priest). returns 'other' if no match was found.
Code:
use List::Util qw(first);
# usage plugin::ClassType($class)
sub ClassType
{
my $class = lc(shift);
my %type = (
hybrid => qr/^b(a)?rd|b(eastlord|st)|pal(adin)?|r(anger|ng)|sh(adowknight|d)$/,
melee => qr/^war(rior)?|m(o)?nk|ber(serker)?|rog(ue)?$/,
caster => qr/^nec(romancer)?|wiz(ard)?|enc(hanter)?|mag(ician)?$/,
priest => qr/^cl(eric|r)|sh(aman|m)|dru(id)?$/
);
(first { $class =~ $type{$_} } keys %type) // 'other';
}
1;
here is an example use in quests/templates/global_player.pl
before:
Code:
sub EVENT_COMBINE_SUCCESS {
if (($recipe_id == 10904) || ($recipe_id == 10905) || ($recipe_id == 10906) || ($recipe_id == 10907)) {
$client->Message(1, "The gem resonates with power as the shards placed within glow unlocking some of the stone's power. You were successful in assembling most of the stone but there are four slots left to fill, where could those four pieces be?");
}
if ($recipe_id == 10903) {
if (($class eq "Bard") || ($class eq "Beastlord") || ($class eq "Paladin") || ($class eq "Ranger") || ($class eq "Shadowknight")) {
quest::summonitem(67666);
quest::summonitem(67704);
}
elsif (($class eq "Warrior") || ($class eq "Monk") || ($class eq "Berserker") || ($class eq "Rogue")) {
quest::summonitem(67665);
quest::summonitem(67704);
}
elsif (($class eq "Cleric") || ($class eq "Shaman") || ($class eq "Druid")) {
quest::summonitem(67667);
quest::summonitem(67704);
}
elsif (($class eq "Necromancer") || ($class eq "Wizard") || ($class eq "Enchanter") || ($class eq "Magician")) {
quest::summonitem(67668);
quest::summonitem(67704);
}
$client->Message(1,"Success");
}
if ($recipe_id == 10346) {
if (($class eq "Bard") || ($class eq "Beastlord") || ($class eq "Paladin") || ($class eq "Ranger") || ($class eq "Shadowknight")) {
quest::summonitem(67661);
quest::summonitem(67704);
}
elsif (($class eq "Warrior") || ($class eq "Monk") || ($class eq "Berserker") || ($class eq "Rogue")) {
quest::summonitem(67660);
quest::summonitem(67704);
}
elsif (($class eq "Cleric") || ($class eq "Shaman") || ($class eq "Druid")) {
quest::summonitem(67662);
quest::summonitem(67704);
}
elsif (($class eq "Necromancer") || ($class eq "Wizard") || ($class eq "Enchanter") || ($class eq "Magician")) {
quest::summonitem(67663);
quest::summonitem(67704);
}
$client->Message(1,"Success");
}
if ($recipe_id == 10334) {
if (($class eq "Bard") || ($class eq "Beastlord") || ($class eq "Paladin") || ($class eq "Ranger") || ($class eq "Shadowknight")) {
quest::summonitem(67654);
quest::summonitem(67704);
}
elsif (($class eq "Warrior") || ($class eq "Monk") || ($class eq "Berserker") || ($class eq "Rogue")) {
quest::summonitem(67653);
quest::summonitem(67704);
}
elsif (($class eq "Cleric") || ($class eq "Shaman") || ($class eq "Druid")) {
quest::summonitem(67655);
quest::summonitem(67704);
}
elsif (($class eq "Necromancer") || ($class eq "Wizard") || ($class eq "Enchanter") || ($class eq "Magician")) {
quest::summonitem(67656);
quest::summonitem(67704);
}
$client->Message(1,"Success");
}
}
after:
Code:
sub EVENT_COMBINE_SUCCESS
{
if ($recipe_id =~ /^1090[4-7]$/) {
$client->Message(1,
"The gem resonates with power as the shards placed within glow unlocking some of the stone's power. ".
"You were successful in assembling most of the stone but there are four slots left to fill, ".
"where could those four pieces be?"
);
}
elsif ($recipe_id =~ /^10(903|346|334)$/) {
my %reward = (
melee => {
10903 => 67665,
10346 => 67660,
10334 => 67653
},
hybrid => {
10903 => 67666,
10346 => 67661,
10334 => 67654
},
priest => {
10903 => 67667,
10346 => 67662,
10334 => 67655
},
caster => {
10903 => 67668,
10346 => 67663,
10334 => 67656
}
);
my $type = plugin::ClassType($class);
quest::summonitem($reward{$type}{$recipe_id});
quest::summonitem(67704);
$client->Message(1,"Success");
}
}
note: i used a single complex data structure and a couple of regular expressions to eliminate the repetitive conditionals in the subroutine.