root/trunk/src/game/Bag.h @ 252

Revision 177, 2.4 kB (checked in by yumileroy, 17 years ago)

[svn] * Avoid access to bag item prototype for getting bag size, use related item
update field instead as more fast source. source mangos.
* Further reduce of DB access in guild handlers.
* Multi-locale DBC extracting - source Foks

*** Devs not responsible if all your player items drop to the ground and get eaten by ants or rabbits.. or some kind of wierd ant-rabbits..

Original author: KingPin?
Date: 2008-11-06 08:20:26-06:00

Line 
1/*
2 * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/>
3 *
4 * Copyright (C) 2008 Trinity <http://www.trinitycore.org/>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21#ifndef TRINITY_BAG_H
22#define TRINITY_BAG_H
23
24// Maximum 36 Slots ( (CONTAINER_END - CONTAINER_FIELD_SLOT_1)/2
25#define MAX_BAG_SIZE 36                                     // 2.0.12
26
27#include "Object.h"
28#include "ItemPrototype.h"
29#include "Unit.h"
30#include "Creature.h"
31#include "Item.h"
32
33class Bag : public Item
34{
35    public:
36
37        Bag();
38        ~Bag();
39
40        void AddToWorld();
41        void RemoveFromWorld();
42
43        bool Create(uint32 guidlow, uint32 itemid, Player const* owner);
44
45        void Clear();
46        void StoreItem( uint8 slot, Item *pItem, bool update );
47        void RemoveItem( uint8 slot, bool update );
48
49        Item* GetItemByPos( uint8 slot ) const;
50        uint32 GetItemCount( uint32 item, Item* eItem = NULL ) const;
51
52        uint8 GetSlotByItemGUID(uint64 guid) const;
53        bool IsEmpty() const;
54        uint32 GetFreeSlots() const;
55        uint32 GetBagSize() const { return GetUInt32Value(CONTAINER_FIELD_NUM_SLOTS); }
56
57        // DB operations
58        // overwrite virtual Item::SaveToDB
59        void SaveToDB();
60        // overwrite virtual Item::LoadFromDB
61        bool LoadFromDB(uint32 guid, uint64 owner_guid, QueryResult *result = NULL);
62        // overwrite virtual Item::DeleteFromDB
63        void DeleteFromDB();
64
65        void BuildCreateUpdateBlockForPlayer(UpdateData *data, Player *target) const;
66
67    protected:
68
69        // Bag Storage space
70        Item* m_bagslot[MAX_BAG_SIZE];
71};
72
73inline Item* NewItemOrBag(ItemPrototype const * proto)
74{
75    return (proto->InventoryType == INVTYPE_BAG) ? new Bag : new Item;
76}
77#endif
Note: See TracBrowser for help on using the browser.