TrinityCore
Loading...
Searching...
No Matches
Item.h
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef TRINITYCORE_ITEM_H
19#define TRINITYCORE_ITEM_H
20
21#include "Object.h"
22#include "Common.h"
23#include "DatabaseEnvFwd.h"
24#include "ItemDefines.h"
25#include "ItemEnchantmentMgr.h"
26#include "ItemTemplate.h"
27#include "Loot.h"
28
29class SpellInfo;
30class Bag;
31class Unit;
32
39
40#define MAX_GEM_SOCKETS MAX_ITEM_PROTO_SOCKETS// (BONUS_ENCHANTMENT_SLOT-SOCK_ENCHANTMENT_SLOT) and item proto size, equal value expected
41
43{
46 ENCHANTMENT_CHARGES_OFFSET = 2 // now here not only charges, but something new in wotlk
47};
48
49#define MAX_ENCHANTMENT_OFFSET 3
50
58
59bool ItemCanGoIntoBag(ItemTemplate const* proto, ItemTemplate const* pBagProto);
60
61class TC_GAME_API Item : public Object
62{
63 friend void AddItemToUpdateQueueOf(Item* item, Player* player);
64 friend void RemoveItemFromUpdateQueueOf(Item* item, Player* player);
65
66 public:
67 static Item* CreateItem(uint32 itemEntry, uint32 count, Player const* player = nullptr);
68 Item* CloneItem(uint32 count, Player const* player = nullptr) const;
69
70 Item();
71
72 virtual bool Create(ObjectGuid::LowType guidlow, uint32 itemId, Player const* owner);
73
74 ItemTemplate const* GetTemplate() const;
75
78 Player* GetOwner()const;
79
82 bool IsBoundAccountWide() const { return GetTemplate()->HasFlag(ITEM_FLAG_IS_BOUND_TO_ACCOUNT); }
83 bool IsBindedNotWith(Player const* player) const;
84 bool IsBoundByEnchant() const;
85 virtual void SaveToDB(CharacterDatabaseTransaction trans);
86 virtual bool LoadFromDB(ObjectGuid::LowType guid, ObjectGuid owner_guid, Field* fields, uint32 entry);
87 static void DeleteFromDB(CharacterDatabaseTransaction trans, ObjectGuid::LowType itemGuid);
88 virtual void DeleteFromDB(CharacterDatabaseTransaction trans);
89 static void DeleteFromInventoryDB(CharacterDatabaseTransaction trans, ObjectGuid::LowType itemGuid);
90
91 void DeleteFromInventoryDB(CharacterDatabaseTransaction trans);
92 void SaveRefundDataToDB();
93 void DeleteRefundDataFromDB(CharacterDatabaseTransaction* trans);
94
95 Bag* ToBag() { if (IsBag()) return reinterpret_cast<Bag*>(this); else return nullptr; }
96 Bag const* ToBag() const { if (IsBag()) return reinterpret_cast<Bag const*>(this); else return nullptr; }
97
102 bool IsBag() const { return GetTemplate()->InventoryType == INVTYPE_BAG; }
103 bool IsCurrencyToken() const { return GetTemplate()->IsCurrencyToken(); }
104 bool IsNotEmptyBag() const;
106 bool CanBeTraded(bool mail = false, bool trade = false) const;
107 void SetInTrade(bool b = true) { mb_in_trade = b; }
108 bool IsInTrade() const { return mb_in_trade; }
109
110 uint32 CalculateDurabilityRepairCost(float discount) const;
111
112 bool HasEnchantRequiredSkill(Player const* player) const;
113 uint32 GetEnchantRequiredLevel() const;
114
115 bool IsFitToSpellRequirements(SpellInfo const* spellInfo) const;
116 bool IsLimitedToAnotherMapOrZone(uint32 cur_mapId, uint32 cur_zoneId) const;
117 bool GemsFitSockets() const;
118
120 void SetCount(uint32 value);
121 uint32 GetMaxStackCount() const { return GetTemplate()->GetMaxStackSize(); }
122 uint8 GetGemCountWithID(uint32 GemID) const;
123 uint8 GetGemCountWithLimitCategory(uint32 limitCategory) const;
124 InventoryResult CanBeMergedPartlyWith(ItemTemplate const* proto) const;
125
126 uint8 GetSlot() const {return m_slot;}
127 Bag* GetContainer() { return m_container; }
128 uint8 GetBagSlot() const;
129 void SetSlot(uint8 slot) { m_slot = slot; }
130 uint16 GetPos() const { return uint16(GetBagSlot()) << 8 | GetSlot(); }
131 void SetContainer(Bag* container) { m_container = container; }
132
133 bool IsInBag() const { return m_container != nullptr; }
134 bool IsEquipped() const;
135
136 uint32 GetSkill();
137 uint32 GetSpell();
138
139 // RandomPropertyId (signed but stored as unsigned)
142 void SetItemRandomProperties(int32 randomPropId);
143 void UpdateItemSuffixFactor();
144 void SetEnchantment(EnchantmentSlot slot, uint32 id, uint32 duration, uint32 charges, ObjectGuid caster = ObjectGuid::Empty);
145 void SetEnchantmentDuration(EnchantmentSlot slot, uint32 duration, Player* owner);
146 void SetEnchantmentCharges(EnchantmentSlot slot, uint32 charges);
147 void ClearEnchantment(EnchantmentSlot slot);
151
152 std::string const& GetText() const { return m_text; }
153 void SetText(std::string const& text) { m_text = text; }
154
155 void SendUpdateSockets();
156
157 void SendTimeUpdate(Player* owner);
158 void UpdateDuration(Player* owner, uint32 diff);
159
160 // spell charges (signed but stored as unsigned)
161 int32 GetSpellCharges(uint8 index/*0..5*/ = 0) const { return GetInt32Value(ITEM_FIELD_SPELL_CHARGES + index); }
162 void SetSpellCharges(uint8 index/*0..5*/, int32 value) { SetInt32Value(ITEM_FIELD_SPELL_CHARGES + index, value); }
163
166
167 // Update States
168 ItemUpdateState GetState() const { return uState; }
169 void SetState(ItemUpdateState state, Player* forplayer = nullptr);
170 bool IsInUpdateQueue() const { return uQueuePos != -1; }
171 uint16 GetQueuePos() const { return uQueuePos; }
172 void FSetState(ItemUpdateState state) // forced
173 {
174 uState = state;
175 }
176
177 bool hasQuest(uint32 quest_id) const override { return GetTemplate()->StartQuest == quest_id; }
178 bool hasInvolvedQuest(uint32 /*quest_id*/) const override { return false; }
179 bool IsPotion() const { return GetTemplate()->IsPotion(); }
180 bool IsWeaponVellum() const { return GetTemplate()->IsWeaponVellum(); }
181 bool IsArmorVellum() const { return GetTemplate()->IsArmorVellum(); }
182 bool IsConjuredConsumable() const { return GetTemplate()->IsConjuredConsumable(); }
183
184 // Item Refund system
185 void SetNotRefundable(Player* owner, bool changestate = true, CharacterDatabaseTransaction* trans = nullptr);
186 void SetRefundRecipient(ObjectGuid const& guid) { m_refundRecipient = guid; }
187 void SetPaidMoney(uint32 money) { m_paidMoney = money; }
188 void SetPaidExtendedCost(uint32 iece) { m_paidExtendedCost = iece; }
189
190 ObjectGuid const& GetRefundRecipient() const { return m_refundRecipient; }
191 uint32 GetPaidMoney() const { return m_paidMoney; }
192 uint32 GetPaidExtendedCost() const { return m_paidExtendedCost; }
193
194 void UpdatePlayedTime(Player* owner);
195 uint32 GetPlayedTime();
196 bool IsRefundExpired();
197
198 // Soulbound trade system
199 void SetSoulboundTradeable(GuidSet const& allowedLooters);
200 void ClearSoulboundTradeable(Player* currentOwner);
201 bool CheckSoulboundTradeExpire();
202
203 void BuildUpdate(UpdateDataMapType&) override;
204
205 bool AddToObjectUpdate() override;
206 void RemoveFromObjectUpdate() override;
207
208 uint32 GetScriptId() const { return GetTemplate()->ScriptId; }
209
210 std::string GetDebugInfo() const override;
211 private:
212 std::string m_text;
217 bool mb_in_trade; // true if item is currently in trade-window
223};
224#endif
SQLTransaction< CharacterDatabaseConnection > CharacterDatabaseTransaction
#define TC_GAME_API
Definition Define.h:114
uint8_t uint8
Definition Define.h:135
int16_t int16
Definition Define.h:130
int32_t int32
Definition Define.h:129
uint16_t uint16
Definition Define.h:134
uint32_t uint32
Definition Define.h:133
EnchantmentSlot
InventoryResult
Definition ItemDefines.h:25
@ ITEM_FIELD_FLAG_REFUNDABLE
@ ITEM_FIELD_FLAG_UNLOCKED
@ ITEM_FIELD_FLAG_SOULBOUND
@ ITEM_FIELD_FLAG_WRAPPED
@ ITEM_FIELD_FLAG_BOP_TRADEABLE
@ ITEM_FLAG_IS_BOUND_TO_ACCOUNT
@ INVTYPE_BAG
void RemoveItemFromUpdateQueueOf(Item *item, Player *player)
Definition Item.cpp:690
void AddItemToUpdateQueueOf(Item *item, Player *player)
Definition Item.cpp:669
#define MAX_ENCHANTMENT_OFFSET
Definition Item.h:49
ItemUpdateState
Definition Item.h:52
@ ITEM_CHANGED
Definition Item.h:54
@ ITEM_REMOVED
Definition Item.h:56
@ ITEM_NEW
Definition Item.h:55
@ ITEM_UNCHANGED
Definition Item.h:53
EnchantmentOffset
Definition Item.h:43
@ ENCHANTMENT_ID_OFFSET
Definition Item.h:44
@ ENCHANTMENT_CHARGES_OFFSET
Definition Item.h:46
@ ENCHANTMENT_DURATION_OFFSET
Definition Item.h:45
bool ItemCanGoIntoBag(ItemTemplate const *proto, ItemTemplate const *pBagProto)
Definition Item.cpp:182
std::set< ObjectGuid > GuidSet
Definition ObjectGuid.h:260
std::unordered_map< Player *, UpdateData > UpdateDataMapType
Definition Object.h:63
static void SaveToDB(QuestPool const &pool, CharacterDatabaseTransaction trans)
@ ITEM_FIELD_DURABILITY
@ ITEM_FIELD_STACK_COUNT
@ ITEM_FIELD_FLAGS
@ ITEM_FIELD_MAXDURABILITY
@ ITEM_FIELD_RANDOM_PROPERTIES_ID
@ ITEM_FIELD_OWNER
@ ITEM_FIELD_PROPERTY_SEED
@ ITEM_FIELD_ENCHANTMENT_1_1
@ ITEM_FIELD_SPELL_CHARGES
Definition Bag.h:27
Class used to access individual fields of database query result.
Definition Field.h:92
Definition Item.h:62
uint32 GetPaidExtendedCost() const
Definition Item.h:192
bool hasInvolvedQuest(uint32) const override
Definition Item.h:178
uint8 GetSlot() const
Definition Item.h:126
std::string const & GetText() const
Definition Item.h:152
bool IsCurrencyToken() const
Definition Item.h:103
uint32 GetScriptId() const
Definition Item.h:208
bool IsWrapped() const
Definition Item.h:100
Bag * GetContainer()
Definition Item.h:127
void SetSpellCharges(uint8 index, int32 value)
Definition Item.h:162
void SetText(std::string const &text)
Definition Item.h:153
void SetBinding(bool val)
Definition Item.h:80
uint32 GetEnchantmentId(EnchantmentSlot slot) const
Definition Item.h:148
int32 GetSpellCharges(uint8 index=0) const
Definition Item.h:161
Bag * m_container
Definition Item.h:214
void SetPaidMoney(uint32 money)
Definition Item.h:187
bool IsBoundAccountWide() const
Definition Item.h:82
bool mb_in_trade
Definition Item.h:217
Bag * ToBag()
Definition Item.h:95
std::string m_text
Definition Item.h:212
uint32 GetEnchantmentDuration(EnchantmentSlot slot) const
Definition Item.h:149
bool IsLocked() const
Definition Item.h:101
int32 GetItemRandomPropertyId() const
Definition Item.h:140
bool IsBOPTradeable() const
Definition Item.h:99
bool IsInBag() const
Definition Item.h:133
bool IsSoulBound() const
Definition Item.h:81
ItemUpdateState GetState() const
Definition Item.h:168
bool IsPotion() const
Definition Item.h:179
bool IsBroken() const
Definition Item.h:105
uint32 GetItemSuffixFactor() const
Definition Item.h:141
bool IsWeaponVellum() const
Definition Item.h:180
uint32 m_paidMoney
Definition Item.h:220
uint16 GetQueuePos() const
Definition Item.h:171
bool IsArmorVellum() const
Definition Item.h:181
ObjectGuid GetOwnerGUID() const
Definition Item.h:76
Bag const * ToBag() const
Definition Item.h:96
time_t m_lastPlayedTimeUpdate
Definition Item.h:218
bool IsRefundable() const
Definition Item.h:98
uint16 GetPos() const
Definition Item.h:130
ObjectGuid m_refundRecipient
Definition Item.h:219
bool IsInTrade() const
Definition Item.h:108
int16 uQueuePos
Definition Item.h:216
void FSetState(ItemUpdateState state)
Definition Item.h:172
uint32 m_paidExtendedCost
Definition Item.h:221
bool IsBag() const
Definition Item.h:102
ObjectGuid const & GetRefundRecipient() const
Definition Item.h:190
void SetPaidExtendedCost(uint32 iece)
Definition Item.h:188
uint32 GetEnchantmentCharges(EnchantmentSlot slot) const
Definition Item.h:150
void SetRefundRecipient(ObjectGuid const &guid)
Definition Item.h:186
uint32 GetPaidMoney() const
Definition Item.h:191
void SetSlot(uint8 slot)
Definition Item.h:129
bool m_lootGenerated
Definition Item.h:165
uint32 GetCount() const
Definition Item.h:119
void SetOwnerGUID(ObjectGuid guid)
Definition Item.h:77
Loot loot
Definition Item.h:164
void SetContainer(Bag *container)
Definition Item.h:131
bool hasQuest(uint32 quest_id) const override
Definition Item.h:177
uint32 GetMaxStackCount() const
Definition Item.h:121
bool IsConjuredConsumable() const
Definition Item.h:182
uint8 m_slot
Definition Item.h:213
bool IsInUpdateQueue() const
Definition Item.h:170
GuidSet allowedGUIDs
Definition Item.h:222
ItemUpdateState uState
Definition Item.h:215
void SetInTrade(bool b=true)
Definition Item.h:107
static ObjectGuid const Empty
Definition ObjectGuid.h:140
uint32 LowType
Definition ObjectGuid.h:142
int32 GetInt32Value(uint16 index) const
Definition Object.cpp:243
void SetInt32Value(uint16 index, int32 value)
Definition Object.cpp:572
uint32 GetUInt32Value(uint16 index) const
Definition Object.cpp:249
virtual bool AddToObjectUpdate()=0
void ApplyModFlag(uint16 index, uint32 flag, bool apply)
Definition Object.cpp:805
void SetGuidValue(uint16 index, ObjectGuid value)
Definition Object.cpp:699
virtual std::string GetDebugInfo() const
Definition Object.cpp:899
virtual void BuildUpdate(UpdateDataMapType &)
Definition Object.h:158
virtual void RemoveFromObjectUpdate()=0
bool HasFlag(uint16 index, uint32 flag) const
Definition Object.cpp:799
ObjectGuid GetGuidValue(uint16 index) const
Definition Object.cpp:281
Definition Unit.h:769
uint32 item_count
Definition Item.h:36
uint32 setid
Definition Item.h:35
SpellInfo const * spells[8]
Definition Item.h:37
bool IsPotion() const
uint32 GetMaxStackSize() const
bool IsCurrencyToken() const
bool IsArmorVellum() const
bool IsConjuredConsumable() const
bool HasFlag(ItemFlags flag) const
uint32 InventoryType
uint32 StartQuest
bool IsWeaponVellum() const
Definition Loot.h:207