AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
Item Class Reference

#include "Item.h"

Inheritance diagram for Item:
Object Bag

Public Member Functions

ItemCloneItem (uint32 count, Player const *player=nullptr) const
 
 Item ()
 
virtual bool Create (ObjectGuid::LowType guidlow, uint32 itemid, Player const *owner)
 
ItemTemplate const * GetTemplate () const
 
ObjectGuid GetOwnerGUID () const
 
void SetOwnerGUID (ObjectGuid guid)
 
PlayerGetOwner () const
 
void SetBinding (bool val)
 
bool IsSoulBound () const
 
bool IsBoundAccountWide () const
 
bool IsBindedNotWith (Player const *player) const
 
bool IsBoundByEnchant () const
 
bool IsBoundByTempEnchant () const
 
virtual void SaveToDB (CharacterDatabaseTransaction trans)
 
virtual bool LoadFromDB (ObjectGuid::LowType guid, ObjectGuid owner_guid, Field *fields, uint32 entry)
 
virtual void DeleteFromDB (CharacterDatabaseTransaction trans)
 
void DeleteFromInventoryDB (CharacterDatabaseTransaction trans)
 
void SaveRefundDataToDB ()
 
void DeleteRefundDataFromDB (CharacterDatabaseTransaction *trans)
 
BagToBag ()
 
const BagToBag () const
 
bool IsLocked () const
 
bool IsBag () const
 
bool IsCurrencyToken () const
 
bool IsNotEmptyBag () const
 
bool IsBroken () const
 
bool CanBeTraded (bool mail=false, bool trade=false) const
 
void SetInTrade (bool b=true)
 
bool IsInTrade () const
 
bool HasEnchantRequiredSkill (Player const *player) const
 
uint32 GetEnchantRequiredLevel () const
 
bool IsFitToSpellRequirements (SpellInfo const *spellInfo) const
 
bool IsLimitedToAnotherMapOrZone (uint32 cur_mapId, uint32 cur_zoneId) const
 
bool GemsFitSockets () const
 
uint32 GetCount () const
 
void SetCount (uint32 value)
 
uint32 GetMaxStackCount () const
 
bool HasSocket () const
 
uint8 GetGemCountWithID (uint32 GemID) const
 
uint8 GetGemCountWithLimitCategory (uint32 limitCategory) const
 
InventoryResult CanBeMergedPartlyWith (ItemTemplate const *proto) const
 
uint8 GetSlot () const
 
BagGetContainer ()
 
uint8 GetBagSlot () const
 
void SetSlot (uint8 slot)
 
uint16 GetPos () const
 
void SetContainer (Bag *container)
 
bool IsInBag () const
 
bool IsEquipped () const
 
uint32 GetSkill ()
 
uint32 GetSpell ()
 
int32 GetItemRandomPropertyId () const
 
uint32 GetItemSuffixFactor () const
 
void SetItemRandomProperties (int32 randomPropId)
 
void UpdateItemSuffixFactor ()
 
void SetEnchantment (EnchantmentSlot slot, uint32 id, uint32 duration, uint32 charges, ObjectGuid caster=ObjectGuid::Empty)
 
void SetEnchantmentDuration (EnchantmentSlot slot, uint32 duration, Player *owner)
 
void SetEnchantmentCharges (EnchantmentSlot slot, uint32 charges)
 
void ClearEnchantment (EnchantmentSlot slot)
 
uint32 GetEnchantmentId (EnchantmentSlot slot) const
 
uint32 GetEnchantmentDuration (EnchantmentSlot slot) const
 
uint32 GetEnchantmentCharges (EnchantmentSlot slot) const
 
std::string const & GetText () const
 
void SetText (std::string const &text)
 
void SendUpdateSockets ()
 
void SendTimeUpdate (Player *owner)
 
void UpdateDuration (Player *owner, uint32 diff)
 
int32 GetSpellCharges (uint8 index=0) const
 
void SetSpellCharges (uint8 index, int32 value)
 
ItemUpdateState GetState () const
 
void SetState (ItemUpdateState state, Player *forplayer=nullptr)
 
void AddToUpdateQueueOf (Player *player)
 
void RemoveFromUpdateQueueOf (Player *player)
 
bool IsInUpdateQueue () const
 
uint32 GetQueuePos () const
 
void FSetState (ItemUpdateState state)
 
bool hasQuest (uint32 quest_id) const override
 
bool hasInvolvedQuest (uint32) const override
 
bool IsPotion () const
 
bool IsWeaponVellum () const
 
bool IsArmorVellum () const
 
bool IsConjuredConsumable () const
 
void SetNotRefundable (Player *owner, bool changestate=true, CharacterDatabaseTransaction *trans=nullptr)
 
void SetRefundRecipient (ObjectGuid::LowType pGuidLow)
 
void SetPaidMoney (uint32 money)
 
void SetPaidExtendedCost (uint32 iece)
 
ObjectGuid::LowType GetRefundRecipient ()
 
uint32 GetPaidMoney ()
 
uint32 GetPaidExtendedCost ()
 
void UpdatePlayedTime (Player *owner)
 
uint32 GetPlayedTime ()
 
bool IsRefundExpired ()
 
void SetSoulboundTradeable (AllowedLooterSet &allowedLooters)
 
void ClearSoulboundTradeable (Player *currentOwner)
 
bool CheckSoulboundTradeExpire ()
 
void BuildUpdate (UpdateDataMapType &data_map, UpdatePlayerSet &) override
 
void AddToObjectUpdate () override
 
void RemoveFromObjectUpdate () override
 
uint32 GetScriptId () const
 
std::string GetDebugInfo () const override
 
- Public Member Functions inherited from Object
virtual ~Object ()
 
bool IsInWorld () const
 
virtual void AddToWorld ()
 
virtual void RemoveFromWorld ()
 
ObjectGuid GetGUID () const
 
PackedGuid const & GetPackGUID () const
 
uint32 GetEntry () const
 
void SetEntry (uint32 entry)
 
float GetObjectScale () const
 
virtual void SetObjectScale (float scale)
 
virtual uint32 GetDynamicFlags () const
 
bool HasDynamicFlag (uint32 flag) const
 
virtual void SetDynamicFlag (uint32 flag)
 
virtual void RemoveDynamicFlag (uint32 flag)
 
virtual void ReplaceAllDynamicFlags (uint32 flag)
 
TypeID GetTypeId () const
 
bool isType (uint16 mask) const
 
virtual void BuildCreateUpdateBlockForPlayer (UpdateData *data, Player *target) const
 
void SendUpdateToPlayer (Player *player)
 
void BuildValuesUpdateBlockForPlayer (UpdateData *data, Player *target) const
 
void BuildOutOfRangeUpdateBlock (UpdateData *data) const
 
void BuildMovementUpdateBlock (UpdateData *data, uint32 flags=0) const
 
virtual void DestroyForPlayer (Player *target, bool onDeath=false) const
 
int32 GetInt32Value (uint16 index) const
 
uint32 GetUInt32Value (uint16 index) const
 
uint64 GetUInt64Value (uint16 index) const
 
float GetFloatValue (uint16 index) const
 
uint8 GetByteValue (uint16 index, uint8 offset) const
 
uint16 GetUInt16Value (uint16 index, uint8 offset) const
 
ObjectGuid GetGuidValue (uint16 index) const
 
void SetInt32Value (uint16 index, int32 value)
 
void SetUInt32Value (uint16 index, uint32 value)
 
void UpdateUInt32Value (uint16 index, uint32 value)
 
void SetUInt64Value (uint16 index, uint64 value)
 
void SetFloatValue (uint16 index, float value)
 
void SetByteValue (uint16 index, uint8 offset, uint8 value)
 
void SetUInt16Value (uint16 index, uint8 offset, uint16 value)
 
void SetInt16Value (uint16 index, uint8 offset, int16 value)
 
void SetGuidValue (uint16 index, ObjectGuid value)
 
void SetStatFloatValue (uint16 index, float value)
 
void SetStatInt32Value (uint16 index, int32 value)
 
bool AddGuidValue (uint16 index, ObjectGuid value)
 
bool RemoveGuidValue (uint16 index, ObjectGuid value)
 
void ApplyModUInt32Value (uint16 index, int32 val, bool apply)
 
void ApplyModInt32Value (uint16 index, int32 val, bool apply)
 
void ApplyModUInt64Value (uint16 index, int32 val, bool apply)
 
void ApplyModPositiveFloatValue (uint16 index, float val, bool apply)
 
void ApplyModSignedFloatValue (uint16 index, float val, bool apply)
 
void ApplyPercentModFloatValue (uint16 index, float val, bool apply)
 
void SetFlag (uint16 index, uint32 newFlag)
 
void RemoveFlag (uint16 index, uint32 oldFlag)
 
void ToggleFlag (uint16 index, uint32 flag)
 
bool HasFlag (uint16 index, uint32 flag) const
 
void ApplyModFlag (uint16 index, uint32 flag, bool apply)
 
void SetByteFlag (uint16 index, uint8 offset, uint8 newFlag)
 
void RemoveByteFlag (uint16 index, uint8 offset, uint8 newFlag)
 
bool HasByteFlag (uint16 index, uint8 offset, uint8 flag) const
 
void SetFlag64 (uint16 index, uint64 newFlag)
 
void RemoveFlag64 (uint16 index, uint64 oldFlag)
 
void ToggleFlag64 (uint16 index, uint64 flag)
 
bool HasFlag64 (uint16 index, uint64 flag) const
 
void ApplyModFlag64 (uint16 index, uint64 flag, bool apply)
 
void ClearUpdateMask (bool remove)
 
uint16 GetValuesCount () const
 
virtual bool hasQuest (uint32) const
 
virtual bool hasInvolvedQuest (uint32) const
 
virtual void BuildUpdate (UpdateDataMapType &, UpdatePlayerSet &)
 
void BuildFieldsUpdate (Player *, UpdateDataMapType &) const
 
void SetFieldNotifyFlag (uint16 flag)
 
void RemoveFieldNotifyFlag (uint16 flag)
 
void ForceValuesUpdateAtIndex (uint32)
 
bool IsPlayer () const
 
PlayerToPlayer ()
 
Player const * ToPlayer () const
 
CreatureToCreature ()
 
Creature const * ToCreature () const
 
UnitToUnit ()
 
Unit const * ToUnit () const
 
GameObjectToGameObject ()
 
GameObject const * ToGameObject () const
 
CorpseToCorpse ()
 
Corpse const * ToCorpse () const
 
DynamicObjectToDynObject ()
 
DynamicObject const * ToDynObject () const
 
virtual std::string GetDebugInfo () const
 

Static Public Member Functions

static ItemCreateItem (uint32 item, uint32 count, Player const *player=nullptr, bool clone=false, uint32 randomPropertyId=0)
 
static void DeleteFromDB (CharacterDatabaseTransaction trans, ObjectGuid::LowType itemGuid)
 
static void DeleteFromInventoryDB (CharacterDatabaseTransaction trans, ObjectGuid::LowType itemGuid)
 
static int32 GenerateItemRandomPropertyId (uint32 item_id)
 
- Static Public Member Functions inherited from Object
static ObjectGuid GetGUID (Object const *o)
 

Public Attributes

Loot loot
 
bool m_lootGenerated
 
- Public Attributes inherited from Object
DataMap CustomData
 

Private Attributes

std::string m_text
 
uint8 m_slot
 
Bagm_container
 
ItemUpdateState uState
 
int32 uQueuePos
 
bool mb_in_trade
 
time_t m_lastPlayedTimeUpdate
 
uint32 m_refundRecipient
 
uint32 m_paidMoney
 
uint32 m_paidExtendedCost
 
AllowedLooterSet allowedGUIDs
 

Additional Inherited Members

- Protected Member Functions inherited from Object
 Object ()
 
void _InitValues ()
 
void _Create (ObjectGuid::LowType guidlow, uint32 entry, HighGuid guidhigh)
 
std::string _ConcatFields (uint16 startIndex, uint16 size) const
 
bool _LoadIntoDataField (std::string const &data, uint32 startOffset, uint32 count)
 
uint32 GetUpdateFieldData (Player const *target, uint32 *&flags) const
 
void BuildMovementUpdate (ByteBuffer *data, uint16 flags) const
 
virtual void BuildValuesUpdate (uint8 updatetype, ByteBuffer *data, Player *target) const
 
virtual void AddToObjectUpdate ()=0
 
