1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #ifndef RY_ITEM_GROUP_MANAGER_H
19 #define RY_ITEM_GROUP_MANAGER_H
21 #include "interface_v3/inventory_manager.h"
22 #include "interface_v3/dbctrl_sheet.h"
23 #include "game_share/inventories.h"
24 #include "game_share/slot_equipment.h"
26 struct CInventoryItem
{
29 INVENTORIES::TInventory origin
;
31 SLOT_EQUIPMENT::TSlotEquipment slot
; // Used to differentiate right/left hands, and for clarity in the xml file
32 CInventoryItem(CDBCtrlSheet
*pCS
, INVENTORIES::TInventory origin
, uint32 indexInBag
, SLOT_EQUIPMENT::TSlotEquipment slot
= SLOT_EQUIPMENT::UNDEFINED
) :
33 pCS(pCS
), origin(origin
), indexInBag(indexInBag
), slot(slot
) {}
40 SLOT_EQUIPMENT::TSlotEquipment slot
; // Used only for dagger (right/left hand slot)
43 // Old variables, present for compatibility reasons
44 std::string sheetName
;
51 CItem(sint32 createTime
, sint32 serial
, SLOT_EQUIPMENT::TSlotEquipment slot
= SLOT_EQUIPMENT::UNDEFINED
) :
52 createTime(createTime
), serial(serial
), slot(slot
) {}
53 //Old constructor, present for compatibility reasons
54 CItem(std::string sheetName
= "", uint16 quality
= 0, uint32 weight
= 0, uint8 color
= 0, sint32 createTime
= 0, sint32 serial
= 0, SLOT_EQUIPMENT::TSlotEquipment slot
= SLOT_EQUIPMENT::UNDEFINED
, uint32 minPrice
= 0, uint32 maxPrice
= std::numeric_limits
<uint32
>::max(), bool usePrice
= false) :
55 sheetName(sheetName
), quality(quality
), weight(weight
), color(color
), createTime(createTime
), serial(serial
), slot(slot
), minPrice(minPrice
), maxPrice(maxPrice
), usePrice(usePrice
) {}
56 //present for compatibility reasons
57 bool useCreateTime() const { return createTime
!= 0 && serial
!= 0;}
63 // return true if any item in the group match the parameter ; slot is UNDEFINED unless the item has been found in the group
64 bool contains(CDBCtrlSheet
*other
);
65 bool contains(CDBCtrlSheet
* other
, SLOT_EQUIPMENT::TSlotEquipment
&slot
);
66 void addItem(sint32 createTime
, sint32 serial
, SLOT_EQUIPMENT::TSlotEquipment slot
);
67 void addRemove(std::string slotName
);
68 void addRemove(SLOT_EQUIPMENT::TSlotEquipment slot
);
69 void writeTo(xmlNodePtr node
);
70 void readFrom(xmlNodePtr node
);
72 // return true if no item inside
73 bool empty() const { return Items
.size() == 0;}
75 std::vector
<CItem
> Items
;
76 std::vector
<SLOT_EQUIPMENT::TSlotEquipment
> removeBeforeEquip
;
79 class CItemGroupManager
{
81 // Singleton management
82 static CItemGroupManager
* getInstance();
83 static void releaseInstance();
92 void unlinkInterface();
93 //Return NULL if no group was found
94 //Return false if no group was found
95 bool moveGroup(std::string name
, INVENTORIES::TInventory dst
);
96 bool equipGroup(std::string name
, bool pullBefore
=true);
97 bool createGroup(std::string name
, bool removeUnequiped
=false);
98 bool deleteGroup(std::string name
);
100 std::vector
<std::string
> getGroupNames(CDBCtrlSheet
*pCS
);
101 //Used to fake invalid actions
105 CItemGroup
* findGroup(std::string name
);
106 std::vector
<CInventoryItem
> matchingItems(CItemGroup
* group
, INVENTORIES::TInventory inventory
);
108 std::vector
<CItemGroup
> _Groups
;
109 std::string
toDbPath(INVENTORIES::TInventory inventory
);
110 // Singleton's instance
111 static CItemGroupManager
*_Instance
;
113 void fakeInvalidActions(NLMISC::TGameCycle time
);
114 void invalidActions(NLMISC::TGameCycle begin
, NLMISC::TGameCycle end
);
116 NLMISC::TGameCycle _EndInvalidAction
;
117 NLMISC::TGameCycle _StartInvalidAction
;
118 //Workaround: sometimes item are marked as equipped by pIM->isBagItemWeared() even tho they aren't really
119 //Because of a synchronisation error between client and server
120 bool isItemReallyEquipped(CDBCtrlSheet
*item
);
123 //Used to migrate old groups ; keep for compatibility purpose
124 bool migrateGroups();
125 //Return a new group who uses create time and serial (param group isn't modified)
126 CItemGroup
migrateGroup(CItemGroup group
);
130 #endif // RY_ITEM_GROUP_MANAGER_H