diff options
Diffstat (limited to 'src/net')
-rw-r--r-- | src/net/inventoryhandler.h | 3 | ||||
-rw-r--r-- | src/net/manaserv/inventoryhandler.cpp | 22 | ||||
-rw-r--r-- | src/net/manaserv/inventoryhandler.h | 6 | ||||
-rw-r--r-- | src/net/tmwa/inventoryhandler.cpp | 24 | ||||
-rw-r--r-- | src/net/tmwa/inventoryhandler.h | 40 |
5 files changed, 37 insertions, 58 deletions
diff --git a/src/net/inventoryhandler.h b/src/net/inventoryhandler.h index 497a4ecb..8a67a7db 100644 --- a/src/net/inventoryhandler.h +++ b/src/net/inventoryhandler.h @@ -22,6 +22,7 @@ #ifndef INVENTORYHANDLER_H #define INVENTORYHANDLER_H +#include "equipment.h" #include "inventory.h" #include "item.h" #include "position.h" @@ -78,6 +79,8 @@ class InventoryHandler virtual unsigned int getVisibleSlotsNumber() const { return 0; } + virtual Equipment::Backend *getEquipmentBackend() = 0; + virtual Position getBoxPosition(unsigned int slotIndex) const { if (slotIndex < (sizeof(fallBackBoxesPosition) diff --git a/src/net/manaserv/inventoryhandler.cpp b/src/net/manaserv/inventoryhandler.cpp index 8898db55..ac3e0f5b 100644 --- a/src/net/manaserv/inventoryhandler.cpp +++ b/src/net/manaserv/inventoryhandler.cpp @@ -24,8 +24,6 @@ #include "equipment.h" #include "inventory.h" #include "item.h" -#include "itemshortcut.h" -#include "localplayer.h" #include "log.h" #include "playerinfo.h" @@ -37,8 +35,6 @@ #include "net/manaserv/messageout.h" #include "net/manaserv/manaserv_protocol.h" -#include "resources/iteminfo.h" - #include "utils/stringutils.h" #define EQUIP_FILE "equip.xml" @@ -279,20 +275,20 @@ void EquipBackend::readBoxNode(xmlNodePtr slotNode) bool EquipBackend::isWeaponSlot(int slotTypeId) const { - for (const auto &slot : mSlots) + for (const auto &[_, slot] : mSlots) { - if (slot.second.slotTypeId == (unsigned)slotTypeId) - return slot.second.weaponSlot; + if (slot.slotTypeId == (unsigned)slotTypeId) + return slot.weaponSlot; } return false; } bool EquipBackend::isAmmoSlot(int slotTypeId) const { - for (const auto &slot : mSlots) + for (const auto &[_, slot] : mSlots) { - if (slot.second.slotTypeId == (unsigned)slotTypeId) - return slot.second.ammoSlot; + if (slot.slotTypeId == (unsigned)slotTypeId) + return slot.ammoSlot; } return false; } @@ -304,7 +300,7 @@ Position EquipBackend::getBoxPosition(unsigned int slotIndex) const return Position(0, 0); } -const std::string& EquipBackend::getBoxBackground(unsigned int slotIndex) const +const std::string &EquipBackend::getBoxBackground(unsigned int slotIndex) const { if (slotIndex < mBoxesBackgroundFile.size()) return mBoxesBackgroundFile.at(slotIndex); @@ -332,7 +328,6 @@ void InventoryHandler::handleMessage(MessageIn &msg) case GPMSG_INVENTORY_FULL: { PlayerInfo::clearInventory(); - PlayerInfo::getEquipment()->setBackend(&mEquipBackend); int count = msg.readInt16(); while (count--) { @@ -374,9 +369,6 @@ void InventoryHandler::handleMessage(MessageIn &msg) it->second.mAmountUsed, it->first); } - // The backend is ready, we can setup the equipment window. - if (equipmentWindow) - equipmentWindow->loadEquipBoxes(); } break; diff --git a/src/net/manaserv/inventoryhandler.h b/src/net/manaserv/inventoryhandler.h index 452ccf3e..a0e978cd 100644 --- a/src/net/manaserv/inventoryhandler.h +++ b/src/net/manaserv/inventoryhandler.h @@ -22,7 +22,6 @@ #ifndef NET_MANASERV_INVENTORYHANDLER_H #define NET_MANASERV_INVENTORYHANDLER_H -#include "equipment.h" #include "eventlistener.h" #include "net/inventoryhandler.h" @@ -63,7 +62,7 @@ class EquipBackend final : public Equipment::Backend, public EventListener Position getBoxPosition(unsigned int slotIndex) const; - const std::string& getBoxBackground(unsigned int slotIndex) const; + const std::string &getBoxBackground(unsigned int slotIndex) const; private: void readEquipFile() override; @@ -133,6 +132,9 @@ class InventoryHandler final : public MessageHandler, Net::InventoryHandler, unsigned int getVisibleSlotsNumber() const override { return mEquipBackend.getVisibleSlotsNumber(); } + Equipment::Backend *getEquipmentBackend() override + { return &mEquipBackend; } + Position getBoxPosition(unsigned int slotIndex) const override { return mEquipBackend.getBoxPosition(slotIndex); } diff --git a/src/net/tmwa/inventoryhandler.cpp b/src/net/tmwa/inventoryhandler.cpp index 0bc1f9c0..0fd4e933 100644 --- a/src/net/tmwa/inventoryhandler.cpp +++ b/src/net/tmwa/inventoryhandler.cpp @@ -30,8 +30,6 @@ #include "localplayer.h" #include "log.h" -#include "gui/equipmentwindow.h" - #include "net/tmwa/messagein.h" #include "net/tmwa/messageout.h" #include "net/tmwa/protocol.h" @@ -104,9 +102,6 @@ InventoryHandler::InventoryHandler() handledMessages = _messages; inventoryHandler = this; - mStorage = nullptr; - mStorageWindow = nullptr; - listen(Event::ItemChannel); } @@ -127,7 +122,6 @@ void InventoryHandler::handleMessage(MessageIn &msg) int index, amount, itemId, equipType; int identified, cards[4], itemType; Inventory *inventory = PlayerInfo::getInventory(); - PlayerInfo::getEquipment()->setBackend(&mEquips); switch (msg.getId()) { @@ -172,8 +166,8 @@ void InventoryHandler::handleMessage(MessageIn &msg) if (msg.getId() == SMSG_PLAYER_INVENTORY) inventory->setItem(index, itemId, amount); else - mInventoryItems.push_back(InventoryItem(index, itemId, - amount, false)); + mInventoryItems.push_back( + InventoryItem { index, itemId, amount, false }); } break; @@ -203,8 +197,8 @@ void InventoryHandler::handleMessage(MessageIn &msg) cards[0], cards[1], cards[2], cards[3]); } - mInventoryItems.push_back(InventoryItem(index, itemId, amount, - false)); + mInventoryItems.push_back( + InventoryItem { index, itemId, amount, false }); } break; @@ -309,10 +303,8 @@ void InventoryHandler::handleMessage(MessageIn &msg) if (!mStorage) mStorage = new Inventory(Inventory::STORAGE, size); - auto it = mInventoryItems.begin(); - auto it_end = mInventoryItems.end(); - for (; it != it_end; it++) - mStorage->setItem((*it).slot, (*it).id, (*it).quantity); + for (auto &item : mInventoryItems) + mStorage->setItem(item.slot, item.id, item.quantity); mInventoryItems.clear(); if (!mStorageWindow) @@ -385,10 +377,6 @@ void InventoryHandler::handleMessage(MessageIn &msg) { mEquips.setEquipment(getSlot(equipType), index); } - - // Load the equipment boxes - if (equipmentWindow) - equipmentWindow->loadEquipBoxes(); } break; diff --git a/src/net/tmwa/inventoryhandler.h b/src/net/tmwa/inventoryhandler.h index 2df5a699..51a0fe51 100644 --- a/src/net/tmwa/inventoryhandler.h +++ b/src/net/tmwa/inventoryhandler.h @@ -22,7 +22,6 @@ #ifndef NET_TA_INVENTORYHANDLER_H #define NET_TA_INVENTORYHANDLER_H -#include "equipment.h" #include "eventlistener.h" #include "inventory.h" #include "log.h" @@ -128,8 +127,7 @@ class EquipBackend final : public Equipment::Backend void triggerUnequip(int slotIndex) const override { - Item *item = getEquipment(slotIndex); - if (item) + if (Item *item = getEquipment(slotIndex)) item->doEvent(Event::DoUnequip); } @@ -143,21 +141,12 @@ class EquipBackend final : public Equipment::Backend /** * Used to cache storage data until we get size data for it. */ -class InventoryItem +struct InventoryItem { - public: - int slot; - int id; - int quantity; - bool equip; - - InventoryItem(int slot, int id, int quantity, bool equip) - { - this->slot = slot; - this->id = id; - this->quantity = quantity; - this->equip = equip; - } + int slot; + int id; + int quantity; + bool equip; }; class InventoryHandler final : public MessageHandler, public Net::InventoryHandler, @@ -184,20 +173,25 @@ class InventoryHandler final : public MessageHandler, public Net::InventoryHandl // Note the slot type id is equal to the slot Index for tA. bool isWeaponSlot(unsigned int slotTypeId) const override { - return (slotTypeId == EQUIP_FIGHT1_SLOT - || slotTypeId == EQUIP_FIGHT1_SLOT); + return (slotTypeId == EQUIP_FIGHT1_SLOT || + slotTypeId == EQUIP_FIGHT1_SLOT); } bool isAmmoSlot(unsigned int slotTypeId) const override { - return (slotTypeId == EQUIP_PROJECTILE_SLOT); + return slotTypeId == EQUIP_PROJECTILE_SLOT; + } + + Equipment::Backend *getEquipmentBackend() override + { + return &mEquips; } private: EquipBackend mEquips; - std::list<InventoryItem> mInventoryItems; - Inventory *mStorage; - InventoryWindow *mStorageWindow; + std::vector<InventoryItem> mInventoryItems; + Inventory *mStorage = nullptr; + InventoryWindow *mStorageWindow = nullptr; }; } // namespace TmwAthena |