virtual void RemoveFromObjectUpdate ()=0
 
void AddToObjectUpdateIfNeeded ()
 
- Protected Attributes inherited from Object
uint16 m_objectType
 
TypeID m_objectTypeId
 
uint16 m_updateFlag
 
union {
   int32 *   m_int32Values
 
   uint32 *   m_uint32Values
 
   float *   m_floatValues
 
}; 
 
UpdateMask _changesMask
 
uint16 m_valuesCount
 
uint16 _fieldNotifyFlags
 
bool m_objectUpdated
 

Detailed Description

Constructor & Destructor Documentation

◆ Item()

Item::Item ( )
264{
267
269
271 m_slot = 0;
273 uQueuePos = -1;
274 m_container = nullptr;
275 m_lootGenerated = false;
276 mb_in_trade = false;
278
280 m_paidMoney = 0;
282}
@ ITEM_NEW
Definition: Item.h:205
@ TYPEID_ITEM
Definition: ObjectGuid.h:35
@ TYPEMASK_ITEM
Definition: ObjectGuid.h:49
@ UPDATEFLAG_LOWGUID
Definition: UpdateData.h:43
@ ITEM_END
Definition: UpdateFields.h:73
Seconds GetGameTime()
Definition: GameTime.cpp:38
int32 uQueuePos
Definition: Item.h:363
Bag * m_container
Definition: Item.h:361
bool mb_in_trade
Definition: Item.h:364
uint32 m_paidMoney
Definition: Item.h:367
time_t m_lastPlayedTimeUpdate
Definition: Item.h:365
uint32 m_paidExtendedCost
Definition: Item.h:368
bool m_lootGenerated
Definition: Item.h:312
uint32 m_refundRecipient
Definition: Item.h:366
uint8 m_slot
Definition: Item.h:360
ItemUpdateState uState
Definition: Item.h:362
uint16 m_objectType
Definition: Object.h:228
uint16 m_valuesCount
Definition: Object.h:242
uint16 m_updateFlag
Definition: Object.h:231
TypeID m_objectTypeId
Definition: Object.h:230

References GameTime::GetGameTime(), ITEM_END, ITEM_NEW, m_container, m_lastPlayedTimeUpdate, m_lootGenerated, Object::m_objectType, Object::m_objectTypeId, m_paidExtendedCost, m_paidMoney, m_refundRecipient, m_slot, Object::m_updateFlag, Object::m_valuesCount, mb_in_trade, TYPEID_ITEM, TYPEMASK_ITEM, UPDATEFLAG_LOWGUID, uQueuePos, and uState.

Member Function Documentation

◆ AddToObjectUpdate()

void Item::AddToObjectUpdate ( )
overridevirtual

Implements Object.

1163{
1164 if (Player* owner = GetOwner())
1165 owner->GetMap()->AddUpdateObject(this);
1166}
Player * GetOwner() const
Definition: Item.cpp:551
Definition: Player.h:1046

References GetOwner().

◆ AddToUpdateQueueOf()

void Item::AddToUpdateQueueOf ( Player player)
747{
748 if (IsInUpdateQueue())
749 return;
750
751 ASSERT(player);
752
753 if (player->GetGUID() != GetOwnerGUID())
754 {
755 LOG_DEBUG("entities.player.items", "Item::AddToUpdateQueueOf - Owner's guid ({}) and player's guid ({}) don't match!", GetOwnerGUID().ToString(), player->GetGUID().ToString());
756 return;
757 }
758
759 if (player->m_itemUpdateQueueBlocked)
760 return;
761
762 player->m_itemUpdateQueue.push_back(this);
763 uQueuePos = player->m_itemUpdateQueue.size() - 1;
764}
#define ASSERT
Definition: Errors.h:68
#define LOG_DEBUG(filterType__,...)
Definition: Log.h:171
std::string ToString(Type &&val, Params &&... params)
Definition: StringConvert.h:250
ObjectGuid GetOwnerGUID() const
Definition: Item.h:225
bool IsInUpdateQueue() const
Definition: Item.h:319
static ObjectGuid GetGUID(Object const *o)
Definition: Object.h:106
std::string ToString() const
Definition: ObjectGuid.cpp:47
std::vector< Item * > m_itemUpdateQueue
Definition: Player.h:2727
bool m_itemUpdateQueueBlocked
Definition: Player.h:2728

References ASSERT, Object::GetGUID(), GetOwnerGUID(), IsInUpdateQueue(), LOG_DEBUG, Player::m_itemUpdateQueue, Player::m_itemUpdateQueueBlocked, ObjectGuid::ToString(), and uQueuePos.

Referenced by SetState().

◆ BuildUpdate()

void Item::BuildUpdate ( UpdateDataMapType data_map,
UpdatePlayerSet  
)
overridevirtual

Reimplemented from Object.

1156{
1157 if (Player* owner = GetOwner())
1158 BuildFieldsUpdate(owner, data_map);
1159 ClearUpdateMask(false);
1160}
void BuildFieldsUpdate(Player *, UpdateDataMapType &) const
Definition: Object.cpp:545
void ClearUpdateMask(bool remove)
Definition: Object.cpp:533

References Object::BuildFieldsUpdate(), Object::ClearUpdateMask(), and GetOwner().

◆ CanBeMergedPartlyWith()

InventoryResult Item::CanBeMergedPartlyWith ( ItemTemplate const *  proto) const
870{
871 // not allow merge looting currently items
872 if (m_lootGenerated)
874
875 // check item type
876 if (GetEntry() != proto->ItemId)
878
879 // check free space (full stacks can't be target of merge
880 if (GetCount() >= proto->GetMaxStackSize())
882
883 return EQUIP_ERR_OK;
884}
@ EQUIP_ERR_ALREADY_LOOTED
Definition: Item.h:90
@ EQUIP_ERR_OK
Definition: Item.h:41
@ EQUIP_ERR_ITEM_CANT_STACK
Definition: Item.h:60
uint32 GetCount() const
Definition: Item.h:263
uint32 GetEntry() const
Definition: Object.h:109

References EQUIP_ERR_ALREADY_LOOTED, EQUIP_ERR_ITEM_CANT_STACK, EQUIP_ERR_OK, GetCount(), Object::GetEntry(), ItemTemplate::GetMaxStackSize(), ItemTemplate::ItemId, and m_lootGenerated.

Referenced by Player::CanStoreItem_InBag(), Player::CanStoreItem_InInventorySlots(), Player::CanStoreItem_InSpecificSlot(), and Player::CanStoreItems().

◆ CanBeTraded()

bool Item::CanBeTraded ( bool  mail = false,
bool  trade = false 
) const
797{
799 return false;
800
801 if (IsBag() && (Player::IsBagPos(GetPos()) || !((Bag const*)this)->IsEmpty()))
802 return false;
803
804 if (Player* owner = GetOwner())
805 {
806 if (owner->CanUnequipItem(GetPos(), false) != EQUIP_ERR_OK)
807 return false;
808
809 // Xinef: check if item is looted now
810 if (owner->GetLootGUID() == GetGUID())
811 return false;
812 }
813
814 if (IsBoundByTempEnchant()) // pussywizard
815 return false;
816
817 if ((!mail || !IsBoundAccountWide()) && IsBoundByEnchant())
818 return false;
819
820 return true;
821}
@ ITEM_FIELD_FLAG_BOP_TRADEABLE
Definition: ItemTemplate.h:118
@ ITEM_FIELD_FLAGS
Definition: UpdateFields.h:42
Definition: Bag.h:28
bool IsBoundByTempEnchant() const
Definition: Item.cpp:860
bool IsBoundAccountWide() const
Definition: Item.h:231
bool IsSoulBound() const
Definition: Item.h:230
uint16 GetPos() const
Definition: Item.h:276
bool IsBoundByEnchant() const
Definition: Item.cpp:849
bool IsBag() const
Definition: Item.h:248
bool HasFlag(uint16 index, uint32 flag) const
Definition: Object.cpp:889
ObjectGuid GetGUID() const
Definition: Object.h:107
static bool IsBagPos(uint16 pos)
Definition: PlayerStorage.cpp:621

References EQUIP_ERR_OK, Object::GetGUID(), GetOwner(), GetPos(), Object::HasFlag(), IsBag(), Player::IsBagPos(), IsBoundAccountWide(), IsBoundByEnchant(), IsBoundByTempEnchant(), IsSoulBound(), ITEM_FIELD_FLAG_BOP_TRADEABLE, and ITEM_FIELD_FLAGS.

Referenced by WorldSession::HandleAuctionSellItem(), WorldSession::HandleSendMail(), and WorldSession::HandleSetTradeItemOpcode().

◆ CheckSoulboundTradeExpire()

bool Item::CheckSoulboundTradeExpire ( )
1280{
1281 // called from owner's update - GetOwner() MUST be valid
1282 if (GetUInt32Value(ITEM_FIELD_CREATE_PLAYED_TIME) + 2 * HOUR < GetOwner()->GetTotalPlayedTime())
1283 {
1285 return true; // remove from tradeable list
1286 }
1287
1288 return false;
1289}
constexpr auto HOUR
Definition: Common.h:57
@ ITEM_FIELD_CREATE_PLAYED_TIME
Definition: UpdateFields.h:71
void ClearSoulboundTradeable(Player *currentOwner)
Definition: Item.cpp:1266
uint32 GetUInt32Value(uint16 index) const
Definition: Object.cpp:305

References ClearSoulboundTradeable(), GetOwner(), Object::GetUInt32Value(), HOUR, and ITEM_FIELD_CREATE_PLAYED_TIME.

◆ ClearEnchantment()

void Item::ClearEnchantment ( EnchantmentSlot  slot)
963{
964 if (!GetEnchantmentId(slot))
965 return;
966
967 for (uint8 x = 0; x < MAX_SPELL_ITEM_ENCHANTMENT_EFFECTS; ++x)
970}
std::uint8_t uint8
Definition: Define.h:110
#define MAX_ENCHANTMENT_OFFSET
Definition: Item.h:191
@ ITEM_CHANGED
Definition: Item.h:204
@ ITEM_FIELD_ENCHANTMENT_1_1
Definition: UpdateFields.h:43
#define MAX_SPELL_ITEM_ENCHANTMENT_EFFECTS
Definition: DBCStructure.h:1814
void SetState(ItemUpdateState state, Player *forplayer=nullptr)
Definition: Item.cpp:716
uint32 GetEnchantmentId(EnchantmentSlot slot) const
Definition: Item.h:295
void SetUInt32Value(uint16 index, uint32 value)
Definition: Object.cpp:650

References GetEnchantmentId(), GetOwner(), ITEM_CHANGED, ITEM_FIELD_ENCHANTMENT_1_1, MAX_ENCHANTMENT_OFFSET, MAX_SPELL_ITEM_ENCHANTMENT_EFFECTS, SetState(), and Object::SetUInt32Value().

Referenced by Player::CastItemCombatSpell(), WorldSession::HandleCancelTempEnchantmentOpcode(), and Player::SetVirtualItemSlot().

◆ ClearSoulboundTradeable()

void Item::ClearSoulboundTradeable ( Player currentOwner)
1267{
1269 if (allowedGUIDs.empty())
1270 return;
1271
1272 allowedGUIDs.clear();
1273 SetState(ITEM_CHANGED, currentOwner);
1275 stmt->SetData(0, GetGUID().GetCounter());
1276 CharacterDatabase.Execute(stmt);
1277}
DatabaseWorkerPool< CharacterDatabaseConnection > CharacterDatabase
Accessor to the character database.
Definition: DatabaseEnv.cpp:21
@ CHAR_DEL_ITEM_BOP_TRADE
Definition: CharacterDatabase.h:121
Definition: PreparedStatement.h:158
Acore::Types::is_default< T > SetData(const uint8 index, T value)
Definition: PreparedStatement.h:78
AllowedLooterSet allowedGUIDs
Definition: Item.h:369
void RemoveFlag(uint16 index, uint32 oldFlag)
Definition: Object.cpp:860

References allowedGUIDs, CHAR_DEL_ITEM_BOP_TRADE, CharacterDatabase, Object::GetGUID(), ITEM_CHANGED, ITEM_FIELD_FLAG_BOP_TRADEABLE, ITEM_FIELD_FLAGS, Object::RemoveFlag(), PreparedStatementBase::SetData(), and SetState().

