TrinityCore
Loading...
Searching...
No Matches
Bag.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 TRINITY_BAG_H
19#define TRINITY_BAG_H
20
21// Maximum 36 Slots ((CONTAINER_END - CONTAINER_FIELD_SLOT_1)/2
22#define MAX_BAG_SIZE 36 // 2.0.12
23
24#include "Item.h"
25
26class TC_GAME_API Bag : public Item
27{
28 public:
29 Bag();
30 ~Bag();
31
32 void AddToWorld() override;
33 void RemoveFromWorld() override;
34
35 bool Create(ObjectGuid::LowType guidlow, uint32 itemid, Player const* owner) override;
36
37 void StoreItem(uint8 slot, Item* pItem, bool update);
38 void RemoveItem(uint8 slot, bool update);
39
40 Item* GetItemByPos(uint8 slot) const;
41 uint32 GetItemCount(uint32 item, Item* eItem = nullptr) const;
42 uint32 GetItemCountWithLimitCategory(uint32 limitCategory, Item* skipItem = nullptr) const;
43
44 uint8 GetSlotByItemGUID(ObjectGuid guid) const;
45 bool IsEmpty() const;
46 uint32 GetFreeSlots() const;
48
49 // DB operations
50 // overwrite virtual Item::SaveToDB
51 void SaveToDB(CharacterDatabaseTransaction trans) override;
52 // overwrite virtual Item::LoadFromDB
53 bool LoadFromDB(ObjectGuid::LowType guid, ObjectGuid owner_guid, Field* fields, uint32 entry) override;
54 // overwrite virtual Item::DeleteFromDB
55 void DeleteFromDB(CharacterDatabaseTransaction trans) override;
56
57 void BuildCreateUpdateBlockForPlayer(UpdateData* data, Player* target) const override;
58
59 std::string GetDebugInfo() const override;
60
61 protected:
62
63 // Bag Storage space
64 Item* m_bagslot[MAX_BAG_SIZE];
65};
66
67inline Item* NewItemOrBag(ItemTemplate const* proto)
68{
69 return (proto->InventoryType == INVTYPE_BAG) ? new Bag : new Item;
70}
71#endif
#define MAX_BAG_SIZE
Definition Bag.h:22
Item * NewItemOrBag(ItemTemplate const *proto)
Definition Bag.h:67
SQLTransaction< CharacterDatabaseConnection > CharacterDatabaseTransaction
#define TC_GAME_API
Definition Define.h:114
uint8_t uint8
Definition Define.h:135
uint32_t uint32
Definition Define.h:133
@ INVTYPE_BAG
@ CONTAINER_FIELD_NUM_SLOTS
Definition Bag.h:27
uint32 GetBagSize() const
Definition Bag.h:47
Class used to access individual fields of database query result.
Definition Field.h:92
Definition Item.h:62
std::string GetDebugInfo() const override
Definition Item.cpp:1266
virtual bool LoadFromDB(ObjectGuid::LowType guid, ObjectGuid owner_guid, Field *fields, uint32 entry)
Definition Item.cpp:409
virtual void SaveToDB(CharacterDatabaseTransaction trans)
Definition Item.cpp:323
virtual bool Create(ObjectGuid::LowType guidlow, uint32 itemId, Player const *owner)
Definition Item.cpp:267
static void DeleteFromDB(CharacterDatabaseTransaction trans, ObjectGuid::LowType itemGuid)
Definition Item.cpp:506
uint32 LowType
Definition ObjectGuid.h:142
uint32 GetUInt32Value(uint16 index) const
Definition Object.cpp:249
virtual void BuildCreateUpdateBlockForPlayer(UpdateData *data, Player *target) const
Definition Object.cpp:170
virtual void AddToWorld()
Definition Object.cpp:126
virtual void RemoveFromWorld()
Definition Object.cpp:145
uint32 InventoryType