summaryrefslogtreecommitdiff
path: root/src/net/manaserv
diff options
context:
space:
mode:
Diffstat (limited to 'src/net/manaserv')
-rw-r--r--src/net/manaserv/inventoryhandler.cpp5
-rw-r--r--src/net/manaserv/inventoryhandler.h41
2 files changed, 44 insertions, 2 deletions
diff --git a/src/net/manaserv/inventoryhandler.cpp b/src/net/manaserv/inventoryhandler.cpp
index ba4031ec..9bf727d1 100644
--- a/src/net/manaserv/inventoryhandler.cpp
+++ b/src/net/manaserv/inventoryhandler.cpp
@@ -61,6 +61,7 @@ void InventoryHandler::handleMessage(Net::MessageIn &msg)
{
case GPMSG_INVENTORY_FULL:
player_node->clearInventory();
+ player_node->mEquipment->setBackend(&mEqiups);
// no break!
case GPMSG_INVENTORY:
@@ -76,7 +77,7 @@ void InventoryHandler::handleMessage(Net::MessageIn &msg)
int id = msg.readInt16();
if (slot < EQUIPMENT_SIZE)
{
- player_node->mEquipment->setEquipment(slot, id);
+ mEqiups.setEquipment(slot, id);
}
else if (slot >= 32 && slot < 32 + getSize(INVENTORY))
{
@@ -104,7 +105,7 @@ void InventoryHandler::unequipItem(const Item *item)
// Tidy equipment directly to avoid weapon still shown bug, for instance
int equipSlot = item->getInvIndex();
logger->log("Unequipping %d", equipSlot);
- player_node->mEquipment->setEquipment(equipSlot, 0);
+ mEqiups.setEquipment(equipSlot, 0);
}
void InventoryHandler::useItem(const Item *item)
diff --git a/src/net/manaserv/inventoryhandler.h b/src/net/manaserv/inventoryhandler.h
index d3feca0a..fd28738c 100644
--- a/src/net/manaserv/inventoryhandler.h
+++ b/src/net/manaserv/inventoryhandler.h
@@ -26,8 +26,46 @@
#include "net/manaserv/messagehandler.h"
+#include "equipment.h"
+
namespace ManaServ {
+class EquipBackend : public Equipment::Backend {
+ public:
+ EquipBackend()
+ { memset(mEquipment, 0, sizeof(mEquipment)); }
+
+ Item *getEquipment(int index) const
+ { return mEquipment[index]; }
+
+ void clear()
+ {
+ for (int i = 0; i < EQUIPMENT_SIZE; ++i)
+ delete mEquipment[i];
+
+ std::fill_n(mEquipment, EQUIPMENT_SIZE, (Item*) 0);
+ }
+
+ void setEquipment(int index, int id, int quantity = 0)
+ {
+ if (mEquipment[index] && mEquipment[index]->getId() == id)
+ return;
+
+ delete mEquipment[index];
+ mEquipment[index] = (id > 0) ? new Item(id, quantity) : 0;
+
+ if (mEquipment[index])
+ {
+ mEquipment[index]->setInvIndex(index);
+ mEquipment[index]->setEquipped(true);
+ mEquipment[index]->setInEquipment(true);
+ }
+ }
+
+ private:
+ Item *mEquipment[EQUIPMENT_SIZE];
+};
+
class InventoryHandler : public MessageHandler, Net::InventoryHandler
{
public:
@@ -57,6 +95,9 @@ class InventoryHandler : public MessageHandler, Net::InventoryHandler
StorageType destination);
size_t getSize(StorageType type) const;
+
+ private:
+ EquipBackend mEqiups;
};
} // namespace ManaServ