Referenced by Player::_LoadItem(), Player::_StoreItem(), CheckSoulboundTradeExpire(), Player::DestroyItem(), Spell::EffectEnchantItemPerm(), Spell::EffectEnchantItemPrismatic(), Spell::EffectEnchantItemTmp(), Player::EquipItem(), and WorldSession::HandleSocketOpcode().

◆ CloneItem()

Item * Item::CloneItem ( uint32  count,
Player const *  player = nullptr 
) const
1121{
1122 // player CAN be nullptr in which case we must not update random properties because that accesses player's item update queue
1123 Item* newItem = CreateItem(GetEntry(), count, player, true, player ? GetItemRandomPropertyId() : 0);
1124 if (!newItem)
1125 return nullptr;
1126
1131 return newItem;
1132}
@ ITEM_FIELD_FLAG_REFUNDABLE
Definition: ItemTemplate.h:122
@ ITEM_FIELD_DURATION
Definition: UpdateFields.h:40
@ ITEM_FIELD_CREATOR
Definition: UpdateFields.h:37
@ ITEM_FIELD_GIFTCREATOR
Definition: UpdateFields.h:38
Definition: Item.h:214
static Item * CreateItem(uint32 item, uint32 count, Player const *player=nullptr, bool clone=false, uint32 randomPropertyId=0)
Definition: Item.cpp:1089
int32 GetItemRandomPropertyId() const
Definition: Item.h:286

References CreateItem(), Object::GetEntry(), GetItemRandomPropertyId(), Object::GetUInt32Value(), ITEM_FIELD_CREATOR, ITEM_FIELD_DURATION, ITEM_FIELD_FLAG_BOP_TRADEABLE, ITEM_FIELD_FLAG_REFUNDABLE, ITEM_FIELD_FLAGS, ITEM_FIELD_GIFTCREATOR, and Object::SetUInt32Value().

Referenced by Guild::BankMoveItemData::_StoreItem(), Player::_StoreItem(), WorldSession::HandleAuctionSellItem(), WorldSession::HandleSellItemOpcode(), and Player::SplitItem().

◆ Create()

bool Item::Create ( ObjectGuid::LowType  guidlow,
uint32  itemid,
Player const *  owner 
)
virtual

Reimplemented in Bag.

285{
286 Object::_Create(guidlow, 0, HighGuid::Item);
287
288 SetEntry(itemid);
289 SetObjectScale(1.0f);
290
291 SetGuidValue(ITEM_FIELD_OWNER, owner ? owner->GetGUID() : ObjectGuid::Empty);
292 SetGuidValue(ITEM_FIELD_CONTAINED, owner ? owner->GetGUID() : ObjectGuid::Empty);
293
294 ItemTemplate const* itemProto = sObjectMgr->GetItemTemplate(itemid);
295 if (!itemProto)
296 return false;
297
301
302 for (uint8 i = 0; i < MAX_ITEM_PROTO_SPELLS; ++i)
303 SetSpellCharges(i, itemProto->Spells[i].SpellCharges);
304
307 sScriptMgr->OnItemCreate(this, itemProto, owner);
308 return true;
309}
#define MAX_ITEM_PROTO_SPELLS
Definition: ItemTemplate.h:624
@ ITEM_FIELD_DURABILITY
Definition: UpdateFields.h:69
@ ITEM_FIELD_STACK_COUNT
Definition: UpdateFields.h:39
@ ITEM_FIELD_MAXDURABILITY
Definition: UpdateFields.h:70
@ ITEM_FIELD_OWNER
Definition: UpdateFields.h:35
@ ITEM_FIELD_CONTAINED
Definition: UpdateFields.h:36
#define sObjectMgr
Definition: ObjectMgr.h:1640
#define sScriptMgr
Definition: ScriptMgr.h:2702
void SetSpellCharges(uint8 index, int32 value)
Definition: Item.h:309
int32 SpellCharges
Definition: ItemTemplate.h:602
Definition: ItemTemplate.h:628
_Spell Spells[MAX_ITEM_PROTO_SPELLS]
Definition: ItemTemplate.h:671
uint32 MaxDurability
Definition: ItemTemplate.h:685
uint32 Duration
Definition: ItemTemplate.h:695
void _Create(ObjectGuid::LowType guidlow, uint32 entry, HighGuid guidhigh)
Definition: Object.cpp:134
void SetGuidValue(uint16 index, ObjectGuid value)
Definition: Object.cpp:723
void SetEntry(uint32 entry)
Definition: Object.h:110
virtual void SetObjectScale(float scale)
Definition: Object.h:113
static ObjectGuid const Empty
Definition: ObjectGuid.h:122

References Object::_Create(), ItemTemplate::Duration, ObjectGuid::Empty, Object::GetGUID(), ITEM_FIELD_CONTAINED, ITEM_FIELD_CREATE_PLAYED_TIME, ITEM_FIELD_DURABILITY, ITEM_FIELD_DURATION, ITEM_FIELD_MAXDURABILITY, ITEM_FIELD_OWNER, ITEM_FIELD_STACK_COUNT, MAX_ITEM_PROTO_SPELLS, ItemTemplate::MaxDurability, Object::SetEntry(), Object::SetGuidValue(), Object::SetObjectScale(), SetSpellCharges(), Object::SetUInt32Value(), sObjectMgr, _Spell::SpellCharges, ItemTemplate::Spells, and sScriptMgr.

Referenced by CreateItem(), and WorldSession::HandleMailCreateTextItem().

◆ CreateItem()

Item * Item::CreateItem ( uint32  item,
uint32  count,
Player const *  player = nullptr,
bool  clone = false,
uint32  randomPropertyId = 0 
)
static
1090{
1091 if (count < 1)
1092 return nullptr; //don't create item at zero count
1093
1094 ItemTemplate const* pProto = sObjectMgr->GetItemTemplate(item);
1095 if (pProto)
1096 {
1097 if (count > pProto->GetMaxStackSize())
1098 count = pProto->GetMaxStackSize();
1099
1100 ASSERT_NODEBUGINFO(count != 0 && "pProto->Stackable == 0 but checked at loading already");
1101
1102 Item* pItem = NewItemOrBag(pProto);
1103 if (pItem->Create(sObjectMgr->GetGenerator<HighGuid::Item>().Generate(), item, player))
1104 {
1105 pItem->SetCount(count);
1106 if (!clone)
1107 pItem->SetItemRandomProperties(randomPropertyId ? randomPropertyId : Item::GenerateItemRandomPropertyId(item));
1108 else if (randomPropertyId)
1109 pItem->SetItemRandomProperties(randomPropertyId);
1110 return pItem;
1111 }
1112 else
1113 delete pItem;
1114 }
1115 else
1116 ABORT();
1117 return nullptr;
1118}
#define ABORT
Definition: Errors.h:76
#define ASSERT_NODEBUGINFO
Definition: Errors.h:69
Item * NewItemOrBag(ItemTemplate const *proto)
Definition: Bag.h:67
virtual bool Create(ObjectGuid::LowType guidlow, uint32 itemid, Player const *owner)
Definition: Item.cpp:284
void SetItemRandomProperties(int32 randomPropId)
Definition: Item.cpp:670
void SetCount(uint32 value)
Definition: Item.h:264
static int32 GenerateItemRandomPropertyId(uint32 item_id)
Definition: Item.cpp:624
uint32 GetMaxStackSize() const
Definition: ItemTemplate.h:738

References ABORT, ASSERT_NODEBUGINFO, Create(), GenerateItemRandomPropertyId(), ItemTemplate::GetMaxStackSize(), NewItemOrBag(), SetCount(), SetItemRandomProperties(), and sObjectMgr.

Referenced by Player::CanEquipNewItem(), CloneItem(), AchievementMgr::CompletedAchievement(), Spell::EffectSummonChangeItem(), Player::EquipNewItem(), item_commandscript::HandleItemRefundCommand(), item_commandscript::HandleItemRestoreCommand(), quest_commandscript::HandleQuestComplete(), quest_commandscript::HandleQuestReward(), send_commandscript::HandleSendItemsCommand(), MailDraft::prepareItems(), Player::SendItemRetrievalMail(), ObjectMgr::SendServerMail(), and Player::StoreNewItem().

◆ DeleteFromDB() [1/2]

void Item::DeleteFromDB ( CharacterDatabaseTransaction  trans)
virtual

Reimplemented in Bag.

529{
530 DeleteFromDB(trans, GetGUID().GetCounter());
531}
static void DeleteFromDB(CharacterDatabaseTransaction trans, ObjectGuid::LowType itemGuid)
Definition: Item.cpp:520

References DeleteFromDB(), and Object::GetGUID().

◆ DeleteFromDB() [2/2]

void Item::DeleteFromDB ( CharacterDatabaseTransaction  trans,
ObjectGuid::LowType  itemGuid 
)
static
521{
522 sScriptMgr->OnGlobalItemDelFromDB(trans, itemGuid);
524 stmt->SetData(0, itemGuid);
525 trans->Append(stmt);
526}
@ CHAR_DEL_ITEM_INSTANCE
Definition: CharacterDatabase.h:127

References CHAR_DEL_ITEM_INSTANCE, CharacterDatabase, PreparedStatementBase::SetData(), and sScriptMgr.

Referenced by Player::_LoadItem(), Guild::BankMoveItemData::_StoreItem(), DeleteFromDB(), Bag::DeleteFromDB(), and WorldSession::HandleAuctionSellItem().

◆ DeleteFromInventoryDB() [1/2]

void Item::DeleteFromInventoryDB ( CharacterDatabaseTransaction  trans)
542{
543 DeleteFromInventoryDB(trans, GetGUID().GetCounter());
544}
static void DeleteFromInventoryDB(CharacterDatabaseTransaction trans, ObjectGuid::LowType itemGuid)
Definition: Item.cpp:534

References DeleteFromInventoryDB(), and Object::GetGUID().

◆ DeleteFromInventoryDB() [2/2]

void Item::DeleteFromInventoryDB ( CharacterDatabaseTransaction  trans,
ObjectGuid::LowType  itemGuid 
)
static

◆ DeleteRefundDataFromDB()

void Item::DeleteRefundDataFromDB ( CharacterDatabaseTransaction trans)
1193{
1194 if (trans)
1195 {
1197 stmt->SetData(0, GetGUID().GetCounter());
1198 (*trans)->Append(stmt);
1199 }
1200}
@ CHAR_DEL_ITEM_REFUND_INSTANCE
Definition: CharacterDatabase.h:371

References CHAR_DEL_ITEM_REFUND_INSTANCE, CharacterDatabase, Object::GetGUID(), and PreparedStatementBase::SetData().

Referenced by SetNotRefundable().

◆ FSetState()

void Item::FSetState ( ItemUpdateState  state)
inline

◆ GemsFitSockets()

bool Item::GemsFitSockets ( ) const
973{
974 for (uint32 enchant_slot = SOCK_ENCHANTMENT_SLOT; enchant_slot < SOCK_ENCHANTMENT_SLOT + MAX_GEM_SOCKETS; ++enchant_slot)
975 {
977
978 if (!SocketColor) // no socket slot
979 continue;
980
981 uint32 enchant_id = GetEnchantmentId(EnchantmentSlot(enchant_slot));
982 if (!enchant_id) // no gems on this socket
983 return false;
984
985 SpellItemEnchantmentEntry const* enchantEntry = sSpellItemEnchantmentStore.LookupEntry(enchant_id);
986 if (!enchantEntry) // invalid gem id on this socket
987 return false;
988
989 uint8 GemColor = 0;
990
991 uint32 gemid = enchantEntry->GemID;
992 if (gemid)
993 {
994 ItemTemplate const* gemProto = sObjectMgr->GetItemTemplate(gemid);
995 if (gemProto)
996 {
997 GemPropertiesEntry const* gemProperty = sGemPropertiesStore.LookupEntry(gemProto->GemProperties);
998 if (gemProperty)
999 GemColor = gemProperty->color;
1000 }
1001 }
1002
1003 if (!(GemColor & SocketColor)) // bad gem color on this socket
1004 return false;
1005 }
1006 return true;
1007}
std::uint32_t uint32
Definition: Define.h:108
DBCStorage< SpellItemEnchantmentEntry > sSpellItemEnchantmentStore(SpellItemEnchantmentfmt)
DBCStorage< GemPropertiesEntry > sGemPropertiesStore(GemPropertiesEntryfmt)
#define MAX_GEM_SOCKETS
Definition: Item.h:182
EnchantmentSlot
Definition: Item.h:162
@ SOCK_ENCHANTMENT_SLOT
Definition: Item.h:165
SocketColor
Definition: ItemTemplate.h:254
ItemTemplate const * GetTemplate() const
Definition: Item.cpp:546
uint32 Color
Definition: ItemTemplate.h:611
uint32 GemProperties
Definition: ItemTemplate.h:692
_Socket Socket[MAX_ITEM_PROTO_SOCKETS]
Definition: ItemTemplate.h:690
Definition: DBCStructure.h:1005
uint32 color
Definition: DBCStructure.h:1008
Definition: DBCStructure.h:1817
uint32 GemID
Definition: DBCStructure.h:1828

