mirror of
https://github.com/ProjectEQ/projecteqquests
synced 2026-08-12 00:26:10 -04:00
Update check_handin.pl
This commit is contained in:
parent
f771122d0d
commit
41799c4bf3
1 changed files with 50 additions and 48 deletions
|
|
@ -1,65 +1,67 @@
|
|||
# plugin::check_handin($item1 => #required_amount,...);
|
||||
# autoreturns extra unused items on success
|
||||
# Automatically returns unused items on success
|
||||
sub check_handin {
|
||||
my $hashref = shift;
|
||||
my %required = @_;
|
||||
foreach my $req (keys %required) {
|
||||
if ((!defined $hashref->{$req}) || ($hashref->{$req} != $required{$req})) {
|
||||
return(0);
|
||||
}
|
||||
my $itemcount = shift;
|
||||
my %required_items = @_;
|
||||
foreach $item_id (keys %required_items) {
|
||||
if (!defined $itemcount->{$item_id} || $itemcount->{$item_id} != $required_items{$item_id}) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ($required_items{$item_id} < $itemcount->{$item_id}) {
|
||||
$itemcount->{$item_id} -= $required_items{$item_id};
|
||||
} else {
|
||||
delete $itemcount->{$item_id};
|
||||
}
|
||||
}
|
||||
foreach my $req (keys %required) {
|
||||
if ($required{$req} < $hashref->{$req}) {
|
||||
$hashref->{$req} -= $required{$req};
|
||||
} else {
|
||||
delete $hashref->{$req};
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
# plugin::return_items();
|
||||
# Returns unused items in your itemcount hash
|
||||
sub return_items {
|
||||
my $hashref = plugin::var('$itemcount');
|
||||
my $client = plugin::val('$client');
|
||||
my $name = plugin::val('$name');
|
||||
my $itemcount = plugin::var('itemcount');
|
||||
my $client = plugin::val('client');
|
||||
my $name = plugin::val('name');
|
||||
my $items_returned = 0;
|
||||
|
||||
my %ItemHash = (
|
||||
0 => [ plugin::val('$item1'), plugin::val('$item1_charges'), plugin::val('$item1_attuned') ],
|
||||
1 => [ plugin::val('$item2'), plugin::val('$item2_charges'), plugin::val('$item2_attuned') ],
|
||||
2 => [ plugin::val('$item3'), plugin::val('$item3_charges'), plugin::val('$item3_attuned') ],
|
||||
3 => [ plugin::val('$item4'), plugin::val('$item4_charges'), plugin::val('$item4_attuned') ],
|
||||
my %items_hash = (
|
||||
0 => [ plugin::val('item1'), plugin::val('item1_charges'), plugin::val('item1_attuned') ],
|
||||
1 => [ plugin::val('item2'), plugin::val('item2_charges'), plugin::val('item2_attuned') ],
|
||||
2 => [ plugin::val('item3'), plugin::val('item3_charges'), plugin::val('item3_attuned') ],
|
||||
3 => [ plugin::val('item4'), plugin::val('item4_charges'), plugin::val('item4_attuned') ],
|
||||
);
|
||||
|
||||
foreach my $k (keys(%{$hashref}))
|
||||
{
|
||||
next if($k == 0);
|
||||
my $rcount = $hashref->{$k};
|
||||
my $r;
|
||||
for ($r = 0; $r < 4; $r++)
|
||||
{
|
||||
if ($rcount > 0 && $ItemHash{$r}[0] && $ItemHash{$r}[0] == $k)
|
||||
{
|
||||
if ($client)
|
||||
{
|
||||
$client->SummonItem($k, $ItemHash{$r}[1], $ItemHash{$r}[2]);
|
||||
quest::say("I have no need for this $name, you can have it back.");
|
||||
foreach $handin_item (keys %{$itemcount}) {
|
||||
next if ($handin_item == 0);
|
||||
$required_count = $itemcount->{$handin_item};
|
||||
foreach $required_slot (0..3) {
|
||||
if (
|
||||
$required_count > 0 &&
|
||||
$items_hash{$required_slot}[0] &&
|
||||
$items_hash{$required_slot}[0] == $handin_item
|
||||
) {
|
||||
if ($client) {
|
||||
$client->SummonItem(
|
||||
$handin_item,
|
||||
$items_hash{$required_slot}[1],
|
||||
$items_hash{$required_slot}[2]
|
||||
);
|
||||
$items_returned = 1;
|
||||
} else {
|
||||
quest::summonitem($handin_item);
|
||||
$items_returned = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
# This shouldn't be needed, but just in case
|
||||
quest::summonitem($k, 0);
|
||||
$items_returned = 1;
|
||||
}
|
||||
$rcount--;
|
||||
$required_count--;
|
||||
}
|
||||
$required_slot++;
|
||||
}
|
||||
delete $hashref->{$k};
|
||||
delete $itemcount->{$handin_item};
|
||||
}
|
||||
|
||||
if ($items_returned) {
|
||||
quest::whisper("I have no need for this $name, you can have it back.");
|
||||
}
|
||||
# Return true if items were returned
|
||||
return $items_returned;
|
||||
|
||||
}
|
||||
|
||||
sub mq_process_items {
|
||||
|
|
@ -159,4 +161,4 @@ sub decode_eqemu_item_hash {
|
|||
}
|
||||
|
||||
return $hashref;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue