Add removeitem(item_id, quantity) to Perl/Lua. (#1156)

- Perl: quest::removeitem(item_id, quantity);
- Lua: eq.remove_item(item_id, quantity);
This commit is contained in:
Alex
2020-12-29 19:21:47 -05:00
committed by GitHub
parent 21a1a7bed7
commit a920d449ff
4 changed files with 65 additions and 0 deletions
+37
View File
@@ -2729,6 +2729,43 @@ int QuestManager::countitem(uint32 item_id) {
return quantity;
}
void QuestManager::removeitem(uint32 item_id, uint32 quantity) {
QuestManagerCurrentQuestVars();
EQ::ItemInstance *item = nullptr;
static const int16 slots[][2] = {
{ EQ::invslot::POSSESSIONS_BEGIN, EQ::invslot::POSSESSIONS_END },
{ EQ::invbag::GENERAL_BAGS_BEGIN, EQ::invbag::GENERAL_BAGS_END },
{ EQ::invbag::CURSOR_BAG_BEGIN, EQ::invbag::CURSOR_BAG_END},
{ EQ::invslot::BANK_BEGIN, EQ::invslot::BANK_END },
{ EQ::invbag::BANK_BAGS_BEGIN, EQ::invbag::BANK_BAGS_END },
{ EQ::invslot::SHARED_BANK_BEGIN, EQ::invslot::SHARED_BANK_END },
{ EQ::invbag::SHARED_BANK_BAGS_BEGIN, EQ::invbag::SHARED_BANK_BAGS_END },
};
int removed_count = 0;
const size_t size = sizeof(slots) / sizeof(slots[0]);
for (int slot_index = 0; slot_index < size; ++slot_index) {
for (int slot_id = slots[slot_index][0]; slot_id <= slots[slot_index][1]; ++slot_id) {
if (removed_count == quantity)
break;
item = initiator->GetInv().GetItem(slot_id);
if (item && item->GetID() == item_id) {
int stack_size = item->IsStackable() ? item->GetCharges() : 1;
if ((removed_count + stack_size) <= quantity) {
removed_count += stack_size;
initiator->DeleteItemInInventory(slot_id, stack_size, true);
} else {
int amount_left = (quantity - removed_count);
if (amount_left > 0 && stack_size >= amount_left) {
removed_count += amount_left;
initiator->DeleteItemInInventory(slot_id, amount_left, true);
}
}
}
}
}
}
void QuestManager::UpdateSpawnTimer(uint32 id, uint32 newTime)
{
bool found = false;