diff options
author | Yohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer> | 2011-08-30 21:09:04 +0200 |
---|---|---|
committer | Yohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer> | 2011-08-30 21:09:04 +0200 |
commit | 5d00678217e5198cb375b4a2214a3e056151bdd9 (patch) | |
tree | 1874f2e8fa941f091e34c2b703c923e89f8a01f5 /src/net/manaserv | |
parent | 19f6ce87e69b42fb69a4739ce363e1346cd569ea (diff) | |
parent | 4ab9c3f14340910e77856a9e12779ee8c6b9be4d (diff) | |
download | mana-5d00678217e5198cb375b4a2214a3e056151bdd9.tar.gz mana-5d00678217e5198cb375b4a2214a3e056151bdd9.tar.bz2 mana-5d00678217e5198cb375b4a2214a3e056151bdd9.tar.xz mana-5d00678217e5198cb375b4a2214a3e056151bdd9.zip |
Merge branch 'equipment-fix'
Diffstat (limited to 'src/net/manaserv')
-rw-r--r-- | src/net/manaserv/inventoryhandler.cpp | 45 | ||||
-rw-r--r-- | src/net/manaserv/inventoryhandler.h | 10 | ||||
-rw-r--r-- | src/net/manaserv/manaserv_protocol.h | 5 |
3 files changed, 51 insertions, 9 deletions
diff --git a/src/net/manaserv/inventoryhandler.cpp b/src/net/manaserv/inventoryhandler.cpp index 1a74f732..67c79a17 100644 --- a/src/net/manaserv/inventoryhandler.cpp +++ b/src/net/manaserv/inventoryhandler.cpp @@ -65,6 +65,11 @@ EquipBackend::EquipBackend() mVisibleSlots = 0; } +EquipBackend::~EquipBackend() +{ + clear(); +} + Item *EquipBackend::getEquipment(int slotIndex) const { Slots::const_iterator it = mSlots.find(slotIndex); @@ -211,19 +216,19 @@ void EquipBackend::readEquipFile() unsigned int slotIndex = 0; mVisibleSlots = 0; - for_each_xml_child_node(childNode, rootNode) + for_each_xml_child_node(slotNode, rootNode) { - if (!xmlStrEqual(childNode->name, BAD_CAST "slot")) + if (!xmlStrEqual(slotNode->name, BAD_CAST "slot")) continue; Slot slot; - slot.slotTypeId = XML::getProperty(childNode, "id", 0); - std::string name = XML::getProperty(childNode, "name", std::string()); - const int capacity = XML::getProperty(childNode, "capacity", 1); - slot.weaponSlot = XML::getBoolProperty(childNode, "weapon", false); - slot.ammoSlot = XML::getBoolProperty(childNode, "ammo", false); + slot.slotTypeId = XML::getProperty(slotNode, "id", 0); + std::string name = XML::getProperty(slotNode, "name", std::string()); + const int capacity = XML::getProperty(slotNode, "capacity", 1); + slot.weaponSlot = XML::getBoolProperty(slotNode, "weapon", false); + slot.ammoSlot = XML::getBoolProperty(slotNode, "ammo", false); - if (XML::getBoolProperty(childNode, "visible", false)) + if (XML::getBoolProperty(slotNode, "visible", false)) ++mVisibleSlots; if (slot.slotTypeId > 0 && capacity > 0) @@ -249,6 +254,23 @@ void EquipBackend::readEquipFile() ++slotIndex; } } + + // Read the box properties + readBoxNode(slotNode); + } +} + +void EquipBackend::readBoxNode(xmlNodePtr slotNode) +{ + for_each_xml_child_node(boxNode, slotNode) + { + if (!xmlStrEqual(boxNode->name, BAD_CAST "box")) + continue; + + int x = XML::getProperty(boxNode, "x" , 0); + int y = XML::getProperty(boxNode, "y" , 0); + + mBoxesPositions.push_back(Position(x, y)); } } @@ -274,6 +296,13 @@ bool EquipBackend::isAmmoSlot(int slotTypeId) const return false; } +Position EquipBackend::getBoxPosition(unsigned int slotIndex) const +{ + if (slotIndex < mBoxesPositions.size()) + return mBoxesPositions.at(slotIndex); + return Position(0, 0); +} + InventoryHandler::InventoryHandler() { static const Uint16 _messages[] = { diff --git a/src/net/manaserv/inventoryhandler.h b/src/net/manaserv/inventoryhandler.h index bf3022ab..446105ee 100644 --- a/src/net/manaserv/inventoryhandler.h +++ b/src/net/manaserv/inventoryhandler.h @@ -38,6 +38,8 @@ class EquipBackend : public Equipment::Backend, public EventListener public: EquipBackend(); + ~EquipBackend(); + Item *getEquipment(int slotIndex) const; std::string getSlotName(int slotIndex) const; void clear(); @@ -59,9 +61,13 @@ class EquipBackend : public Equipment::Backend, public EventListener bool isWeaponSlot(int slotTypeId) const; bool isAmmoSlot(int slotTypeId) const; + Position getBoxPosition(unsigned int slotIndex) const; + private: void readEquipFile(); + void readBoxNode(xmlNodePtr slotNode); + struct Slot { Slot(): item(0), @@ -107,6 +113,7 @@ class EquipBackend : public Equipment::Backend, public EventListener // slot client index, slot info typedef std::map<unsigned int, Slot> Slots; Slots mSlots; + std::vector<Position> mBoxesPositions; }; class InventoryHandler : public MessageHandler, Net::InventoryHandler, @@ -132,6 +139,9 @@ class InventoryHandler : public MessageHandler, Net::InventoryHandler, unsigned int getVisibleSlotsNumber() const { return mEquipBackend.getVisibleSlotsNumber(); } + Position getBoxPosition(unsigned int slotIndex) const + { return mEquipBackend.getBoxPosition(slotIndex); } + private: EquipBackend mEquipBackend; }; diff --git a/src/net/manaserv/manaserv_protocol.h b/src/net/manaserv/manaserv_protocol.h index 2c790d26..49548132 100644 --- a/src/net/manaserv/manaserv_protocol.h +++ b/src/net/manaserv/manaserv_protocol.h @@ -24,7 +24,10 @@ namespace ManaServ { -enum { PROTOCOL_VERSION = 1 }; +enum { + PROTOCOL_VERSION = 1, + SUPPORTED_DB_VERSION = 15 +}; /** * Enumerated type for communicated messages: |