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 ( )
263{
266
268
270 m_slot = 0;
272 uQueuePos = -1;
273 m_container = nullptr;
274 m_lootGenerated = false;
275 mb_in_trade = false;
277
279 m_paidMoney = 0;
281}
@ 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.

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

References GetOwner().

◆ AddToUpdateQueueOf()

void Item::AddToUpdateQueueOf ( Player player)
746{
747 if (IsInUpdateQueue())
748 return;
749
750 ASSERT(player);
751
752 if (player->GetGUID() != GetOwnerGUID())
753 {
754 LOG_DEBUG("entities.player.items", "Item::AddToUpdateQueueOf - Owner's guid ({}) and player's guid ({}) don't match!", GetOwnerGUID().ToString(), player->GetGUID().ToString());
755 return;
756 }
757
758 if (player->m_itemUpdateQueueBlocked)
759 return;
760
761 player->m_itemUpdateQueue.push_back(this);
762 uQueuePos = player->m_itemUpdateQueue.size() - 1;
763}
#define ASSERT
Definition: Errors.h:68
#define LOG_DEBUG(filterType__,...)
Definition: Log.h:169
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:2742
bool m_itemUpdateQueueBlocked
Definition: Player.h:2743

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.

1155{
1156 if (Player* owner = GetOwner())
1157 BuildFieldsUpdate(owner, data_map);
1158 ClearUpdateMask(false);
1159}
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
869{
870 // not allow merge looting currently items
871 if (m_lootGenerated)
873
874 // check item type
875 if (GetEntry() != proto->ItemId)
877
878 // check free space (full stacks can't be target of merge
879 if (GetCount() >= proto->GetMaxStackSize())
881
882 return EQUIP_ERR_OK;
883}
@ 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
796{
798 return false;
799
800 if (IsBag() && (Player::IsBagPos(GetPos()) || !((Bag const*)this)->IsEmpty()))
801 return false;
802
803 if (Player* owner = GetOwner())
804 {
805 if (owner->CanUnequipItem(GetPos(), false) != EQUIP_ERR_OK)
806 return false;
807
808 // Xinef: check if item is looted now
809 if (owner->GetLootGUID() == GetGUID())
810 return false;
811 }
812
813 if (IsBoundByTempEnchant()) // pussywizard
814 return false;
815
816 if ((!mail || !IsBoundAccountWide()) && IsBoundByEnchant())
817 return false;
818
819 return true;
820}
@ 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:859
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:848
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:618

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 ( )
1279{
1280 // called from owner's update - GetOwner() MUST be valid
1281 if (GetUInt32Value(ITEM_FIELD_CREATE_PLAYED_TIME) + 2 * HOUR < GetOwner()->GetTotalPlayedTime())
1282 {
1284 return true; // remove from tradeable list
1285 }
1286
1287 return false;
1288}
constexpr auto HOUR
Definition: Common.h:50
@ ITEM_FIELD_CREATE_PLAYED_TIME
Definition: UpdateFields.h:71
void ClearSoulboundTradeable(Player *currentOwner)
Definition: Item.cpp:1265
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)
962{
963 if (!GetEnchantmentId(slot))
964 return;
965
966 for (uint8 x = 0; x < MAX_SPELL_ITEM_ENCHANTMENT_EFFECTS; ++x)
969}
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:1839
void SetState(ItemUpdateState state, Player *forplayer=nullptr)
Definition: Item.cpp:715
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)
1266{
1268 if (allowedGUIDs.empty())
1269 return;
1270
1271 allowedGUIDs.clear();
1272 SetState(ITEM_CHANGED, currentOwner);
1274 stmt->SetData(0, GetGUID().GetCounter());
1275 CharacterDatabase.Execute(stmt);
1276}
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
1120{
1121 // player CAN be nullptr in which case we must not update random properties because that accesses player's item update queue
1122 Item* newItem = CreateItem(GetEntry(), count, player, true, player ? GetItemRandomPropertyId() : 0);
1123 if (!newItem)
1124 return nullptr;
1125
1130 return newItem;
1131}
@ 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:1088
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.