References _Socket::Color, GemPropertiesEntry::color, SpellItemEnchantmentEntry::GemID, ItemTemplate::GemProperties, GetEnchantmentId(), GetTemplate(), MAX_GEM_SOCKETS, sGemPropertiesStore, sObjectMgr, SOCK_ENCHANTMENT_SLOT, ItemTemplate::Socket, and sSpellItemEnchantmentStore.

Referenced by WorldSession::HandleSocketOpcode().

◆ GenerateItemRandomPropertyId()

int32 Item::GenerateItemRandomPropertyId ( uint32  item_id)
static
625{
626 ItemTemplate const* itemProto = sObjectMgr->GetItemTemplate(item_id);
627
628 if (!itemProto)
629 return 0;
630
631 // item must have one from this field values not null if it can have random enchantments
632 if ((!itemProto->RandomProperty) && (!itemProto->RandomSuffix))
633 return 0;
634
635 // item can have not null only one from field values
636 if ((itemProto->RandomProperty) && (itemProto->RandomSuffix))
637 {
638 LOG_ERROR("sql.sql", "Item template {} have RandomProperty == {} and RandomSuffix == {}, but must have one from field =0", itemProto->ItemId, itemProto->RandomProperty, itemProto->RandomSuffix);
639 return 0;
640 }
641
642 // RandomProperty case
643 if (itemProto->RandomProperty)
644 {
645 uint32 randomPropId = GetItemEnchantMod(itemProto->RandomProperty);
646 ItemRandomPropertiesEntry const* random_id = sItemRandomPropertiesStore.LookupEntry(randomPropId);
647 if (!random_id)
648 {
649 LOG_ERROR("sql.sql", "Enchantment id #{} used but it doesn't have records in 'ItemRandomProperties.dbc'", randomPropId);
650 return 0;
651 }
652
653 return random_id->ID;
654 }
655 // RandomSuffix case
656 else
657 {
658 uint32 randomPropId = GetItemEnchantMod(itemProto->RandomSuffix);
659 ItemRandomSuffixEntry const* random_id = sItemRandomSuffixStore.LookupEntry(randomPropId);
660 if (!random_id)
661 {
662 LOG_ERROR("sql.sql", "Enchantment id #{} used but it doesn't have records in sItemRandomSuffixStore.", randomPropId);
663 return 0;
664 }
665
666 return -int32(random_id->ID);
667 }
668}
std::int32_t int32
Definition: Define.h:104
#define LOG_ERROR(filterType__,...)
Definition: Log.h:159
DBCStorage< ItemRandomSuffixEntry > sItemRandomSuffixStore(ItemRandomSuffixfmt)
DBCStorage< ItemRandomPropertiesEntry > sItemRandomPropertiesStore(ItemRandomPropertiesfmt)
uint32 GetItemEnchantMod(int32 entry)
Definition: ItemEnchantmentMgr.cpp:81
int32 RandomProperty
Definition: ItemTemplate.h:681
int32 RandomSuffix
Definition: ItemTemplate.h:682
uint32 ItemId
Definition: ItemTemplate.h:629
Definition: DBCStructure.h:1186
uint32 ID
Definition: DBCStructure.h:1187
Definition: DBCStructure.h:1196
uint32 ID
Definition: DBCStructure.h:1197

References GetItemEnchantMod(), ItemRandomPropertiesEntry::ID, ItemRandomSuffixEntry::ID, ItemTemplate::ItemId, LOG_ERROR, ItemTemplate::RandomProperty, ItemTemplate::RandomSuffix, sItemRandomPropertiesStore, sItemRandomSuffixStore, and sObjectMgr.

Referenced by CreateItem(), and LootItem::LootItem().

◆ GetBagSlot()

◆ GetContainer()

Bag * Item::GetContainer ( )
inline

◆ GetCount()

◆ GetDebugInfo()

std::string Item::GetDebugInfo ( ) const
overridevirtual

Reimplemented from Object.

1292{
1293 std::stringstream sstr;
1294 sstr << Object::GetDebugInfo() << "\n"
1295 << std::boolalpha
1296 << "Owner: " << GetOwnerGUID().ToString() << " Count: " << GetCount()
1297 << " BagSlot: " << std::to_string(GetBagSlot()) << " Slot: " << std::to_string(GetSlot()) << " Equipped: " << IsEquipped();
1298 return sstr.str();
1299}
bool IsEquipped() const
Definition: Item.cpp:791
uint8 GetBagSlot() const
Definition: Item.cpp:786
virtual std::string GetDebugInfo() const
Definition: Object.cpp:1009

References GetBagSlot(), GetCount(), Object::GetDebugInfo(), GetOwnerGUID(), GetSlot(), IsEquipped(), and ObjectGuid::ToString().

Referenced by Bag::GetDebugInfo().

◆ GetEnchantmentCharges()

◆ GetEnchantmentDuration()

◆ GetEnchantmentId()

◆ GetEnchantRequiredLevel()

uint32 Item::GetEnchantRequiredLevel ( ) const
836{
837 uint32 level = 0;
838
839 // Check all enchants for required level
840 for (uint32 enchant_slot = PERM_ENCHANTMENT_SLOT; enchant_slot < MAX_ENCHANTMENT_SLOT; ++enchant_slot)
841 if (uint32 enchant_id = GetEnchantmentId(EnchantmentSlot(enchant_slot)))
842 if (SpellItemEnchantmentEntry const* enchantEntry = sSpellItemEnchantmentStore.LookupEntry(enchant_id))
843 if (enchantEntry->requiredLevel > level)
844 level = enchantEntry->requiredLevel;
845
846 return level;
847}
@ PERM_ENCHANTMENT_SLOT
Definition: Item.h:163
@ MAX_ENCHANTMENT_SLOT
Definition: Item.h:177

References GetEnchantmentId(), MAX_ENCHANTMENT_SLOT, PERM_ENCHANTMENT_SLOT, and sSpellItemEnchantmentStore.

◆ GetGemCountWithID()

uint8 Item::GetGemCountWithID ( uint32  GemID) const
1017{
1018 uint8 count = 0;
1019 for (uint32 enchant_slot = SOCK_ENCHANTMENT_SLOT; enchant_slot < SOCK_ENCHANTMENT_SLOT + MAX_GEM_SOCKETS; ++enchant_slot)
1020 {
1021 uint32 enchant_id = GetEnchantmentId(EnchantmentSlot(enchant_slot));
1022 if (!enchant_id)
1023 continue;
1024
1025 SpellItemEnchantmentEntry const* enchantEntry = sSpellItemEnchantmentStore.LookupEntry(enchant_id);
1026 if (!enchantEntry)
1027 continue;
1028
1029 if (GemID == enchantEntry->GemID)
1030 ++count;
1031 }
1032 return count;
1033}

References SpellItemEnchantmentEntry::GemID, GetEnchantmentId(), MAX_GEM_SOCKETS, SOCK_ENCHANTMENT_SLOT, and sSpellItemEnchantmentStore.

Referenced by Bag::GetItemCount(), and Player::HasItemOrGemWithIdEquipped().

◆ GetGemCountWithLimitCategory()

uint8 Item::GetGemCountWithLimitCategory ( uint32  limitCategory) const
1036{
1037 uint8 count = 0;
1038 for (uint32 enchant_slot = SOCK_ENCHANTMENT_SLOT; enchant_slot < SOCK_ENCHANTMENT_SLOT + MAX_GEM_SOCKETS; ++enchant_slot)
1039 {
1040 uint32 enchant_id = GetEnchantmentId(EnchantmentSlot(enchant_slot));
1041 if (!enchant_id)
1042 continue;
1043
1044 SpellItemEnchantmentEntry const* enchantEntry = sSpellItemEnchantmentStore.LookupEntry(enchant_id);
1045 if (!enchantEntry)
1046 continue;
1047
1048 ItemTemplate const* gemProto = sObjectMgr->GetItemTemplate(enchantEntry->GemID);
1049 if (!gemProto)
1050 continue;
1051
1052 if (gemProto->ItemLimitCategory == limitCategory)
1053 ++count;
1054 }
1055 return count;
1056}
uint32 ItemLimitCategory
Definition: ItemTemplate.h:696

References SpellItemEnchantmentEntry::GemID, GetEnchantmentId(), ItemTemplate::ItemLimitCategory, MAX_GEM_SOCKETS, sObjectMgr, SOCK_ENCHANTMENT_SLOT, and sSpellItemEnchantmentStore.

Referenced by Player::CanEquipUniqueItem(), and Player::HasItemOrGemWithLimitCategoryEquipped().

◆ GetItemRandomPropertyId()

◆ GetItemSuffixFactor()

◆ GetMaxStackCount()

◆ GetOwner()

◆ GetOwnerGUID()

◆ GetPaidExtendedCost()

uint32 Item::GetPaidExtendedCost ( )
inline

◆ GetPaidMoney()

uint32 Item::GetPaidMoney ( )
inline

◆ GetPlayedTime()

uint32 Item::GetPlayedTime ( )

◆ GetPos()

◆ GetQueuePos()

uint32 Item::GetQueuePos ( ) const
inline

◆ GetRefundRecipient()

ObjectGuid::LowType Item::GetRefundRecipient ( )
inline

◆ GetScriptId()

◆ GetSkill()

uint32 Item::GetSkill ( )
558{
559 return GetTemplate()->GetSkill();
560}
uint32 GetSkill() const
Definition: ItemTemplate.h:791

References ItemTemplate::GetSkill(), and GetTemplate().

Referenced by Player::CanUseItem(), Player::GetBaseWeaponSkillValue(), Unit::GetWeaponSkillValue(), and Player::UpdateWeaponSkill().

◆ GetSlot()

◆ GetSpell()

uint32 Item::GetSpell ( )
563{
564 ItemTemplate const* proto = GetTemplate();
565
566 switch (proto->Class)
567 {
569 switch (proto->SubClass)
570 {
572 return 196;
574 return 197;
576 return 264;
578 return 266;
580 return 198;
582 return 199;
584 return 200;
586 return 201;
588 return 202;
590 return 227;
592 return 1180;
594 return 2567;
596 return 3386;
598 return 5011;
600 return 5009;
601 default:
602 return 0;
603 }
604 case ITEM_CLASS_ARMOR:
605 switch (proto->SubClass)
606 {
608 return 9078;
610 return 9077;
612 return 8737;
614 return 750;
616 return 9116;
617 default:
618 return 0;
619 }
620 }
621 return 0;
622}
@ ITEM_SUBCLASS_WEAPON_CROSSBOW
Definition: ItemTemplate.h:371
@ ITEM_SUBCLASS_WEAPON_GUN
Definition: ItemTemplate.h:356
@ ITEM_SUBCLASS_WEAPON_AXE2
Definition: ItemTemplate.h:354
@ ITEM_SUBCLASS_WEAPON_SPEAR
Definition: ItemTemplate.h:370
@ ITEM_SUBCLASS_WEAPON_STAFF
Definition: ItemTemplate.h:363
@ ITEM_SUBCLASS_WEAPON_MACE
Definition: ItemTemplate.h:357
@ ITEM_SUBCLASS_WEAPON_MACE2
Definition: ItemTemplate.h:358
@ ITEM_SUBCLASS_WEAPON_DAGGER
Definition: ItemTemplate.h:368
@ ITEM_SUBCLASS_WEAPON_BOW
Definition: ItemTemplate.h:355
@ ITEM_SUBCLASS_WEAPON_SWORD
Definition: ItemTemplate.h:360
@ ITEM_SUBCLASS_WEAPON_AXE
Definition: ItemTemplate.h:353
@ ITEM_SUBCLASS_WEAPON_WAND
Definition: ItemTemplate.h:372
@ ITEM_SUBCLASS_WEAPON_THROWN
Definition: ItemTemplate.h:369
@ ITEM_SUBCLASS_WEAPON_SWORD2
Definition: ItemTemplate.h:361
@ ITEM_SUBCLASS_WEAPON_POLEARM
Definition: ItemTemplate.h:359
@ ITEM_SUBCLASS_ARMOR_MAIL
Definition: ItemTemplate.h:402
@ ITEM_SUBCLASS_ARMOR_CLOTH
Definition: ItemTemplate.h:400
@ ITEM_SUBCLASS_ARMOR_LEATHER
Definition: ItemTemplate.h:401
@ ITEM_SUBCLASS_ARMOR_SHIELD
Definition: ItemTemplate.h:405
@ ITEM_SUBCLASS_ARMOR_PLATE
Definition: ItemTemplate.h:403
@ ITEM_CLASS_ARMOR
Definition: ItemTemplate.h:304
@ ITEM_CLASS_WEAPON
Definition: ItemTemplate.h:302
uint32 Class
Definition: ItemTemplate.h:630
uint32 SubClass
Definition: ItemTemplate.h:631

