diff options
-rw-r--r-- | mana.cbp | 9 | ||||
-rw-r--r-- | src/CMakeLists.txt | 3 | ||||
-rw-r--r-- | src/Makefile.am | 3 | ||||
-rw-r--r-- | src/equipment.cpp | 59 | ||||
-rw-r--r-- | src/equipment.h | 24 | ||||
-rw-r--r-- | src/net/ea/equipmenthandler.cpp | 234 | ||||
-rw-r--r-- | src/net/ea/equipmenthandler.h | 45 | ||||
-rw-r--r-- | src/net/ea/generalhandler.cpp | 3 | ||||
-rw-r--r-- | src/net/ea/generalhandler.h | 1 | ||||
-rw-r--r-- | src/net/ea/inventoryhandler.cpp | 120 | ||||
-rw-r--r-- | src/net/ea/inventoryhandler.h | 48 | ||||
-rw-r--r-- | src/net/manaserv/inventoryhandler.cpp | 5 | ||||
-rw-r--r-- | src/net/manaserv/inventoryhandler.h | 41 |
13 files changed, 223 insertions, 372 deletions
@@ -180,7 +180,6 @@ <Unit filename="src\emoteshortcut.h" /> <Unit filename="src\engine.cpp" /> <Unit filename="src\engine.h" /> - <Unit filename="src\equipment.cpp" /> <Unit filename="src\equipment.h" /> <Unit filename="src\flooritem.cpp" /> <Unit filename="src\flooritem.h" /> @@ -465,14 +464,6 @@ <Option target="eAthena" /> <Option target="UNIX eAthena" /> </Unit> - <Unit filename="src\net\ea\equipmenthandler.cpp"> - <Option target="eAthena" /> - <Option target="UNIX eAthena" /> - </Unit> - <Unit filename="src\net\ea\equipmenthandler.h"> - <Option target="eAthena" /> - <Option target="UNIX eAthena" /> - </Unit> <Unit filename="src\net\ea\gamehandler.cpp"> <Option target="eAthena" /> <Option target="UNIX eAthena" /> diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index afbb4555..be13b2da 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -369,7 +369,6 @@ SET(SRCS emoteshortcut.h engine.cpp engine.h - equipment.cpp equipment.h flooritem.cpp flooritem.h @@ -460,8 +459,6 @@ SET(SRCS_EA net/ea/charserverhandler.h net/ea/chathandler.cpp net/ea/chathandler.h - net/ea/equipmenthandler.cpp - net/ea/equipmenthandler.h net/ea/gamehandler.cpp net/ea/gamehandler.h net/ea/generalhandler.cpp diff --git a/src/Makefile.am b/src/Makefile.am index cb54815e..21750f26 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -315,7 +315,6 @@ mana_SOURCES = gui/widgets/avatar.cpp \ emoteshortcut.h \ engine.cpp \ engine.h \ - equipment.cpp \ equipment.h \ flooritem.cpp \ flooritem.h \ @@ -459,8 +458,6 @@ mana_SOURCES += \ net/ea/charserverhandler.h \ net/ea/chathandler.cpp \ net/ea/chathandler.h \ - net/ea/equipmenthandler.cpp \ - net/ea/equipmenthandler.h \ net/ea/gamehandler.cpp \ net/ea/gamehandler.h \ net/ea/generalhandler.cpp \ diff --git a/src/equipment.cpp b/src/equipment.cpp deleted file mode 100644 index 76382528..00000000 --- a/src/equipment.cpp +++ /dev/null @@ -1,59 +0,0 @@ -/* - * The Mana World - * Copyright (C) 2004 The Mana World Development Team - * - * This file is part of The Mana World. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "equipment.h" -#include "item.h" - -#include <algorithm> - -Equipment::Equipment() -{ - std::fill_n(mEquipment, EQUIPMENT_SIZE, (Item*) 0); -} - -Equipment::~Equipment() -{ - clear(); -} - -void Equipment::clear() -{ - for (int i = 0; i < EQUIPMENT_SIZE; ++i) - delete mEquipment[i]; - - std::fill_n(mEquipment, EQUIPMENT_SIZE, (Item*) 0); -} - -void Equipment::setEquipment(int index, int id, int quantity) -{ - 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); - } -} diff --git a/src/equipment.h b/src/equipment.h index c7058269..f76c0bc6 100644 --- a/src/equipment.h +++ b/src/equipment.h @@ -32,14 +32,14 @@ class Equipment /** * Constructor. */ - Equipment(); + Equipment(): mBackend(NULL) {} /** * Destructor. */ - ~Equipment(); + ~Equipment() { mBackend = NULL; } - enum EquipmentSlots + enum Slot { EQUIP_TORSO_SLOT = 0, EQUIP_GLOVES_SLOT = 1, @@ -55,24 +55,34 @@ class Equipment EQUIP_VECTOREND }; + class Backend { + public: + virtual Item *getEquipment(int index) const = 0; + virtual void clear() = 0; + }; + /** * Get equipment at the given slot. */ - Item *getEquipment(int index) - { return mEquipment[index]; } + Item *getEquipment(int index) const + { return mBackend ? mBackend->getEquipment(index) : 0; } /** * Clears equipment. */ - void clear(); + void clear() + { if (mBackend) mBackend->clear(); } /** * Set equipment at the given slot. */ void setEquipment(int index, int id, int quantity = 0); + void setBackend(Backend *backend) + { mBackend = backend; } + private: - Item *mEquipment[EQUIPMENT_SIZE]; + Backend *mBackend; }; #endif diff --git a/src/net/ea/equipmenthandler.cpp b/src/net/ea/equipmenthandler.cpp deleted file mode 100644 index 28a2940c..00000000 --- a/src/net/ea/equipmenthandler.cpp +++ /dev/null @@ -1,234 +0,0 @@ -/* - * The Mana World - * Copyright (C) 2004 The Mana World Development Team - * - * This file is part of The Mana World. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "net/ea/equipmenthandler.h" - -#include "net/ea/protocol.h" - -#include "net/messagein.h" - -#include "equipment.h" -#include "inventory.h" -#include "item.h" -#include "localplayer.h" -#include "log.h" - -#include "gui/widgets/chattab.h" - -#include "utils/gettext.h" - -const Equipment::EquipmentSlots EQUIP_POINTS[Equipment::EQUIP_VECTOREND] = { - Equipment::EQUIP_LEGS_SLOT, - Equipment::EQUIP_FIGHT1_SLOT, - Equipment::EQUIP_GLOVES_SLOT, - Equipment::EQUIP_RING2_SLOT, - Equipment::EQUIP_RING1_SLOT, - Equipment::EQUIP_FIGHT2_SLOT, - Equipment::EQUIP_FEET_SLOT, - Equipment::EQUIP_NECK_SLOT, - Equipment::EQUIP_HEAD_SLOT, - Equipment::EQUIP_TORSO_SLOT, - Equipment::EQUIP_PROJECTILE_SLOT}; - -Item *equips[Equipment::EQUIP_VECTOREND]; - -namespace EAthena { - -enum { debugEquipment = 1 }; - -void setEquipment(int eAthenaSlot, int index, bool equiped) -{ - if (!eAthenaSlot) - return; - - Item *item = player_node->getInventory()->getItem(index); - - if (!item) - return; - - int position = 0; - - if (eAthenaSlot & 0x8000) { // Arrows - position = Equipment::EQUIP_PROJECTILE_SLOT; - } - else - { - /* - * An item may occupy more than 1 slot. If so, it's - * only shown as equipped on the *first* slot. - */ - int mask = 1; - while (!(eAthenaSlot & mask)) - { - mask <<= 1; - position++; - } - - position = EQUIP_POINTS[position]; - } - - if (equips[position]) - equips[position]->setEquipped(false); - - if (equiped && item) - { - equips[position] = item; - item->setEquipped(true); - player_node->mEquipment->setEquipment(position, item->getId(), item->getQuantity()); - - if (debugEquipment) - { - logger->log("Equipping: %i %i at position %i", - index, eAthenaSlot, position); - } - } - else - { - equips[position] = NULL; - player_node->mEquipment->setEquipment(position, -1); - - if (debugEquipment) - { - logger->log("Unequipping: %i %i at position %i", - index, eAthenaSlot, position); - } - } -} - -void clearEquipment() -{ - for (int i = 0; i < Equipment::EQUIP_VECTOREND; i++) - { - if (equips[i]) - { - equips[i]->setEquipped(false); - player_node->mEquipment->setEquipment(i, -1); - } - - equips[i] = NULL; - } -} - -Item *getRealEquipedItem(const Item *equipped) -{ - if (!equipped) - return NULL; - - for (int i = 0; i < Equipment::EQUIP_VECTOREND; i++) - { - if (equips[i] && equipped->getId() == equips[i]->getId()) - return equips[i]; - } - - return NULL; -} - -EquipmentHandler::EquipmentHandler() -{ - static const Uint16 _messages[] = { - SMSG_PLAYER_EQUIPMENT, - SMSG_PLAYER_EQUIP, - SMSG_PLAYER_UNEQUIP, - SMSG_PLAYER_ARROW_EQUIP, - SMSG_PLAYER_ATTACK_RANGE, - 0 - }; - handledMessages = _messages; - memset(equips, 0, sizeof(equips)); -} - -void EquipmentHandler::handleMessage(Net::MessageIn &msg) -{ - int itemCount; - int index, equipPoint, itemId; - int type; - Inventory *inventory = player_node->getInventory(); - - switch (msg.getId()) - { - case SMSG_PLAYER_EQUIPMENT: - msg.readInt16(); // length - itemCount = (msg.getLength() - 4) / 20; - - for (int loop = 0; loop < itemCount; loop++) - { - index = msg.readInt16() - INVENTORY_OFFSET; - itemId = msg.readInt16(); - msg.readInt8(); // type - msg.readInt8(); // identify flag - msg.readInt16(); // equip type - equipPoint = msg.readInt16(); - msg.readInt8(); // attribute - msg.readInt8(); // refine - msg.skip(8); // card - - inventory->setItem(index, itemId, 1, true); - - setEquipment(equipPoint, index, true); - } - break; - - case SMSG_PLAYER_EQUIP: - index = msg.readInt16() - INVENTORY_OFFSET; - equipPoint = msg.readInt16(); - type = msg.readInt8(); - - if (!type) - { - localChatTab->chatLog(_("Unable to equip."), BY_SERVER); - break; - } - - setEquipment(equipPoint, index, true); - break; - - case SMSG_PLAYER_UNEQUIP: - index = msg.readInt16() - INVENTORY_OFFSET; - equipPoint = msg.readInt16(); - type = msg.readInt8(); - - if (!type) { - localChatTab->chatLog(_("Unable to unequip."), BY_SERVER); - break; - } - - setEquipment(equipPoint, index, false); - break; - - case SMSG_PLAYER_ATTACK_RANGE: - player_node->setAttackRange(msg.readInt16()); - break; - - case SMSG_PLAYER_ARROW_EQUIP: - index = msg.readInt16(); - - if (index <= 1) - break; - - index -= INVENTORY_OFFSET; - - logger->log("Arrows equipped: %i", index); - setEquipment(0x8000, index, true); - break; - } -} - -} // namespace EAthena diff --git a/src/net/ea/equipmenthandler.h b/src/net/ea/equipmenthandler.h deleted file mode 100644 index 32ea83c4..00000000 --- a/src/net/ea/equipmenthandler.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * The Mana World - * Copyright (C) 2004 The Mana World Development Team - * - * This file is part of The Mana World. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef NET_EA_EQUIPMENTHANDLER_H -#define NET_EA_EQUIPMENTHANDLER_H - -#include "net/ea/messagehandler.h" - -class Item; - -namespace EAthena { - -void setEquipment(int eAthenaSlot, int index, bool equiped); -void clearEquipment(); -Item *getRealEquipedItem(const Item *equipped); - -class EquipmentHandler : public MessageHandler -{ - public: - EquipmentHandler(); - - virtual void handleMessage(Net::MessageIn &msg); -}; - -} // namespace EAthena - -#endif // NET_EA_EQUIPMENTHANDLER_H diff --git a/src/net/ea/generalhandler.cpp b/src/net/ea/generalhandler.cpp index 3818afec..44542ddc 100644 --- a/src/net/ea/generalhandler.cpp +++ b/src/net/ea/generalhandler.cpp @@ -35,7 +35,6 @@ #include "net/ea/buysellhandler.h" #include "net/ea/chathandler.h" #include "net/ea/charserverhandler.h" -#include "net/ea/equipmenthandler.h" #include "net/ea/gamehandler.h" #include "net/ea/inventoryhandler.h" #include "net/ea/itemhandler.h" @@ -75,7 +74,6 @@ GeneralHandler::GeneralHandler(): mBuySellHandler(new BuySellHandler), mCharHandler(new CharServerHandler), mChatHandler(new ChatHandler), - mEquipmentHandler(new EquipmentHandler), mGameHandler(new GameHandler), mInventoryHandler(new InventoryHandler), mItemHandler(new ItemHandler), @@ -158,7 +156,6 @@ void GeneralHandler::load() mNetwork->registerHandler(mBuySellHandler.get()); mNetwork->registerHandler(mChatHandler.get()); mNetwork->registerHandler(mCharHandler.get()); - mNetwork->registerHandler(mEquipmentHandler.get()); mNetwork->registerHandler(mGameHandler.get()); mNetwork->registerHandler(mInventoryHandler.get()); mNetwork->registerHandler(mItemHandler.get()); diff --git a/src/net/ea/generalhandler.h b/src/net/ea/generalhandler.h index abedd2f4..29dbcd3f 100644 --- a/src/net/ea/generalhandler.h +++ b/src/net/ea/generalhandler.h @@ -59,7 +59,6 @@ class GeneralHandler : public MessageHandler, public Net::GeneralHandler MessageHandlerPtr mBuySellHandler; MessageHandlerPtr mCharHandler; MessageHandlerPtr mChatHandler; - MessageHandlerPtr mEquipmentHandler; MessageHandlerPtr mGameHandler; MessageHandlerPtr mInventoryHandler; MessageHandlerPtr mItemHandler; diff --git a/src/net/ea/inventoryhandler.cpp b/src/net/ea/inventoryhandler.cpp index fbd5c9b3..d7758321 100644 --- a/src/net/ea/inventoryhandler.cpp +++ b/src/net/ea/inventoryhandler.cpp @@ -21,7 +21,6 @@ #include "net/ea/inventoryhandler.h" -#include "net/ea/equipmenthandler.h" #include "net/ea/protocol.h" #include "net/messagein.h" @@ -48,8 +47,41 @@ extern Net::InventoryHandler *inventoryHandler; +const Equipment::Slot EQUIP_POINTS[Equipment::EQUIP_VECTOREND] = { + Equipment::EQUIP_LEGS_SLOT, + Equipment::EQUIP_FIGHT1_SLOT, + Equipment::EQUIP_GLOVES_SLOT, + Equipment::EQUIP_RING2_SLOT, + Equipment::EQUIP_RING1_SLOT, + Equipment::EQUIP_FIGHT2_SLOT, + Equipment::EQUIP_FEET_SLOT, + Equipment::EQUIP_NECK_SLOT, + Equipment::EQUIP_HEAD_SLOT, + Equipment::EQUIP_TORSO_SLOT, + Equipment::EQUIP_PROJECTILE_SLOT}; + namespace EAthena { +int getSlot(int eAthenaSlot) +{ + if (eAthenaSlot == 0) + { + return Equipment::EQUIP_VECTOREND; + } + + if (eAthenaSlot & 0x8000) + return Equipment::EQUIP_PROJECTILE_SLOT; + + int mask = 1; + int position = 0; + while (!(eAthenaSlot & mask)) + { + mask <<= 1; + position++; + } + return EQUIP_POINTS[position]; +} + enum { debugInventory = 1 }; InventoryHandler::InventoryHandler() @@ -66,6 +98,11 @@ InventoryHandler::InventoryHandler() SMSG_PLAYER_STORAGE_ADD, SMSG_PLAYER_STORAGE_REMOVE, SMSG_PLAYER_STORAGE_CLOSE, + SMSG_PLAYER_EQUIPMENT, + SMSG_PLAYER_EQUIP, + SMSG_PLAYER_UNEQUIP, + SMSG_PLAYER_ARROW_EQUIP, + SMSG_PLAYER_ATTACK_RANGE, 0 }; handledMessages = _messages; @@ -74,7 +111,7 @@ InventoryHandler::InventoryHandler() void InventoryHandler::handleMessage(Net::MessageIn &msg) { - int number; + int number, flag; int index, amount, itemId, equipType, arrow; int identified, cards[4], itemType; Inventory *inventory = player_node->getInventory(); @@ -87,7 +124,9 @@ void InventoryHandler::handleMessage(Net::MessageIn &msg) if (msg.getId() == SMSG_PLAYER_INVENTORY) { // Clear inventory - this will be a complete refresh - clearEquipment(); + mEquips.clear(); + player_node->mEquipment->setBackend(&mEquips); + inventory->clear(); } @@ -124,6 +163,8 @@ void InventoryHandler::handleMessage(Net::MessageIn &msg) if (Item *item = inventory->getItem(index)) item->setEquipment(true); } + + //const Item *item = inventory->getItem(index); } else { storage->setItem(index, itemId, amount, false); } @@ -281,6 +322,73 @@ void InventoryHandler::handleMessage(Net::MessageIn &msg) storage->clear(); player_node->setInStorage(false); break; + + case SMSG_PLAYER_EQUIPMENT: + msg.readInt16(); // length + number = (msg.getLength() - 4) / 20; + + for (int loop = 0; loop < number; loop++) + { + index = msg.readInt16() - INVENTORY_OFFSET; + itemId = msg.readInt16(); + msg.readInt8(); // type + msg.readInt8(); // identify flag + msg.readInt16(); // equip type + equipType = msg.readInt16(); + msg.readInt8(); // attribute + msg.readInt8(); // refine + msg.skip(8); // card + + inventory->setItem(index, itemId, 1, true); + + mEquips.setEquipment(getSlot(equipType), index); + } + break; + + case SMSG_PLAYER_EQUIP: + index = msg.readInt16() - INVENTORY_OFFSET; + equipType = msg.readInt16(); + flag = msg.readInt8(); + + if (!flag) + { + localChatTab->chatLog(_("Unable to equip."), BY_SERVER); + } + else + { + mEquips.setEquipment(getSlot(equipType), index); + } + break; + + case SMSG_PLAYER_UNEQUIP: + index = msg.readInt16() - INVENTORY_OFFSET; + equipType = msg.readInt16(); + flag = msg.readInt8(); + + if (!flag) { + localChatTab->chatLog(_("Unable to unequip."), BY_SERVER); + } + else + { + mEquips.setEquipment(getSlot(equipType), 0); + } + break; + + case SMSG_PLAYER_ATTACK_RANGE: + player_node->setAttackRange(msg.readInt16()); + break; + + case SMSG_PLAYER_ARROW_EQUIP: + index = msg.readInt16(); + + if (index <= 1) + break; + + index -= INVENTORY_OFFSET; + + logger->log("Arrows equipped: %i", index); + mEquips.setEquipment(Equipment::EQUIP_PROJECTILE_SLOT, index); + break; } } @@ -296,14 +404,14 @@ void InventoryHandler::equipItem(const Item *item) void InventoryHandler::unequipItem(const Item *item) { - const Item *real_item = item->isInEquipment() ? getRealEquipedItem(item) + /*const Item *real_item = item->isInEquipment() ? getRealEquipedItem(item) : item; if (!real_item) - return; + return;*/ MessageOut outMsg(CMSG_PLAYER_UNEQUIP); - outMsg.writeInt16(real_item->getInvIndex() + INVENTORY_OFFSET); + outMsg.writeInt16(item->getInvIndex() + INVENTORY_OFFSET); } void InventoryHandler::useItem(const Item *item) diff --git a/src/net/ea/inventoryhandler.h b/src/net/ea/inventoryhandler.h index 83a2b440..82c2a36e 100644 --- a/src/net/ea/inventoryhandler.h +++ b/src/net/ea/inventoryhandler.h @@ -27,8 +27,53 @@ #include "net/ea/messagehandler.h" +#include "equipment.h" +#include "inventory.h" +#include "localplayer.h" + namespace EAthena { +class EquipBackend : public Equipment::Backend { + public: + Item *getEquipment(int index) const + { + int invyIndex = mEquipment[index]; + if (invyIndex == 0) + { + return NULL; + } + return player_node->getInventory()->getItem(invyIndex); + } + + void clear() + { + for (int i = 0; i < EQUIPMENT_SIZE; i++) + { + if (mEquipment[i]) + { + Item* item = player_node->getInventory()->getItem(i); + if (item) + { + item->setEquipped(false); + } + } + + mEquipment[i] = 0; + } + } + + void setEquipment(int index, int inventoryIndex) + { + mEquipment[index] = inventoryIndex; + Item* item = player_node->getInventory()->getItem(inventoryIndex); + if (item) + item->setEquipped(true); + } + + private: + int mEquipment[EQUIPMENT_SIZE]; +}; + class InventoryHandler : public MessageHandler, public Net::InventoryHandler { public: @@ -58,6 +103,9 @@ class InventoryHandler : public MessageHandler, public Net::InventoryHandler StorageType destination); size_t getSize(StorageType type) const; + + private: + EquipBackend mEquips; }; } // namespace EAthena 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 |