OregonCore  revision fb2a440-git
Your Favourite TBC server
Item.h
Go to the documentation of this file.
1 /*
2  * This file is part of the OregonCore 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 OREGONCORE_ITEM_H
19 #define OREGONCORE_ITEM_H
20 
21 #include "Common.h"
22 #include "Object.h"
23 #include "LootMgr.h"
24 #include "ItemPrototype.h"
25 #include "QueryResult.h"
26 
27 struct SpellEntry;
28 class Bag;
29 class QueryResult;
30 
32 {
35  SpellEntry const* spells[8];
36 };
37 
39 {
120  // probably exist more
121 };
122 
124 {
134 };
135 
137 {
139  SELL_ERR_CANT_SELL_ITEM = 2, // merchant doesn't like that item
140  SELL_ERR_CANT_FIND_VENDOR = 3, // merchant doesn't like you
141  SELL_ERR_YOU_DONT_OWN_THAT_ITEM = 4, // you don't own that item
142  SELL_ERR_UNK = 5, // nothing appears...
143  SELL_ERR_ONLY_EMPTY_BAG = 6 // can only do with empty bags
144 };
145 
146 // -1 from client enchantment slot number
148 {
156 
157  PROP_ENCHANTMENT_SLOT_0 = 6, // used with RandomSuffix
158  PROP_ENCHANTMENT_SLOT_1 = 7, // used with RandomSuffix
159  PROP_ENCHANTMENT_SLOT_2 = 8, // used with RandomSuffix and RandomProperty
160  PROP_ENCHANTMENT_SLOT_3 = 9, // used with RandomProperty
161  PROP_ENCHANTMENT_SLOT_4 = 10, // used with RandomProperty
163 };
164 
165 #define MAX_VISIBLE_ITEM_OFFSET 16 // 16 fields per visible item (creator(2) + enchantments(12) + properties(1) + pad(1))
166 
168 {
172 };
173 
174 #define MAX_ENCHANTMENT_OFFSET 3
175 
177 {
182 };
183 
185 {
188  ITEM_NEW = 2,
190 };
191 
192 #define MAX_ITEM_REQ_TARGET_TYPE 2
193 
194 bool ItemCanGoIntoBag(ItemTemplate const* proto, ItemTemplate const* pBagProto);
195 
196 class Item : public Object
197 {
198  public:
199  static Item* CreateItem(uint32 item, uint32 count, Player const* player = NULL);
200  Item* CloneItem(uint32 count, Player const* player = NULL) const;
201 
202  Item ();
203 
204  virtual bool Create(uint32 guidlow, uint32 itemid, Player const* owner);
205 
206  ItemTemplate const* GetProto() const;
207 
208  uint64 const& GetOwnerGUID() const
209  {
210  return GetUInt64Value(ITEM_FIELD_OWNER);
211  }
212  void SetOwnerGUID(uint64 guid)
213  {
214  SetUInt64Value(ITEM_FIELD_OWNER, guid);
215  }
216  Player* GetOwner()const;
217 
218  void SetBinding(bool val) { ApplyModFlag(ITEM_FIELD_FLAGS, ITEM_FLAG_SOULBOUND, val); }
219  bool IsSoulBound() const { return HasFlag(ITEM_FIELD_FLAGS, ITEM_FLAG_SOULBOUND); }
220 
221  bool IsBindedNotWith(Player const* player) const;
222  bool IsBoundByEnchant() const;
223  virtual void SaveToDB();
224  virtual bool LoadFromDB(uint32 guid, uint64 owner_guid, Field* fields);
225  virtual void DeleteFromDB();
226  void DeleteFromInventoryDB();
227 
228  bool IsLocked() const { return !HasFlag(ITEM_FIELD_FLAGS, ITEM_FLAG_UNLOCKED); }
229  bool IsBag() const
230  {
231  return GetProto()->InventoryType == INVTYPE_BAG;
232  }
233  bool IsBroken() const
234  {
235  return GetUInt32Value(ITEM_FIELD_MAXDURABILITY) > 0 && GetUInt32Value(ITEM_FIELD_DURABILITY) == 0;
236  }
237  bool CanBeTraded() const;
238  void SetInTrade(bool b = true)
239  {
240  mb_in_trade = b;
241  }
242  bool IsInTrade() const
243  {
244  return mb_in_trade;
245  }
246 
247  bool IsFitToSpellRequirements(SpellEntry const* spellInfo) const;
248  bool IsLimitedToAnotherMapOrZone(uint32 cur_mapId, uint32 cur_zoneId) const;
249  bool GemsFitSockets() const;
250 
251  uint32 GetCount() const
252  {
253  return GetUInt32Value(ITEM_FIELD_STACK_COUNT);
254  }
256  {
257  SetUInt32Value(ITEM_FIELD_STACK_COUNT, value);
258  }
260  {
261  return GetProto()->Stackable;
262  }
263  uint8 GetGemCountWithID(uint32 GemID) const;
264  uint8 CanBeMergedPartlyWith(ItemTemplate const* proto) const;
265 
266  uint8 GetSlot() const
267  {
268  return m_slot;
269  }
271  {
272  return m_container;
273  }
274  uint8 GetBagSlot() const;
275  void SetSlot(uint8 slot)
276  {
277  m_slot = slot;
278  }
279  uint16 GetPos() const
280  {
281  return uint16(GetBagSlot()) << 8 | GetSlot();
282  }
283  void SetContainer(Bag* container)
284  {
285  m_container = container;
286  }
287 
288  bool IsInBag() const
289  {
290  return m_container != NULL;
291  }
292  bool IsEquipped() const;
293 
294  uint32 GetSkill();
295  uint32 GetSpell();
296 
297  // RandomPropertyId (signed but stored as unsigned)
299  {
300  return GetInt32Value(ITEM_FIELD_RANDOM_PROPERTIES_ID);
301  }
303  {
304  return GetUInt32Value(ITEM_FIELD_PROPERTY_SEED);
305  }
306  void SetItemRandomProperties(int32 randomPropId);
307  void UpdateItemSuffixFactor();
308  static int32 GenerateItemRandomPropertyId(uint32 item_id);
309  void SetEnchantment(EnchantmentSlot slot, uint32 id, uint32 duration, uint32 charges);
310  void SetEnchantmentDuration(EnchantmentSlot slot, uint32 duration, Player* owner);
311  void SetEnchantmentCharges(EnchantmentSlot slot, uint32 charges);
312  void ClearEnchantment(EnchantmentSlot slot);
314  {
315  return GetUInt32Value(ITEM_FIELD_ENCHANTMENT + slot * MAX_ENCHANTMENT_OFFSET + ENCHANTMENT_ID_OFFSET);
316  }
318  {
320  }
322  {
324  }
325 
326  void SendTimeUpdate(Player* owner);
327  void UpdateDuration(Player* owner, uint32 diff);
328 
329  // spell charges (signed but stored as unsigned)
330  int32 GetSpellCharges(uint8 index/*0..5*/ = 0) const
331  {
332  return GetInt32Value(ITEM_FIELD_SPELL_CHARGES + index);
333  }
334  void SetSpellCharges(uint8 index/*0..5*/, int32 value)
335  {
336  SetInt32Value(ITEM_FIELD_SPELL_CHARGES + index, value);
337  }
338 
341 
342  // Update States
344  {
345  return uState;
346  }
347  void SetState(ItemUpdateState state, Player* forplayer = NULL);
348  void AddToUpdateQueueOf(Player* player);
349  void RemoveFromUpdateQueueOf(Player* player);
350  bool IsInUpdateQueue() const
351  {
352  return uQueuePos != -1;
353  }
355  {
356  return uQueuePos;
357  }
358  void FSetState(ItemUpdateState state) // forced
359  {
360  uState = state;
361  }
362 
363  bool hasQuest(uint32 quest_id) const override
364  {
365  ItemTemplate const* itemProto = GetProto();
366  return itemProto && itemProto->StartQuest == quest_id;
367  }
368  bool hasInvolvedQuest(uint32 /*quest_id*/) const override
369  {
370  return false;
371  }
372 
373  void BuildUpdate(UpdateDataMapType&) override;
374 
375  private:
380  bool mb_in_trade; // true if item is currently in trade-window
381 };
382 #endif
383 
Definition: Object.h:130
uint32 GetCount() const
Definition: Item.h:251
uint32 InventoryType
int32 GetSpellCharges(uint8 index=0) const
Definition: Item.h:330
bool mb_in_trade
Definition: Item.h:380
void SetContainer(Bag *container)
Definition: Item.h:283
void SetBinding(bool val)
Definition: Item.h:218
uint32 GetItemSuffixFactor() const
Definition: Item.h:302
bool IsSoulBound() const
Definition: Item.h:219
Bag * GetContainer()
Definition: Item.h:270
EnchantmentOffset
Definition: Item.h:167
uint32 GetMaxStackCount() const
Definition: Item.h:259
void FSetState(ItemUpdateState state)
Definition: Item.h:358
Definition: Field.h:24
SellFailure
Definition: Item.h:136
bool IsLocked() const
Definition: Item.h:228
ItemUpdateState GetState() const
Definition: Item.h:343
void SetInTrade(bool b=true)
Definition: Item.h:238
bool m_lootGenerated
Definition: Item.h:340
uint16 GetPos() const
Definition: Item.h:279
bool hasInvolvedQuest(uint32) const override
Definition: Item.h:368
ACE_INT32 int32
Definition: Define.h:67
InventoryChangeFailure
Definition: Item.h:38
void SetCount(uint32 value)
Definition: Item.h:255
uint16 GetQueuePos() const
Definition: Item.h:354
void SetOwnerGUID(uint64 guid)
Definition: Item.h:212
Bag * m_container
Definition: Item.h:377
bool IsBag() const
Definition: Item.h:229
int32 GetItemRandomPropertyId() const
Definition: Item.h:298
uint32 GetEnchantmentDuration(EnchantmentSlot slot) const
Definition: Item.h:317
uint32 setid
Definition: Item.h:33
bool hasQuest(uint32 quest_id) const override
Definition: Item.h:363
ItemUpdateState uState
Definition: Item.h:378
SpellEntry const * spells[8]
Definition: Item.h:35
bool ItemCanGoIntoBag(ItemTemplate const *proto, ItemTemplate const *pBagProto)
Definition: Item.cpp:166
Definition: Bag.h:27
ACE_UINT8 uint8
Definition: Define.h:73
void SetSlot(uint8 slot)
Definition: Item.h:275
Definition: LootMgr.h:290
Definition: Item.h:196
#define MAX_ENCHANTMENT_OFFSET
Definition: Item.h:174
etc mysql my cnf *Then change max_allowed_packet to a bigger value
UNORDERED_MAP< Player *, UpdateData > UpdateDataMapType
Definition: Object.h:126
uint8 m_slot
Definition: Item.h:376
int16 uQueuePos
Definition: Item.h:379
uint8 GetSlot() const
Definition: Item.h:266
void SetSpellCharges(uint8 index, int32 value)
Definition: Item.h:334
ACE_UINT64 uint64
Definition: Define.h:70
bool IsBroken() const
Definition: Item.h:233
bool IsInTrade() const
Definition: Item.h:242
ItemUpdateState
Definition: Item.h:184
uint32 GetEnchantmentCharges(EnchantmentSlot slot) const
Definition: Item.h:321
EnchantmentSlot
Definition: Item.h:147
uint32 Stackable
EnchantmentSlotMask
Definition: Item.h:176
Definition: Item.h:188
bool IsInBag() const
Definition: Item.h:288
ACE_UINT16 uint16
Definition: Define.h:72
ACE_INT16 int16
Definition: Define.h:68
bool IsInUpdateQueue() const
Definition: Item.h:350
ACE_UINT32 uint32
Definition: Define.h:71
uint32 item_count
Definition: Item.h:34
Definition: Player.h:922
Loot loot
Definition: Item.h:339
uint64 const & GetOwnerGUID() const
Definition: Item.h:208
BuyFailure
Definition: Item.h:123
uint32 StartQuest
uint32 GetEnchantmentId(EnchantmentSlot slot) const
Definition: Item.h:313