c0ncrete |
12-16-2012 10:02 PM |
callbacks by example
the majority of the additional lines come from my breaking up the quest::say() and quest::emote() text to a maximum width of 80 columns. the horizontal scrolling you're likely experiencing is what happens when you put long strings in a single line. other than that, i didn't bother correcting any of the text.
most of the logic is handled in a single foreach loop, which has very readable syntax because of how the $items hashref is constructed.
before (bloodfields/Barowsar.pl):
Code:
sub EVENT_ITEM
{
%rhands = ("Monk" => 70786, "Beastlord" => 70842, "Druid" => 70779);
%rwrists = ("Monk" => 70785, "Beastlord" => 70841, "Druid" => 70778);
%rarms = ("Monk" => 70784, "Beastlord" => 70840, "Druid" => 70777);
%rhead = ("Monk" => 70783, "Beastlord" => 70839, "Druid" => 70776);
%rchest = ("Monk" => 70788, "Beastlord" => 70844, "Druid" => 70781);
%rlegs = ("Monk" => 70789, "Beastlord" => 70845, "Druid" => 70782);
%rfeet = ("Monk" => 70787, "Beastlord" => 70843, "Druid" => 70780);
my $ihands = $rhands{$class};
my $iwrists = $rwrists{$class};
my $iarms = $rarms{$class};
my $ihead = $rhead{$class};
my $ichest = $rchest{$class};
my $ilegs = $rlegs{$class};
my $ifeet = $rfeet{$class};
if($faction <= 2) #must be warmly to do this quest
{
if (plugin::check_handin(\%itemcount, 51446 => 1, 51467 => 2))
{
quest::say("Fantastic work $race . The loss of the shard should prevent the opportunity we were waiting for. Please take these and wear them with pride."); #made up
quest::exp(100000);
quest::summonitem($ihands);
}
if (plugin::check_handin(\%itemcount, 51445 => 1, 51466 => 2))
{
quest::say("The Blood Standard of Dranik! I did not believe it still existed! This will bring hope to the few dragorn who still resist Mata Muram. I only wish I was ready to join them. Thank you. As promised, here is a leather wristguard as a reward.");
quest::exp(100000);
quest::summonitem($iwrists);
}
if (plugin::check_handin(\%itemcount, 51444 => 1, 51465 => 2))
{
quest::emote("looks at the map with yearning, 'Thankyou young $race, just seeing this brings some hope to my heart that one day what was may be again. Take these sleeves and use them to bring down the muramite."); #made up
quest::exp(100000);
quest::summonitem($iarms);
}
if (plugin::check_handin(\%itemcount, 51440 => 1, 51461 => 2))
{
quest::emote("takes the book and scrolls from you gratefully, 'Excellent, with these writings I should be able to begin to understand discord, hopefully giving me information we can use to our advantage. Here $name, take this as promised."); #made up
quest::exp(100000);
quest::summonitem($ihead);
}
if (plugin::check_handin(\%itemcount, 51441 => 1, 51462 => 3))
{
quest::say("He lives yet! You see it glows still, if only faintly.' Barowsar pauses for a moment in quite contemplation before continuing. 'Here $name, this was my finest work, and you deserve no loss for the favor you have done me this day."); #made up
quest::exp(100000);
quest::summonitem($ichest);
}
if (plugin::check_handin(\%itemcount, 51442 => 1, 51463 => 3))
{
quest::emote("quickly conceals the ember within the bowls. 'Good work. I will lay this ember to rest, so that the spirits of this forsaken place may rest at last. As promises here is your reward."); #made up
quest::exp(100000);
quest::summonitem($ilegs);
}
if (plugin::check_handin(\%itemcount, 51443 => 1, 51464 => 2))
{
quest::say("Well done $name. I understand the Muramites guard these well. I'll bury this stone so the dragorn of Kuua can move on from the horrors of the past and instead look to the future. As promised, here is a pair of finely crafted leather boots as your reward.");
quest::exp(100000);
quest::summonitem($ifeet);
}
else
{
plugin::return_items(\%itemcount);
quest::say("I am sorry $name, but these are not the items i was looking for."); #made up text
}
}
else
{
plugin::return_items(\%itemcount);
quest::emote("returns the items to you without responding."); #made up text
}
}
after:
Code:
sub earned
{
unshift @_, plugin::var('itemcount');
plugin::check_handin(@_);
}
sub give
{
quest::exp(100000);
quest::summonitem(shift);
}
sub EVENT_ITEM
{
if ($faction <= 2 and $class =~ /^dru|mon|bea/) {
my $items = {
head => {
earned => sub { earned(51440 => 1, 51461 => 2) },
Druid => 70776, Monk => 70783, Beastlord => 70839,
spam => sub { quest::emote(
"takes the book and scrolls from you gratefully, " .
"'Excellent, with these writings I should be able to " .
"begin to understand discord, hopefully giving me " .
"information we can use to our advantage. Here $name, " .
"take this as promised."
) }
},
chest => {
earned => sub { earned(51441 => 1, 51462 => 3) },
Druid => 70781, Monk => 70788, Beastlord => 70844,
spam => sub { quest::say(
"He lives yet! You see it glows still, if only faintly.' " .
"Barowsar pauses for a moment in quite contemplation " .
"before continuing. 'Here $name, this was my finest work, ".
"and you deserve no loss for the favor you have done me " .
"this day."
) }
},
legs => {
earned => sub { earned(51442 => 1, 51463 => 3) },
Druid => 70782, Monk => 70789, Beastlord => 70845,
spam => sub { quest::emote(
"quickly conceals the ember within the bowls. 'Good work. ".
"I will lay this ember to rest, so that the spirits of " .
"this forsaken place may rest at last. As promises here " .
"is your reward."
) }
},
feet => {
earned => sub { earned(51443 => 1, 51464 => 2) },
Druid => 70780, Monk => 70787, Beastlord => 70843,
spam => sub { quest::say(
"Well done $name. I understand the Muramites guard these " .
"well. I'll bury this stone so the dragorn of Kuua can " .
"move on from the horrors of the past and instead look to ".
"the future. As promised, here is a pair of finely " .
"crafted leather boots as your reward."
) }
},
arms => {
earned => sub { earned(51444 => 1, 51465 => 2) },
Druid => 70777, Monk => 70784, Beastlord => 70840,
spam => sub { quest::emote(
"looks at the map with yearning, 'Thankyou young $race, ".
"just seeing this brings some hope to my heart that one ".
"day what was may be again. Take these sleeves and use " .
"them to bring down the muramite."
) }
},
wrist => {
earned => sub { earned(51445 => 1, 51466 => 2) },
Druid => 70778, Monk => 70785, Beastlord => 70841,
spam => sub { quest::say(
"The Blood Standard of Dranik! I did not believe it still ".
"existed! This will bring hope to the few dragorn who " .
"still resist Mata Muram. I only wish I was ready to join ".
"them. Thank you. As promised, here is a leather wrist-" .
"guard as a reward."
) }
},
hands => {
earned => sub { earned(51446 => 1, 51467 => 2) },
Druid => 70779, Monk => 70786, Beastlord => 70842,
spam => sub { quest::say(
"Fantastic work $race. The loss of the shard should " .
"prevent the opportunity we were waiting for. Please take ".
"these and wear them with pride." # /boggle
) }
}
};
foreach my $slot (keys %$items) {
my $reward = $items->{$slot};
$reward->{spam}() and
give $reward->{$class} and
last if $reward->{earned}();
}
}
plugin::return_items(\%itemcount);
}
|