284{
285 Object::_Create(guidlow, 0, HighGuid::Item);
286
287 SetEntry(itemid);
288 SetObjectScale(1.0f);
289
290 SetGuidValue(ITEM_FIELD_OWNER, owner ? owner->GetGUID() : ObjectGuid::Empty);
291 SetGuidValue(ITEM_FIELD_CONTAINED, owner ? owner->GetGUID() : ObjectGuid::Empty);
292
293 ItemTemplate const* itemProto = sObjectMgr->GetItemTemplate(itemid);
294 if (!itemProto)
295 return false;
296
300
301 for (uint8 i = 0; i < MAX_ITEM_PROTO_SPELLS; ++i)
302 SetSpellCharges(i, itemProto->Spells[i].SpellCharges);
303
306 sScriptMgr->OnItemCreate(this, itemProto, owner);
307 return true;
308}
#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:698
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
1089{
1090 if (count < 1)
1091 return nullptr; //don't create item at zero count
1092
1093 ItemTemplate const* pProto = sObjectMgr->GetItemTemplate(item);
1094 if (pProto)
1095 {
1096 if (count > pProto->GetMaxStackSize())
1097 count = pProto->GetMaxStackSize();
1098
1099 ASSERT_NODEBUGINFO(count != 0 && "pProto->Stackable == 0 but checked at loading already");
1100
1101 Item* pItem = NewItemOrBag(pProto);
1102 if (pItem->Create(sObjectMgr->GetGenerator<HighGuid::Item>().Generate(), item, player))
1103 {
1104 pItem->SetCount(count);
1105 if (!clone)
1106 pItem->SetItemRandomProperties(randomPropertyId ? randomPropertyId : Item::GenerateItemRandomPropertyId(item));
1107 else if (randomPropertyId)
1108 pItem->SetItemRandomProperties(randomPropertyId);
1109 return pItem;
1110 }
1111 else
1112 delete pItem;
1113 }
1114 else
1115 ABORT();
1116 return nullptr;
1117}
#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:283
void SetItemRandomProperties(int32 randomPropId)
Definition: Item.cpp:669
void SetCount(uint32 value)
Definition: Item.h:264
static int32 GenerateItemRandomPropertyId(uint32 item_id)
Definition: Item.cpp:623
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(), spell_gen_spirit_of_competition_participant::HandleScript(), spell_gen_spirit_of_competition_winner::HandleScript(), send_commandscript::HandleSendItemsCommand(), MailDraft::prepareItems(), Player::SendItemRetrievalMail(), ObjectMgr::SendServerMail(), and Player::StoreNewItem().

◆ DeleteFromDB() [1/2]

void Item::DeleteFromDB ( CharacterDatabaseTransaction  trans)
virtual

Reimplemented in Bag.

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

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

◆ DeleteFromDB() [2/2]

void Item::DeleteFromDB ( CharacterDatabaseTransaction  trans,
ObjectGuid::LowType  itemGuid 
)
static
520{
521 sScriptMgr->OnGlobalItemDelFromDB(trans, itemGuid);
523 stmt->SetData(0, itemGuid);
524 trans->Append(stmt);
525}
@ 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)
541{
542 DeleteFromInventoryDB(trans, GetGUID().GetCounter());
543}
static void DeleteFromInventoryDB(CharacterDatabaseTransaction trans, ObjectGuid::LowType itemGuid)
Definition: Item.cpp:533

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

◆ DeleteFromInventoryDB() [2/2]

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

◆ DeleteRefundDataFromDB()

