diff options
author | Jared Adams <jaxad0127@gmail.com> | 2009-12-07 11:34:29 -0700 |
---|---|---|
committer | Jared Adams <jaxad0127@gmail.com> | 2009-12-07 11:34:29 -0700 |
commit | 2f310b3040dcb56bd9ed1868dfa4f74b3fd00136 (patch) | |
tree | 81957f3eef8130b51e3dd85578ef18f56c274139 /src/net/manaserv | |
parent | fc48c24c6d366e165cbcfbd022d9421790089890 (diff) | |
download | mana-2f310b3040dcb56bd9ed1868dfa4f74b3fd00136.tar.gz mana-2f310b3040dcb56bd9ed1868dfa4f74b3fd00136.tar.bz2 mana-2f310b3040dcb56bd9ed1868dfa4f74b3fd00136.tar.xz mana-2f310b3040dcb56bd9ed1868dfa4f74b3fd00136.zip |
Simplify Equipment handling
Also merge eAthena's EquipmentHandler and InventoryHander. Fixes http://mantis.themanaworld.org/view.php?id=888 .
Diffstat (limited to 'src/net/manaserv')
-rw-r--r-- | src/net/manaserv/inventoryhandler.cpp | 5 | ||||
-rw-r--r-- | src/net/manaserv/inventoryhandler.h | 41 |
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 |