summaryrefslogtreecommitdiff
path: root/src/net
diff options
context:
space:
mode:
Diffstat (limited to 'src/net')
-rw-r--r--src/net/inventoryhandler.h25
-rw-r--r--src/net/manaserv/inventoryhandler.cpp40
-rw-r--r--src/net/manaserv/inventoryhandler.h8
3 files changed, 65 insertions, 8 deletions
diff --git a/src/net/inventoryhandler.h b/src/net/inventoryhandler.h
index f1dea956..83ef91a7 100644
--- a/src/net/inventoryhandler.h
+++ b/src/net/inventoryhandler.h
@@ -24,11 +24,27 @@
#include "inventory.h"
#include "item.h"
+#include "position.h"
#include <iosfwd>
namespace Net {
+// Default positions of the boxes, 2nd dimension is X and Y respectively.
+const int fallBackBoxesPosition[][2] = {
+ { 90, 40 }, // EQUIP_TORSO_SLOT
+ { 8, 78 }, // EQUIP_GLOVES_SLOT
+ { 70, 0 }, // EQUIP_HEAD_SLOT
+ { 50, 208 }, // EQUIP_LEGS_SLOT
+ { 90, 208 }, // EQUIP_FEET_SLOT
+ { 8, 168 }, // EQUIP_RING1_SLOT
+ { 129, 168 }, // EQUIP_RING2_SLOT
+ { 50, 40 }, // EQUIP_NECK_SLOT
+ { 8, 123 }, // EQUIP_FIGHT1_SLOT
+ { 129, 123 }, // EQUIP_FIGHT2_SLOT
+ { 129, 78 } // EQUIP_PROJECTILE_SLOT
+};
+
class InventoryHandler
{
public:
@@ -45,6 +61,15 @@ class InventoryHandler
virtual unsigned int getVisibleSlotsNumber() const
{ return 0; }
+
+ virtual Position getBoxPosition(unsigned int slotIndex) const
+ {
+ if (slotIndex < (sizeof(fallBackBoxesPosition)
+ / sizeof(fallBackBoxesPosition[0][0])))
+ return Position(fallBackBoxesPosition[slotIndex][0],
+ fallBackBoxesPosition[slotIndex][1]);
+ return Position(0,0);
+ }
};
} // namespace Net
diff --git a/src/net/manaserv/inventoryhandler.cpp b/src/net/manaserv/inventoryhandler.cpp
index 1a74f732..94494319 100644
--- a/src/net/manaserv/inventoryhandler.cpp
+++ b/src/net/manaserv/inventoryhandler.cpp
@@ -211,19 +211,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 +249,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 +291,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..1e05b49d 100644
--- a/src/net/manaserv/inventoryhandler.h
+++ b/src/net/manaserv/inventoryhandler.h
@@ -59,9 +59,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 +111,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 +137,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;
};