References ItemTemplate::Class, GetTemplate(), ITEM_CLASS_ARMOR, ITEM_CLASS_WEAPON, ITEM_SUBCLASS_ARMOR_CLOTH, ITEM_SUBCLASS_ARMOR_LEATHER, ITEM_SUBCLASS_ARMOR_MAIL, ITEM_SUBCLASS_ARMOR_PLATE, ITEM_SUBCLASS_ARMOR_SHIELD, ITEM_SUBCLASS_WEAPON_AXE, ITEM_SUBCLASS_WEAPON_AXE2, ITEM_SUBCLASS_WEAPON_BOW, ITEM_SUBCLASS_WEAPON_CROSSBOW, ITEM_SUBCLASS_WEAPON_DAGGER, ITEM_SUBCLASS_WEAPON_GUN, ITEM_SUBCLASS_WEAPON_MACE, ITEM_SUBCLASS_WEAPON_MACE2, ITEM_SUBCLASS_WEAPON_POLEARM, ITEM_SUBCLASS_WEAPON_SPEAR, ITEM_SUBCLASS_WEAPON_STAFF, ITEM_SUBCLASS_WEAPON_SWORD, ITEM_SUBCLASS_WEAPON_SWORD2, ITEM_SUBCLASS_WEAPON_THROWN, ITEM_SUBCLASS_WEAPON_WAND, and ItemTemplate::SubClass.

◆ GetSpellCharges()

int32 Item::GetSpellCharges ( uint8  index = 0) const
inline

◆ GetState()

◆ GetTemplate()

ItemTemplate const * Item::GetTemplate ( ) const
547{
548 return sObjectMgr->GetItemTemplate(GetEntry());
549}

References Object::GetEntry(), and sObjectMgr.

Referenced by Player::_ApplyAllItemMods(), Player::_ApplyAllLevelScaleItemMods(), Player::_ApplyItemMods(), Player::_LoadItem(), Player::_RemoveAllItemMods(), Player::_SaveInventory(), Player::_StoreItem(), AddItemsSetItem(), Player::AddQuestAndCheckCompletion(), Player::ApplyEnchantment(), Player::ApplyEquipCooldown(), Player::ApplyItemEquipSpell(), Player::AutoUnequipOffhandIfNeed(), AuctionHouseObject::BuildListAuctionItems(), AuraEffect::CalculateAmount(), Player::CanBankItem(), Player::CanEquipItem(), Player::CanEquipUniqueItem(), Player::CanStoreItem_InBag(), Player::CanStoreItem_InSpecificSlot(), Player::CanStoreItems(), Player::CanUnequipItem(), Player::CanUseItem(), Player::CastItemUseSpell(), Player::CheckAmmoCompatibility(), Spell::CheckCast(), Spell::CheckItems(), Player::CreateCorpse(), Player::DestroyItem(), Spell::DoCreateItem(), WorldSession::DoLootRelease(), Spell::DoSpellHitOnUnit(), Player::DurabilityRepair(), Spell::EffectDisEnchant(), Spell::EffectEnchantItemPerm(), Spell::EffectFeedPet(), Spell::EffectMilling(), Spell::EffectOpenLock(), Spell::EffectProspecting(), Player::EquipItem(), EquippedOk(), GemsFitSockets(), AuctionHouseMgr::GetAuctionDeposit(), Player::GetAverageItemLevel(), Player::GetAverageItemLevelForDF(), Player::GetItemCount(), Bag::GetItemCount(), GetMaxStackCount(), GetScriptId(), Player::GetShield(), GetSkill(), GetSpell(), Unit::GetUnitBlockChance(), Player::GetWeaponForAttack(), WorldSession::HandleAuctionSellItem(), WorldSession::HandleAutoEquipItemOpcode(), debug_commandscript::HandleDebugItemExpireCommand(), WorldSession::HandleDestroyItemOpcode(), WorldSession::HandleOpenItemOpcode(), WorldSession::HandleOpenWrappedItemCallback(), WorldSession::HandleReadItem(), WorldSession::HandleSellItemOpcode(), WorldSession::HandleSendMail(), WorldSession::HandleSocketOpcode(), WorldSession::HandleUseItemOpcode(), WorldSession::HandleWrapItemOpcode(), Player::HasItemOrGemWithIdEquipped(), Player::HasItemOrGemWithLimitCategoryEquipped(), Player::HasItemTotemCategory(), hasQuest(), HasSocket(), IsArmorVellum(), IsBag(), IsBoundAccountWide(), IsConjuredConsumable(), IsCurrencyToken(), IsFitToSpellRequirements(), IsLimitedToAnotherMapOrZone(), IsPotion(), Unit::IsTriggeredAtSpellProcEvent(), Player::IsTwoHandUsed(), IsWeaponVellum(), LoadFromDB(), Bag::LoadFromDB(), WorldSession::recoveryItem(), Player::RemoveItem(), Player::SendEquipError(), Player::SendLoot(), Player::SetRegularAttackTime(), Player::StoreItem(), Player::StoreNewItem(), Spell::SummonGuardian(), Player::SwapItem(), Spell::TakeAmmo(), Spell::TakeCastItem(), Spell::TakeReagents(), Player::ToggleMetaGemsActive(), UpdateDuration(), Player::UpdateItemDuration(), Player::UpdateWeaponSkill(), Player::VisualizeItem(), and Spell::WriteAmmoToPacket().

◆ GetText()

std::string const & Item::GetText ( ) const
inline
299{ return m_text; }
std::string m_text
Definition: Item.h:359

References m_text.

◆ HasEnchantRequiredSkill()

bool Item::HasEnchantRequiredSkill ( Player const *  player) const
824{
825 // Check all enchants for required skill
826 for (uint32 enchant_slot = PERM_ENCHANTMENT_SLOT; enchant_slot < MAX_ENCHANTMENT_SLOT; ++enchant_slot)
827 if (uint32 enchant_id = GetEnchantmentId(EnchantmentSlot(enchant_slot)))
828 if (SpellItemEnchantmentEntry const* enchantEntry = sSpellItemEnchantmentStore.LookupEntry(enchant_id))
829 if (enchantEntry->requiredSkill && player->GetSkillValue(enchantEntry->requiredSkill) < enchantEntry->requiredSkillValue)
830 return false;
831
832 return true;
833}

References GetEnchantmentId(), Player::GetSkillValue(), MAX_ENCHANTMENT_SLOT, PERM_ENCHANTMENT_SLOT, and sSpellItemEnchantmentStore.

◆ hasInvolvedQuest()

bool Item::hasInvolvedQuest ( uint32  ) const
inlineoverridevirtual

Reimplemented from Object.

327{ return false; }

◆ hasQuest()

bool Item::hasQuest ( uint32  quest_id) const
inlineoverridevirtual

Reimplemented from Object.

326{ return GetTemplate()->StartQuest == quest_id; }
uint32 StartQuest
Definition: ItemTemplate.h:677

References GetTemplate(), and ItemTemplate::StartQuest.

◆ HasSocket()

bool Item::HasSocket ( ) const
1010{
1011 // There can only be one socket added, and it's always in slot `PRISMATIC_ENCHANTMENT_SLOT`.
1012 // Built-in sockets Socket from upgrade
1014}
@ PRISMATIC_ENCHANTMENT_SLOT
Definition: Item.h:169

References _Socket::Color, GetEnchantmentId(), GetTemplate(), PRISMATIC_ENCHANTMENT_SLOT, and ItemTemplate::Socket.

Referenced by Player::_ApplyItemMods(), Player::CorrectMetaGemEnchants(), and Player::EnchantmentFitsRequirements().

◆ IsArmorVellum()

bool Item::IsArmorVellum ( ) const
inline
330{ return GetTemplate()->IsArmorVellum(); }
bool IsArmorVellum() const
Definition: ItemTemplate.h:828

References GetTemplate(), and ItemTemplate::IsArmorVellum().

Referenced by Spell::CheckItems(), and Spell::EffectEnchantItemPerm().

◆ IsBag()

bool Item::IsBag ( ) const
inline

◆ IsBindedNotWith()

bool Item::IsBindedNotWith ( Player const *  player) const
1135{
1136 // not binded item
1137 if (!IsSoulBound())
1138 return false;
1139
1140 // own item
1141 if (GetOwnerGUID() == player->GetGUID())
1142 return false;
1143
1145 if (allowedGUIDs.find(player->GetGUID()) != allowedGUIDs.end())
1146 return false;
1147
1148 // BOA item case
1149 if (IsBoundAccountWide())
1150 return false;
1151
1152 return true;
1153}

References allowedGUIDs, Object::GetGUID(), GetOwnerGUID(), Object::HasFlag(), IsBoundAccountWide(), IsSoulBound(), ITEM_FIELD_FLAG_BOP_TRADEABLE, and ITEM_FIELD_FLAGS.

Referenced by Player::CanBankItem(), Player::CanEquipItem(), Player::CanStoreItem(), Player::CanStoreItems(), and Player::CanUseItem().

◆ IsBoundAccountWide()

bool Item::IsBoundAccountWide ( ) const
inline
231{ return (GetTemplate()->Flags & ITEM_FLAG_IS_BOUND_TO_ACCOUNT) != 0; }
@ ITEM_FLAG_IS_BOUND_TO_ACCOUNT
Definition: ItemTemplate.h:175

References GetTemplate(), and ITEM_FLAG_IS_BOUND_TO_ACCOUNT.

Referenced by CanBeTraded(), WorldSession::HandleSendMail(), and IsBindedNotWith().

◆ IsBoundByEnchant()

bool Item::IsBoundByEnchant ( ) const
850{
851 // Check all enchants for soulbound
852 for (uint32 enchant_slot = PERM_ENCHANTMENT_SLOT; enchant_slot < MAX_ENCHANTMENT_SLOT; ++enchant_slot)
853 if (uint32 enchant_id = GetEnchantmentId(EnchantmentSlot(enchant_slot)))
854 if (SpellItemEnchantmentEntry const* enchantEntry = sSpellItemEnchantmentStore.LookupEntry(enchant_id))
855 if (enchantEntry->slot & ENCHANTMENT_CAN_SOULBOUND)
856 return true;
857 return false;
858}
@ ENCHANTMENT_CAN_SOULBOUND
Definition: Item.h:195

References ENCHANTMENT_CAN_SOULBOUND, GetEnchantmentId(), MAX_ENCHANTMENT_SLOT, PERM_ENCHANTMENT_SLOT, and sSpellItemEnchantmentStore.

Referenced by CanBeTraded().

◆ IsBoundByTempEnchant()

bool Item::IsBoundByTempEnchant ( ) const
861{
863 if (SpellItemEnchantmentEntry const* enchantEntry = sSpellItemEnchantmentStore.LookupEntry(enchant_id))
864 if (enchantEntry->slot & ENCHANTMENT_CAN_SOULBOUND)
865 return true;
866 return false;
867}
@ TEMP_ENCHANTMENT_SLOT
Definition: Item.h:164

References ENCHANTMENT_CAN_SOULBOUND, GetEnchantmentId(), sSpellItemEnchantmentStore, and TEMP_ENCHANTMENT_SLOT.

Referenced by CanBeTraded().

◆ IsBroken()

◆ IsConjuredConsumable()

bool Item::IsConjuredConsumable ( ) const
inline
331{ return GetTemplate()->IsConjuredConsumable(); }
bool IsConjuredConsumable() const
Definition: ItemTemplate.h:829

