/*
* Copyright (C) 2008-2015 TrinityCore
* Copyright (C) 2005-2009 MaNGOS
*
* 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 .
*/
#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 "UpdateData.h"
#include "ObjectAccessor.h"
#include "SpellInfo.h"
#include "DB2Stores.h"
#include "NPCPackets.h"
#include "ItemPackets.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_PROTO_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_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::HandleBuyItemInSlotOpcode(WorldPacket& recvData)
{
TC_LOG_DEBUG("network", "WORLD: Received CMSG_BUY_ITEM_IN_SLOT");
ObjectGuid vendorguid, bagguid;
uint32 item, slot, count;
uint8 bagslot;
recvData >> vendorguid >> item >> slot >> bagguid >> bagslot >> count;
// client expects count starting at 1, and we send vendorslot+1 to client already
if (slot > 0)
--slot;
else
return; // cheating
uint8 bag = NULL_BAG; // init for case invalid bagGUID
Item* bagItem = NULL;
// find bag slot by bag guid
if (bagguid == _player->GetGUID())
bag = INVENTORY_SLOT_BAG_0;
else
bagItem = _player->GetItemByGuid(bagguid);
if (bagItem && bagItem->IsBag())
bag = bagItem->GetSlot();
// bag not found, cheating?
if (bag == NULL_BAG)
return;
GetPlayer()->BuyItemFromVendorSlot(vendorguid, slot, item, count, bag, bagslot);
}
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)
{
TC_LOG_DEBUG("network", "WORLD: Recvd CMSG_LIST_INVENTORY");
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_FLAGS_EXTRA_HORDE_ONLY && _player->GetTeam() == ALLIANCE) ||
(itemTemplate->GetFlags2() & ITEM_FLAGS_EXTRA_ALLIANCE_ONLY && _player->GetTeam() == HORDE))
continue;
// Items sold out are not displayed in list
if (leftInStock == 0)
continue;
}
ConditionList conditions = sConditionMgr->GetConditionsForNpcVendorEvent(vendor->GetEntry(), vendorItem->item);
if (!sConditionMgr->IsObjectMeetToConditions(_player, vendor, conditions))
{
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.WriteAsPacked();
data << caster.WriteAsPacked();
data << uint32(itemId);
data << uint32(enchantId);
GetPlayer()->SendMessageToSet(&data, true);
}
void WorldSession::SendItemEnchantTimeUpdate(ObjectGuid Playerguid, ObjectGuid Itemguid, uint32 slot, uint32 Duration)
{
// last check 2.0.10
WorldPacket data(SMSG_ITEM_ENCHANT_TIME_UPDATE, (8+4+4+8));
data << Itemguid;
data << uint32(slot);
data << uint32(Duration);
data << Playerguid;
SendPacket(&data);
}
void WorldSession::HandleWrapItem(WorldPackets::Item::WrapItem& packet)
{
TC_LOG_DEBUG("network", "Received opcode CMSG_WRAP_ITEM");
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_PROTO_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_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::HandleSocketOpcode(WorldPacket& recvData)
{
TC_LOG_DEBUG("network", "WORLD: CMSG_SOCKET_GEMS");
ObjectGuid item_guid;
ObjectGuid gem_guids[MAX_GEM_SOCKETS];
recvData >> item_guid;
if (!item_guid)
return;
for (int i = 0; i < MAX_GEM_SOCKETS; ++i)
recvData >> gem_guids[i];
//cheat -> tried to socket same gem multiple times
if ((!gem_guids[0].IsEmpty() && (gem_guids[0] == gem_guids[1] || gem_guids[0] == gem_guids[2])) ||
(!gem_guids[1].IsEmpty() && (gem_guids[1] == gem_guids[2])))
return;
Item* itemTarget = _player->GetItemByGuid(item_guid);
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] = !gem_guids[i].IsEmpty() ? _player->GetItemByGuid(gem_guids[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 && itemProto->ExtendedData->SocketColor[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 (!itemProto->ExtendedData->SocketColor[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_PROTO_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(gem_guids[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(WorldPacket& recvData)
{
TC_LOG_DEBUG("network", "WORLD: CMSG_CANCEL_TEMP_ENCHANTMENT");
uint32 slot;
recvData >> slot;
// apply only to equipped item
if (!Player::IsEquipmentPos(INVENTORY_SLOT_BAG_0, slot))
return;
Item* item = GetPlayer()->GetItemByPos(INVENTORY_SLOT_BAG_0, 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(WorldPacket &recvData)
{
TC_LOG_DEBUG("network", "WORLD: CMSG_ITEM_PURCHASE_REFUND");
ObjectGuid guid;
recvData >> guid; // item guid
Item* item = _player->GetItemByGuid(guid);
if (!item)
{
TC_LOG_DEBUG("network", "Item refund: item not found!");
return;
}
// Don't try to refund item currently being disenchanted
if (_player->GetLootGUID() == guid)
return;
GetPlayer()->RefundItem(item);
}
/**
* Handles the packet sent by the client when requesting information about item text.
*
* This function is called when player clicks on item which has some flag set
*/
void WorldSession::HandleItemTextQuery(WorldPacket& recvData )
{
ObjectGuid itemGuid;
recvData >> itemGuid;
TC_LOG_DEBUG("network", "CMSG_ITEM_TEXT_QUERY %s", itemGuid.ToString().c_str());
WorldPacket data(SMSG_QUERY_ITEM_TEXT_RESPONSE, 14); // guess size
if (Item* item = _player->GetItemByGuid(itemGuid))
{
data << uint8(0); // has text
data << itemGuid; // item guid
data << item->GetText();
}
else
{
data << uint8(1); // no text
}
SendPacket(&data);
}
void WorldSession::HandleTransmogrifyItems(WorldPacket& recvData)
{
TC_LOG_DEBUG("network", "WORLD: Received CMSG_TRANSMOGRIFY_ITEMS");
Player* player = GetPlayer();
// Read data
uint32 count = recvData.ReadBits(22);
if (count >= EQUIPMENT_SLOT_END)
{
TC_LOG_DEBUG("network", "WORLD: HandleTransmogrifyItems - Player (%s, name: %s) sent a wrong count (%u) when transmogrifying items.", player->GetGUID().ToString().c_str(), player->GetName().c_str(), count);
recvData.rfinish();
return;
}
std::vector itemGuids(count, ObjectGuid());
std::vector newEntries(count, 0);
std::vector slots(count, 0);
for (uint8 i = 0; i < count; ++i)
{
itemGuids[i][0] = recvData.ReadBit();
itemGuids[i][5] = recvData.ReadBit();
itemGuids[i][6] = recvData.ReadBit();
itemGuids[i][2] = recvData.ReadBit();
itemGuids[i][3] = recvData.ReadBit();
itemGuids[i][7] = recvData.ReadBit();
itemGuids[i][4] = recvData.ReadBit();
itemGuids[i][1] = recvData.ReadBit();
}
ObjectGuid npcGuid;
npcGuid[7] = recvData.ReadBit();
npcGuid[3] = recvData.ReadBit();
npcGuid[5] = recvData.ReadBit();
npcGuid[6] = recvData.ReadBit();
npcGuid[1] = recvData.ReadBit();
npcGuid[4] = recvData.ReadBit();
npcGuid[0] = recvData.ReadBit();
npcGuid[2] = recvData.ReadBit();
recvData.FlushBits();
for (uint32 i = 0; i < count; ++i)
{
recvData >> newEntries[i];
recvData.ReadByteSeq(itemGuids[i][1]);
recvData.ReadByteSeq(itemGuids[i][5]);
recvData.ReadByteSeq(itemGuids[i][0]);
recvData.ReadByteSeq(itemGuids[i][4]);
recvData.ReadByteSeq(itemGuids[i][6]);
recvData.ReadByteSeq(itemGuids[i][7]);
recvData.ReadByteSeq(itemGuids[i][3]);
recvData.ReadByteSeq(itemGuids[i][2]);
recvData >> slots[i];
}
recvData.ReadByteSeq(npcGuid[7]);
recvData.ReadByteSeq(npcGuid[2]);
recvData.ReadByteSeq(npcGuid[5]);
recvData.ReadByteSeq(npcGuid[4]);
recvData.ReadByteSeq(npcGuid[3]);
recvData.ReadByteSeq(npcGuid[1]);
recvData.ReadByteSeq(npcGuid[6]);
recvData.ReadByteSeq(npcGuid[0]);
// Validate
if (!player->GetNPCIfCanInteractWith(npcGuid, UNIT_NPC_FLAG_TRANSMOGRIFIER))
{
TC_LOG_DEBUG("network", "WORLD: HandleTransmogrifyItems - %s not found or player can't interact with it.", npcGuid.ToString().c_str());
return;
}
int64 cost = 0;
std::vector- transmogrifier(count, NULL);
std::vector
- transmogrified(count, NULL);
for (uint8 i = 0; i < count; ++i)
{
// slot of the transmogrified item
if (slots[i] >= EQUIPMENT_SLOT_END)
{
TC_LOG_DEBUG("network", "WORLD: HandleTransmogrifyItems - Player (%s, name: %s) tried to transmogrify %s with a wrong slot (%u) when transmogrifying items.", player->GetGUID().ToString().c_str(), player->GetName().c_str(), itemGuids[i].ToString().c_str(), slots[i]);
return;
}
// transmogrified item
Item* itemTransmogrified = player->GetItemByPos(INVENTORY_SLOT_BAG_0, slots[i]);
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(), slots[i]);
return;
}
// if not resetting look
Item* itemTransmogrifier = NULL;
if (newEntries[i])
{
// entry of the transmogrifier item
ItemTemplate const* proto = sObjectMgr->GetItemTemplate(newEntries[i]);
if (!proto)
{
TC_LOG_DEBUG("network", "WORLD: HandleTransmogrifyItems - Player (%s, name: %s) tried to transmogrify to an invalid item (entry: %u).", player->GetGUID().ToString().c_str(), player->GetName().c_str(), newEntries[i]);
return;
}
// guid of the transmogrifier item
itemTransmogrifier = player->GetItemByGuid(itemGuids[i]);
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(), itemGuids[i].ToString().c_str());
return;
}
// entry of transmogrifier and from packet
if (itemTransmogrifier->GetEntry() != newEntries[i])
{
TC_LOG_DEBUG("network", "WORLD: HandleTransmogrifyItems - Player (%s, name: %s) tried to transmogrify with an invalid entry (entry: %u) for %s.", player->GetGUID().ToString().c_str(), player->GetName().c_str(), newEntries[i], itemGuids[i].ToString().c_str());
return;
}
// validity of the transmogrification items
if (!Item::CanTransmogrifyItemWithItem(itemTransmogrified, itemTransmogrifier))
{
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(), itemTransmogrifier->GetEntry());
return;
}
// add cost
cost += itemTransmogrified->GetSpecialPrice();
}
transmogrifier[i] = itemTransmogrifier;
transmogrified[i] = itemTransmogrified;
}
if (cost) // 0 cost if reverting look
{
if (!player->HasEnoughMoney(cost))
return;
player->ModifyMoney(-cost);
}
// Everything is fine, proceed
for (uint8 i = 0; i < count; ++i)
{
if (transmogrifier[i])
{
// Transmogrify
transmogrified[i]->SetModifier(ITEM_MODIFIER_TRANSMOG_ITEM_ID, newEntries[i]);
player->SetVisibleItemSlot(slots[i], transmogrified[i]);
transmogrified[i]->UpdatePlayedTime(player);
transmogrified[i]->SetOwnerGUID(player->GetGUID());
transmogrified[i]->SetNotRefundable(player);
transmogrified[i]->ClearSoulboundTradeable(player);
if (transmogrifier[i]->GetTemplate()->GetBonding() == BIND_WHEN_EQUIPED || transmogrifier[i]->GetTemplate()->GetBonding() == BIND_WHEN_USE)
transmogrifier[i]->SetBinding(true);
transmogrifier[i]->SetOwnerGUID(player->GetGUID());
transmogrifier[i]->SetNotRefundable(player);
transmogrifier[i]->ClearSoulboundTradeable(player);
}
else
{
// Reset
transmogrified[i]->SetModifier(ITEM_MODIFIER_TRANSMOG_ITEM_ID, 0);
player->SetVisibleItemSlot(slots[i], transmogrified[i]);
}
}
}
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;
}