TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Bag.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
3  * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License as published by the
7  * Free Software Foundation; either version 2 of the License, or (at your
8  * option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13  * more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef TRINITY_BAG_H
20 #define TRINITY_BAG_H
21 
22 // Maximum 36 Slots ((CONTAINER_END - CONTAINER_FIELD_SLOT_1)/2
23 #define MAX_BAG_SIZE 36 // 2.0.12
24 
25 #include "Item.h"
26 #include "ItemTemplate.h"
27 
28 class TC_GAME_API Bag : public Item
29 {
30  public:
31 
32  Bag();
33  ~Bag();
34 
35  void AddToWorld() override;
36  void RemoveFromWorld() override;
37 
38  bool Create(ObjectGuid::LowType guidlow, uint32 itemid, Player const* owner) override;
39 
40  void Clear();
41  void StoreItem(uint8 slot, Item* pItem, bool update);
42  void RemoveItem(uint8 slot, bool update);
43 
44  Item* GetItemByPos(uint8 slot) const;
45  uint32 GetItemCount(uint32 item, Item* eItem = NULL) const;
46  uint32 GetItemCountWithLimitCategory(uint32 limitCategory, Item* skipItem = NULL) const;
47 
48  uint8 GetSlotByItemGUID(ObjectGuid guid) const;
49  bool IsEmpty() const;
50  uint32 GetFreeSlots() const;
52 
53  // DB operations
54  // overwrite virtual Item::SaveToDB
55  void SaveToDB(SQLTransaction& trans) override;
56  // overwrite virtual Item::LoadFromDB
57  bool LoadFromDB(ObjectGuid::LowType guid, ObjectGuid owner_guid, Field* fields, uint32 entry) override;
58  // overwrite virtual Item::DeleteFromDB
59  void DeleteFromDB(SQLTransaction& trans) override;
60 
61  void BuildCreateUpdateBlockForPlayer(UpdateData* data, Player* target) const override;
62 
63  protected:
64 
65  // Bag Storage space
66  Item* m_bagslot[MAX_BAG_SIZE];
67 };
68 
69 inline Item* NewItemOrBag(ItemTemplate const* proto)
70 {
71  return (proto->GetInventoryType() == INVTYPE_BAG) ? new Bag : new Item;
72 }
73 
74 #endif
uint32 GetUInt32Value(uint16 index) const
Definition: Object.cpp:300
Definition: UpdateFields.h:71
#define MAX_BAG_SIZE
Definition: Bag.h:23
Class used to access individual fields of database query result.
Definition: Field.h:56
virtual bool Create(ObjectGuid::LowType guidlow, uint32 itemid, Player const *owner)
Definition: Item.cpp:254
arena_t NULL
Definition: jemalloc_internal.h:624
virtual bool LoadFromDB(ObjectGuid::LowType guid, ObjectGuid ownerGuid, Field *fields, uint32 entry)
Definition: Item.cpp:411
uint64 LowType
Definition: ObjectGuid.h:199
Definition: UpdateData.h:59
virtual void SaveToDB(SQLTransaction &trans)
Definition: Item.cpp:311
InventoryType GetInventoryType() const
Definition: ItemTemplate.h:664
Definition: Bag.h:28
Item * NewItemOrBag(ItemTemplate const *proto)
Definition: Bag.h:69
Definition: Item.h:259
uint32_t uint32
Definition: Define.h:150
uint32 GetBagSize() const
Definition: Bag.h:51
virtual void RemoveFromWorld()
Definition: Object.cpp:156
Definition: ItemTemplate.h:350
virtual void AddToWorld()
Definition: Object.cpp:142
virtual void BuildCreateUpdateBlockForPlayer(UpdateData *data, Player *target) const
Definition: Object.cpp:167
static void DeleteFromDB(SQLTransaction &trans, ObjectGuid::LowType itemGuid)
Definition: Item.cpp:518
Definition: ItemTemplate.h:647
#define TC_GAME_API
Definition: Define.h:134
uint8_t uint8
Definition: Define.h:152
Definition: ObjectGuid.h:189
std::shared_ptr< Transaction > SQLTransaction
Definition: Transaction.h:58