References GetTemplate(), and ItemTemplate::IsConjuredConsumable().

◆ IsCurrencyToken()

bool Item::IsCurrencyToken ( ) const
inline
249{ return GetTemplate()->IsCurrencyToken(); }
bool IsCurrencyToken() const
Definition: ItemTemplate.h:736

References GetTemplate(), and ItemTemplate::IsCurrencyToken().

◆ IsEquipped()

◆ IsFitToSpellRequirements()

bool Item::IsFitToSpellRequirements ( SpellInfo const *  spellInfo) const
887{
888 ItemTemplate const* proto = GetTemplate();
889
890 if (spellInfo->EquippedItemClass != -1) // -1 == any item class
891 {
892 // Special case - accept vellum for armor/weapon requirements
893 if ((spellInfo->EquippedItemClass == ITEM_CLASS_ARMOR && proto->IsArmorVellum())
894 || (spellInfo->EquippedItemClass == ITEM_CLASS_WEAPON && proto->IsWeaponVellum()))
895 if (spellInfo->IsAbilityOfSkillType(SKILL_ENCHANTING)) // only for enchanting spells
896 return true;
897
898 if (spellInfo->EquippedItemClass != int32(proto->Class))
899 return false; // wrong item class
900
901 if (spellInfo->EquippedItemSubClassMask != 0) // 0 == any subclass
902 {
903 if ((spellInfo->EquippedItemSubClassMask & (1 << proto->SubClass)) == 0)
904 return false; // subclass not present in mask
905 }
906 }
907
908 if (spellInfo->EquippedItemInventoryTypeMask != 0) // 0 == any inventory type
909 {
910 // Special case - accept weapon type for main and offhand requirements
911 if (proto->InventoryType == INVTYPE_WEAPON &&
912 (spellInfo->EquippedItemInventoryTypeMask & (1 << INVTYPE_WEAPONMAINHAND) ||
913 spellInfo->EquippedItemInventoryTypeMask & (1 << INVTYPE_WEAPONOFFHAND)))
914 return true;
915 else if ((spellInfo->EquippedItemInventoryTypeMask & (1 << proto->InventoryType)) == 0)
916 return false; // inventory type not present in mask
917 }
918
919 return true;
920}
@ INVTYPE_WEAPON
Definition: ItemTemplate.h:278
@ INVTYPE_WEAPONMAINHAND
Definition: ItemTemplate.h:286
@ INVTYPE_WEAPONOFFHAND
Definition: ItemTemplate.h:287
@ SKILL_ENCHANTING
Definition: SharedDefines.h:2926
bool IsWeaponVellum() const
Definition: ItemTemplate.h:827

References ItemTemplate::Class, SpellInfo::EquippedItemClass, SpellInfo::EquippedItemInventoryTypeMask, SpellInfo::EquippedItemSubClassMask, GetTemplate(), ItemTemplate::InventoryType, INVTYPE_WEAPON, INVTYPE_WEAPONMAINHAND, INVTYPE_WEAPONOFFHAND, SpellInfo::IsAbilityOfSkillType(), ItemTemplate::IsArmorVellum(), ItemTemplate::IsWeaponVellum(), ITEM_CLASS_ARMOR, ITEM_CLASS_WEAPON, SKILL_ENCHANTING, and ItemTemplate::SubClass.

Referenced by Player::_ApplyWeaponDependentAuraCritMod(), Player::_ApplyWeaponDependentAuraDamageMod(), Spell::CheckItems(), Player::HasItemFitToSpellRequirements(), Aura::IsProcTriggeredOnEvent(), and Player::UpdateExpertise().

◆ IsInBag()

bool Item::IsInBag ( ) const
inline
279{ return m_container != nullptr; }

References m_container.

Referenced by IsEquipped().

◆ IsInTrade()

bool Item::IsInTrade ( ) const
inline
254{ return mb_in_trade; }

References mb_in_trade.

Referenced by Player::CanStoreItems(), and Player::HasItemCount().

◆ IsInUpdateQueue()

bool Item::IsInUpdateQueue ( ) const
inline

◆ IsLimitedToAnotherMapOrZone()

bool Item::IsLimitedToAnotherMapOrZone ( uint32  cur_mapId,
uint32  cur_zoneId 
) const
1059{
1060 ItemTemplate const* proto = GetTemplate();
1061 return proto && ((proto->Map && proto->Map != cur_mapId) || (proto->Area && proto->Area != cur_zoneId));
1062}
uint32 Map
Definition: ItemTemplate.h:687
uint32 Area
Definition: ItemTemplate.h:686

References ItemTemplate::Area, GetTemplate(), and ItemTemplate::Map.

Referenced by Player::_LoadItem().

◆ IsLocked()

bool Item::IsLocked ( ) const
inline
@ ITEM_FIELD_FLAG_UNLOCKED
Definition: ItemTemplate.h:112

References Object::HasFlag(), ITEM_FIELD_FLAG_UNLOCKED, and ITEM_FIELD_FLAGS.

Referenced by Spell::CheckCast(), and WorldSession::HandleOpenItemOpcode().

◆ IsNotEmptyBag()

◆ IsPotion()

bool Item::IsPotion ( ) const
inline
328{ return GetTemplate()->IsPotion(); }
bool IsPotion() const
Definition: ItemTemplate.h:826

References GetTemplate(), and ItemTemplate::IsPotion().

Referenced by Spell::CheckCast(), and Spell::SendSpellCooldown().

◆ IsRefundExpired()

bool Item::IsRefundExpired ( )
1256{
1257 return (GetPlayedTime() > 2 * HOUR);
1258}
uint32 GetPlayedTime()
Definition: Item.cpp:1248

References GetPlayedTime(), and HOUR.

Referenced by Player::RefundItem().

◆ IsSoulBound()

◆ IsWeaponVellum()

bool Item::IsWeaponVellum ( ) const
inline

◆ LoadFromDB()

bool Item::LoadFromDB ( ObjectGuid::LowType  guid,
ObjectGuid  owner_guid,
Field fields,
uint32  entry 
)
virtual

Reimplemented in Bag.

422{
423 // 0 1 2 3 4 5 6 7 8 9 10
424 //result = CharacterDatabase.Query("SELECT creatorGuid, giftCreatorGuid, count, duration, charges, flags, enchantments, randomPropertyId, durability, playedTime, text FROM item_instance WHERE guid = '{}'", guid);
425
426 // create item before any checks for store correct guid
427 // and allow use "FSetState(ITEM_REMOVED); SaveToDB();" for deleting item from DB
428 Object::_Create(guid, 0, HighGuid::Item);
429
430 // Set entry, MUST be before proto check
431 SetEntry(entry);
432 SetObjectScale(1.0f);
433
434 ItemTemplate const* proto = GetTemplate();
435 if (!proto)
436 {
437 LOG_ERROR("entities.item", "Invalid entry {} for item {}. Refusing to load.", GetEntry(), GetGUID().ToString());
438 return false;
439 }
440
441 // set owner (not if item is only loaded for gbank/auction/mail
442 if (owner_guid)
443 SetOwnerGUID(owner_guid);
444
445 bool need_save = false; // need explicit save data at load fixes
446 SetGuidValue(ITEM_FIELD_CREATOR, ObjectGuid::Create<HighGuid::Player>(fields[0].Get<uint32>()));
447 SetGuidValue(ITEM_FIELD_GIFTCREATOR, ObjectGuid::Create<HighGuid::Player>(fields[1].Get<uint32>()));
448 SetCount(fields[2].Get<uint32>());
449
450 uint32 duration = fields[3].Get<uint32>();
452 // update duration if need, and remove if not need
453 if ((proto->Duration == 0) != (duration == 0))
454 {
456 need_save = true;
457 }
458
459 std::vector<std::string_view> tokens = Acore::Tokenize(fields[4].Get<std::string_view>(), ' ', false);
460 if (tokens.size() == MAX_ITEM_PROTO_SPELLS)
461 {
462 for (uint8 i = 0; i < MAX_ITEM_PROTO_SPELLS; ++i)
463 {
464 if (Optional<int32> charges = Acore::StringTo<int32>(tokens[i]))
465 SetSpellCharges(i, *charges);
466 else
467 LOG_ERROR("entities.item", "Invalid charge info '{}' for item {}, charge data not loaded.", tokens.at(i), GetGUID().ToString());
468 }
469 }
470
471 SetUInt32Value(ITEM_FIELD_FLAGS, fields[5].Get<uint32>());
472 // Remove bind flag for items vs NO_BIND set
473 if (IsSoulBound() && proto->Bonding == NO_BIND && sScriptMgr->CanApplySoulboundFlag(this, proto))
474 {
476 need_save = true;
477 }
478
479 std::string enchants = fields[6].Get<std::string>();
480
482 {
483 LOG_WARN("entities.item", "Invalid enchantment data '{}' for item {}. Forcing partial load.", fields[6].Get<std::string>(), GetGUID().ToString());
484 }
485
486 SetInt32Value(ITEM_FIELD_RANDOM_PROPERTIES_ID, fields[7].Get<int16>());
487 // recalculate suffix factor
488 if (GetItemRandomPropertyId() < 0)
490
491 uint32 durability = fields[8].Get<uint16>();
493
494 // update max durability (and durability) if need
495 // xinef: do not overwrite durability for wrapped items!!
498 {
500 need_save = true;
501 }
502
503 SetUInt32Value(ITEM_FIELD_CREATE_PLAYED_TIME, fields[9].Get<uint32>());
504 SetText(fields[10].Get<std::string>());
505
506 if (need_save) // normal item changed state set not work at loading
507 {
512 stmt->SetData(3, guid);
513 CharacterDatabase.Execute(stmt);
514 }
515
516 return true;
517}
#define LOG_WARN(filterType__,...)
Definition: Log.h:163
std::optional< T > Optional
Optional helper class to wrap optional values within.
Definition: Optional.h:24
@ CHAR_UPD_ITEM_INSTANCE_ON_LOAD
Definition: CharacterDatabase.h:126
@ ITEM_FIELD_FLAG_WRAPPED
Definition: ItemTemplate.h:113
@ NO_BIND
Definition: ItemTemplate.h:96
std::vector< std::string_view > Tokenize(std::string_view str, char sep, bool keepEmpty)
Definition: Tokenize.cpp:20
std::enable_if_t< std::is_arithmetic_v< T >, T > Get() const
Definition: Field.h:113
void UpdateItemSuffixFactor()
Definition: Item.cpp:708
void SetText(std::string const &text)
Definition: Item.h:300
void SetOwnerGUID(ObjectGuid guid)
Definition: Item.h:226
uint32 Bonding
Definition: ItemTemplate.h:672
void SetInt32Value(uint16 index, int32 value)
Definition: Object.cpp:637
void ApplyModFlag(uint16 index, uint32 flag, bool apply)
Definition: Object.cpp:899
bool _LoadIntoDataField(std::string const &data, uint32 startOffset, uint32 count)
Definition: Object.cpp:612

References Object::_Create(), Object::_LoadIntoDataField(), Object::ApplyModFlag(), ItemTemplate::Bonding, CHAR_UPD_ITEM_INSTANCE_ON_LOAD, CharacterDatabase, ItemTemplate::Duration, Field::Get(), Object::GetEntry(), Object::GetGUID(), GetItemRandomPropertyId(), GetTemplate(), Object::GetUInt32Value(), Object::HasFlag(), IsSoulBound(), ITEM_FIELD_CREATE_PLAYED_TIME, ITEM_FIELD_CREATOR, ITEM_FIELD_DURABILITY, ITEM_FIELD_DURATION, ITEM_FIELD_ENCHANTMENT_1_1, ITEM_FIELD_FLAG_SOULBOUND, ITEM_FIELD_FLAG_WRAPPED, ITEM_FIELD_FLAGS, ITEM_FIELD_GIFTCREATOR, ITEM_FIELD_MAXDURABILITY, ITEM_FIELD_RANDOM_PROPERTIES_ID, LOG_ERROR, LOG_WARN, MAX_ENCHANTMENT_OFFSET, MAX_ENCHANTMENT_SLOT, MAX_ITEM_PROTO_SPELLS, ItemTemplate::MaxDurability, NO_BIND, SetCount(), PreparedStatementBase::SetData(), Object::SetEntry(), Object::SetGuidValue(), Object::SetInt32Value(), Object::SetObjectScale(), SetOwnerGUID(), SetSpellCharges(), SetText(), Object::SetUInt32Value(), sScriptMgr, Acore::Tokenize(), and UpdateItemSuffixFactor().

