From cb23bcec8f8a1d8863ab25adc39a58415e5be88c Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Fri, 12 Sep 2014 19:27:29 +0300 Subject: In inventoryhandler use for each packet own function. --- src/net/tmwa/inventoryhandler.cpp | 98 +++++++++++++++++++++++++-------------- 1 file changed, 62 insertions(+), 36 deletions(-) (limited to 'src/net/tmwa/inventoryhandler.cpp') diff --git a/src/net/tmwa/inventoryhandler.cpp b/src/net/tmwa/inventoryhandler.cpp index 7e5bf3946..ed4630bb2 100644 --- a/src/net/tmwa/inventoryhandler.cpp +++ b/src/net/tmwa/inventoryhandler.cpp @@ -82,10 +82,13 @@ void InventoryHandler::handleMessage(Net::MessageIn &msg) switch (msg.getId()) { case SMSG_PLAYER_INVENTORY: - case SMSG_PLAYER_STORAGE_ITEMS: processPlayerInventory(msg); break; + case SMSG_PLAYER_STORAGE_ITEMS: + processPlayerStorage(msg); + break; + case SMSG_PLAYER_STORAGE_EQUIP: processPlayerStorageEquip(msg); break; @@ -342,41 +345,33 @@ void InventoryHandler::processPlayerInventoryAdd(Net::MessageIn &msg) void InventoryHandler::processPlayerInventory(Net::MessageIn &msg) { BLOCK_START("InventoryHandler::processPlayerInventory") - const bool playerInvintory = msg.getId() == SMSG_PLAYER_INVENTORY; Inventory *const inventory = localPlayer ? PlayerInfo::getInventory() : nullptr; - if (playerInvintory) - { - if (PlayerInfo::getEquipment()) - { - // Clear inventory - this will be a complete refresh - mEquips.clear(); - PlayerInfo::getEquipment()->setBackend(&mEquips); - } - if (inventory) - inventory->clear(); - } - else + if (PlayerInfo::getEquipment()) { - mInventoryItems.clear(); + // Clear inventory - this will be a complete refresh + mEquips.clear(); + PlayerInfo::getEquipment()->setBackend(&mEquips); } - msg.readInt16(); // length + if (inventory) + inventory->clear(); + + msg.readInt16("len"); const int number = (msg.getLength() - 4) / 18; for (int loop = 0; loop < number; loop++) { int cards[4]; - const int index = msg.readInt16() - (playerInvintory - ? INVENTORY_OFFSET : STORAGE_OFFSET); - const int itemId = msg.readInt16(); - const uint8_t itemType = msg.readUInt8(); - uint8_t identified = msg.readUInt8(); - const int amount = msg.readInt16(); - const int arrow = msg.readInt16(); + const int index = msg.readInt16("index") - INVENTORY_OFFSET; + const int itemId = msg.readInt16("item id"); + const uint8_t itemType = msg.readUInt8("item type"); + uint8_t identified = msg.readUInt8("identified"); + const int amount = msg.readInt16("amount"); + const int arrow = msg.readInt16("arrow"); for (int i = 0; i < 4; i++) - cards[i] = msg.readInt16(); + cards[i] = msg.readInt16("card"); if (mDebugInventory) { @@ -389,22 +384,53 @@ void InventoryHandler::processPlayerInventory(Net::MessageIn &msg) if (serverVersion < 1 && identified > 1) identified = 1; - if (playerInvintory) + // Trick because arrows are not considered equipment + const bool isEquipment = arrow & 0x8000; + + if (inventory) { - // Trick because arrows are not considered equipment - const bool isEquipment = arrow & 0x8000; - - if (inventory) - { - inventory->setItem(index, itemId, amount, - 0, identified, isEquipment); - } + inventory->setItem(index, itemId, amount, + 0, identified, isEquipment); } - else + } + BLOCK_END("InventoryHandler::processPlayerInventory") +} + +void InventoryHandler::processPlayerStorage(Net::MessageIn &msg) +{ + BLOCK_START("InventoryHandler::processPlayerInventory") + Inventory *const inventory = localPlayer + ? PlayerInfo::getInventory() : nullptr; + mInventoryItems.clear(); + + msg.readInt16("len"); + const int number = (msg.getLength() - 4) / 18; + + for (int loop = 0; loop < number; loop++) + { + int cards[4]; + const int index = msg.readInt16("index") - STORAGE_OFFSET; + const int itemId = msg.readInt16("item id"); + const uint8_t itemType = msg.readUInt8("item type"); + uint8_t identified = msg.readUInt8("identified"); + const int amount = msg.readInt16("amount"); + const int arrow = msg.readInt16("arrow"); + for (int i = 0; i < 4; i++) + cards[i] = msg.readInt16("card"); + + if (mDebugInventory) { - mInventoryItems.push_back(Ea::InventoryItem(index, itemId, - amount, 0, identified, false)); + logger->log("Index: %d, ID: %d, Type: %d, Identified: %d, " + "Qty: %d, Cards: %d, %d, %d, %d", + index, itemId, itemType, identified, amount, + cards[0], cards[1], cards[2], cards[3]); } + + if (serverVersion < 1 && identified > 1) + identified = 1; + + mInventoryItems.push_back(Ea::InventoryItem(index, itemId, + amount, 0, identified, false)); } BLOCK_END("InventoryHandler::processPlayerInventory") } -- cgit v1.2.3-70-g09d2