Core/Items: DestroyItemCount also searches bank
Closes #8240 Signed-off-by: Nay <dnpd.dd@gmail.com>
This commit is contained in:
1 parent
5cd2f6fef9
commit
9776bdfdfa
1 file changed
+97
-35
@@ -12688,7 +12688,7 @@ void Player::DestroyItem(uint8 bag, uint8 slot, bool update)
|
||||
}
|
||||
}
|
||||
|
||||
void Player::DestroyItemCount(uint32 item, uint32 count, bool update, bool unequip_check)
|
||||
void Player::DestroyItemCount(uint32 itemEntry, uint32 count, bool update, bool unequip_check)
|
||||
{
|
||||
sLog->outDebug(LOG_FILTER_PLAYER_ITEMS, "STORAGE: DestroyItemCount item = %u, count = %u", item, count);
|
||||
uint32 remcount = 0;
|
||||
@@ -12696,14 +12696,14 @@ void Player::DestroyItemCount(uint32 item, uint32 count, bool update, bool unequ
|
||||
// in inventory
|
||||
for (uint8 i = INVENTORY_SLOT_ITEM_START; i < INVENTORY_SLOT_ITEM_END; ++i)
|
||||
{
|
||||
if (Item* pItem = GetItemByPos(INVENTORY_SLOT_BAG_0, i))
|
||||
if (Item* item = GetItemByPos(INVENTORY_SLOT_BAG_0, i))
|
||||
{
|
||||
if (pItem->GetEntry() == item && !pItem->IsInTrade())
|
||||
if (item->GetEntry() == itemEntry && !item->IsInTrade())
|
||||
{
|
||||
if (pItem->GetCount() + remcount <= count)
|
||||
if (item->GetCount() + remcount <= count)
|
||||
{
|
||||
// all items in inventory can unequipped
|
||||
remcount += pItem->GetCount();
|
||||
remcount += item->GetCount();
|
||||
DestroyItem(INVENTORY_SLOT_BAG_0, i, update);
|
||||
|
||||
if (remcount >= count)
|
||||
@@ -12711,11 +12711,11 @@ void Player::DestroyItemCount(uint32 item, uint32 count, bool update, bool unequ
|
||||
}
|
||||
else
|
||||
{
|
||||
ItemRemovedQuestCheck(pItem->GetEntry(), count - remcount);
|
||||
pItem->SetCount(pItem->GetCount() - count + remcount);
|
||||
ItemRemovedQuestCheck(item->GetEntry(), count - remcount);
|
||||
item->SetCount(item->GetCount() - count + remcount);
|
||||
if (IsInWorld() && update)
|
||||
pItem->SendUpdateToPlayer(this);
|
||||
pItem->SetState(ITEM_CHANGED, this);
|
||||
item->SendUpdateToPlayer(this);
|
||||
item->SetState(ITEM_CHANGED, this);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -12724,14 +12724,14 @@ void Player::DestroyItemCount(uint32 item, uint32 count, bool update, bool unequ
|
||||
|
||||
for (uint8 i = KEYRING_SLOT_START; i < CURRENCYTOKEN_SLOT_END; ++i)
|
||||
{
|
||||
if (Item* pItem = GetItemByPos(INVENTORY_SLOT_BAG_0, i))
|
||||
if (Item* item = GetItemByPos(INVENTORY_SLOT_BAG_0, i))
|
||||
{
|
||||
if (pItem->GetEntry() == item && !pItem->IsInTrade())
|
||||
if (item->GetEntry() == itemEntry && !item->IsInTrade())
|
||||
{
|
||||
if (pItem->GetCount() + remcount <= count)
|
||||
if (item->GetCount() + remcount <= count)
|
||||
{
|
||||
// all keys can be unequipped
|
||||
remcount += pItem->GetCount();
|
||||
remcount += item->GetCount();
|
||||
DestroyItem(INVENTORY_SLOT_BAG_0, i, update);
|
||||
|
||||
if (remcount >= count)
|
||||
@@ -12739,11 +12739,11 @@ void Player::DestroyItemCount(uint32 item, uint32 count, bool update, bool unequ
|
||||
}
|
||||
else
|
||||
{
|
||||
ItemRemovedQuestCheck(pItem->GetEntry(), count - remcount);
|
||||
pItem->SetCount(pItem->GetCount() - count + remcount);
|
||||
ItemRemovedQuestCheck(item->GetEntry(), count - remcount);
|
||||
item->SetCount(item->GetCount() - count + remcount);
|
||||
if (IsInWorld() && update)
|
||||
pItem->SendUpdateToPlayer(this);
|
||||
pItem->SetState(ITEM_CHANGED, this);
|
||||
item->SendUpdateToPlayer(this);
|
||||
item->SetState(ITEM_CHANGED, this);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -12753,18 +12753,18 @@ void Player::DestroyItemCount(uint32 item, uint32 count, bool update, bool unequ
|
||||
// in inventory bags
|
||||
for (uint8 i = INVENTORY_SLOT_BAG_START; i < INVENTORY_SLOT_BAG_END; i++)
|
||||
{
|
||||
if (Bag* pBag = GetBagByPos(i))
|
||||
if (Bag* bag = GetBagByPos(i))
|
||||
{
|
||||
for (uint32 j = 0; j < pBag->GetBagSize(); j++)
|
||||
for (uint32 j = 0; j < bag->GetBagSize(); j++)
|
||||
{
|
||||
if (Item* pItem = pBag->GetItemByPos(j))
|
||||
if (Item* item = bag->GetItemByPos(j))
|
||||
{
|
||||
if (pItem->GetEntry() == item && !pItem->IsInTrade())
|
||||
if (item->GetEntry() == itemEntry && !item->IsInTrade())
|
||||
{
|
||||
// all items in bags can be unequipped
|
||||
if (pItem->GetCount() + remcount <= count)
|
||||
if (item->GetCount() + remcount <= count)
|
||||
{
|
||||
remcount += pItem->GetCount();
|
||||
remcount += item->GetCount();
|
||||
DestroyItem(i, j, update);
|
||||
|
||||
if (remcount >= count)
|
||||
@@ -12772,11 +12772,11 @@ void Player::DestroyItemCount(uint32 item, uint32 count, bool update, bool unequ
|
||||
}
|
||||
else
|
||||
{
|
||||
ItemRemovedQuestCheck(pItem->GetEntry(), count - remcount);
|
||||
pItem->SetCount(pItem->GetCount() - count + remcount);
|
||||
ItemRemovedQuestCheck(item->GetEntry(), count - remcount);
|
||||
item->SetCount(item->GetCount() - count + remcount);
|
||||
if (IsInWorld() && update)
|
||||
pItem->SendUpdateToPlayer(this);
|
||||
pItem->SetState(ITEM_CHANGED, this);
|
||||
item->SendUpdateToPlayer(this);
|
||||
item->SetState(ITEM_CHANGED, this);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -12788,15 +12788,15 @@ void Player::DestroyItemCount(uint32 item, uint32 count, bool update, bool unequ
|
||||
// in equipment and bag list
|
||||
for (uint8 i = EQUIPMENT_SLOT_START; i < INVENTORY_SLOT_BAG_END; i++)
|
||||
{
|
||||
if (Item* pItem = GetItemByPos(INVENTORY_SLOT_BAG_0, i))
|
||||
if (Item* item = GetItemByPos(INVENTORY_SLOT_BAG_0, i))
|
||||
{
|
||||
if (pItem && pItem->GetEntry() == item && !pItem->IsInTrade())
|
||||
if (item && item->GetEntry() == itemEntry && !item->IsInTrade())
|
||||
{
|
||||
if (pItem->GetCount() + remcount <= count)
|
||||
if (item->GetCount() + remcount <= count)
|
||||
{
|
||||
if (!unequip_check || CanUnequipItem(INVENTORY_SLOT_BAG_0 << 8 | i, false) == EQUIP_ERR_OK)
|
||||
{
|
||||
remcount += pItem->GetCount();
|
||||
remcount += item->GetCount();
|
||||
DestroyItem(INVENTORY_SLOT_BAG_0, i, update);
|
||||
|
||||
if (remcount >= count)
|
||||
@@ -12805,16 +12805,78 @@ void Player::DestroyItemCount(uint32 item, uint32 count, bool update, bool unequ
|
||||
}
|
||||
else
|
||||
{
|
||||
ItemRemovedQuestCheck(pItem->GetEntry(), count - remcount);
|
||||
pItem->SetCount(pItem->GetCount() - count + remcount);
|
||||
ItemRemovedQuestCheck(item->GetEntry(), count - remcount);
|
||||
item->SetCount(item->GetCount() - count + remcount);
|
||||
if (IsInWorld() && update)
|
||||
pItem->SendUpdateToPlayer(this);
|
||||
pItem->SetState(ITEM_CHANGED, this);
|
||||
item->SendUpdateToPlayer(this);
|
||||
item->SetState(ITEM_CHANGED, this);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// in bank
|
||||
for (uint8 i = BANK_SLOT_ITEM_START; i < BANK_SLOT_ITEM_END; i++)
|
||||
{
|
||||
if (Item* item = GetItemByPos(INVENTORY_SLOT_BAG_0, i))
|
||||
{
|
||||
if (item->GetEntry() == itemEntry && !item->IsInTrade())
|
||||
{
|
||||
if (item->GetCount() + remcount <= count)
|
||||
{
|
||||
remcount += item->GetCount();
|
||||
DestroyItem(INVENTORY_SLOT_BAG_0, i, update);
|
||||
if (remcount >= count)
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
ItemRemovedQuestCheck(item->GetEntry(), count - remcount);
|
||||
item->SetCount(item->GetCount() - count + remcount);
|
||||
if (IsInWorld() && update)
|
||||
item->SendUpdateToPlayer(this);
|
||||
item->SetState(ITEM_CHANGED, this);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// in bank bags
|
||||
for (uint8 i = BANK_SLOT_BAG_START; i < BANK_SLOT_BAG_END; i++)
|
||||
{
|
||||
if (Bag* bag = GetBagByPos(i))
|
||||
{
|
||||
for (uint32 j = 0; j < bag->GetBagSize(); j++)
|
||||
{
|
||||
if (Item* item = bag->GetItemByPos(j))
|
||||
{
|
||||
if (item->GetEntry() == itemEntry && !item->IsInTrade())
|
||||
{
|
||||
// all items in bags can be unequipped
|
||||
if (item->GetCount() + remcount <= count)
|
||||
{
|
||||
remcount += item->GetCount();
|
||||
DestroyItem(i, j, update);
|
||||
|
||||
if (remcount >= count)
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
ItemRemovedQuestCheck(item->GetEntry(), count - remcount);
|
||||
item->SetCount(item->GetCount() - count + remcount);
|
||||
if (IsInWorld() && update)
|
||||
item->SendUpdateToPlayer(this);
|
||||
item->SetState(ITEM_CHANGED, this);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Player::DestroyZoneLimitedItem(bool update, uint32 new_zone)
|
||||
|
||||
Reference in new issue
Block a user