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

@@ -0,0 +1,197 @@
/*
* This file is part of the AzerothCore Project. See AUTHORS file for Copyright information
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by the
* Free Software Foundation; either version 3 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "BankPackets.h"
#include "Item.h"
#include "DBCStores.h"
#include "Log.h"
#include "Opcodes.h"
#include "Player.h"
#include "WorldPacket.h"
#include "WorldSession.h"
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;
}
void WorldSession::HandleBankerActivateOpcode(WorldPacket& recvData)
{
ObjectGuid guid;
LOG_DEBUG("network", "WORLD: Received CMSG_BANKER_ACTIVATE");
recvData >> guid;
Creature* unit = GetPlayer()->GetNPCIfCanInteractWith(guid, UNIT_NPC_FLAG_BANKER);
if (!unit)
{
LOG_DEBUG("network", "WORLD: HandleBankerActivateOpcode - Unit (%s) not found or you can not interact with him.", guid.ToString().c_str());
return;
}
// remove fake death
if (GetPlayer()->HasUnitState(UNIT_STATE_DIED))
GetPlayer()->RemoveAurasByType(SPELL_AURA_FEIGN_DEATH);
SendShowBank(guid);
}
void WorldSession::HandleAutoBankItemOpcode(WorldPackets::Bank::AutoBankItem& packet)
{
LOG_DEBUG("network", "STORAGE: receive bag = %u, slot = %u", packet.Bag, packet.Slot);
if (!CanUseBank())
{
LOG_DEBUG("network", "WORLD: HandleAutoBankItemOpcode - Unit (%s) not found or you can't interact with him.", m_currentBankerGUID.ToString().c_str());
return;
}
Item* item = _player->GetItemByPos(packet.Bag, packet.Slot);
if (!item)
return;
ItemPosCountVec dest;
InventoryResult msg = _player->CanBankItem(NULL_BAG, NULL_SLOT, dest, item, false);
if (msg != EQUIP_ERR_OK)
{
_player->SendEquipError(msg, item, nullptr);
return;
}
if (dest.size() == 1 && dest[0].pos == item->GetPos())
{
_player->SendEquipError(EQUIP_ERR_NONE, item, nullptr);
return;
}
_player->RemoveItem(packet.Bag, packet.Slot, true);
_player->ItemRemovedQuestCheck(item->GetEntry(), item->GetCount());
_player->BankItem(dest, item, true);
_player->UpdateTitansGrip();
}
void WorldSession::HandleAutoStoreBankItemOpcode(WorldPackets::Bank::AutoStoreBankItem& packet)
{
LOG_DEBUG("network", "STORAGE: receive bag = %u, slot = %u", packet.Bag, packet.Slot);
if (!CanUseBank())
{
LOG_DEBUG("network", "WORLD: HandleAutoStoreBankItemOpcode - Unit (%s) not found or you can't interact with him.", m_currentBankerGUID.ToString().c_str());
return;
}
Item* item = _player->GetItemByPos(packet.Bag, packet.Slot);
if (!item)
return;
if (_player->IsBankPos(packet.Bag, packet.Slot)) // moving from bank to inventory
{
ItemPosCountVec dest;
InventoryResult msg = _player->CanStoreItem(NULL_BAG, NULL_SLOT, dest, item, false);
if (msg != EQUIP_ERR_OK)
{
_player->SendEquipError(msg, item, nullptr);
return;
}
_player->RemoveItem(packet.Bag, packet.Slot, true);
if (Item const* storedItem = _player->StoreItem(dest, item, true))
_player->ItemAddedQuestCheck(storedItem->GetEntry(), storedItem->GetCount());
}
else // moving from inventory to bank
{
ItemPosCountVec dest;
InventoryResult msg = _player->CanBankItem(NULL_BAG, NULL_SLOT, dest, item, false);
if (msg != EQUIP_ERR_OK)
{
_player->SendEquipError(msg, item, nullptr);
return;
}
_player->RemoveItem(packet.Bag, packet.Slot, true);
_player->ItemRemovedQuestCheck(item->GetEntry(), item->GetCount());
_player->BankItem(dest, item, true);
_player->UpdateTitansGrip();
}
}
void WorldSession::HandleBuyBankSlotOpcode(WorldPackets::Bank::BuyBankSlot& buyBankSlot)
{
WorldPackets::Bank::BuyBankSlotResult packet;
if (!CanUseBank(buyBankSlot.Banker))
{
packet.Result = ERR_BANKSLOT_NOTBANKER;
SendPacket(packet.Write());
LOG_DEBUG("network", "WORLD: HandleBuyBankSlotOpcode - %s not found or you can't interact with him.", buyBankSlot.Banker.ToString().c_str());
return;
}
uint32 slot = _player->GetBankBagSlotCount();
// next slot
++slot;
LOG_INFO("network", "PLAYER: Buy bank bag slot, slot number = %u", slot);
BankBagSlotPricesEntry const* slotEntry = sBankBagSlotPricesStore.LookupEntry(slot);
if (!slotEntry)
{
packet.Result = ERR_BANKSLOT_FAILED_TOO_MANY;
SendPacket(packet.Write());
return;
}
uint32 price = slotEntry->price;
if (!_player->HasEnoughMoney(price))
{
packet.Result = ERR_BANKSLOT_INSUFFICIENT_FUNDS;
SendPacket(packet.Write());
return;
}
_player->SetBankBagSlotCount(slot);
_player->ModifyMoney(-int32(price));
packet.Result = ERR_BANKSLOT_OK;
SendPacket(packet.Write());
_player->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_BUY_BANK_SLOT);
}
void WorldSession::SendShowBank(ObjectGuid guid)
{
m_currentBankerGUID = guid;
WorldPackets::Bank::ShowBank packet;
packet.Banker = guid;
SendPacket(packet.Write());
}

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)

View File

@@ -69,36 +69,6 @@ void WorldSession::SendTabardVendorActivate(ObjectGuid guid)
SendPacket(&data);
}
void WorldSession::HandleBankerActivateOpcode(WorldPacket& recvData)
{
ObjectGuid guid;
LOG_DEBUG("network", "WORLD: Received CMSG_BANKER_ACTIVATE");
recvData >> guid;
Creature* unit = GetPlayer()->GetNPCIfCanInteractWith(guid, UNIT_NPC_FLAG_BANKER);
if (!unit)
{
LOG_DEBUG("network", "WORLD: HandleBankerActivateOpcode - Unit (%s) not found or you can not interact with him.", guid.ToString().c_str());
return;
}
// remove fake death
if (GetPlayer()->HasUnitState(UNIT_STATE_DIED))
GetPlayer()->RemoveAurasByType(SPELL_AURA_FEIGN_DEATH);
SendShowBank(guid);
}
void WorldSession::SendShowBank(ObjectGuid guid)
{
WorldPacket data(SMSG_SHOW_BANK, 8);
data << guid;
m_currentBankerGUID = guid;
SendPacket(&data);
}
void WorldSession::SendShowMailBox(ObjectGuid guid)
{
WorldPacket data(SMSG_SHOW_MAILBOX, 8);

View File

@@ -18,6 +18,7 @@
#ifndef AllPackets_h__
#define AllPackets_h__
#include "BankPackets.h"
#include "GuildPackets.h"
#endif // AllPackets_h__

View File

@@ -0,0 +1,49 @@
/*
* This file is part of the AzerothCore Project. See AUTHORS file for Copyright information
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by the
* Free Software Foundation; either version 3 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "BankPackets.h"
void WorldPackets::Bank::AutoBankItem::Read()
{
_worldPacket >> Bag;
_worldPacket >> Slot;
}
void WorldPackets::Bank::AutoStoreBankItem::Read()
{
_worldPacket >> Bag;
_worldPacket >> Slot;
}
void WorldPackets::Bank::BuyBankSlot::Read()
{
_worldPacket >> Banker;
}
WorldPacket const* WorldPackets::Bank::BuyBankSlotResult::Write()
{
_worldPacket << uint32(Result);
return &_worldPacket;
}
WorldPacket const* WorldPackets::Bank::ShowBank::Write()
{
_worldPacket << Banker;
return &_worldPacket;
}

View File

@@ -0,0 +1,81 @@
/*
* This file is part of the AzerothCore Project. See AUTHORS file for Copyright information
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by the
* Free Software Foundation; either version 3 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef BankPackets_h__
#define BankPackets_h__
#include "Packet.h"
#include "ObjectGuid.h"
namespace WorldPackets
{
namespace Bank
{
class AutoBankItem final : public ClientPacket
{
public:
AutoBankItem(WorldPacket&& packet) : ClientPacket(CMSG_AUTOBANK_ITEM, std::move(packet)) { }
void Read() override;
uint8 Bag = 0;
uint8 Slot = 0;
};
class AutoStoreBankItem final : public ClientPacket
{
public:
AutoStoreBankItem(WorldPacket&& packet) : ClientPacket(CMSG_AUTOSTORE_BANK_ITEM, std::move(packet)) { }
void Read() override;
uint8 Bag = 0;
uint8 Slot = 0;
};
class BuyBankSlot final : public ClientPacket
{
public:
BuyBankSlot(WorldPacket&& packet) : ClientPacket(CMSG_BUY_BANK_SLOT, std::move(packet)) { }
void Read() override;
ObjectGuid Banker;
};
class BuyBankSlotResult final : public ServerPacket
{
public:
BuyBankSlotResult() : ServerPacket(SMSG_BUY_BANK_SLOT_RESULT, 4) { }
WorldPacket const* Write() override;
uint32 Result = 0;
};
class ShowBank final : public ServerPacket
{
public:
ShowBank() : ServerPacket(SMSG_SHOW_BANK, 8) { }
WorldPacket const* Write() override;
ObjectGuid Banker;
};
}
}
#endif // BankPackets_h__

View File

@@ -71,6 +71,14 @@ namespace lfg
namespace WorldPackets
{
namespace Bank
{
class AutoBankItem;
class AutoStoreBankItem;
class BuyBankSlot;
}
namespace Guild
{
class QueryGuildInfo;
@@ -669,8 +677,6 @@ public: // opcodes handlers
void SendActivateTaxiReply(ActivateTaxiReply reply);
void HandleTabardVendorActivateOpcode(WorldPacket& recvPacket);
void HandleBankerActivateOpcode(WorldPacket& recvPacket);
void HandleBuyBankSlotOpcode(WorldPacket& recvPacket);
void HandleTrainerListOpcode(WorldPacket& recvPacket);
void HandleTrainerBuySpellOpcode(WorldPacket& recvPacket);
void HandlePetitionShowListOpcode(WorldPacket& recvPacket);
@@ -718,6 +724,12 @@ public: // opcodes handlers
void HandleAuctionPlaceBid(WorldPacket& recvData);
void HandleAuctionListPendingSales(WorldPacket& recvData);
// Bank
void HandleBankerActivateOpcode(WorldPacket& recvData);
void HandleAutoBankItemOpcode(WorldPackets::Bank::AutoBankItem& packet);
void HandleAutoStoreBankItemOpcode(WorldPackets::Bank::AutoStoreBankItem& packet);
void HandleBuyBankSlotOpcode(WorldPackets::Bank::BuyBankSlot& buyBankSlot);
void HandleGetMailList(WorldPacket& recvData);
void HandleSendMail(WorldPacket& recvData);
void HandleMailTakeMoney(WorldPacket& recvData);
@@ -744,8 +756,6 @@ public: // opcodes handlers
void HandleAutoEquipItemSlotOpcode(WorldPacket& recvPacket);
void HandleSwapItem(WorldPacket& recvPacket);
void HandleBuybackItem(WorldPacket& recvPacket);
void HandleAutoBankItemOpcode(WorldPacket& recvPacket);
void HandleAutoStoreBankItemOpcode(WorldPacket& recvPacket);
void HandleWrapItemOpcode(WorldPacket& recvPacket);
void HandleAttackSwingOpcode(WorldPacket& recvPacket);