void Item::DeleteRefundDataFromDB ( CharacterDatabaseTransaction trans)
1192{
1193 if (trans)
1194 {
1196 stmt->SetData(0, GetGUID().GetCounter());
1197 (*trans)->Append(stmt);
1198 }
1199}
@ 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
972{
973 for (uint32 enchant_slot = SOCK_ENCHANTMENT_SLOT; enchant_slot < SOCK_ENCHANTMENT_SLOT + MAX_GEM_SOCKETS; ++enchant_slot)
974 {
976
977 if (!SocketColor) // no socket slot
978 continue;
979
980 uint32 enchant_id = GetEnchantmentId(EnchantmentSlot(enchant_slot));
981 if (!enchant_id) // no gems on this socket
982 return false;
983
984 SpellItemEnchantmentEntry const* enchantEntry = sSpellItemEnchantmentStore.LookupEntry(enchant_id);
985 if (!enchantEntry) // invalid gem id on this socket
986 return false;
987
988 uint8 GemColor = 0;
989
990 uint32 gemid = enchantEntry->GemID;
991 if (gemid)
992 {
993 ItemTemplate const* gemProto = sObjectMgr->GetItemTemplate(gemid);
994 if (gemProto)
995 {
996 GemPropertiesEntry const* gemProperty = sGemPropertiesStore.LookupEntry(gemProto->GemProperties);
997 if (gemProperty)
998 GemColor = gemProperty->color;
999 }
1000 }
1001
1002 if (!(GemColor & SocketColor)) // bad gem color on this socket
1003 return false;
1004 }
1005 return true;
1006}
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:545
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:1842
uint32 GemID
Definition: DBCStructure.h:1853

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

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.

1291{
1292 std::stringstream sstr;
1293 sstr << Object::GetDebugInfo() << "\n"
1294 << std::boolalpha
1295 << "Owner: " << GetOwnerGUID().ToString() << " Count: " << GetCount()
1296 << " BagSlot: " << std::to_string(GetBagSlot()) << " Slot: " << std::to_string(GetSlot()) << " Equipped: " << IsEquipped();
1297 return sstr.str();
1298}
bool IsEquipped() const
Definition: Item.cpp:790
uint8 GetBagSlot() const
Definition: Item.cpp:785
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
835{
836 uint32 level = 0;
837
838 // Check all enchants for required level
839 for (uint32 enchant_slot = PERM_ENCHANTMENT_SLOT; enchant_slot < MAX_ENCHANTMENT_SLOT; ++enchant_slot)
840 if (uint32 enchant_id = GetEnchantmentId(EnchantmentSlot(enchant_slot)))
841 if (SpellItemEnchantmentEntry const* enchantEntry = sSpellItemEnchantmentStore.LookupEntry(enchant_id))
842 if (enchantEntry->requiredLevel > level)
843 level = enchantEntry->requiredLevel;
844
845 return level;
846}
@ 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
1016{
1017 uint8 count = 0;
1018 for (uint32 enchant_slot = SOCK_ENCHANTMENT_SLOT; enchant_slot < SOCK_ENCHANTMENT_SLOT + MAX_GEM_SOCKETS; ++enchant_slot)
1019 {
1020 uint32 enchant_id = GetEnchantmentId(EnchantmentSlot(enchant_slot));
1021 if (!enchant_id)
1022 continue;
1023
1024 SpellItemEnchantmentEntry const* enchantEntry = sSpellItemEnchantmentStore.LookupEntry(enchant_id);
1025 if (!enchantEntry)
1026 continue;
1027
1028 if (GemID == enchantEntry->GemID)
1029 ++count;
1030 }
1031 return count;
1032}

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
1035{
1036 uint8 count = 0;
1037 for (uint32 enchant_slot = SOCK_ENCHANTMENT_SLOT; enchant_slot < SOCK_ENCHANTMENT_SLOT + MAX_GEM_SOCKETS; ++enchant_slot)
1038 {
1039 uint32 enchant_id = GetEnchantmentId(EnchantmentSlot(enchant_slot));
1040 if (!enchant_id)
1041 continue;
1042
1043 SpellItemEnchantmentEntry const* enchantEntry = sSpellItemEnchantmentStore.LookupEntry(enchant_id);
1044 if (!enchantEntry)
1045 continue;
1046
1047 ItemTemplate const* gemProto = sObjectMgr->GetItemTemplate(enchantEntry->GemID);
1048 if (!gemProto)
1049 continue;
1050
1051 if (gemProto->ItemLimitCategory == limitCategory)
1052 ++count;
1053 }
1054 return count;
1055}
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 ( )
557{
558 return GetTemplate()->GetSkill();
559}
uint32 GetSkill() const
Definition: ItemTemplate.h:793

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

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