Referenced by Player::_LoadItem(), Player::_LoadMailedItem(), AuctionHouseMgr::LoadAuctionItems(), Bag::LoadFromDB(), and Guild::BankTab::LoadItemFromDB().

◆ RemoveFromObjectUpdate()

void Item::RemoveFromObjectUpdate ( )
overridevirtual

Implements Object.

1169{
1170 if (Player* owner = GetOwner())
1171 owner->GetMap()->RemoveUpdateObject(this);
1172}

References GetOwner().

◆ RemoveFromUpdateQueueOf()

void Item::RemoveFromUpdateQueueOf ( Player player)
767{
768 if (!IsInUpdateQueue())
769 return;
770
771 ASSERT(player);
772
773 if (player->GetGUID() != GetOwnerGUID())
774 {
775 LOG_DEBUG("entities.player.items", "Item::RemoveFromUpdateQueueOf - Owner's guid ({}) and player's guid ({}) don't match!", GetOwnerGUID().ToString(), player->GetGUID().ToString());
776 return;
777 }
778
779 if (player->m_itemUpdateQueueBlocked)
780 return;
781
782 player->m_itemUpdateQueue[uQueuePos] = nullptr;
783 uQueuePos = -1;
784}

References ASSERT, Object::GetGUID(), GetOwnerGUID(), IsInUpdateQueue(), LOG_DEBUG, Player::m_itemUpdateQueue, Player::m_itemUpdateQueueBlocked, ObjectGuid::ToString(), and uQueuePos.

Referenced by WorldSession::HandleSellItemOpcode(), and SetState().

◆ SaveRefundDataToDB()

void Item::SaveRefundDataToDB ( )
1175{
1176 CharacterDatabaseTransaction trans = CharacterDatabase.BeginTransaction();
1177
1179 stmt->SetData(0, GetGUID().GetCounter());
1180 trans->Append(stmt);
1181
1182 stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_ITEM_REFUND_INSTANCE);
1183 stmt->SetData(0, GetGUID().GetCounter());
1184 stmt->SetData(1, GetRefundRecipient());
1185 stmt->SetData(2, GetPaidMoney());
1186 stmt->SetData(3, uint16(GetPaidExtendedCost()));
1187 trans->Append(stmt);
1188
1189 CharacterDatabase.CommitTransaction(trans);
1190}
SQLTransaction< CharacterDatabaseConnection > CharacterDatabaseTransaction
Definition: DatabaseEnvFwd.h:70
@ CHAR_INS_ITEM_REFUND_INSTANCE
Definition: CharacterDatabase.h:372
uint32 GetPaidExtendedCost()
Definition: Item.h:340
uint32 GetPaidMoney()
Definition: Item.h:339
ObjectGuid::LowType GetRefundRecipient()
Definition: Item.h:338

References CHAR_DEL_ITEM_REFUND_INSTANCE, CHAR_INS_ITEM_REFUND_INSTANCE, CharacterDatabase, Object::GetGUID(), GetPaidExtendedCost(), GetPaidMoney(), GetRefundRecipient(), and PreparedStatementBase::SetData().

Referenced by Player::_StoreOrEquipNewItem().

◆ SaveToDB()

void Item::SaveToDB ( CharacterDatabaseTransaction  trans)
virtual

Reimplemented in Bag.

339{
340 bool isInTransaction = static_cast<bool>(trans);
341 if (!isInTransaction)
342 trans = CharacterDatabase.BeginTransaction();
343
345 switch (uState)
346 {
347 case ITEM_NEW:
348 case ITEM_CHANGED:
349 {
350 uint8 index = 0;
352 stmt->SetData( index, GetEntry());
353 stmt->SetData(++index, GetOwnerGUID().GetCounter());
354 stmt->SetData(++index, GetGuidValue(ITEM_FIELD_CREATOR).GetCounter());
355 stmt->SetData(++index, GetGuidValue(ITEM_FIELD_GIFTCREATOR).GetCounter());
356 stmt->SetData(++index, GetCount());
358
359 std::ostringstream ssSpells;
360 for (uint8 i = 0; i < MAX_ITEM_PROTO_SPELLS; ++i)
361 ssSpells << GetSpellCharges(i) << ' ';
362 stmt->SetData(++index, ssSpells.str());
363
364 stmt->SetData(++index, GetUInt32Value(ITEM_FIELD_FLAGS));
365
366 std::ostringstream ssEnchants;
367 for (uint8 i = 0; i < MAX_ENCHANTMENT_SLOT; ++i)
368 {
369 ssEnchants << GetEnchantmentId(EnchantmentSlot(i)) << ' ';
370 ssEnchants << GetEnchantmentDuration(EnchantmentSlot(i)) << ' ';
371 ssEnchants << GetEnchantmentCharges(EnchantmentSlot(i)) << ' ';
372 }
373 stmt->SetData(++index, ssEnchants.str());
374
375 stmt->SetData (++index, GetItemRandomPropertyId());
378 stmt->SetData(++index, m_text);
379 stmt->SetData(++index, guid);
380
381 trans->Append(stmt);
382
384 {
385 stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_GIFT_OWNER);
386 stmt->SetData(0, GetOwnerGUID().GetCounter());
387 stmt->SetData(1, guid);
388 trans->Append(stmt);
389 }
390 break;
391 }
392 case ITEM_REMOVED:
393 {
395 stmt->SetData(0, guid);
396 trans->Append(stmt);
397
399 {
400 stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_GIFT);
401 stmt->SetData(0, guid);
402 trans->Append(stmt);
403 }
404
405 if (!isInTransaction)
406 CharacterDatabase.CommitTransaction(trans);
407
408 delete this;
409 return;
410 }
411 case ITEM_UNCHANGED:
412 break;
413 }
414
416
417 if (!isInTransaction)
418 CharacterDatabase.CommitTransaction(trans);
419}
@ CHAR_UPD_ITEM_INSTANCE
Definition: CharacterDatabase.h:125
@ CHAR_UPD_GIFT_OWNER
Definition: CharacterDatabase.h:129
@ CHAR_DEL_GIFT
Definition: CharacterDatabase.h:130
@ CHAR_REP_ITEM_INSTANCE
Definition: CharacterDatabase.h:124
@ ITEM_REMOVED
Definition: Item.h:206
@ ITEM_UNCHANGED
Definition: Item.h:203
int32 GetSpellCharges(uint8 index=0) const
Definition: Item.h:308
uint32 GetEnchantmentDuration(EnchantmentSlot slot) const
Definition: Item.h:296
uint32 GetEnchantmentCharges(EnchantmentSlot slot) const
Definition: Item.h:297
LowType GetCounter() const
Definition: ObjectGuid.h:147
uint32 LowType
Definition: ObjectGuid.h:124

References CHAR_DEL_GIFT, CHAR_DEL_ITEM_INSTANCE, CHAR_REP_ITEM_INSTANCE, CHAR_UPD_GIFT_OWNER, CHAR_UPD_ITEM_INSTANCE, CharacterDatabase, GetCount(), ObjectGuid::GetCounter(), GetEnchantmentCharges(), GetEnchantmentDuration(), GetEnchantmentId(), Object::GetEntry(), Object::GetGUID(), Object::GetGuidValue(), GetItemRandomPropertyId(), GetOwnerGUID(), GetSpellCharges(), Object::GetUInt32Value(), Object::HasFlag(), ITEM_CHANGED, ITEM_FIELD_CREATE_PLAYED_TIME, ITEM_FIELD_CREATOR, ITEM_FIELD_DURABILITY, ITEM_FIELD_DURATION, ITEM_FIELD_FLAG_WRAPPED, ITEM_FIELD_FLAGS, ITEM_FIELD_GIFTCREATOR, ITEM_NEW, ITEM_REMOVED, ITEM_UNCHANGED, m_text, MAX_ENCHANTMENT_SLOT, MAX_ITEM_PROTO_SPELLS, PreparedStatementBase::SetData(), SetState(), and uState.

Referenced by Player::_LoadItem(), Player::_LoadMailedItem(), Player::_SaveInventory(), Player::AutoUnequipOffhandIfNeed(), AchievementMgr::CompletedAchievement(), WorldSession::HandleAuctionSellItem(), WorldSession::HandleSendMail(), Bag::SaveToDB(), and MailDraft::SendReturnToSender().

◆ SendTimeUpdate()

void Item::SendTimeUpdate ( Player owner)
1078{
1080 if (!duration)
1081 return;
1082
1083 WorldPacket data(SMSG_ITEM_TIME_UPDATE, (8 + 4));
1084 data << GetGUID();
1085 data << uint32(duration);
1086 owner->GetSession()->SendPacket(&data);
1087}
@ SMSG_ITEM_TIME_UPDATE
Definition: Opcodes.h:520
WorldSession * GetSession() const
Definition: Player.h:1948
Definition: WorldPacket.h:27
void SendPacket(WorldPacket const *packet)
Send a packet to the client.
Definition: WorldSession.cpp:207

References Object::GetGUID(), Player::GetSession(), Object::GetUInt32Value(), ITEM_FIELD_DURATION, WorldSession::SendPacket(), and SMSG_ITEM_TIME_UPDATE.

Referenced by Player::AddItemDurations().

◆ SendUpdateSockets()

void Item::SendUpdateSockets ( )
1065{
1066 WorldPacket data(SMSG_SOCKET_GEMS_RESULT, 8 + 4 + 4 + 4 + 4);
1067 data << GetGUID();
1070
1071 GetOwner()->GetSession()->SendPacket(&data);
1072}
@ BONUS_ENCHANTMENT_SLOT
Definition: Item.h:168
@ SMSG_SOCKET_GEMS_RESULT
Definition: Opcodes.h:1321

References BONUS_ENCHANTMENT_SLOT, GetEnchantmentId(), Object::GetGUID(), GetOwner(), Player::GetSession(), WorldSession::SendPacket(), SMSG_SOCKET_GEMS_RESULT, and SOCK_ENCHANTMENT_SLOT.

Referenced by WorldSession::HandleSocketOpcode().

◆ SetBinding()

◆ SetContainer()

void Item::SetContainer ( Bag container)
inline

◆ SetCount()

◆ SetEnchantment()

void Item::SetEnchantment ( EnchantmentSlot  slot,
uint32  id,
uint32  duration,
uint32  charges,
ObjectGuid  caster = ObjectGuid::Empty 
)
923{
924 // Better lost small time at check in comparison lost time at item save to DB.
925 if ((GetEnchantmentId(slot) == id) && (GetEnchantmentDuration(slot) == duration) && (GetEnchantmentCharges(slot) == charges))
926 return;
927
928 Player* owner = GetOwner();
930 {
931 if (uint32 oldEnchant = GetEnchantmentId(slot))
933
934 if (id)
935 owner->GetSession()->SendEnchantmentLog(GetOwnerGUID(), caster, GetEntry(), id);
936 }
937
941 SetState(ITEM_CHANGED, owner);
942}
@ MAX_INSPECTED_ENCHANTMENT_SLOT
Definition: Item.h:170
void SendEnchantmentLog(ObjectGuid target, ObjectGuid caster, uint32 itemId, uint32 enchantId)
Definition: ItemHandler.cpp:1226

References ObjectGuid::Empty, ENCHANTMENT_CHARGES_OFFSET, ENCHANTMENT_DURATION_OFFSET, ENCHANTMENT_ID_OFFSET, GetEnchantmentCharges(), GetEnchantmentDuration(), GetEnchantmentId(), Object::GetEntry(), GetOwner(), GetOwnerGUID(), Player::GetSession(), ITEM_CHANGED, ITEM_FIELD_ENCHANTMENT_1_1, MAX_ENCHANTMENT_OFFSET, MAX_INSPECTED_ENCHANTMENT_SLOT, WorldSession::SendEnchantmentLog(), SetState(), and Object::SetUInt32Value().

Referenced by Spell::EffectEnchantHeldItem(), Spell::EffectEnchantItemPerm(), Spell::EffectEnchantItemPrismatic(), Spell::EffectEnchantItemTmp(), Spell::EffectSummonChangeItem(), WorldSession::HandleSocketOpcode(), and SetItemRandomProperties().

◆ SetEnchantmentCharges()

◆ SetEnchantmentDuration()

