From 221d67c4774bf41e6f2f0f73fb6914030e33bdde Mon Sep 17 00:00:00 2001 From: Thorbjørn Lindeijer Date: Thu, 22 Aug 2024 17:58:31 +0200 Subject: Fixed initialization of equipment backend For new characters (and in general, when logging in with a character that had nothing equipped), the equipment backend wasn't being initialized. This resulted in the equipment not being visible in the Equipment window. Fixes #83 --- src/net/tmwa/inventoryhandler.cpp | 24 ++++++----------------- src/net/tmwa/inventoryhandler.h | 40 +++++++++++++++++---------------------- 2 files changed, 23 insertions(+), 41 deletions(-) (limited to 'src/net/tmwa') 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 mInventoryItems; - Inventory *mStorage; - InventoryWindow *mStorageWindow; + std::vector mInventoryItems; + Inventory *mStorage = nullptr; + InventoryWindow *mStorageWindow = nullptr; }; } // namespace TmwAthena -- cgit v1.2.3-70-g09d2