summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorYohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer>2011-07-27 14:46:41 +0200
committerYohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer>2011-07-27 14:46:41 +0200
commit8aaa341a8ee51853737eabf52fe369f75be07e93 (patch)
tree2fe6df6d53955da0f06d175db303df40751faa84 /src/common
parent006a213747eb8063ad543211b9776caba027ea4a (diff)
downloadmanaserv-8aaa341a8ee51853737eabf52fe369f75be07e93.tar.gz
manaserv-8aaa341a8ee51853737eabf52fe369f75be07e93.tar.bz2
manaserv-8aaa341a8ee51853737eabf52fe369f75be07e93.tar.xz
manaserv-8aaa341a8ee51853737eabf52fe369f75be07e93.zip
Begun Applying the new equipment slot handling design.
now, the equipment slots are independant from the inventory slots according to the inventory and equipment data. This will permit to avoid checking the equipment each time one touches the inventory and vice versa, and make the former delayed mode useless. Also, note that equipped items will be removed from inventory and readded once unequipped. The design will permit the following, even if not implemented yet: - To make equipment items stackable again, if wanted. - Have more than one item with the same id equipped on different slots using the itemInstance field. Note: I didn't add the database structure updates yet, to see whether other changes may later go along with those.
Diffstat (limited to 'src/common')
-rw-r--r--src/common/inventorydata.h46
1 files changed, 41 insertions, 5 deletions
diff --git a/src/common/inventorydata.h b/src/common/inventorydata.h
index 9127c816..e7c81170 100644
--- a/src/common/inventorydata.h
+++ b/src/common/inventorydata.h
@@ -35,20 +35,56 @@
*/
struct InventoryItem
{
+ InventoryItem():
+ itemId(0), amount(0)
+ {}
+
unsigned int itemId;
unsigned int amount;
};
-// slot id -> { item }
-typedef std::map< unsigned short, InventoryItem > InventoryData;
-// equip slot type -> { slot ids }
-// Equipment taking up multiple slots will be referenced multiple times
-typedef std::multimap< unsigned int, unsigned int > EquipData;
+
+struct EquipmentItem
+{
+ EquipmentItem():
+ itemId(0), itemInstance(0)
+ {}
+
+ // The item id taken from the item db.
+ unsigned int itemId;
+ // A unique instance number used to separate items when equipping the same
+ // item id multiple times on possible multiple slots.
+ unsigned int itemInstance;
+};
+
+// inventory slot id -> { item }
+typedef std::map< unsigned int, InventoryItem > InventoryData;
+
+// equip slot id -> { item id }
+// Equipment taking up multiple equip slot ids will be referenced multiple times
+typedef std::multimap< unsigned int, EquipmentItem > EquipData;
/**
* Structure storing the equipment and inventory of a Player.
*/
struct Possessions
{
+ friend class Inventory;
+public:
+ const EquipData &getEquipment() const
+ { return equipSlots; }
+
+ const InventoryData &getInventory() const
+ { return inventory; }
+
+ /**
+ * Should be done only at character serialization and storage load time.
+ */
+ void setEquipment(EquipData &equipData)
+ { equipSlots.swap(equipData); }
+ void setInventory(InventoryData &inventoryData)
+ { inventory.swap(inventoryData); }
+
+private:
InventoryData inventory;
EquipData equipSlots;
};