summaryrefslogtreecommitdiff
path: root/src/net/ea
diff options
context:
space:
mode:
authorJared Adams <jaxad0127@gmail.com>2009-04-01 11:09:41 -0600
committerJared Adams <jaxad0127@gmail.com>2009-04-01 11:09:41 -0600
commit2a11fd111231a7e40c560e0240578a2b4a2126c2 (patch)
treee6024c5e40fc96ad4ec85b8e4136a4982a35eb02 /src/net/ea
parent33048e36c1fdc642459b0101ad0ab9c63807a3e7 (diff)
downloadmana-2a11fd111231a7e40c560e0240578a2b4a2126c2.tar.gz
mana-2a11fd111231a7e40c560e0240578a2b4a2126c2.tar.bz2
mana-2a11fd111231a7e40c560e0240578a2b4a2126c2.tar.xz
mana-2a11fd111231a7e40c560e0240578a2b4a2126c2.zip
Make eAthena's inventory handler
Also cleanup some related #ifdefs in LocalPlayer.
Diffstat (limited to 'src/net/ea')
-rw-r--r--src/net/ea/inventoryhandler.cpp63
-rw-r--r--src/net/ea/inventoryhandler.h18
2 files changed, 80 insertions, 1 deletions
diff --git a/src/net/ea/inventoryhandler.cpp b/src/net/ea/inventoryhandler.cpp
index e1429093..79e7d2da 100644
--- a/src/net/ea/inventoryhandler.cpp
+++ b/src/net/ea/inventoryhandler.cpp
@@ -24,6 +24,7 @@
#include "net/ea/protocol.h"
#include "net/messagein.h"
+#include "net/messageout.h"
#include "configuration.h"
#include "inventory.h"
@@ -46,6 +47,8 @@
enum { debugInventory = 1 };
+InventoryHandler *invyHandler;
+
InventoryHandler::InventoryHandler()
{
static const Uint16 _messages[] = {
@@ -63,6 +66,7 @@ InventoryHandler::InventoryHandler()
0
};
handledMessages = _messages;
+ invyHandler = this;
}
void InventoryHandler::handleMessage(MessageIn &msg)
@@ -295,3 +299,62 @@ void InventoryHandler::handleMessage(MessageIn &msg)
break;
}
}
+
+void InventoryHandler::equipItem(Item *item)
+{
+ if (!item)
+ return;
+
+ MessageOut outMsg(CMSG_PLAYER_EQUIP);
+ outMsg.writeInt16(item->getInvIndex() + INVENTORY_OFFSET);
+ outMsg.writeInt16(0);
+}
+
+void InventoryHandler::unequipItem(Item *item)
+{
+ if (!item)
+ return;
+
+ MessageOut outMsg(CMSG_PLAYER_UNEQUIP);
+ outMsg.writeInt16(item->getInvIndex() + INVENTORY_OFFSET);
+}
+
+void InventoryHandler::useItem(Item *item)
+{
+ if (!item)
+ return;
+
+ MessageOut outMsg(CMSG_PLAYER_INVENTORY_USE);
+ outMsg.writeInt16(item->getInvIndex() + INVENTORY_OFFSET);
+ outMsg.writeInt32(item->getId()); // unused
+}
+
+void InventoryHandler::dropItem(Item *item, int amount)
+{
+ // TODO: Fix wrong coordinates of drops, serverside? (what's wrong here?)
+ MessageOut outMsg(CMSG_PLAYER_INVENTORY_DROP);
+ outMsg.writeInt16(item->getInvIndex() + INVENTORY_OFFSET);
+ outMsg.writeInt16(amount);
+}
+
+void InventoryHandler::closeStorage()
+{
+ MessageOut outMsg(CMSG_CLOSE_STORAGE);
+}
+
+void InventoryHandler::moveItem(StorageType source, int slot, int amount,
+ StorageType destination)
+{
+ if (source == INVENTORY && destination == STORAGE)
+ {
+ MessageOut outMsg(CMSG_MOVE_TO_STORAGE);
+ outMsg.writeInt16(slot + INVENTORY_OFFSET);
+ outMsg.writeInt32(amount);
+ }
+ else if (source == STORAGE && destination == INVENTORY)
+ {
+ MessageOut outMsg(CSMG_MOVE_FROM_STORAGE);
+ outMsg.writeInt16(slot + STORAGE_OFFSET);
+ outMsg.writeInt32(amount);
+ }
+}
diff --git a/src/net/ea/inventoryhandler.h b/src/net/ea/inventoryhandler.h
index a35021f5..def4285f 100644
--- a/src/net/ea/inventoryhandler.h
+++ b/src/net/ea/inventoryhandler.h
@@ -23,13 +23,29 @@
#define NET_EA_INVENTORYHANDLER_H
#include "net/messagehandler.h"
+#include "net/net.h"
-class InventoryHandler : public MessageHandler
+class InventoryHandler : public MessageHandler, public Net::InvyHandler
{
public:
InventoryHandler();
virtual void handleMessage(MessageIn &msg);
+
+ virtual void equipItem(Item *item);
+
+ virtual void unequipItem(Item *item);
+
+ virtual void useItem(Item *item);
+
+ virtual void dropItem(Item *item, int amount);
+
+ virtual void closeStorage();
+
+ virtual void moveItem(StorageType source, int slot, int amount,
+ StorageType destination);
};
+extern InventoryHandler *invyHandler;
+
#endif // NET_EA_INVENTORYHANDLER_H