◆ GetSlot()

◆ GetSpell()

uint32 Item::GetSpell ( )
562{
563 ItemTemplate const* proto = GetTemplate();
564
565 switch (proto->Class)
566 {
568 switch (proto->SubClass)
569 {
571 return 196;
573 return 197;
575 return 264;
577 return 266;
579 return 198;
581 return 199;
583 return 200;
585 return 201;
587 return 202;
589 return 227;
591 return 1180;
593 return 2567;
595 return 3386;
597 return 5011;
599 return 5009;
600 default:
601 return 0;
602 }
603 case ITEM_CLASS_ARMOR:
604 switch (proto->SubClass)
605 {
607 return 9078;
609 return 9077;
611 return 8737;
613 return 750;
615 return 9116;
616 default:
617 return 0;
618 }
619 }
620 return 0;
621}
@ 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
546{
547 return sObjectMgr->GetItemTemplate(GetEntry());
548}

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

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
1009{
1010 // There can only be one socket added, and it's always in slot `PRISMATIC_ENCHANTMENT_SLOT`.
1011 // Built-in sockets Socket from upgrade
1013}
@ 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:830

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
1134{
1135 // not binded item
1136 if (!IsSoulBound())
1137 return false;
1138
1139 // own item
1140 if (GetOwnerGUID() == player->GetGUID())
1141 return false;
1142
1144 if (allowedGUIDs.find(player->GetGUID()) != allowedGUIDs.end())
1145 return false;
1146
1147 // BOA item case
1148 if (IsBoundAccountWide())
1149 return false;
1150
1151 return true;
1152}

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
849{
850 // Check all enchants for soulbound
851 for (uint32 enchant_slot = PERM_ENCHANTMENT_SLOT; enchant_slot < MAX_ENCHANTMENT_SLOT; ++enchant_slot)
852 if (uint32 enchant_id = GetEnchantmentId(EnchantmentSlot(enchant_slot)))
853 if (SpellItemEnchantmentEntry const* enchantEntry = sSpellItemEnchantmentStore.LookupEntry(enchant_id))
854 if (enchantEntry->slot & ENCHANTMENT_CAN_SOULBOUND)
855 return true;
856 return false;
857}
@ 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
860{
862 if (SpellItemEnchantmentEntry const* enchantEntry = sSpellItemEnchantmentStore.LookupEntry(enchant_id))
863 if (enchantEntry->slot & ENCHANTMENT_CAN_SOULBOUND)
864 return true;
865 return false;
866}
@ 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:831

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

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
1058{
1059 ItemTemplate const* proto = GetTemplate();
1060 return proto && ((proto->Map && proto->Map != cur_mapId) || (proto->Area && proto->Area != cur_zoneId));
1061}
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()

bool Item::IsNotEmptyBag ( ) const

◆ IsPotion()

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

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

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

◆ IsRefundExpired()

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

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.

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

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

References GetOwner().

◆ RemoveFromUpdateQueueOf()

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

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 ( )
1174{
1175 CharacterDatabaseTransaction trans = CharacterDatabase.BeginTransaction();
1176
1178 stmt->SetData(0, GetGUID().GetCounter());
1179 trans->Append(stmt);
1180
1181 stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_ITEM_REFUND_INSTANCE);
1182 stmt->SetData(0, GetGUID().GetCounter());
1183 stmt->SetData(1, GetRefundRecipient());
1184 stmt->SetData(2, GetPaidMoney());
1185 stmt->SetData(3, uint16(GetPaidExtendedCost()));
1186 trans->Append(stmt);
1187
1188 CharacterDatabase.CommitTransaction(trans);
1189}
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.

