refactor(Core/Packets): Bank packets (#9627)

This commit is contained in:
IntelligentQuantum
2021-12-30 22:30:24 +03:30
committed by GitHub
parent b2dd9eec5a
commit 53a6fb7513
7 changed files with 342 additions and 189 deletions

View File

@@ -1144,143 +1144,6 @@ void WorldSession::HandleAutoStoreBagItemOpcode(WorldPacket& recvData)
_player->UpdateTitansGrip();
}
void WorldSession::HandleBuyBankSlotOpcode(WorldPacket& recvPacket)
{
LOG_DEBUG("network", "WORLD: CMSG_BUY_BANK_SLOT");
ObjectGuid guid;
recvPacket >> guid;
if (!CanUseBank(guid))
{
//TC_LOG_DEBUG("network", "WORLD: HandleBuyBankSlotOpcode - Unit (%s) not found or you can't interact with him.", guid.ToString().c_str());
return;
}
uint32 slot = _player->GetBankBagSlotCount();
// next slot
++slot;
LOG_DEBUG("network.opcode", "PLAYER: Buy bank bag slot, slot number = %u", slot);
BankBagSlotPricesEntry const* slotEntry = sBankBagSlotPricesStore.LookupEntry(slot);
WorldPacket data(SMSG_BUY_BANK_SLOT_RESULT, 4);
if (!slotEntry)
{
data << uint32(ERR_BANKSLOT_FAILED_TOO_MANY);
SendPacket(&data);
return;
}
uint32 price = slotEntry->price;
if (!_player->HasEnoughMoney(price))
{
data << uint32(ERR_BANKSLOT_INSUFFICIENT_FUNDS);
SendPacket(&data);
return;
}
_player->SetBankBagSlotCount(slot);
_player->ModifyMoney(-int32(price));
data << uint32(ERR_BANKSLOT_OK);
SendPacket(&data);
_player->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_BUY_BANK_SLOT);
}
void WorldSession::HandleAutoBankItemOpcode(WorldPacket& recvPacket)
{
LOG_DEBUG("network", "WORLD: CMSG_AUTOBANK_ITEM");
uint8 srcbag, srcslot;
recvPacket >> srcbag >> srcslot;
LOG_DEBUG("network", "STORAGE: receive srcbag = %u, srcslot = %u", srcbag, srcslot);
if (!CanUseBank())
{
//TC_LOG_DEBUG("network", "WORLD: HandleAutoBankItemOpcode - Unit (%s) not found or you can't interact with him.", m_currentBankerGUID.ToString().c_str());
return;
}
Item* pItem = _player->GetItemByPos(srcbag, srcslot);
if (!pItem)
return;
ItemPosCountVec dest;
InventoryResult msg = _player->CanBankItem(NULL_BAG, NULL_SLOT, dest, pItem, false);
if (msg != EQUIP_ERR_OK)
{
_player->SendEquipError(msg, pItem, nullptr);
return;
}
if (dest.size() == 1 && dest[0].pos == pItem->GetPos())
{
_player->SendEquipError(EQUIP_ERR_NONE, pItem, nullptr);
return;
}
_player->RemoveItem(srcbag, srcslot, true);
_player->ItemRemovedQuestCheck(pItem->GetEntry(), pItem->GetCount());
_player->BankItem(dest, pItem, true);
_player->UpdateTitansGrip();
}
void WorldSession::HandleAutoStoreBankItemOpcode(WorldPacket& recvPacket)
{
LOG_DEBUG("network", "WORLD: CMSG_AUTOSTORE_BANK_ITEM");
uint8 srcbag, srcslot;
recvPacket >> srcbag >> srcslot;
LOG_DEBUG("network", "STORAGE: receive srcbag = %u, srcslot = %u", srcbag, srcslot);
if (!CanUseBank())
{
//TC_LOG_DEBUG("network", "WORLD: HandleAutoStoreBankItemOpcode - Unit (%s) not found or you can't interact with him.", m_currentBankerGUID.ToString().c_str());
return;
}
Item* pItem = _player->GetItemByPos(srcbag, srcslot);
if (!pItem)
return;
if (_player->IsBankPos(srcbag, srcslot)) // moving from bank to inventory
{
ItemPosCountVec dest;
InventoryResult msg = _player->CanStoreItem(NULL_BAG, NULL_SLOT, dest, pItem, false);
if (msg != EQUIP_ERR_OK)
{
_player->SendEquipError(msg, pItem, nullptr);
return;
}
uint32 count = pItem->GetCount();
_player->RemoveItem(srcbag, srcslot, true);
if (Item const* storedItem = _player->StoreItem(dest, pItem, true))
_player->ItemAddedQuestCheck(storedItem->GetEntry(), count);
}
else // moving from inventory to bank
{
ItemPosCountVec dest;
InventoryResult msg = _player->CanBankItem(NULL_BAG, NULL_SLOT, dest, pItem, false);
if (msg != EQUIP_ERR_OK)
{
_player->SendEquipError(msg, pItem, nullptr);
return;
}
_player->RemoveItem(srcbag, srcslot, true);
_player->ItemRemovedQuestCheck(pItem->GetEntry(), pItem->GetCount());
_player->BankItem(dest, pItem, true);
_player->UpdateTitansGrip();
}
}
void WorldSession::HandleSetAmmoOpcode(WorldPacket& recvData)
{
if (!_player->IsAlive())
@@ -1767,24 +1630,6 @@ void WorldSession::HandleItemTextQuery(WorldPacket& recvData )
SendPacket(&data);
}
bool WorldSession::CanUseBank(ObjectGuid bankerGUID) const
{
// bankerGUID parameter is optional, set to 0 by default.
if (!bankerGUID)
bankerGUID = m_currentBankerGUID;
bool isUsingBankCommand = (bankerGUID == GetPlayer()->GetGUID() && bankerGUID == m_currentBankerGUID);
if (!isUsingBankCommand)
{
Creature* creature = GetPlayer()->GetNPCIfCanInteractWith(bankerGUID, UNIT_NPC_FLAG_BANKER);
if (!creature)
return false;
}
return true;
}
bool WorldSession::recoveryItem(Item* pItem)
{
if (sWorld->getBoolConfig(CONFIG_ITEMDELETE_METHOD)