summaryrefslogtreecommitdiff
path: root/src/net/ea/inventoryhandler.cpp
diff options
context:
space:
mode:
authorPhilipp Sehmisch <crush@themanaworld.org>2009-03-29 18:33:44 +0200
committerPhilipp Sehmisch <crush@themanaworld.org>2009-03-29 18:33:44 +0200
commit9587fb9b86ee4081ba14d23c1133bf1a09ee4578 (patch)
tree7682df3ec17534be553caae85ffa9e5a68c9a815 /src/net/ea/inventoryhandler.cpp
parent63b41440a0555c6b39141eab94ef4627f712b476 (diff)
parent8748f26234bba1e71bbe059147fb02256f8cec2a (diff)
downloadmana-9587fb9b86ee4081ba14d23c1133bf1a09ee4578.tar.gz
mana-9587fb9b86ee4081ba14d23c1133bf1a09ee4578.tar.bz2
mana-9587fb9b86ee4081ba14d23c1133bf1a09ee4578.tar.xz
mana-9587fb9b86ee4081ba14d23c1133bf1a09ee4578.zip
Merge branch 'master' of git@gitorious.org:tmw/mainline
Diffstat (limited to 'src/net/ea/inventoryhandler.cpp')
-rw-r--r--src/net/ea/inventoryhandler.cpp107
1 files changed, 67 insertions, 40 deletions
diff --git a/src/net/ea/inventoryhandler.cpp b/src/net/ea/inventoryhandler.cpp
index 21ae6dcb..e1429093 100644
--- a/src/net/ea/inventoryhandler.cpp
+++ b/src/net/ea/inventoryhandler.cpp
@@ -32,9 +32,10 @@
#include "localplayer.h"
#include "log.h"
-#include "gui/chat.h"
#include "gui/storagewindow.h"
+#include "gui/widgets/chattab.h"
+
#include "resources/iteminfo.h"
#include "utils/gettext.h"
@@ -43,6 +44,8 @@
#include <SDL_types.h>
+enum { debugInventory = 1 };
+
InventoryHandler::InventoryHandler()
{
static const Uint16 _messages[] = {
@@ -74,28 +77,26 @@ void InventoryHandler::handleMessage(MessageIn &msg)
{
case SMSG_PLAYER_INVENTORY:
case SMSG_PLAYER_STORAGE_ITEMS:
- switch (msg.getId()) {
- case SMSG_PLAYER_INVENTORY:
- // Clear inventory - this will be a complete refresh
- inventory->clear();
- break;
- case SMSG_PLAYER_STORAGE_ITEMS:
- /*
- * This packet will always be followed by a
- * SMSG_PLAYER_STORAGE_EQUIP packet. The two packets
- * together comprise a complete refresh of storage, so
- * clear storage here
- */
- storage->clear();
- break;
- default:
- logger->log("HOW DID WE GET HERE?");
- return;
+ if (msg.getId() == SMSG_PLAYER_INVENTORY)
+ {
+ // Clear inventory - this will be a complete refresh
+ inventory->clear();
+ }
+ else
+ {
+ /*
+ * This packet will always be followed by a
+ * SMSG_PLAYER_STORAGE_EQUIP packet. The two packets
+ * together comprise a complete refresh of storage, so
+ * clear storage here
+ */
+ storage->clear();
}
msg.readInt16(); // length
number = (msg.getLength() - 4) / 18;
- for (int loop = 0; loop < number; loop++) {
+ for (int loop = 0; loop < number; loop++)
+ {
index = msg.readInt16();
itemId = msg.readInt16();
itemType = msg.readInt8();
@@ -105,6 +106,17 @@ void InventoryHandler::handleMessage(MessageIn &msg)
for (int i = 0; i < 4; i++)
cards[i] = msg.readInt16();
+ index -= (msg.getId() == SMSG_PLAYER_INVENTORY) ?
+ INVENTORY_OFFSET : STORAGE_OFFSET;
+
+ if (debugInventory)
+ {
+ 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 (msg.getId() == SMSG_PLAYER_INVENTORY) {
inventory->setItem(index, itemId, amount, false);
@@ -114,8 +126,6 @@ void InventoryHandler::handleMessage(MessageIn &msg)
item->setEquipment(true);
}
} else {
- 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]);
storage->setItem(index, itemId, amount, false);
}
}
@@ -126,7 +136,7 @@ void InventoryHandler::handleMessage(MessageIn &msg)
number = (msg.getLength() - 4) / 20;
for (int loop = 0; loop < number; loop++) {
- index = msg.readInt16();
+ index = msg.readInt16() - STORAGE_OFFSET;
itemId = msg.readInt16();
itemType = msg.readInt8();
identified = msg.readInt8();
@@ -138,14 +148,20 @@ void InventoryHandler::handleMessage(MessageIn &msg)
for (int i = 0; i < 4; i++)
cards[i] = msg.readInt16();
- 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 (debugInventory)
+ {
+ 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]);
+ }
+
storage->setItem(index, itemId, amount, false);
}
break;
case SMSG_PLAYER_INVENTORY_ADD:
- index = msg.readInt16();
+ index = msg.readInt16() - INVENTORY_OFFSET;
amount = msg.readInt16();
itemId = msg.readInt16();
identified = msg.readInt8();
@@ -156,20 +172,26 @@ void InventoryHandler::handleMessage(MessageIn &msg)
equipType = msg.readInt16();
itemType = msg.readInt8();
- if (msg.readInt8() > 0) {
- if (config.getValue("showpickupchat", true)) {
+ if (msg.readInt8() > 0)
+ {
+ if (config.getValue("showpickupchat", true))
localChatTab->chatLog(_("Unable to pick up item"), BY_SERVER);
- }
- } else {
+ }
+ else
+ {
const ItemInfo &itemInfo = ItemDB::get(itemId);
const std::string amountStr =
(amount > 1) ? toString(amount) : "a";
- if (config.getValue("showpickupchat", true)) {
+
+ if (config.getValue("showpickupchat", true))
+ {
localChatTab->chatLog(strprintf(_("You picked up %s [%s]"),
amountStr.c_str(), itemInfo.getName().c_str()),
BY_SERVER);
}
- if (config.getValue("showpickupparticle", false)) {
+
+ if (config.getValue("showpickupparticle", false))
+ {
player_node->pickedUp(itemInfo.getName());
}
@@ -183,9 +205,10 @@ void InventoryHandler::handleMessage(MessageIn &msg)
break;
case SMSG_PLAYER_INVENTORY_REMOVE:
- index = msg.readInt16();
+ index = msg.readInt16() - INVENTORY_OFFSET;
amount = msg.readInt16();
- if (Item *item = inventory->getItem(index)) {
+ if (Item *item = inventory->getItem(index))
+ {
item->increaseQuantity(-amount);
if (item->getQuantity() == 0)
inventory->removeItemAt(index);
@@ -193,7 +216,7 @@ void InventoryHandler::handleMessage(MessageIn &msg)
break;
case SMSG_PLAYER_INVENTORY_USE:
- index = msg.readInt16();
+ index = msg.readInt16() - INVENTORY_OFFSET;
msg.readInt16(); // item id
msg.readInt32(); // id
amount = msg.readInt16();
@@ -204,7 +227,7 @@ void InventoryHandler::handleMessage(MessageIn &msg)
break;
case SMSG_ITEM_USE_RESPONSE:
- index = msg.readInt16();
+ index = msg.readInt16() - INVENTORY_OFFSET;
amount = msg.readInt16();
if (msg.readInt8() == 0) {
@@ -230,7 +253,7 @@ void InventoryHandler::handleMessage(MessageIn &msg)
/*
* Move an item into storage
*/
- index = msg.readInt16();
+ index = msg.readInt16() - STORAGE_OFFSET;
amount = msg.readInt32();
itemId = msg.readInt16();
identified = msg.readInt8();
@@ -239,10 +262,13 @@ void InventoryHandler::handleMessage(MessageIn &msg)
for (int i = 0; i < 4; i++)
cards[i] = msg.readInt16();
- if (Item *item = storage->getItem(index)) {
+ if (Item *item = storage->getItem(index))
+ {
item->setId(itemId);
item->increaseQuantity(amount);
- } else {
+ }
+ else
+ {
storage->setItem(index, itemId, amount, false);
}
break;
@@ -251,9 +277,10 @@ void InventoryHandler::handleMessage(MessageIn &msg)
/*
* Move an item out of storage
*/
- index = msg.readInt16();
+ index = msg.readInt16() - STORAGE_OFFSET;
amount = msg.readInt16();
- if (Item *item = storage->getItem(index)) {
+ if (Item *item = storage->getItem(index))
+ {
item->increaseQuantity(-amount);
if (item->getQuantity() == 0)
storage->removeItemAt(index);