mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-16 07:30:42 +01:00
1291 lines
49 KiB
C++
1291 lines
49 KiB
C++
/*
|
|
* Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
|
|
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
* under the terms of the GNU General Public License as published by the
|
|
* Free Software Foundation; either version 2 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 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 "Common.h"
|
|
#include "WorldPacket.h"
|
|
#include "WorldSession.h"
|
|
#include "Opcodes.h"
|
|
#include "Log.h"
|
|
#include "ObjectMgr.h"
|
|
#include "Player.h"
|
|
#include "Item.h"
|
|
#include "DB2Stores.h"
|
|
#include "NPCPackets.h"
|
|
#include "ItemPackets.h"
|
|
#include "BattlePetMgr.h"
|
|
|
|
void WorldSession::HandleSplitItemOpcode(WorldPackets::Item::SplitItem& splitItem)
|
|
{
|
|
if (!splitItem.Inv.Items.empty())
|
|
{
|
|
TC_LOG_ERROR("network", "HandleSplitItemOpcode - Invalid ItemCount (" SZFMTD ")", splitItem.Inv.Items.size());
|
|
return;
|
|
}
|
|
|
|
TC_LOG_DEBUG("network", "HandleSplitItemOpcode: receive FromPackSlot: %u, FromSlot: %u, ToPackSlot: %u, ToSlot: %u, Quantity: %u",
|
|
splitItem.FromPackSlot, splitItem.FromSlot, splitItem.ToPackSlot, splitItem.ToSlot, splitItem.Quantity);
|
|
|
|
uint16 src = ((splitItem.FromPackSlot << 8) | splitItem.FromSlot);
|
|
uint16 dst = ((splitItem.ToPackSlot << 8) | splitItem.ToSlot);
|
|
|
|
if (src == dst)
|
|
return;
|
|
|
|
// check count - if zero it's fake packet
|
|
if (!splitItem.Quantity)
|
|
return;
|
|
|
|
if (!_player->IsValidPos(splitItem.FromPackSlot, splitItem.FromSlot, true))
|
|
{
|
|
_player->SendEquipError(EQUIP_ERR_ITEM_NOT_FOUND);
|
|
return;
|
|
}
|
|
|
|
if (!_player->IsValidPos(splitItem.ToPackSlot, splitItem.ToSlot, false)) // can be autostore pos
|
|
{
|
|
_player->SendEquipError(EQUIP_ERR_WRONG_SLOT);
|
|
return;
|
|
}
|
|
|
|
_player->SplitItem(src, dst, splitItem.Quantity);
|
|
}
|
|
|
|
void WorldSession::HandleSwapInvItemOpcode(WorldPackets::Item::SwapInvItem& swapInvItem)
|
|
{
|
|
if (swapInvItem.Inv.Items.size() != 2)
|
|
{
|
|
TC_LOG_ERROR("network", "HandleSwapInvItemOpcode - Invalid itemCount (" SZFMTD ")", swapInvItem.Inv.Items.size());
|
|
return;
|
|
}
|
|
|
|
TC_LOG_DEBUG("network", "HandleSwapInvItemOpcode: receive Slot1: %u, Slot2: %u",
|
|
swapInvItem.Slot1, swapInvItem.Slot2);
|
|
|
|
// prevent attempt swap same item to current position generated by client at special checting sequence
|
|
if (swapInvItem.Slot1 == swapInvItem.Slot2)
|
|
return;
|
|
|
|
if (!_player->IsValidPos(INVENTORY_SLOT_BAG_0, swapInvItem.Slot1, true))
|
|
{
|
|
_player->SendEquipError(EQUIP_ERR_ITEM_NOT_FOUND);
|
|
return;
|
|
}
|
|
|
|
if (!_player->IsValidPos(INVENTORY_SLOT_BAG_0, swapInvItem.Slot2, true))
|
|
{
|
|
_player->SendEquipError(EQUIP_ERR_WRONG_SLOT);
|
|
return;
|
|
}
|
|
|
|
if (_player->IsBankPos(INVENTORY_SLOT_BAG_0, swapInvItem.Slot1) && !CanUseBank())
|
|
{
|
|
TC_LOG_DEBUG("network", "HandleSwapInvItemOpcode - Unit (%s) not found or you can't interact with him.", m_currentBankerGUID.ToString().c_str());
|
|
return;
|
|
}
|
|
|
|
if (_player->IsBankPos(INVENTORY_SLOT_BAG_0, swapInvItem.Slot2) && !CanUseBank())
|
|
{
|
|
TC_LOG_DEBUG("network", "HandleSwapInvItemOpcode - Unit (%s) not found or you can't interact with him.", m_currentBankerGUID.ToString().c_str());
|
|
return;
|
|
}
|
|
|
|
uint16 src = ((INVENTORY_SLOT_BAG_0 << 8) | swapInvItem.Slot1);
|
|
uint16 dst = ((INVENTORY_SLOT_BAG_0 << 8) | swapInvItem.Slot2);
|
|
|
|
_player->SwapItem(src, dst);
|
|
}
|
|
|
|
void WorldSession::HandleAutoEquipItemSlotOpcode(WorldPackets::Item::AutoEquipItemSlot& autoEquipItemSlot)
|
|
{
|
|
// cheating attempt, client should never send opcode in that case
|
|
if (autoEquipItemSlot.Inv.Items.size() != 1 || !Player::IsEquipmentPos(INVENTORY_SLOT_BAG_0, autoEquipItemSlot.ItemDstSlot))
|
|
return;
|
|
|
|
Item* item = _player->GetItemByGuid(autoEquipItemSlot.Item);
|
|
uint16 dstPos = autoEquipItemSlot.ItemDstSlot | (INVENTORY_SLOT_BAG_0 << 8);
|
|
uint16 srcPos = autoEquipItemSlot.Inv.Items[0].Slot | (uint32(autoEquipItemSlot.Inv.Items[0].ContainerSlot) << 8);
|
|
|
|
if (!item || item->GetPos() != srcPos || srcPos == dstPos)
|
|
return;
|
|
|
|
_player->SwapItem(srcPos, dstPos);
|
|
}
|
|
|
|
void WorldSession::HandleSwapItem(WorldPackets::Item::SwapItem& swapItem)
|
|
{
|
|
if (swapItem.Inv.Items.size() != 2)
|
|
{
|
|
TC_LOG_ERROR("network", "HandleSwapItem - Invalid itemCount (" SZFMTD ")", swapItem.Inv.Items.size());
|
|
return;
|
|
}
|
|
|
|
TC_LOG_DEBUG("network", "HandleSwapItem: receive ContainerSlotA: %u, SlotA: %u, ContainerSlotB: %u, SlotB: %u",
|
|
swapItem.ContainerSlotA, swapItem.SlotA, swapItem.ContainerSlotB, swapItem.SlotB);
|
|
|
|
uint16 src = ((swapItem.ContainerSlotA << 8) | swapItem.SlotA);
|
|
uint16 dst = ((swapItem.ContainerSlotB << 8) | swapItem.SlotB);
|
|
|
|
// prevent attempt swap same item to current position generated by client at special checting sequence
|
|
if (src == dst)
|
|
return;
|
|
|
|
if (!_player->IsValidPos(swapItem.ContainerSlotA, swapItem.SlotA, true))
|
|
{
|
|
_player->SendEquipError(EQUIP_ERR_ITEM_NOT_FOUND);
|
|
return;
|
|
}
|
|
|
|
if (!_player->IsValidPos(swapItem.ContainerSlotB, swapItem.SlotB, true))
|
|
{
|
|
_player->SendEquipError(EQUIP_ERR_WRONG_SLOT);
|
|
return;
|
|
}
|
|
|
|
if (_player->IsBankPos(swapItem.ContainerSlotA, swapItem.SlotA) && !CanUseBank())
|
|
{
|
|
TC_LOG_DEBUG("network", "HandleSwapItem - Unit (%s) not found or you can't interact with him.", m_currentBankerGUID.ToString().c_str());
|
|
return;
|
|
}
|
|
|
|
if (_player->IsBankPos(swapItem.ContainerSlotB, swapItem.SlotB) && !CanUseBank())
|
|
{
|
|
TC_LOG_DEBUG("network", "HandleSwapItem - Unit (%s) not found or you can't interact with him.", m_currentBankerGUID.ToString().c_str());
|
|
return;
|
|
}
|
|
|
|
_player->SwapItem(src, dst);
|
|
}
|
|
|
|
void WorldSession::HandleAutoEquipItemOpcode(WorldPackets::Item::AutoEquipItem& autoEquipItem)
|
|
{
|
|
if (autoEquipItem.Inv.Items.size() != 1)
|
|
{
|
|
TC_LOG_ERROR("network", "HandleAutoEquipItemOpcode - Invalid itemCount (" SZFMTD ")", autoEquipItem.Inv.Items.size());
|
|
return;
|
|
}
|
|
|
|
TC_LOG_DEBUG("network", "HandleAutoEquipItemOpcode: receive PackSlot: %u, Slot: %u",
|
|
autoEquipItem.PackSlot, autoEquipItem.Slot);
|
|
|
|
Item* srcItem = _player->GetItemByPos(autoEquipItem.PackSlot, autoEquipItem.Slot);
|
|
if (!srcItem)
|
|
return; // only at cheat
|
|
|
|
uint16 dest;
|
|
InventoryResult msg = _player->CanEquipItem(NULL_SLOT, dest, srcItem, !srcItem->IsBag());
|
|
if (msg != EQUIP_ERR_OK)
|
|
{
|
|
_player->SendEquipError(msg, srcItem);
|
|
return;
|
|
}
|
|
|
|
uint16 src = srcItem->GetPos();
|
|
if (dest == src) // prevent equip in same slot, only at cheat
|
|
return;
|
|
|
|
Item* dstItem = _player->GetItemByPos(dest);
|
|
if (!dstItem) // empty slot, simple case
|
|
{
|
|
_player->RemoveItem(autoEquipItem.PackSlot, autoEquipItem.Slot, true);
|
|
_player->EquipItem(dest, srcItem, true);
|
|
_player->AutoUnequipOffhandIfNeed();
|
|
}
|
|
else // have currently equipped item, not simple case
|
|
{
|
|
uint8 dstbag = dstItem->GetBagSlot();
|
|
uint8 dstslot = dstItem->GetSlot();
|
|
|
|
msg = _player->CanUnequipItem(dest, !srcItem->IsBag());
|
|
if (msg != EQUIP_ERR_OK)
|
|
{
|
|
_player->SendEquipError(msg, dstItem);
|
|
return;
|
|
}
|
|
|
|
// check dest->src move possibility
|
|
ItemPosCountVec sSrc;
|
|
uint16 eSrc = 0;
|
|
if (_player->IsInventoryPos(src))
|
|
{
|
|
msg = _player->CanStoreItem(autoEquipItem.PackSlot, autoEquipItem.Slot, sSrc, dstItem, true);
|
|
if (msg != EQUIP_ERR_OK)
|
|
msg = _player->CanStoreItem(autoEquipItem.PackSlot, NULL_SLOT, sSrc, dstItem, true);
|
|
if (msg != EQUIP_ERR_OK)
|
|
msg = _player->CanStoreItem(NULL_BAG, NULL_SLOT, sSrc, dstItem, true);
|
|
}
|
|
else if (_player->IsBankPos(src))
|
|
{
|
|
msg = _player->CanBankItem(autoEquipItem.PackSlot, autoEquipItem.Slot, sSrc, dstItem, true);
|
|
if (msg != EQUIP_ERR_OK)
|
|
msg = _player->CanBankItem(autoEquipItem.PackSlot, NULL_SLOT, sSrc, dstItem, true);
|
|
if (msg != EQUIP_ERR_OK)
|
|
msg = _player->CanBankItem(NULL_BAG, NULL_SLOT, sSrc, dstItem, true);
|
|
}
|
|
else if (_player->IsEquipmentPos(src))
|
|
{
|
|
msg = _player->CanEquipItem(autoEquipItem.Slot, eSrc, dstItem, true);
|
|
if (msg == EQUIP_ERR_OK)
|
|
msg = _player->CanUnequipItem(eSrc, true);
|
|
}
|
|
|
|
if (msg != EQUIP_ERR_OK)
|
|
{
|
|
_player->SendEquipError(msg, dstItem, srcItem);
|
|
return;
|
|
}
|
|
|
|
// now do moves, remove...
|
|
_player->RemoveItem(dstbag, dstslot, false);
|
|
_player->RemoveItem(autoEquipItem.PackSlot, autoEquipItem.Slot, false);
|
|
|
|
// add to dest
|
|
_player->EquipItem(dest, srcItem, true);
|
|
|
|
// add to src
|
|
if (_player->IsInventoryPos(src))
|
|
_player->StoreItem(sSrc, dstItem, true);
|
|
else if (_player->IsBankPos(src))
|
|
_player->BankItem(sSrc, dstItem, true);
|
|
else if (_player->IsEquipmentPos(src))
|
|
_player->EquipItem(eSrc, dstItem, true);
|
|
|
|
_player->AutoUnequipOffhandIfNeed();
|
|
}
|
|
}
|
|
|
|
void WorldSession::HandleDestroyItemOpcode(WorldPackets::Item::DestroyItem& destroyItem)
|
|
{
|
|
TC_LOG_DEBUG("network", "HandleDestroyItemOpcode: receive ContainerId: %u, SlotNum: %u, Count: %u",
|
|
destroyItem.ContainerId, destroyItem.SlotNum, destroyItem.Count);
|
|
|
|
uint16 pos = (destroyItem.ContainerId << 8) | destroyItem.SlotNum;
|
|
|
|
// prevent drop unequipable items (in combat, for example) and non-empty bags
|
|
if (_player->IsEquipmentPos(pos) || _player->IsBagPos(pos))
|
|
{
|
|
InventoryResult msg = _player->CanUnequipItem(pos, false);
|
|
if (msg != EQUIP_ERR_OK)
|
|
{
|
|
_player->SendEquipError(msg, _player->GetItemByPos(pos));
|
|
return;
|
|
}
|
|
}
|
|
|
|
Item* item = _player->GetItemByPos(destroyItem.ContainerId, destroyItem.SlotNum);
|
|
if (!item)
|
|
{
|
|
_player->SendEquipError(EQUIP_ERR_ITEM_NOT_FOUND);
|
|
return;
|
|
}
|
|
|
|
if (item->GetTemplate()->GetFlags() & ITEM_FLAG_INDESTRUCTIBLE)
|
|
{
|
|
_player->SendEquipError(EQUIP_ERR_DROP_BOUND_ITEM, NULL, NULL);
|
|
return;
|
|
}
|
|
|
|
if (destroyItem.Count)
|
|
{
|
|
uint32 i_count = destroyItem.Count;
|
|
_player->DestroyItemCount(item, i_count, true);
|
|
}
|
|
else
|
|
_player->DestroyItem(destroyItem.ContainerId, destroyItem.SlotNum, true);
|
|
}
|
|
|
|
void WorldSession::HandleReadItem(WorldPackets::Item::ReadItem& readItem)
|
|
{
|
|
Item* item = _player->GetItemByPos(readItem.PackSlot, readItem.Slot);
|
|
if (item && item->GetTemplate()->GetPageText())
|
|
{
|
|
InventoryResult msg = _player->CanUseItem(item);
|
|
if (msg == EQUIP_ERR_OK)
|
|
{
|
|
WorldPackets::Item::ReadItemResultOK packet;
|
|
packet.Item = item->GetGUID();
|
|
SendPacket(packet.Write());
|
|
|
|
TC_LOG_INFO("network", "STORAGE: Item page sent");
|
|
}
|
|
else
|
|
{
|
|
/// @todo: 6.x research new values
|
|
/*WorldPackets::Item::ReadItemResultFailed packet;
|
|
packet.Item = item->GetGUID();
|
|
packet.Subcode = ??;
|
|
packet.Delay = ??;
|
|
SendPacket(packet.Write());*/
|
|
|
|
TC_LOG_INFO("network", "STORAGE: Unable to read item");
|
|
_player->SendEquipError(msg, item, NULL);
|
|
}
|
|
}
|
|
else
|
|
_player->SendEquipError(EQUIP_ERR_ITEM_NOT_FOUND, NULL, NULL);
|
|
}
|
|
|
|
void WorldSession::HandleSellItemOpcode(WorldPackets::Item::SellItem& packet)
|
|
{
|
|
TC_LOG_DEBUG("network", "WORLD: Received CMSG_SELL_ITEM: Vendor %s, Item %s, Amount: %u",
|
|
packet.VendorGUID.ToString().c_str(), packet.ItemGUID.ToString().c_str(), packet.Amount);
|
|
|
|
if (packet.ItemGUID.IsEmpty())
|
|
return;
|
|
|
|
Creature* creature = GetPlayer()->GetNPCIfCanInteractWith(packet.VendorGUID, UNIT_NPC_FLAG_VENDOR);
|
|
if (!creature)
|
|
{
|
|
TC_LOG_DEBUG("network", "WORLD: HandleSellItemOpcode - %s not found or you can not interact with him.", packet.VendorGUID.ToString().c_str());
|
|
_player->SendSellError(SELL_ERR_CANT_FIND_VENDOR, nullptr, packet.ItemGUID);
|
|
return;
|
|
}
|
|
|
|
// remove fake death
|
|
if (GetPlayer()->HasUnitState(UNIT_STATE_DIED))
|
|
GetPlayer()->RemoveAurasByType(SPELL_AURA_FEIGN_DEATH);
|
|
|
|
Item* pItem = _player->GetItemByGuid(packet.ItemGUID);
|
|
if (pItem)
|
|
{
|
|
// prevent sell not owner item
|
|
if (_player->GetGUID() != pItem->GetOwnerGUID())
|
|
{
|
|
_player->SendSellError(SELL_ERR_CANT_SELL_ITEM, creature, packet.ItemGUID);
|
|
return;
|
|
}
|
|
|
|
// prevent sell non empty bag by drag-and-drop at vendor's item list
|
|
if (pItem->IsNotEmptyBag())
|
|
{
|
|
_player->SendSellError(SELL_ERR_CANT_SELL_ITEM, creature, packet.ItemGUID);
|
|
return;
|
|
}
|
|
|
|
// prevent sell currently looted item
|
|
if (_player->GetLootGUID() == pItem->GetGUID())
|
|
{
|
|
_player->SendSellError(SELL_ERR_CANT_SELL_ITEM, creature, packet.ItemGUID);
|
|
return;
|
|
}
|
|
|
|
// prevent selling item for sellprice when the item is still refundable
|
|
// this probably happens when right clicking a refundable item, the client sends both
|
|
// CMSG_SELL_ITEM and CMSG_REFUND_ITEM (unverified)
|
|
if (pItem->HasFlag(ITEM_FIELD_FLAGS, ITEM_FIELD_FLAG_REFUNDABLE))
|
|
return; // Therefore, no feedback to client
|
|
|
|
// special case at auto sell (sell all)
|
|
if (packet.Amount == 0)
|
|
packet.Amount = pItem->GetCount();
|
|
else
|
|
{
|
|
// prevent sell more items that exist in stack (possible only not from client)
|
|
if (packet.Amount > pItem->GetCount())
|
|
{
|
|
_player->SendSellError(SELL_ERR_CANT_SELL_ITEM, creature, packet.ItemGUID);
|
|
return;
|
|
}
|
|
}
|
|
|
|
ItemTemplate const* pProto = pItem->GetTemplate();
|
|
if (pProto)
|
|
{
|
|
if (pProto->GetSellPrice() > 0)
|
|
{
|
|
if (packet.Amount < pItem->GetCount()) // need split items
|
|
{
|
|
Item* pNewItem = pItem->CloneItem(packet.Amount, _player);
|
|
if (!pNewItem)
|
|
{
|
|
TC_LOG_ERROR("network", "WORLD: HandleSellItemOpcode - could not create clone of item %u; count = %u", pItem->GetEntry(), packet.Amount);
|
|
_player->SendSellError(SELL_ERR_CANT_SELL_ITEM, creature, packet.ItemGUID);
|
|
return;
|
|
}
|
|
|
|
pItem->SetCount(pItem->GetCount() - packet.Amount);
|
|
_player->ItemRemovedQuestCheck(pItem->GetEntry(), packet.Amount);
|
|
if (_player->IsInWorld())
|
|
pItem->SendUpdateToPlayer(_player);
|
|
pItem->SetState(ITEM_CHANGED, _player);
|
|
|
|
_player->AddItemToBuyBackSlot(pNewItem);
|
|
if (_player->IsInWorld())
|
|
pNewItem->SendUpdateToPlayer(_player);
|
|
}
|
|
else
|
|
{
|
|
_player->ItemRemovedQuestCheck(pItem->GetEntry(), pItem->GetCount());
|
|
_player->RemoveItem(pItem->GetBagSlot(), pItem->GetSlot(), true);
|
|
pItem->RemoveFromUpdateQueueOf(_player);
|
|
_player->AddItemToBuyBackSlot(pItem);
|
|
}
|
|
|
|
uint32 money = pProto->GetSellPrice() * packet.Amount;
|
|
_player->ModifyMoney(money);
|
|
_player->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_MONEY_FROM_VENDORS, money);
|
|
}
|
|
else
|
|
_player->SendSellError(SELL_ERR_CANT_SELL_ITEM, creature, packet.ItemGUID);
|
|
return;
|
|
}
|
|
}
|
|
_player->SendSellError(SELL_ERR_CANT_FIND_ITEM, creature, packet.ItemGUID);
|
|
return;
|
|
}
|
|
|
|
void WorldSession::HandleBuybackItem(WorldPackets::Item::BuyBackItem& packet)
|
|
{
|
|
TC_LOG_DEBUG("network", "WORLD: Received CMSG_BUYBACK_ITEM: Vendor %s, Slot: %u", packet.VendorGUID.ToString().c_str(), packet.Slot);
|
|
|
|
Creature* creature = GetPlayer()->GetNPCIfCanInteractWith(packet.VendorGUID, UNIT_NPC_FLAG_VENDOR);
|
|
if (!creature)
|
|
{
|
|
TC_LOG_DEBUG("network", "WORLD: HandleBuybackItem - Unit (%s) not found or you can not interact with him.", packet.VendorGUID.ToString().c_str());
|
|
_player->SendSellError(SELL_ERR_CANT_FIND_VENDOR, NULL, ObjectGuid::Empty);
|
|
return;
|
|
}
|
|
|
|
// remove fake death
|
|
if (GetPlayer()->HasUnitState(UNIT_STATE_DIED))
|
|
GetPlayer()->RemoveAurasByType(SPELL_AURA_FEIGN_DEATH);
|
|
|
|
Item* pItem = _player->GetItemFromBuyBackSlot(packet.Slot);
|
|
if (pItem)
|
|
{
|
|
uint32 price = _player->GetUInt32Value(PLAYER_FIELD_BUYBACK_PRICE_1 + packet.Slot - BUYBACK_SLOT_START);
|
|
if (!_player->HasEnoughMoney(uint64(price)))
|
|
{
|
|
_player->SendBuyError(BUY_ERR_NOT_ENOUGHT_MONEY, creature, pItem->GetEntry(), 0);
|
|
return;
|
|
}
|
|
|
|
ItemPosCountVec dest;
|
|
InventoryResult msg = _player->CanStoreItem(NULL_BAG, NULL_SLOT, dest, pItem, false);
|
|
if (msg == EQUIP_ERR_OK)
|
|
{
|
|
_player->ModifyMoney(-(int32)price);
|
|
_player->RemoveItemFromBuyBackSlot(packet.Slot, false);
|
|
_player->ItemAddedQuestCheck(pItem->GetEntry(), pItem->GetCount());
|
|
_player->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_RECEIVE_EPIC_ITEM, pItem->GetEntry(), pItem->GetCount());
|
|
_player->StoreItem(dest, pItem, true);
|
|
}
|
|
else
|
|
_player->SendEquipError(msg, pItem, NULL);
|
|
return;
|
|
}
|
|
else
|
|
_player->SendBuyError(BUY_ERR_CANT_FIND_ITEM, creature, 0, 0);
|
|
}
|
|
|
|
void WorldSession::HandleBuyItemOpcode(WorldPackets::Item::BuyItem& packet)
|
|
{
|
|
// client expects count starting at 1, and we send vendorslot+1 to client already
|
|
if (packet.Muid > 0)
|
|
--packet.Muid;
|
|
else
|
|
return; // cheating
|
|
|
|
switch (packet.ItemType)
|
|
{
|
|
case ITEM_VENDOR_TYPE_ITEM:
|
|
{
|
|
Item* bagItem = _player->GetItemByGuid(packet.ContainerGUID);
|
|
|
|
uint8 bag = NULL_BAG;
|
|
if (bagItem && bagItem->IsBag())
|
|
bag = bagItem->GetSlot();
|
|
else if (packet.ContainerGUID == GetPlayer()->GetGUID()) // The client sends the player guid when trying to store an item in the default backpack
|
|
bag = INVENTORY_SLOT_BAG_0;
|
|
|
|
GetPlayer()->BuyItemFromVendorSlot(packet.VendorGUID, packet.Muid, packet.Item.ItemID,
|
|
packet.Quantity, bag, packet.Slot);
|
|
break;
|
|
}
|
|
case ITEM_VENDOR_TYPE_CURRENCY:
|
|
{
|
|
GetPlayer()->BuyCurrencyFromVendorSlot(packet.VendorGUID, packet.Muid, packet.Item.ItemID, packet.Quantity);
|
|
break;
|
|
}
|
|
default:
|
|
{
|
|
TC_LOG_DEBUG("network", "WORLD: received wrong itemType (%u) in HandleBuyItemOpcode", packet.ItemType);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
void WorldSession::HandleListInventoryOpcode(WorldPackets::NPC::Hello& packet)
|
|
{
|
|
if (!GetPlayer()->IsAlive())
|
|
return;
|
|
|
|
SendListInventory(packet.Unit);
|
|
}
|
|
|
|
void WorldSession::SendListInventory(ObjectGuid vendorGuid)
|
|
{
|
|
TC_LOG_DEBUG("network", "WORLD: Sent SMSG_LIST_INVENTORY");
|
|
|
|
Creature* vendor = GetPlayer()->GetNPCIfCanInteractWith(vendorGuid, UNIT_NPC_FLAG_VENDOR);
|
|
if (!vendor)
|
|
{
|
|
TC_LOG_DEBUG("network", "WORLD: SendListInventory - %s not found or you can not interact with him.", vendorGuid.ToString().c_str());
|
|
_player->SendSellError(SELL_ERR_CANT_FIND_VENDOR, NULL, ObjectGuid::Empty);
|
|
return;
|
|
}
|
|
|
|
// remove fake death
|
|
if (GetPlayer()->HasUnitState(UNIT_STATE_DIED))
|
|
GetPlayer()->RemoveAurasByType(SPELL_AURA_FEIGN_DEATH);
|
|
|
|
// Stop the npc if moving
|
|
if (vendor->HasUnitState(UNIT_STATE_MOVING))
|
|
vendor->StopMoving();
|
|
|
|
VendorItemData const* vendorItems = vendor->GetVendorItems();
|
|
uint32 rawItemCount = vendorItems ? vendorItems->GetItemCount() : 0;
|
|
|
|
WorldPackets::NPC::VendorInventory packet;
|
|
packet.Vendor = vendor->GetGUID();
|
|
|
|
packet.Items.resize(rawItemCount);
|
|
|
|
const float discountMod = _player->GetReputationPriceDiscount(vendor);
|
|
uint8 count = 0;
|
|
for (uint32 slot = 0; slot < rawItemCount; ++slot)
|
|
{
|
|
VendorItem const* vendorItem = vendorItems->GetItem(slot);
|
|
if (!vendorItem)
|
|
continue;
|
|
|
|
WorldPackets::NPC::VendorItem& item = packet.Items[count];
|
|
|
|
if (vendorItem->Type == ITEM_VENDOR_TYPE_ITEM)
|
|
{
|
|
ItemTemplate const* itemTemplate = sObjectMgr->GetItemTemplate(vendorItem->item);
|
|
if (!itemTemplate)
|
|
continue;
|
|
|
|
int32 leftInStock = !vendorItem->maxcount ? -1 : vendor->GetVendorItemCurrentCount(vendorItem);
|
|
if (!_player->IsGameMaster()) // ignore conditions if GM on
|
|
{
|
|
// Respect allowed class
|
|
if (!(itemTemplate->GetAllowableClass() & _player->getClassMask()) && itemTemplate->GetBonding() == BIND_WHEN_PICKED_UP)
|
|
continue;
|
|
|
|
// Only display items in vendor lists for the team the player is on
|
|
if ((itemTemplate->GetFlags2() & ITEM_FLAG2_HORDE_ONLY && _player->GetTeam() == ALLIANCE) ||
|
|
(itemTemplate->GetFlags2() & ITEM_FLAG2_ALLIANCE_ONLY && _player->GetTeam() == HORDE))
|
|
continue;
|
|
|
|
// Items sold out are not displayed in list
|
|
if (leftInStock == 0)
|
|
continue;
|
|
}
|
|
|
|
if (!sConditionMgr->IsObjectMeetingVendorItemConditions(vendor->GetEntry(), vendorItem->item, _player, vendor))
|
|
{
|
|
TC_LOG_DEBUG("condition", "SendListInventory: conditions not met for creature entry %u item %u", vendor->GetEntry(), vendorItem->item);
|
|
continue;
|
|
}
|
|
|
|
int32 price = vendorItem->IsGoldRequired(itemTemplate) ? uint32(floor(itemTemplate->GetBuyPrice() * discountMod)) : 0;
|
|
|
|
if (int32 priceMod = _player->GetTotalAuraModifier(SPELL_AURA_MOD_VENDOR_ITEMS_PRICES))
|
|
price -= CalculatePct(price, priceMod);
|
|
|
|
item.MuID = slot + 1; // client expects counting to start at 1
|
|
item.Durability = itemTemplate->MaxDurability;
|
|
item.ExtendedCostID = vendorItem->ExtendedCost;
|
|
item.Type = vendorItem->Type;
|
|
item.Quantity = leftInStock;
|
|
item.StackCount = itemTemplate->GetBuyCount();
|
|
item.Price = price;
|
|
|
|
item.Item.ItemID = vendorItem->item;
|
|
}
|
|
else if (vendorItem->Type == ITEM_VENDOR_TYPE_CURRENCY)
|
|
{
|
|
CurrencyTypesEntry const* currencyTemplate = sCurrencyTypesStore.LookupEntry(vendorItem->item);
|
|
if (!currencyTemplate)
|
|
continue;
|
|
|
|
if (!vendorItem->ExtendedCost)
|
|
continue; // there's no price defined for currencies, only extendedcost is used
|
|
|
|
item.MuID = slot + 1; // client expects counting to start at 1
|
|
item.ExtendedCostID = vendorItem->ExtendedCost;
|
|
item.Item.ItemID = vendorItem->item;
|
|
item.Type = vendorItem->Type;
|
|
item.StackCount = vendorItem->maxcount;
|
|
}
|
|
else
|
|
continue;
|
|
|
|
if (++count >= MAX_VENDOR_ITEMS)
|
|
break;
|
|
}
|
|
|
|
// Resize vector to real size (some items can be skipped due to checks)
|
|
packet.Items.resize(count);
|
|
|
|
SendPacket(packet.Write());
|
|
}
|
|
|
|
void WorldSession::HandleAutoStoreBagItemOpcode(WorldPackets::Item::AutoStoreBagItem& packet)
|
|
{
|
|
if (!packet.Inv.Items.empty())
|
|
{
|
|
TC_LOG_ERROR("network", "HandleAutoStoreBagItemOpcode - Invalid itemCount (" SZFMTD ")", packet.Inv.Items.size());
|
|
return;
|
|
}
|
|
|
|
TC_LOG_DEBUG("network", "HandleAutoStoreBagItemOpcode: receive ContainerSlotA: %u, SlotA: %u, ContainerSlotB: %u",
|
|
packet.ContainerSlotA, packet.SlotA, packet.ContainerSlotB);
|
|
|
|
Item* item = _player->GetItemByPos(packet.ContainerSlotA, packet.SlotA);
|
|
if (!item)
|
|
return;
|
|
|
|
if (!_player->IsValidPos(packet.ContainerSlotB, NULL_SLOT, false)) // can be autostore pos
|
|
{
|
|
_player->SendEquipError(EQUIP_ERR_WRONG_SLOT);
|
|
return;
|
|
}
|
|
|
|
uint16 src = item->GetPos();
|
|
|
|
// check unequip potability for equipped items and bank bags
|
|
if (_player->IsEquipmentPos(src) || _player->IsBagPos(src))
|
|
{
|
|
InventoryResult msg = _player->CanUnequipItem(src, !_player->IsBagPos(src));
|
|
if (msg != EQUIP_ERR_OK)
|
|
{
|
|
_player->SendEquipError(msg, item);
|
|
return;
|
|
}
|
|
}
|
|
|
|
ItemPosCountVec dest;
|
|
InventoryResult msg = _player->CanStoreItem(packet.ContainerSlotB, NULL_SLOT, dest, item, false);
|
|
if (msg != EQUIP_ERR_OK)
|
|
{
|
|
_player->SendEquipError(msg, item);
|
|
return;
|
|
}
|
|
|
|
// no-op: placed in same slot
|
|
if (dest.size() == 1 && dest[0].pos == src)
|
|
{
|
|
// just remove grey item state
|
|
_player->SendEquipError(EQUIP_ERR_INTERNAL_BAG_ERROR, item);
|
|
return;
|
|
}
|
|
|
|
_player->RemoveItem(packet.ContainerSlotA, packet.SlotA, true);
|
|
_player->StoreItem(dest, item, true);
|
|
}
|
|
|
|
void WorldSession::SendEnchantmentLog(ObjectGuid target, ObjectGuid caster, uint32 itemId, uint32 enchantId)
|
|
{
|
|
WorldPacket data(SMSG_ENCHANTMENT_LOG, (8+8+4+4));
|
|
data << target;
|
|
data << caster;
|
|
data << uint32(itemId);
|
|
data << uint32(enchantId);
|
|
GetPlayer()->SendMessageToSet(&data, true);
|
|
}
|
|
|
|
void WorldSession::SendItemEnchantTimeUpdate(ObjectGuid Playerguid, ObjectGuid Itemguid, uint32 slot, uint32 Duration)
|
|
{
|
|
WorldPackets::Item::ItemEnchantTimeUpdate data;
|
|
data.ItemGuid = Itemguid;
|
|
data.DurationLeft = Duration;
|
|
data.Slot = slot;
|
|
data.OwnerGuid = Playerguid;
|
|
SendPacket(data.Write());
|
|
}
|
|
|
|
void WorldSession::HandleWrapItem(WorldPackets::Item::WrapItem& packet)
|
|
{
|
|
if (packet.Inv.Items.size() != 2)
|
|
{
|
|
TC_LOG_ERROR("network", "HandleWrapItem - Invalid itemCount (" SZFMTD ")", packet.Inv.Items.size());
|
|
return;
|
|
}
|
|
|
|
/// @todo: 6.x find better way for read
|
|
// Gift
|
|
uint8 giftContainerSlot = packet.Inv.Items[0].ContainerSlot;
|
|
uint8 giftSlot = packet.Inv.Items[0].Slot;
|
|
// Item
|
|
uint8 itemContainerSlot = packet.Inv.Items[1].ContainerSlot;
|
|
uint8 itemSlot = packet.Inv.Items[1].Slot;
|
|
|
|
TC_LOG_DEBUG("network", "HandleWrapItem - Receive giftContainerSlot = %u, giftSlot = %u, itemContainerSlot = %u, itemSlot = %u", giftContainerSlot, giftSlot, itemContainerSlot, itemSlot);
|
|
|
|
Item* gift = _player->GetItemByPos(giftContainerSlot, giftSlot);
|
|
if (!gift)
|
|
{
|
|
_player->SendEquipError(EQUIP_ERR_ITEM_NOT_FOUND, gift, NULL);
|
|
return;
|
|
}
|
|
|
|
if (!(gift->GetTemplate()->GetFlags() & ITEM_FLAG_WRAPPER)) // cheating: non-wrapper wrapper
|
|
{
|
|
_player->SendEquipError(EQUIP_ERR_ITEM_NOT_FOUND, gift, NULL);
|
|
return;
|
|
}
|
|
|
|
Item* item = _player->GetItemByPos(itemContainerSlot, itemSlot);
|
|
if (!item)
|
|
{
|
|
_player->SendEquipError(EQUIP_ERR_ITEM_NOT_FOUND, item, NULL);
|
|
return;
|
|
}
|
|
|
|
if (item == gift) // not possable with pacjket from real client
|
|
{
|
|
_player->SendEquipError(EQUIP_ERR_CANT_WRAP_WRAPPED, item, NULL);
|
|
return;
|
|
}
|
|
|
|
if (item->IsEquipped())
|
|
{
|
|
_player->SendEquipError(EQUIP_ERR_CANT_WRAP_EQUIPPED, item, NULL);
|
|
return;
|
|
}
|
|
|
|
if (!item->GetGuidValue(ITEM_FIELD_GIFTCREATOR).IsEmpty()) // HasFlag(ITEM_FIELD_FLAGS, ITEM_FLAGS_WRAPPED);
|
|
{
|
|
_player->SendEquipError(EQUIP_ERR_CANT_WRAP_WRAPPED, item, NULL);
|
|
return;
|
|
}
|
|
|
|
if (item->IsBag())
|
|
{
|
|
_player->SendEquipError(EQUIP_ERR_CANT_WRAP_BAGS, item, NULL);
|
|
return;
|
|
}
|
|
|
|
if (item->IsSoulBound())
|
|
{
|
|
_player->SendEquipError(EQUIP_ERR_CANT_WRAP_BOUND, item, NULL);
|
|
return;
|
|
}
|
|
|
|
if (item->GetMaxStackCount() != 1)
|
|
{
|
|
_player->SendEquipError(EQUIP_ERR_CANT_WRAP_STACKABLE, item, NULL);
|
|
return;
|
|
}
|
|
|
|
// maybe not correct check (it is better than nothing)
|
|
if (item->GetTemplate()->GetMaxCount() > 0)
|
|
{
|
|
_player->SendEquipError(EQUIP_ERR_CANT_WRAP_UNIQUE, item, NULL);
|
|
return;
|
|
}
|
|
|
|
SQLTransaction trans = CharacterDatabase.BeginTransaction();
|
|
|
|
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_CHAR_GIFT);
|
|
stmt->setUInt64(0, item->GetOwnerGUID().GetCounter());
|
|
stmt->setUInt64(1, item->GetGUID().GetCounter());
|
|
stmt->setUInt32(2, item->GetEntry());
|
|
stmt->setUInt32(3, item->GetUInt32Value(ITEM_FIELD_FLAGS));
|
|
trans->Append(stmt);
|
|
|
|
item->SetEntry(gift->GetEntry());
|
|
|
|
switch (item->GetEntry())
|
|
{
|
|
case 5042:
|
|
item->SetEntry(5043);
|
|
break;
|
|
case 5048:
|
|
item->SetEntry(5044);
|
|
break;
|
|
case 17303:
|
|
item->SetEntry(17302);
|
|
break;
|
|
case 17304:
|
|
item->SetEntry(17305);
|
|
break;
|
|
case 17307:
|
|
item->SetEntry(17308);
|
|
break;
|
|
case 21830:
|
|
item->SetEntry(21831);
|
|
break;
|
|
}
|
|
|
|
item->SetGuidValue(ITEM_FIELD_GIFTCREATOR, _player->GetGUID());
|
|
item->SetUInt32Value(ITEM_FIELD_FLAGS, ITEM_FIELD_FLAG_WRAPPED);
|
|
item->SetState(ITEM_CHANGED, _player);
|
|
|
|
if (item->GetState() == ITEM_NEW) // save new item, to have alway for `character_gifts` record in `item_instance`
|
|
{
|
|
// after save it will be impossible to remove the item from the queue
|
|
item->RemoveFromUpdateQueueOf(_player);
|
|
item->SaveToDB(trans); // item gave inventory record unchanged and can be save standalone
|
|
}
|
|
CharacterDatabase.CommitTransaction(trans);
|
|
|
|
uint32 count = 1;
|
|
_player->DestroyItemCount(gift, count, true);
|
|
}
|
|
|
|
void WorldSession::HandleSocketGems(WorldPackets::Item::SocketGems& socketGems)
|
|
{
|
|
if (!socketGems.ItemGuid)
|
|
return;
|
|
|
|
//cheat -> tried to socket same gem multiple times
|
|
if ((!socketGems.GemItem[0].IsEmpty() && (socketGems.GemItem[0] == socketGems.GemItem[1] || socketGems.GemItem[0] == socketGems.GemItem[2])) ||
|
|
(!socketGems.GemItem[1].IsEmpty() && (socketGems.GemItem[1] == socketGems.GemItem[2])))
|
|
return;
|
|
|
|
Item* itemTarget = _player->GetItemByGuid(socketGems.ItemGuid);
|
|
if (!itemTarget) //missing item to socket
|
|
return;
|
|
|
|
ItemTemplate const* itemProto = itemTarget->GetTemplate();
|
|
if (!itemProto)
|
|
return;
|
|
|
|
//this slot is excepted when applying / removing meta gem bonus
|
|
uint8 slot = itemTarget->IsEquipped() ? itemTarget->GetSlot() : uint8(NULL_SLOT);
|
|
|
|
Item* Gems[MAX_GEM_SOCKETS];
|
|
for (int i = 0; i < MAX_GEM_SOCKETS; ++i)
|
|
Gems[i] = !socketGems.GemItem[i].IsEmpty() ? _player->GetItemByGuid(socketGems.GemItem[i]) : NULL;
|
|
|
|
GemPropertiesEntry const* GemProps[MAX_GEM_SOCKETS];
|
|
for (int i = 0; i < MAX_GEM_SOCKETS; ++i) //get geminfo from dbc storage
|
|
GemProps[i] = (Gems[i]) ? sGemPropertiesStore.LookupEntry(Gems[i]->GetTemplate()->GetGemProperties()) : NULL;
|
|
|
|
// Find first prismatic socket
|
|
int32 firstPrismatic = 0;
|
|
while (firstPrismatic < MAX_GEM_SOCKETS && itemTarget->GetSocketColor(firstPrismatic))
|
|
++firstPrismatic;
|
|
|
|
for (int i = 0; i < MAX_GEM_SOCKETS; ++i) //check for hack maybe
|
|
{
|
|
if (!GemProps[i])
|
|
continue;
|
|
|
|
// tried to put gem in socket where no socket exists (take care about prismatic sockets)
|
|
if (!itemTarget->GetSocketColor(i))
|
|
{
|
|
// no prismatic socket
|
|
if (!itemTarget->GetEnchantmentId(PRISMATIC_ENCHANTMENT_SLOT))
|
|
return;
|
|
|
|
if (i != firstPrismatic)
|
|
return;
|
|
}
|
|
|
|
// tried to put normal gem in meta socket
|
|
if (itemTarget->GetSocketColor(i) == SOCKET_COLOR_META && GemProps[i]->Type != SOCKET_COLOR_META)
|
|
return;
|
|
|
|
// tried to put meta gem in normal socket
|
|
if (itemTarget->GetSocketColor(i) != SOCKET_COLOR_META && GemProps[i]->Type == SOCKET_COLOR_META)
|
|
return;
|
|
|
|
// tried to put normal gem in cogwheel socket
|
|
if (itemTarget->GetSocketColor(i) == SOCKET_COLOR_COGWHEEL && GemProps[i]->Type != SOCKET_COLOR_COGWHEEL)
|
|
return;
|
|
|
|
// tried to put cogwheel gem in normal socket
|
|
if (itemTarget->GetSocketColor(i) != SOCKET_COLOR_COGWHEEL && GemProps[i]->Type == SOCKET_COLOR_COGWHEEL)
|
|
return;
|
|
}
|
|
|
|
uint32 GemEnchants[MAX_GEM_SOCKETS];
|
|
uint32 OldEnchants[MAX_GEM_SOCKETS];
|
|
for (int i = 0; i < MAX_GEM_SOCKETS; ++i) //get new and old enchantments
|
|
{
|
|
GemEnchants[i] = (GemProps[i]) ? GemProps[i]->EnchantID : 0;
|
|
OldEnchants[i] = itemTarget->GetEnchantmentId(EnchantmentSlot(SOCK_ENCHANTMENT_SLOT+i));
|
|
}
|
|
|
|
// check unique-equipped conditions
|
|
for (int i = 0; i < MAX_GEM_SOCKETS; ++i)
|
|
{
|
|
if (!Gems[i])
|
|
continue;
|
|
|
|
// continue check for case when attempt add 2 similar unique equipped gems in one item.
|
|
ItemTemplate const* iGemProto = Gems[i]->GetTemplate();
|
|
|
|
// unique item (for new and already placed bit removed enchantments
|
|
if (iGemProto->GetFlags() & ITEM_FLAG_UNIQUE_EQUIPPED)
|
|
{
|
|
for (int j = 0; j < MAX_GEM_SOCKETS; ++j)
|
|
{
|
|
if (i == j) // skip self
|
|
continue;
|
|
|
|
if (Gems[j])
|
|
{
|
|
if (iGemProto->GetId() == Gems[j]->GetEntry())
|
|
{
|
|
_player->SendEquipError(EQUIP_ERR_ITEM_UNIQUE_EQUIPPABLE_SOCKETED, itemTarget, NULL);
|
|
return;
|
|
}
|
|
}
|
|
else if (OldEnchants[j])
|
|
{
|
|
if (SpellItemEnchantmentEntry const* enchantEntry = sSpellItemEnchantmentStore.LookupEntry(OldEnchants[j]))
|
|
{
|
|
if (iGemProto->GetId() == enchantEntry->SRCItemID)
|
|
{
|
|
_player->SendEquipError(EQUIP_ERR_ITEM_UNIQUE_EQUIPPABLE_SOCKETED, itemTarget, NULL);
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// unique limit type item
|
|
int32 limit_newcount = 0;
|
|
if (iGemProto->GetItemLimitCategory())
|
|
{
|
|
if (ItemLimitCategoryEntry const* limitEntry = sItemLimitCategoryStore.LookupEntry(iGemProto->GetItemLimitCategory()))
|
|
{
|
|
// NOTE: limitEntry->mode is not checked because if item has limit then it is applied in equip case
|
|
for (int j = 0; j < MAX_GEM_SOCKETS; ++j)
|
|
{
|
|
if (Gems[j])
|
|
{
|
|
// new gem
|
|
if (iGemProto->GetItemLimitCategory() == Gems[j]->GetTemplate()->GetItemLimitCategory())
|
|
++limit_newcount;
|
|
}
|
|
else if (OldEnchants[j])
|
|
{
|
|
// existing gem
|
|
if (SpellItemEnchantmentEntry const* enchantEntry = sSpellItemEnchantmentStore.LookupEntry(OldEnchants[j]))
|
|
if (ItemTemplate const* jProto = sObjectMgr->GetItemTemplate(enchantEntry->SRCItemID))
|
|
if (iGemProto->GetItemLimitCategory() == jProto->GetItemLimitCategory())
|
|
++limit_newcount;
|
|
}
|
|
}
|
|
|
|
if (limit_newcount > 0 && uint32(limit_newcount) > limitEntry->Quantity)
|
|
{
|
|
_player->SendEquipError(EQUIP_ERR_ITEM_UNIQUE_EQUIPPABLE_SOCKETED, itemTarget, NULL);
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
// for equipped item check all equipment for duplicate equipped gems
|
|
if (itemTarget->IsEquipped())
|
|
{
|
|
if (InventoryResult res = _player->CanEquipUniqueItem(Gems[i], slot, std::max(limit_newcount, 0)))
|
|
{
|
|
_player->SendEquipError(res, itemTarget, NULL);
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
bool SocketBonusActivated = itemTarget->GemsFitSockets(); //save state of socketbonus
|
|
_player->ToggleMetaGemsActive(slot, false); //turn off all metagems (except for the target item)
|
|
|
|
//if a meta gem is being equipped, all information has to be written to the item before testing if the conditions for the gem are met
|
|
|
|
//remove ALL enchants
|
|
for (uint32 enchant_slot = SOCK_ENCHANTMENT_SLOT; enchant_slot < SOCK_ENCHANTMENT_SLOT + MAX_GEM_SOCKETS; ++enchant_slot)
|
|
_player->ApplyEnchantment(itemTarget, EnchantmentSlot(enchant_slot), false);
|
|
|
|
for (int i = 0; i < MAX_GEM_SOCKETS; ++i)
|
|
{
|
|
if (GemEnchants[i])
|
|
{
|
|
itemTarget->SetEnchantment(EnchantmentSlot(SOCK_ENCHANTMENT_SLOT+i), GemEnchants[i], 0, 0, _player->GetGUID());
|
|
if (Item* guidItem = _player->GetItemByGuid(socketGems.GemItem[i]))
|
|
{
|
|
uint32 gemCount = 1;
|
|
_player->DestroyItemCount(guidItem, gemCount, true);
|
|
}
|
|
}
|
|
}
|
|
|
|
for (uint32 enchant_slot = SOCK_ENCHANTMENT_SLOT; enchant_slot < SOCK_ENCHANTMENT_SLOT+MAX_GEM_SOCKETS; ++enchant_slot)
|
|
_player->ApplyEnchantment(itemTarget, EnchantmentSlot(enchant_slot), true);
|
|
|
|
bool SocketBonusToBeActivated = itemTarget->GemsFitSockets();//current socketbonus state
|
|
if (SocketBonusActivated ^ SocketBonusToBeActivated) //if there was a change...
|
|
{
|
|
_player->ApplyEnchantment(itemTarget, BONUS_ENCHANTMENT_SLOT, false);
|
|
itemTarget->SetEnchantment(BONUS_ENCHANTMENT_SLOT, (SocketBonusToBeActivated ? itemTarget->GetTemplate()->GetSocketBonus() : 0), 0, 0, _player->GetGUID());
|
|
_player->ApplyEnchantment(itemTarget, BONUS_ENCHANTMENT_SLOT, true);
|
|
//it is not displayed, client has an inbuilt system to determine if the bonus is activated
|
|
}
|
|
|
|
_player->ToggleMetaGemsActive(slot, true); //turn on all metagems (except for target item)
|
|
|
|
_player->RemoveTradeableItem(itemTarget);
|
|
itemTarget->ClearSoulboundTradeable(_player); // clear tradeable flag
|
|
|
|
itemTarget->SendUpdateSockets();
|
|
}
|
|
|
|
void WorldSession::HandleCancelTempEnchantmentOpcode(WorldPackets::Item::CancelTempEnchantment& cancelTempEnchantment)
|
|
{
|
|
// apply only to equipped item
|
|
if (!Player::IsEquipmentPos(INVENTORY_SLOT_BAG_0, cancelTempEnchantment.Slot))
|
|
return;
|
|
|
|
Item* item = GetPlayer()->GetItemByPos(INVENTORY_SLOT_BAG_0, cancelTempEnchantment.Slot);
|
|
|
|
if (!item)
|
|
return;
|
|
|
|
if (!item->GetEnchantmentId(TEMP_ENCHANTMENT_SLOT))
|
|
return;
|
|
|
|
GetPlayer()->ApplyEnchantment(item, TEMP_ENCHANTMENT_SLOT, false);
|
|
item->ClearEnchantment(TEMP_ENCHANTMENT_SLOT);
|
|
}
|
|
|
|
void WorldSession::HandleGetItemPurchaseData(WorldPackets::Item::GetItemPurchaseData& packet)
|
|
{
|
|
Item* item = _player->GetItemByGuid(packet.ItemGUID);
|
|
if (!item)
|
|
{
|
|
TC_LOG_DEBUG("network", "HandleGetItemPurchaseData: Item %s not found!", packet.ItemGUID.ToString().c_str());
|
|
return;
|
|
}
|
|
|
|
TC_LOG_DEBUG("network", "HandleGetItemPurchaseData: Item %s", packet.ItemGUID.ToString().c_str());
|
|
|
|
GetPlayer()->SendRefundInfo(item);
|
|
}
|
|
|
|
void WorldSession::HandleItemRefund(WorldPackets::Item::ItemPurchaseRefund& packet)
|
|
{
|
|
Item* item = _player->GetItemByGuid(packet.ItemGUID);
|
|
if (!item)
|
|
{
|
|
TC_LOG_DEBUG("network", "WorldSession::HandleItemRefund: Item (%s) not found!", packet.ItemGUID.ToString().c_str());
|
|
return;
|
|
}
|
|
|
|
// Don't try to refund item currently being disenchanted
|
|
if (_player->GetLootGUID() == packet.ItemGUID)
|
|
return;
|
|
|
|
GetPlayer()->RefundItem(item);
|
|
}
|
|
|
|
void WorldSession::HandleTransmogrifyItems(WorldPackets::Item::TransmogrifyItems& transmogrifyItems)
|
|
{
|
|
Player* player = GetPlayer();
|
|
// Validate
|
|
if (!player->GetNPCIfCanInteractWith(transmogrifyItems.Npc, UNIT_NPC_FLAG_TRANSMOGRIFIER))
|
|
{
|
|
TC_LOG_DEBUG("network", "WORLD: HandleTransmogrifyItems - %s not found or player can't interact with it.", transmogrifyItems.Npc.ToString().c_str());
|
|
return;
|
|
}
|
|
|
|
int64 cost = 0;
|
|
std::unordered_map<Item*, Item*> transmogItems;
|
|
std::unordered_map<Item*, std::pair<VoidStorageItem*, BonusData>> transmogVoidItems;
|
|
std::vector<Item*> resetAppearanceItems;
|
|
|
|
for (WorldPackets::Item::TransmogrifyItem const& transmogItem : transmogrifyItems.Items)
|
|
{
|
|
// slot of the transmogrified item
|
|
if (transmogItem.Slot >= EQUIPMENT_SLOT_END)
|
|
{
|
|
TC_LOG_DEBUG("network", "WORLD: HandleTransmogrifyItems - Player (%s, name: %s) tried to transmogrify wrong slot (%u) when transmogrifying items.", player->GetGUID().ToString().c_str(), player->GetName().c_str(), transmogItem.Slot);
|
|
return;
|
|
}
|
|
|
|
// transmogrified item
|
|
Item* itemTransmogrified = player->GetItemByPos(INVENTORY_SLOT_BAG_0, transmogItem.Slot);
|
|
if (!itemTransmogrified)
|
|
{
|
|
TC_LOG_DEBUG("network", "WORLD: HandleTransmogrifyItems - Player (%s, name: %s) tried to transmogrify an invalid item in a valid slot (slot: %u).", player->GetGUID().ToString().c_str(), player->GetName().c_str(), transmogItem.Slot);
|
|
return;
|
|
}
|
|
if (player->CanUseItem(itemTransmogrified->GetTemplate()) != EQUIP_ERR_OK)
|
|
{
|
|
TC_LOG_DEBUG("network", "WORLD: HandleTransmogrifyItems - Player (%s, name: %s) tried to transmogrify an unequippable item in a valid slot (slot: %u).", player->GetGUID().ToString().c_str(), player->GetName().c_str(), transmogItem.Slot);
|
|
return;
|
|
}
|
|
|
|
WorldPackets::Item::ItemInstance itemInstance;
|
|
BonusData const* bonus = nullptr;
|
|
if (transmogItem.SrcItemGUID)
|
|
{
|
|
// guid of the transmogrifier item
|
|
Item* itemTransmogrifier = player->GetItemByGuid(*transmogItem.SrcItemGUID);
|
|
if (!itemTransmogrifier)
|
|
{
|
|
TC_LOG_DEBUG("network", "WORLD: HandleTransmogrifyItems - Player (%s, name: %s) tried to transmogrify with an invalid item (%s).", player->GetGUID().ToString().c_str(), player->GetName().c_str(), transmogItem.SrcItemGUID->ToString().c_str());
|
|
return;
|
|
}
|
|
if (player->CanUseItem(itemTransmogrifier->GetTemplate()) != EQUIP_ERR_OK)
|
|
{
|
|
TC_LOG_DEBUG("network", "WORLD: HandleTransmogrifyItems - Player (%s, name: %s) tried to transmogrify with an unequippable item (%s).", player->GetGUID().ToString().c_str(), player->GetName().c_str(), transmogItem.SrcItemGUID->ToString().c_str());
|
|
return;
|
|
}
|
|
|
|
itemInstance.Initialize(itemTransmogrifier);
|
|
bonus = itemTransmogrifier->GetBonus();
|
|
transmogItems[itemTransmogrified] = itemTransmogrifier;
|
|
}
|
|
else if (transmogItem.SrcVoidItemGUID)
|
|
{
|
|
// guid of the transmogrifier item
|
|
uint8 slot;
|
|
VoidStorageItem* itemTransmogrifier = player->GetVoidStorageItem(transmogItem.SrcVoidItemGUID->GetCounter(), slot);
|
|
if (!itemTransmogrifier)
|
|
{
|
|
TC_LOG_DEBUG("network", "WORLD: HandleTransmogrifyItems - Player (%s, name: %s) tried to transmogrify with an invalid void storage item (%s).", player->GetGUID().ToString().c_str(), player->GetName().c_str(), transmogItem.SrcVoidItemGUID->ToString().c_str());
|
|
return;
|
|
}
|
|
ItemTemplate const * transmogrifierTemplate = sObjectMgr->GetItemTemplate(itemTransmogrifier->ItemEntry);
|
|
if (player->CanUseItem(transmogrifierTemplate) != EQUIP_ERR_OK)
|
|
{
|
|
TC_LOG_DEBUG("network", "WORLD: HandleTransmogrifyItems - Player (%s, name: %s) tried to transmogrify with an unequippable void storage item (%s).", player->GetGUID().ToString().c_str(), player->GetName().c_str(), transmogItem.SrcVoidItemGUID->ToString().c_str());
|
|
return;
|
|
}
|
|
|
|
itemInstance.Initialize(itemTransmogrifier);
|
|
std::pair<VoidStorageItem*, BonusData>& transmogData = transmogVoidItems[itemTransmogrified];
|
|
transmogData.first = itemTransmogrifier;
|
|
transmogData.second.Initialize(itemInstance);
|
|
bonus = &transmogData.second;
|
|
}
|
|
else
|
|
{
|
|
resetAppearanceItems.push_back(itemTransmogrified);
|
|
continue;
|
|
}
|
|
|
|
// entry of transmogrifier and from packet
|
|
if (itemInstance != transmogItem.Item)
|
|
{
|
|
TC_LOG_DEBUG("network", "WORLD: HandleTransmogrifyItems - Player (%s, name: %s) tried to transmogrify with an invalid item instance data for %s.", player->GetGUID().ToString().c_str(), player->GetName().c_str(), transmogItem.SrcItemGUID->ToString().c_str());
|
|
return;
|
|
}
|
|
|
|
// validity of the transmogrification items
|
|
if (!Item::CanTransmogrifyItemWithItem(itemTransmogrified, transmogItem.Item, bonus))
|
|
{
|
|
TC_LOG_DEBUG("network", "WORLD: HandleTransmogrifyItems - Player (%s, name: %s) failed CanTransmogrifyItemWithItem (%u with %u).", player->GetGUID().ToString().c_str(), player->GetName().c_str(), itemTransmogrified->GetEntry(), transmogItem.Item.ItemID);
|
|
return;
|
|
}
|
|
|
|
// add cost
|
|
cost += itemTransmogrified->GetSpecialPrice();
|
|
}
|
|
|
|
if (cost) // 0 cost if reverting look
|
|
{
|
|
if (!player->HasEnoughMoney(cost))
|
|
return;
|
|
player->ModifyMoney(-cost);
|
|
}
|
|
|
|
// Everything is fine, proceed
|
|
for (auto& transmogPair : transmogItems)
|
|
{
|
|
Item* transmogrified = transmogPair.first;
|
|
Item* transmogrifier = transmogPair.second;
|
|
|
|
transmogrified->SetModifier(ITEM_MODIFIER_TRANSMOG_ITEM_ID, transmogrifier->GetEntry());
|
|
transmogrified->SetModifier(ITEM_MODIFIER_TRANSMOG_APPEARANCE_MOD, transmogrifier->GetAppearanceModId());
|
|
player->SetVisibleItemSlot(transmogrified->GetSlot(), transmogrified);
|
|
|
|
transmogrified->SetNotRefundable(player);
|
|
transmogrified->ClearSoulboundTradeable(player);
|
|
|
|
transmogrifier->SetNotRefundable(player);
|
|
transmogrifier->ClearSoulboundTradeable(player);
|
|
|
|
if (transmogrifier->GetTemplate()->GetBonding() == BIND_WHEN_EQUIPED || transmogrifier->GetTemplate()->GetBonding() == BIND_WHEN_USE)
|
|
transmogrifier->SetBinding(true);
|
|
}
|
|
|
|
for (auto& transmogVoirPair : transmogVoidItems)
|
|
{
|
|
Item* transmogrified = transmogVoirPair.first;
|
|
VoidStorageItem* transmogrifier = transmogVoirPair.second.first;
|
|
BonusData& bonus = transmogVoirPair.second.second;
|
|
|
|
transmogrified->SetModifier(ITEM_MODIFIER_TRANSMOG_ITEM_ID, transmogrifier->ItemEntry);
|
|
transmogrified->SetModifier(ITEM_MODIFIER_TRANSMOG_APPEARANCE_MOD, bonus.AppearanceModID);
|
|
player->SetVisibleItemSlot(transmogrified->GetSlot(), transmogrified);
|
|
|
|
transmogrified->SetNotRefundable(player);
|
|
transmogrified->ClearSoulboundTradeable(player);
|
|
}
|
|
|
|
for (Item* item : resetAppearanceItems)
|
|
{
|
|
item->SetModifier(ITEM_MODIFIER_TRANSMOG_ITEM_ID, 0);
|
|
item->SetModifier(ITEM_MODIFIER_TRANSMOG_APPEARANCE_MOD, 0);
|
|
player->SetVisibleItemSlot(item->GetSlot(), item);
|
|
}
|
|
}
|
|
|
|
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::HandleUseCritterItem(WorldPackets::Item::UseCritterItem& useCritterItem)
|
|
{
|
|
Item* item = _player->GetItemByGuid(useCritterItem.ItemGuid);
|
|
if (!item)
|
|
return;
|
|
|
|
ItemToBattlePetSpeciesEntry const* itemToBattlePetSpecies = sItemToBattlePetSpeciesStore.LookupEntry(item->GetEntry());
|
|
if (!itemToBattlePetSpecies)
|
|
return;
|
|
|
|
BattlePetSpeciesEntry const* battlePetSpecies = sBattlePetSpeciesStore.LookupEntry(itemToBattlePetSpecies->BattlePetSpeciesID);
|
|
if (!battlePetSpecies)
|
|
return;
|
|
|
|
GetBattlePetMgr()->AddPet(battlePetSpecies->ID, battlePetSpecies->CreatureID, BattlePetMgr::RollPetBreed(battlePetSpecies->ID), BattlePetMgr::GetDefaultPetQuality(battlePetSpecies->ID));
|
|
_player->DestroyItem(item->GetBagSlot(), item->GetSlot(), true);
|
|
}
|