summaryrefslogtreecommitdiff
path: root/src/net
diff options
context:
space:
mode:
authorJared Adams <jaxad0127@gmail.com>2009-03-08 18:40:48 -0600
committerIra Rice <irarice@gmail.com>2009-03-09 00:52:56 -0600
commit5fa3f62d0d6d9cbffeef0f6a2497aae023dbadcf (patch)
treea905c74e059311b5adf10a6eacbe53482d95c380 /src/net
parent6ea994477c58912785729e7922eb90862a1ab13c (diff)
downloadmana-5fa3f62d0d6d9cbffeef0f6a2497aae023dbadcf.tar.gz
mana-5fa3f62d0d6d9cbffeef0f6a2497aae023dbadcf.tar.bz2
mana-5fa3f62d0d6d9cbffeef0f6a2497aae023dbadcf.tar.xz
mana-5fa3f62d0d6d9cbffeef0f6a2497aae023dbadcf.zip
Add an interface for eAthena's storage system
Diffstat (limited to 'src/net')
-rw-r--r--src/net/inventoryhandler.cpp84
-rw-r--r--src/net/playerhandler.cpp2
2 files changed, 60 insertions, 26 deletions
diff --git a/src/net/inventoryhandler.cpp b/src/net/inventoryhandler.cpp
index b0511080..553ec8fd 100644
--- a/src/net/inventoryhandler.cpp
+++ b/src/net/inventoryhandler.cpp
@@ -34,6 +34,7 @@
#include "../log.h"
#include "../gui/chat.h"
+#include "../gui/storagewindow.h"
#include "../resources/iteminfo.h"
@@ -72,7 +73,6 @@ void InventoryHandler::handleMessage(MessageIn *msg)
{
case SMSG_PLAYER_INVENTORY:
case SMSG_PLAYER_STORAGE_ITEMS:
- case SMSG_PLAYER_STORAGE_EQUIP:
switch (msg->getId()) {
case SMSG_PLAYER_INVENTORY:
// Clear inventory - this will be a complete refresh
@@ -86,11 +86,10 @@ void InventoryHandler::handleMessage(MessageIn *msg)
* clear storage here
*/
storage->clear();
- logger->log("Received SMSG_PLAYER_STORAGE_ITEMS");
break;
default:
- logger->log("Received SMSG_PLAYER_STORAGE_EQUIP");
- break;
+ logger->log("HOW DID WE GET HERE?");
+ return;
}
msg->readInt16(); // length
number = (msg->getLength() - 4) / 18;
@@ -100,17 +99,8 @@ void InventoryHandler::handleMessage(MessageIn *msg)
itemId = msg->readInt16();
itemType = msg->readInt8();
identified = msg->readInt8();
- if (msg->getId() == SMSG_PLAYER_STORAGE_EQUIP) {
- amount = 1;
- msg->readInt16(); // Equip Point?
- } else {
- amount = msg->readInt16();
- }
+ amount = msg->readInt16();
arrow = msg->readInt16();
- if (msg->getId() == SMSG_PLAYER_STORAGE_EQUIP) {
- msg->readInt8(); // Attribute (broken)
- msg->readInt8(); // Refine level
- }
for (int i = 0; i < 4; i++)
cards[i] = msg->readInt16();
@@ -130,6 +120,29 @@ void InventoryHandler::handleMessage(MessageIn *msg)
}
break;
+ case SMSG_PLAYER_STORAGE_EQUIP:
+ msg->readInt16(); // length
+ number = (msg->getLength() - 4) / 20;
+
+ for (int loop = 0; loop < number; loop++) {
+ index = msg->readInt16();
+ itemId = msg->readInt16();
+ itemType = msg->readInt8();
+ identified = msg->readInt8();
+ amount = 1;
+ msg->readInt16(); // Equip Point?
+ msg->readInt16(); // Another Equip Point?
+ msg->readInt8(); // Attribute (broken)
+ msg->readInt8(); // Refine level
+ 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]);
+ storage->setItem(index, itemId, amount, false);
+ }
+ break;
+
case SMSG_PLAYER_INVENTORY_ADD:
index = msg->readInt16();
amount = msg->readInt16();
@@ -203,35 +216,54 @@ void InventoryHandler::handleMessage(MessageIn *msg)
case SMSG_PLAYER_STORAGE_STATUS:
/*
- * Basic slots used vs total slots info
- * We don't really need this information, but this is
- * the closest we get to an "Open Storage" packet
- * from the server. It always comes after the two
- * SMSG_PLAYER_STORAGE_... packets that update
- * storage contents.
+ * This is the closest we get to an "Open Storage" packet from the
+ * server. It always comes after the two SMSG_PLAYER_STORAGE_...
+ * packets that update storage contents..
*/
- logger->log("Received SMSG_PLAYER_STORAGE_STATUS");
player_node->setInStorage(true);
+ msg->readInt16(); // Storage capacity
+ msg->readInt16(); // Used count
break;
case SMSG_PLAYER_STORAGE_ADD:
/*
* Move an item into storage
*/
+ index = msg->readInt16();
+ amount = msg->readInt32();
+ itemId = msg->readInt16();
+ identified = msg->readInt8();
+ msg->readInt8(); // attribute
+ msg->readInt8(); // refine
+ for (int i = 0; i < 4; i++)
+ cards[i] = msg->readInt16();
+
+ if (Item *item = storage->getItem(index)) {
+ item->setId(itemId);
+ item->increaseQuantity(amount);
+ } else {
+ storage->setItem(index, itemId, amount, false);
+ }
break;
case SMSG_PLAYER_STORAGE_REMOVE:
/*
- * Move an item out of storage
- */
+ * Move an item out of storage
+ */
+ index = msg->readInt16();
+ amount = msg->readInt16();
+ if (Item *item = storage->getItem(index)) {
+ item->increaseQuantity(-amount);
+ if (item->getQuantity() == 0)
+ storage->removeItemAt(index);
+ }
break;
case SMSG_PLAYER_STORAGE_CLOSE:
/*
- * Storage access has been closed
- */
+ * Storage access has been closed
+ */
player_node->setInStorage(false);
- logger->log("Received SMSG_PLAYER_STORAGE_CLOSE");
break;
}
}
diff --git a/src/net/playerhandler.cpp b/src/net/playerhandler.cpp
index 232cf075..6533ac1e 100644
--- a/src/net/playerhandler.cpp
+++ b/src/net/playerhandler.cpp
@@ -39,6 +39,7 @@
#include "../gui/ok_dialog.h"
#include "../gui/sell.h"
#include "../gui/skill.h"
+#include "../gui/storagewindow.h"
#include "../gui/viewport.h"
#include "../utils/stringutils.h"
@@ -92,6 +93,7 @@ namespace {
buyDialog->setVisible(false);
sellDialog->setVisible(false);
buySellDialog->setVisible(false);
+ if (storageWindow->isVisible()) storageWindow->close();
current_npc = 0;
}
} deathListener;