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 98 Slots ((CONTAINER_END - CONTAINER_FIELD_SLOT_1)/2
22#define MAX_BAG_SIZE 98 // 11.0.0
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(UF::UpdateFieldFlag flags, ByteBuffer& data, Player const* target) const override;
58 void BuildValuesUpdate(UF::UpdateFieldFlag flags, ByteBuffer& data, Player const* target) const override;
59 void ClearValuesChangesMask() 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, bool ignoreNestedChangesMask) const;
64
65 struct ValuesUpdateForPlayerWithMaskSender // sender compatible with MessageDistDeliverer
66 {
67 explicit ValuesUpdateForPlayerWithMaskSender(Bag const* owner) : Owner(owner), IgnoreNestedChangesMask(false) { }
68
69 Bag const* Owner;
74
75 void operator()(Player const* player) const;
76 };
77
79
80 protected:
81 void SetBagSize(uint32 numSlots) { SetUpdateFieldValue(m_values.ModifyValue(&Bag::m_containerData).ModifyValue(&UF::ContainerData::NumSlots), numSlots); }
82 void SetSlot(uint32 slot, ObjectGuid guid) { SetUpdateFieldValue(m_values.ModifyValue(&Bag::m_containerData).ModifyValue(&UF::ContainerData::Slots, slot), guid); }
83
84 // Bag Storage space
85 Item* m_bagslot[MAX_BAG_SIZE];
86};
87
88#endif
#define MAX_BAG_SIZE
Definition Bag.h:22
ItemContext
Definition DBCEnums.h:1315
SQLTransaction< CharacterDatabaseConnection > CharacterDatabaseTransaction
#define TC_GAME_API
Definition Define.h:129
uint8_t uint8
Definition Define.h:156
int32_t int32
Definition Define.h:150
uint32_t uint32
Definition Define.h:154
uint16 flags
@ TYPEID_CONTAINER
Definition ObjectGuid.h:40
Definition Bag.h:27
uint32 GetBagSize() const
Definition Bag.h:45
UF::UpdateField< UF::ContainerData, int32(WowCS::EntityFragment::CGObject), TYPEID_CONTAINER > m_containerData
Definition Bag.h:78
void SetSlot(uint32 slot, ObjectGuid guid)
Definition Bag.h:82
void SetBagSize(uint32 numSlots)
Definition Bag.h:81
void SetUpdateFieldValue(UF::UpdateFieldPrivateSetter< T > setter, typename UF::UpdateFieldPrivateSetter< T >::value_type value)
Definition BaseEntity.h:221
virtual void BuildCreateUpdateBlockForPlayer(UpdateData *data, Player *target) const
Class used to access individual fields of database query result.
Definition Field.h:94
Definition Item.h:179
void BuildValuesUpdateForPlayerWithMask(UpdateData *data, UF::ObjectData::Mask const &requestedObjectMask, UF::ItemData::Mask const &requestedItemMask, Player const *target, bool ignoreNestedChangesMask) const
Definition Item.cpp:1836
virtual void SaveToDB(CharacterDatabaseTransaction trans)
Definition Item.cpp:639
void ClearValuesChangesMask() override
Definition Item.cpp:1877
virtual bool Create(ObjectGuid::LowType guidlow, uint32 itemId, ItemContext context, Player const *owner)
Definition Item.cpp:510
void BuildValuesUpdate(UF::UpdateFieldFlag flags, ByteBuffer &data, Player const *target) const override
Definition Item.cpp:1813
virtual bool LoadFromDB(ObjectGuid::LowType guid, ObjectGuid ownerGuid, Field *fields, uint32 entry)
Definition Item.cpp:907
void BuildValuesCreate(UF::UpdateFieldFlag flags, ByteBuffer &data, Player const *target) const override
Definition Item.cpp:1807
static void DeleteFromDB(CharacterDatabaseTransaction trans, ObjectGuid::LowType itemGuid)
Definition Item.cpp:1180
uint64 LowType
Definition ObjectGuid.h:321
void AddToWorld() override
Definition Object.cpp:83
void RemoveFromWorld() override
Definition Object.cpp:93
UpdateFieldFlag
Definition UpdateField.h:37
UF::ObjectData::Base ObjectMask
Definition Bag.h:70
ValuesUpdateForPlayerWithMaskSender(Bag const *owner)
Definition Bag.h:67
UF::ContainerData::Base ContainerMask
Definition Bag.h:72
UpdateField< uint32, 0, 1 > NumSlots
UpdateFieldArray< ObjectGuid, 98, 2, 3 > Slots