void Item::SetEnchantmentDuration ( EnchantmentSlot  slot,
uint32  duration,
Player owner 
)
944{
945 if (GetEnchantmentDuration(slot) == duration)
946 return;
947
949 SetState(ITEM_CHANGED, owner);
950 // Cannot use GetOwner() here, has to be passed as an argument to avoid freeze due to hashtable locking
951}

References ENCHANTMENT_DURATION_OFFSET, GetEnchantmentDuration(), ITEM_CHANGED, ITEM_FIELD_ENCHANTMENT_1_1, MAX_ENCHANTMENT_OFFSET, SetState(), and Object::SetUInt32Value().

Referenced by Player::RemoveEnchantmentDurations().

◆ SetInTrade()

void Item::SetInTrade ( bool  b = true)
inline
253{ mb_in_trade = b; }

References mb_in_trade.

Referenced by clearAcceptTradeMode(), and setAcceptTradeMode().

◆ SetItemRandomProperties()

void Item::SetItemRandomProperties ( int32  randomPropId)
671{
672 if (!randomPropId)
673 return;
674
675 if (randomPropId > 0)
676 {
677 ItemRandomPropertiesEntry const* item_rand = sItemRandomPropertiesStore.LookupEntry(randomPropId);
678 if (item_rand)
679 {
681 {
684 }
687 }
688 }
689 else
690 {
691 ItemRandomSuffixEntry const* item_rand = sItemRandomSuffixStore.LookupEntry(-randomPropId);
692 if (item_rand)
693 {
696 {
700 }
701
704 }
705 }
706}
@ PROP_ENCHANTMENT_SLOT_0
Definition: Item.h:172
uint32 GetItemSuffixFactor() const
Definition: Item.h:287
void SetEnchantment(EnchantmentSlot slot, uint32 id, uint32 duration, uint32 charges, ObjectGuid caster=ObjectGuid::Empty)
Definition: Item.cpp:922
std::array< uint32, MAX_ITEM_ENCHANTMENT_EFFECTS > Enchantment
Definition: DBCStructure.h:1189
std::array< uint32, MAX_ITEM_ENCHANTMENT_EFFECTS > Enchantment
Definition: DBCStructure.h:1201

References ItemRandomPropertiesEntry::Enchantment, ItemRandomSuffixEntry::Enchantment, Object::GetInt32Value(), GetItemSuffixFactor(), GetOwner(), ItemRandomPropertiesEntry::ID, ItemRandomSuffixEntry::ID, ITEM_CHANGED, ITEM_FIELD_RANDOM_PROPERTIES_ID, MAX_ENCHANTMENT_SLOT, PROP_ENCHANTMENT_SLOT_0, SetEnchantment(), Object::SetInt32Value(), SetState(), sItemRandomPropertiesStore, sItemRandomSuffixStore, and UpdateItemSuffixFactor().

Referenced by CreateItem().

◆ SetNotRefundable()

void Item::SetNotRefundable ( Player owner,
bool  changestate = true,
CharacterDatabaseTransaction trans = nullptr 
)
1203{
1205 return;
1206
1208 // Following is not applicable in the trading procedure
1209 if (changestate)
1210 SetState(ITEM_CHANGED, owner);
1211
1213 SetPaidMoney(0);
1216
1218}
void DeleteRefundDataFromDB(CharacterDatabaseTransaction *trans)
Definition: Item.cpp:1192
void SetPaidMoney(uint32 money)
Definition: Item.h:336
void SetRefundRecipient(ObjectGuid::LowType pGuidLow)
Definition: Item.h:335
void SetPaidExtendedCost(uint32 iece)
Definition: Item.h:337
void DeleteRefundReference(ObjectGuid itemGUID)
Definition: Player.cpp:15394

References DeleteRefundDataFromDB(), Player::DeleteRefundReference(), Object::GetGUID(), Object::HasFlag(), ITEM_CHANGED, ITEM_FIELD_FLAG_REFUNDABLE, ITEM_FIELD_FLAGS, Object::RemoveFlag(), SetPaidExtendedCost(), SetPaidMoney(), SetRefundRecipient(), and SetState().

Referenced by Player::_StoreItem(), Player::DestroyItem(), Player::EquipItem(), WorldSession::HandleSendMail(), Player::RefundItem(), Player::SendRefundInfo(), and UpdatePlayedTime().

◆ SetOwnerGUID()

◆ SetPaidExtendedCost()

void Item::SetPaidExtendedCost ( uint32  iece)
inline

◆ SetPaidMoney()

void Item::SetPaidMoney ( uint32  money)
inline

◆ SetRefundRecipient()

void Item::SetRefundRecipient ( ObjectGuid::LowType  pGuidLow)
inline

◆ SetSlot()

void Item::SetSlot ( uint8  slot)
inline

◆ SetSoulboundTradeable()

void Item::SetSoulboundTradeable ( AllowedLooterSet allowedLooters)
1261{
1263 allowedGUIDs = allowedLooters;
1264}
void SetFlag(uint16 index, uint32 newFlag)
Definition: Object.cpp:845

References allowedGUIDs, ITEM_FIELD_FLAG_BOP_TRADEABLE, ITEM_FIELD_FLAGS, and Object::SetFlag().

Referenced by Player::_LoadItem(), and Player::StoreNewItem().

◆ SetSpellCharges()

void Item::SetSpellCharges ( uint8  index,
int32  value 
)
inline

◆ SetState()

void Item::SetState ( ItemUpdateState  state,
Player forplayer = nullptr 
)
717{
718 if (uState == ITEM_NEW && state == ITEM_REMOVED)
719 {
720 // pretend the item never existed
721 if (forplayer)
722 {
723 RemoveFromUpdateQueueOf(forplayer);
724 forplayer->DeleteRefundReference(GetGUID());
725 }
726 delete this;
727 return;
728 }
729 if (state != ITEM_UNCHANGED)
730 {
731 // new items must stay in new state until saved
732 if (uState != ITEM_NEW)
733 uState = state;
734 if (forplayer)
735 AddToUpdateQueueOf(forplayer);
736 }
737 else
738 {
739 // unset in queue
740 // the item must be removed from the queue manually
741 uQueuePos = -1;
743 }
744}
void AddToUpdateQueueOf(Player *player)
Definition: Item.cpp:746
void RemoveFromUpdateQueueOf(Player *player)
Definition: Item.cpp:766

References AddToUpdateQueueOf(), Player::DeleteRefundReference(), Object::GetGUID(), ITEM_NEW, ITEM_REMOVED, ITEM_UNCHANGED, RemoveFromUpdateQueueOf(), uQueuePos, and uState.

Referenced by Player::_StoreItem(), ClearEnchantment(), ClearSoulboundTradeable(), Player::DestroyItem(), Player::DestroyItemCount(), Player::DurabilityPointsLoss(), Player::DurabilityRepair(), Spell::EffectOpenLock(), Player::EquipItem(), WorldSession::HandleAuctionSellItem(), WorldSession::HandleMailTakeItem(), WorldSession::HandleOpenWrappedItemCallback(), WorldSession::HandlePetitionBuyOpcode(), WorldSession::HandleSellItemOpcode(), WorldSession::HandleUseItemOpcode(), WorldSession::HandleWrapItemOpcode(), Player::MoveItemToInventory(), Player::RemoveItemFromBuyBackSlot(), SaveToDB(), SetEnchantment(), SetEnchantmentCharges(), SetEnchantmentDuration(), SetItemRandomProperties(), SetNotRefundable(), Player::SplitItem(), Player::SwapItem(), Spell::TakeCastItem(), UpdateDuration(), UpdatePlayedTime(), and Player::VisualizeItem().

◆ SetText()

void Item::SetText ( std::string const &  text)
inline
300{ m_text = text; }

References m_text.

Referenced by WorldSession::HandleMailCreateTextItem(), and LoadFromDB().

◆ ToBag() [1/2]

Bag * Item::ToBag ( )
inline
244{ if (IsBag()) return reinterpret_cast<Bag*>(this); else return nullptr; }

References IsBag().

Referenced by Player::_LoadInventory(), Player::GetBagByPos(), debug_commandscript::HandleDebugGetItemStateCommand(), IsNotEmptyBag(), and Player::SwapItem().

◆ ToBag() [2/2]

const Bag * Item::ToBag ( ) const
inline
245{ if (IsBag()) return reinterpret_cast<const Bag*>(this); else return nullptr; }

References IsBag().

◆ UpdateDuration()

void Item::UpdateDuration ( Player owner,
uint32  diff 
)
321{
323 return;
324
325 LOG_DEBUG("entities.player.items", "Item::UpdateDuration Item (Entry: {} Duration {} Diff {})", GetEntry(), GetUInt32Value(ITEM_FIELD_DURATION), diff);
326
328 {
329 sScriptMgr->OnItemExpire(owner, GetTemplate());
330 owner->DestroyItem(GetBagSlot(), GetSlot(), true);
331 return;
332 }
333
335 SetState(ITEM_CHANGED, owner); // save new time in database
336}
void DestroyItem(uint8 bag, uint8 slot, bool update)
Definition: PlayerStorage.cpp:3051

References Player::DestroyItem(), GetBagSlot(), Object::GetEntry(), GetSlot(), GetTemplate(), Object::GetUInt32Value(), ITEM_CHANGED, ITEM_FIELD_DURATION, LOG_DEBUG, SetState(), Object::SetUInt32Value(), and sScriptMgr.

Referenced by Player::UpdateItemDuration().

◆ UpdateItemSuffixFactor()

void Item::UpdateItemSuffixFactor ( )
709{
710 uint32 suffixFactor = GenerateEnchSuffixFactor(GetEntry());
711 if (GetItemSuffixFactor() == suffixFactor)
712 return;
714}
uint32 GenerateEnchSuffixFactor(uint32 item_id)
Definition: ItemEnchantmentMgr.cpp:122

References GenerateEnchSuffixFactor(), Object::GetEntry(), GetItemSuffixFactor(), ITEM_FIELD_PROPERTY_SEED, and Object::SetUInt32Value().

Referenced by LoadFromDB(), and SetItemRandomProperties().

◆ UpdatePlayedTime()

void Item::UpdatePlayedTime ( Player owner)
1221{
1222 /* Here we update our played time
1223 We simply add a number to the current played time,
1224 based on the time elapsed since the last update hereof.
1225 */
1226 // Get current played time
1228 // Calculate time elapsed since last played time update
1229 time_t curtime = GameTime::GetGameTime().count();
1230 uint32 elapsed = uint32(curtime - m_lastPlayedTimeUpdate);
1231 uint32 new_playtime = current_playtime + elapsed;
1232 // Check if the refund timer has expired yet
1233 if (new_playtime <= 2 * HOUR)
1234 {
1235 // No? Proceed.
1236 // Update the data field
1238 // Flag as changed to get saved to DB
1239 SetState(ITEM_CHANGED, owner);
1240 // Speaks for itself
1241 m_lastPlayedTimeUpdate = curtime;
1242 return;
1243 }
1244 // Yes
1245 SetNotRefundable(owner);
1246}
void SetNotRefundable(Player *owner, bool changestate=true, CharacterDatabaseTransaction *trans=nullptr)
Definition: Item.cpp:1202

References GameTime::GetGameTime(), Object::GetUInt32Value(), HOUR, ITEM_CHANGED, ITEM_FIELD_CREATE_PLAYED_TIME, m_lastPlayedTimeUpdate, SetNotRefundable(), SetState(), and Object::SetUInt32Value().

Referenced by Player::_SaveInventory(), and Player::SendRefundInfo().

Member Data Documentation

◆ allowedGUIDs

◆ loot

◆ m_container

Bag* Item::m_container
private

◆ m_lastPlayedTimeUpdate

time_t Item::m_lastPlayedTimeUpdate
private

◆ m_lootGenerated

◆ m_paidExtendedCost

uint32 Item::m_paidExtendedCost
private

◆ m_paidMoney

uint32 Item::m_paidMoney
private

Referenced by GetPaidMoney(), Item(), and SetPaidMoney().

◆ m_refundRecipient

uint32 Item::m_refundRecipient
private

◆ m_slot

uint8 Item::m_slot
private

Referenced by GetSlot(), IsEquipped(), Item(), and SetSlot().

◆ m_text

std::string Item::m_text
private

Referenced by GetText(), SaveToDB(), and SetText().

◆ mb_in_trade

bool Item::mb_in_trade
private

Referenced by IsInTrade(), Item(), and SetInTrade().

◆ uQueuePos

◆ uState

ItemUpdateState Item::uState
private