TrinityCore
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, ItemContext context, 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
42 uint8 GetSlotByItemGUID(ObjectGuid guid) const;
43 bool IsEmpty() const;
44 uint32 GetFreeSlots() const;
45 uint32 GetBagSize() const { return m_containerData->NumSlots; }
46
47 // DB operations
48 // overwrite virtual Item::SaveToDB
49 void SaveToDB(CharacterDatabaseTransaction trans) override;
50 // overwrite virtual Item::LoadFromDB
51 bool LoadFromDB(ObjectGuid::LowType guid, ObjectGuid owner_guid, Field* fields, uint32 entry) override;
52 // overwrite virtual Item::DeleteFromDB
53 void DeleteFromDB(CharacterDatabaseTransaction trans) override;
54
55 protected:
56 void BuildCreateUpdateBlockForPlayer(UpdateData* data, Player* target) const override;
57 void BuildValuesCreate(ByteBuffer* data, Player const* target) const override;
58 void BuildValuesUpdate(ByteBuffer* data, Player const* target) const override;
59 void ClearUpdateMask(bool remove) override;
60
61 public:
62 void BuildValuesUpdateForPlayerWithMask(UpdateData* data, UF::ObjectData::Mask const& requestedObjectMask, UF::ItemData::Mask const& requestedItemMask,
63 UF::ContainerData::Mask const& requestedContainerMask, Player const* target) const;
64
65 struct ValuesUpdateForPlayerWithMaskSender // sender compatible with MessageDistDeliverer
66 {
67 explicit ValuesUpdateForPlayerWithMaskSender(Bag const* owner) : Owner(owner) { }
68
69 Bag const* Owner;
73
74 void operator()(Player const* player) const;
75 };
76
77 std::string GetDebugInfo() const override;
78
80
81 protected:
82 void SetBagSize(uint32 numSlots) { SetUpdateFieldValue(m_values.ModifyValue(&Bag::m_containerData).ModifyValue(&UF::ContainerData::NumSlots), numSlots); }
83 void SetSlot(uint32 slot, ObjectGuid guid) { SetUpdateFieldValue(m_values.ModifyValue(&Bag::m_containerData).ModifyValue(&UF::ContainerData::Slots, slot), guid); }
84
85 // Bag Storage space
86 Item* m_bagslot[MAX_BAG_SIZE];
87};
88
89#endif
#define MAX_BAG_SIZE
Definition: Bag.h:22
ItemContext
Definition: DBCEnums.h:1063
SQLTransaction< CharacterDatabaseConnection > CharacterDatabaseTransaction
#define TC_GAME_API
Definition: Define.h:123
uint8_t uint8
Definition: Define.h:144
uint32_t uint32
Definition: Define.h:142
Definition: Bag.h:27
uint32 GetBagSize() const
Definition: Bag.h:45
UF::UpdateField< UF::ContainerData, 0, TYPEID_CONTAINER > m_containerData
Definition: Bag.h:79
void SetSlot(uint32 slot, ObjectGuid guid)
Definition: Bag.h:83
void SetBagSize(uint32 numSlots)
Definition: Bag.h:82
Class used to access individual fields of database query result.
Definition: Field.h:90
Definition: Item.h:170
std::string GetDebugInfo() const override
Definition: Item.cpp:2819
virtual void SaveToDB(CharacterDatabaseTransaction trans)
Definition: Item.cpp:561
void BuildValuesUpdateForPlayerWithMask(UpdateData *data, UF::ObjectData::Mask const &requestedObjectMask, UF::ItemData::Mask const &requestedItemMask, Player const *target) const
Definition: Item.cpp:1751
void ClearUpdateMask(bool remove) override
Definition: Item.cpp:1791
void BuildValuesCreate(ByteBuffer *data, Player const *target) const override
Definition: Item.cpp:1708
virtual bool Create(ObjectGuid::LowType guidlow, uint32 itemId, ItemContext context, Player const *owner)
Definition: Item.cpp:468
void BuildValuesUpdate(ByteBuffer *data, Player const *target) const override
Definition: Item.cpp:1719
virtual bool LoadFromDB(ObjectGuid::LowType guid, ObjectGuid ownerGuid, Field *fields, uint32 entry)
Definition: Item.cpp:828
static void DeleteFromDB(CharacterDatabaseTransaction trans, ObjectGuid::LowType itemGuid)
Definition: Item.cpp:1088
uint64 LowType
Definition: ObjectGuid.h:278
virtual void BuildCreateUpdateBlockForPlayer(UpdateData *data, Player *target) const
Definition: Object.cpp:137
void SetUpdateFieldValue(UF::UpdateFieldSetter< T > setter, typename UF::UpdateFieldSetter< T >::value_type value)
Definition: Object.h:287
virtual void AddToWorld()
Definition: Object.cpp:107
virtual void RemoveFromWorld()
Definition: Object.cpp:124
UF::ObjectData::Base ObjectMask
Definition: Bag.h:70
ValuesUpdateForPlayerWithMaskSender(Bag const *owner)
Definition: Bag.h:67
UF::ContainerData::Base ContainerMask
Definition: Bag.h:72
UF::ItemData::Base ItemMask
Definition: Bag.h:71
UpdateFieldArray< ObjectGuid, 36, 2, 3 > Slots
Definition: UpdateFields.h:154
UpdateField< uint32, 0, 1 > NumSlots
Definition: UpdateFields.h:153