diff options
Diffstat (limited to 'src/net')
-rw-r--r-- | src/net/ea/inventoryhandler.cpp | 63 | ||||
-rw-r--r-- | src/net/ea/inventoryhandler.h | 18 | ||||
-rw-r--r-- | src/net/inventoryhandler.h | 6 |
3 files changed, 83 insertions, 4 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 diff --git a/src/net/inventoryhandler.h b/src/net/inventoryhandler.h index ebd35489..cbd1b6c5 100644 --- a/src/net/inventoryhandler.h +++ b/src/net/inventoryhandler.h @@ -34,11 +34,11 @@ class InvyHandler virtual void unequipItem(Item *item) {} - virtual void useItem(int slot, Item *item) {} + virtual void useItem(Item *item) {} - virtual void dropItem(int slot, int amount) {} + virtual void dropItem(Item *item, int amount) {} - virtual void splitItem(int slot, int amount) {} + virtual void splitItem(Item *item, int amount) {} virtual void openStorage() {} |