summaryrefslogtreecommitdiff
path: root/src/net/tmwa/inventoryhandler.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2014-09-12 19:27:29 +0300
committerAndrei Karas <akaras@inbox.ru>2014-09-13 17:41:29 +0300
commitcb23bcec8f8a1d8863ab25adc39a58415e5be88c (patch)
treeef02b4c3e9028eac10118101aa090f4ad8a9d96e /src/net/tmwa/inventoryhandler.cpp
parentba54aed00801d29e4b5b6c77e1aed23a038ba7e6 (diff)
downloadmv-cb23bcec8f8a1d8863ab25adc39a58415e5be88c.tar.gz
mv-cb23bcec8f8a1d8863ab25adc39a58415e5be88c.tar.bz2
mv-cb23bcec8f8a1d8863ab25adc39a58415e5be88c.tar.xz
mv-cb23bcec8f8a1d8863ab25adc39a58415e5be88c.zip
In inventoryhandler use for each packet own function.
Diffstat (limited to 'src/net/tmwa/inventoryhandler.cpp')
-rw-r--r--src/net/tmwa/inventoryhandler.cpp98
1 files changed, 62 insertions, 36 deletions
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")
}