338{
339 bool isInTransaction = static_cast<bool>(trans);
340 if (!isInTransaction)
341 trans = CharacterDatabase.BeginTransaction();
342
344 switch (uState)
345 {
346 case ITEM_NEW:
347 case ITEM_CHANGED:
348 {
349 uint8 index = 0;
351 stmt->SetData( index, GetEntry());
352 stmt->SetData(++index, GetOwnerGUID().GetCounter());
353 stmt->SetData(++index, GetGuidValue(ITEM_FIELD_CREATOR).GetCounter());
354 stmt->SetData(++index, GetGuidValue(ITEM_FIELD_GIFTCREATOR).GetCounter());
355 stmt->SetData(++index, GetCount());
357
358 std::ostringstream ssSpells;
359 for (uint8 i = 0; i < MAX_ITEM_PROTO_SPELLS; ++i)
360 ssSpells << GetSpellCharges(i) << ' ';
361 stmt->SetData(++index, ssSpells.str());
362
363 stmt->SetData(++index, GetUInt32Value(ITEM_FIELD_FLAGS));
364
365 std::ostringstream ssEnchants;
366 for (uint8 i = 0; i < MAX_ENCHANTMENT_SLOT; ++i)
367 {
368 ssEnchants << GetEnchantmentId(EnchantmentSlot(i)) << ' ';
369 ssEnchants << GetEnchantmentDuration(EnchantmentSlot(i)) << ' ';
370 ssEnchants << GetEnchantmentCharges(EnchantmentSlot(i)) << ' ';
371 }
372 stmt->SetData(++index, ssEnchants.str());
373
374 stmt->SetData (++index, GetItemRandomPropertyId());
377 stmt->SetData(++index, m_text);
378 stmt->SetData(++index, guid);
379
380 trans->Append(stmt);
381
383 {
384 stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_GIFT_OWNER);
385 stmt->SetData(0, GetOwnerGUID().GetCounter());
386 stmt->SetData(1, guid);
387 trans->Append(stmt);
388 }
389 break;
390 }
391 case ITEM_REMOVED:
392 {
394 stmt->SetData(0, guid);
395 trans->Append(stmt);
396
398 {
399 stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_GIFT);
400 stmt->SetData(0, guid);
401 trans->Append(stmt);
402 }
403
404 if (!isInTransaction)
405 CharacterDatabase.CommitTransaction(trans);
406
407 delete this;
408 return;
409 }
410 case ITEM_UNCHANGED:
411 break;
412 }
413
415
416 if (!isInTransaction)
417 CharacterDatabase.CommitTransaction(trans);
418}
@ 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)
1077{
1079 if (!duration)
1080 return;
1081
1082 WorldPacket data(SMSG_ITEM_TIME_UPDATE, (8 + 4));
1083 data << GetGUID();
1084 data << uint32(duration);
1085 owner->GetSession()->SendPacket(&data);
1086}
@ SMSG_ITEM_TIME_UPDATE
Definition: Opcodes.h:520
WorldSession * GetSession() const
Definition: Player.h:1961
Definition: WorldPacket.h:27
void SendPacket(WorldPacket const *packet)
Send a packet to the client.
Definition: WorldSession.cpp:212

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 ( )
1064{
1065 WorldPacket data(SMSG_SOCKET_GEMS_RESULT, 8 + 4 + 4 + 4 + 4);
1066 data << GetGUID();
1069
1070 GetOwner()->GetSession()->SendPacket(&data);
1071}
@ 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 
)
922{
923 // Better lost small time at check in comparison lost time at item save to DB.
924 if ((GetEnchantmentId(slot) == id) && (GetEnchantmentDuration(slot) == duration) && (GetEnchantmentCharges(slot) == charges))
925 return;
926
927 Player* owner = GetOwner();
929 {
930 if (uint32 oldEnchant = GetEnchantmentId(slot))
932
933 if (id)
934 owner->GetSession()->SendEnchantmentLog(GetOwnerGUID(), caster, GetEntry(), id);
935 }
936
940 SetState(ITEM_CHANGED, owner);
941}
@ MAX_INSPECTED_ENCHANTMENT_SLOT
Definition: Item.h:170
void SendEnchantmentLog(ObjectGuid target, ObjectGuid caster, uint32 itemId, uint32 enchantId)
Definition: ItemHandler.cpp:1222

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 
)
943{
944 if (GetEnchantmentDuration(slot) == duration)
945 return;
946
948 SetState(ITEM_CHANGED, owner);
949 // Cannot use GetOwner() here, has to be passed as an argument to avoid freeze due to hashtable locking
950}

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)
670{
671 if (!randomPropId)
672 return;
673
674 if (randomPropId > 0)
675 {
676 ItemRandomPropertiesEntry const* item_rand = sItemRandomPropertiesStore.LookupEntry(randomPropId);
677 if (item_rand)
678 {
680 {
683 }
686 }
687 }
688 else
689 {
690 ItemRandomSuffixEntry const* item_rand = sItemRandomSuffixStore.LookupEntry(-randomPropId);
691 if (item_rand)
692 {
695 {
699 }
700
703 }
704 }
705}
@ 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:921
std::array< uint32, MAX_ITEM_ENCHANTMENT_EFFECTS > Enchantment
Definition: DBCStructure.h:1201
std::array< uint32, MAX_ITEM_ENCHANTMENT_EFFECTS > Enchantment
Definition: DBCStructure.h:1213

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 
)
1202{
1204 return;
1205
1207 // Following is not applicable in the trading procedure
1208 if (changestate)
1209 SetState(ITEM_CHANGED, owner);
1210
1212 SetPaidMoney(0);
1215
1217}
void DeleteRefundDataFromDB(CharacterDatabaseTransaction *trans)
Definition: Item.cpp:1191
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:15431

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)
1260{
1262 allowedGUIDs = allowedLooters;
1263}
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 
)
716{
717 if (uState == ITEM_NEW && state == ITEM_REMOVED)
718 {
719 // pretend the item never existed
720 if (forplayer)
721 {
722 RemoveFromUpdateQueueOf(forplayer);
723 forplayer->DeleteRefundReference(GetGUID());
724 }
725 delete this;
726 return;
727 }
728 if (state != ITEM_UNCHANGED)
729 {
730 // new items must stay in new state until saved
731 if (uState != ITEM_NEW)
732 uState = state;
733 if (forplayer)
734 AddToUpdateQueueOf(forplayer);
735 }
736 else
737 {
738 // unset in queue
739 // the item must be removed from the queue manually
740 uQueuePos = -1;
742 }
743}
void AddToUpdateQueueOf(Player *player)
Definition: Item.cpp:745
void RemoveFromUpdateQueueOf(Player *player)
Definition: Item.cpp:765

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 
)
320{
322 return;
323
324 LOG_DEBUG("entities.player.items", "Item::UpdateDuration Item (Entry: {} Duration {} Diff {})", GetEntry(), GetUInt32Value(ITEM_FIELD_DURATION), diff);
325
327 {
328 sScriptMgr->OnItemExpire(owner, GetTemplate());
329 owner->DestroyItem(GetBagSlot(), GetSlot(), true);
330 return;
331 }
332
334 SetState(ITEM_CHANGED, owner); // save new time in database
335}
void DestroyItem(uint8 bag, uint8 slot, bool update)
Definition: PlayerStorage.cpp:3045

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

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