diff options
author | Jared Adams <jaxad0127@gmail.com> | 2009-05-06 08:22:19 -0600 |
---|---|---|
committer | Jared Adams <jaxad0127@gmail.com> | 2009-05-06 08:22:19 -0600 |
commit | 429e82f91487d48ecb5a1742ec6fb6987a2bc9bd (patch) | |
tree | d3789c7ef91680ba6a6a0eee56664ba3de690d94 /src/net | |
parent | 678c2316e34021bb16ac08eb48186f5570dc691b (diff) | |
download | mana-429e82f91487d48ecb5a1742ec6fb6987a2bc9bd.tar.gz mana-429e82f91487d48ecb5a1742ec6fb6987a2bc9bd.tar.bz2 mana-429e82f91487d48ecb5a1742ec6fb6987a2bc9bd.tar.xz mana-429e82f91487d48ecb5a1742ec6fb6987a2bc9bd.zip |
Remove more inventory handling support #ifdefs
This also fixes some minor bugs and centralizes some logic.
Diffstat (limited to 'src/net')
-rw-r--r-- | src/net/ea/inventoryhandler.cpp | 20 | ||||
-rw-r--r-- | src/net/ea/inventoryhandler.h | 14 | ||||
-rw-r--r-- | src/net/inventoryhandler.h | 14 | ||||
-rw-r--r-- | src/net/tmwserv/inventoryhandler.cpp | 32 | ||||
-rw-r--r-- | src/net/tmwserv/inventoryhandler.h | 14 |
5 files changed, 68 insertions, 26 deletions
diff --git a/src/net/ea/inventoryhandler.cpp b/src/net/ea/inventoryhandler.cpp index 17b64548..1c48aa6c 100644 --- a/src/net/ea/inventoryhandler.cpp +++ b/src/net/ea/inventoryhandler.cpp @@ -301,7 +301,7 @@ void InventoryHandler::handleMessage(MessageIn &msg) } } -void InventoryHandler::equipItem(Item *item) +void InventoryHandler::equipItem(const Item *item) { if (!item) return; @@ -311,7 +311,7 @@ void InventoryHandler::equipItem(Item *item) outMsg.writeInt16(0); } -void InventoryHandler::unequipItem(Item *item) +void InventoryHandler::unequipItem(const Item *item) { if (!item) return; @@ -320,7 +320,7 @@ void InventoryHandler::unequipItem(Item *item) outMsg.writeInt16(item->getInvIndex() + INVENTORY_OFFSET); } -void InventoryHandler::useItem(Item *item) +void InventoryHandler::useItem(const Item *item) { if (!item) return; @@ -330,7 +330,7 @@ void InventoryHandler::useItem(Item *item) outMsg.writeInt32(item->getId()); // unused } -void InventoryHandler::dropItem(Item *item, int amount) +void InventoryHandler::dropItem(const Item *item, int amount) { // TODO: Fix wrong coordinates of drops, serverside? (what's wrong here?) MessageOut outMsg(CMSG_PLAYER_INVENTORY_DROP); @@ -338,7 +338,17 @@ void InventoryHandler::dropItem(Item *item, int amount) outMsg.writeInt16(amount); } -void InventoryHandler::splitItem(Item *item, int amount) +bool InventoryHandler::canSplit(const Item *item) +{ + return false; +} + +void InventoryHandler::splitItem(const Item *item, int amount) +{ + // Not implemented for eAthena (possible?) +} + +void InventoryHandler::moveItem(int oldIndex, int newIndex) { // Not implemented for eAthena (possible?) } diff --git a/src/net/ea/inventoryhandler.h b/src/net/ea/inventoryhandler.h index 391c13f4..30408dad 100644 --- a/src/net/ea/inventoryhandler.h +++ b/src/net/ea/inventoryhandler.h @@ -35,15 +35,19 @@ class InventoryHandler : public MessageHandler, public Net::InventoryHandler void handleMessage(MessageIn &msg); - void equipItem(Item *item); + void equipItem(const Item *item); - void unequipItem(Item *item); + void unequipItem(const Item *item); - void useItem(Item *item); + void useItem(const Item *item); - void dropItem(Item *item, int amount); + void dropItem(const Item *item, int amount); - void splitItem(Item *item, int amount); + bool canSplit(const Item *item); + + void splitItem(const Item *item, int amount); + + void moveItem(int oldIndex, int newIndex); void openStorage(); diff --git a/src/net/inventoryhandler.h b/src/net/inventoryhandler.h index 73a07710..19060797 100644 --- a/src/net/inventoryhandler.h +++ b/src/net/inventoryhandler.h @@ -31,15 +31,19 @@ namespace Net { class InventoryHandler { public: - virtual void equipItem(Item *item) = 0; + virtual void equipItem(const Item *item) = 0; - virtual void unequipItem(Item *item) = 0; + virtual void unequipItem(const Item *item) = 0; - virtual void useItem(Item *item) = 0; + virtual void useItem(const Item *item) = 0; - virtual void dropItem(Item *item, int amount) = 0; + virtual void dropItem(const Item *item, int amount) = 0; - virtual void splitItem(Item *item, int amount) = 0; + virtual bool canSplit(const Item *item) = 0; + + virtual void splitItem(const Item *item, int amount) = 0; + + virtual void moveItem(int oldIndex, int newIndex) = 0; virtual void openStorage() = 0; diff --git a/src/net/tmwserv/inventoryhandler.cpp b/src/net/tmwserv/inventoryhandler.cpp index 103c1c51..75886948 100644 --- a/src/net/tmwserv/inventoryhandler.cpp +++ b/src/net/tmwserv/inventoryhandler.cpp @@ -25,6 +25,7 @@ #include "net/tmwserv/protocol.h" #include "net/tmwserv/gameserver/internal.h" +#include "net/tmwserv/gameserver/player.h" #include "net/messagein.h" #include "net/messageout.h" @@ -87,28 +88,28 @@ void InventoryHandler::handleMessage(MessageIn &msg) } } -void InventoryHandler::equipItem(Item *item) +void InventoryHandler::equipItem(const Item *item) { MessageOut msg(PGMSG_EQUIP); msg.writeInt8(item->getInvIndex()); Net::GameServer::connection->send(msg); } -void InventoryHandler::unequipItem(Item *item) +void InventoryHandler::unequipItem(const Item *item) { MessageOut msg(PGMSG_UNEQUIP); msg.writeInt8(item->getInvIndex()); Net::GameServer::connection->send(msg); } -void InventoryHandler::useItem(Item *item) +void InventoryHandler::useItem(const Item *item) { MessageOut msg(PGMSG_USE_ITEM); msg.writeInt8(item->getInvIndex()); Net::GameServer::connection->send(msg); } -void InventoryHandler::dropItem(Item *item, int amount) +void InventoryHandler::dropItem(const Item *item, int amount) { MessageOut msg(PGMSG_DROP); msg.writeInt8(item->getInvIndex()); @@ -116,9 +117,28 @@ void InventoryHandler::dropItem(Item *item, int amount) Net::GameServer::connection->send(msg); } -void InventoryHandler::splitItem(Item *item, int amount) +bool InventoryHandler::canSplit(const Item *item) { - // TODO + return item && !item->isEquipment() && item->getQuantity() > 1; +} + +void InventoryHandler::splitItem(const Item *item, int amount) +{ + int newIndex = player_node->getInventory()->getFreeSlot(); + if (newIndex > Inventory::NO_SLOT_INDEX) + { + Net::GameServer::Player::moveItem( + item->getInvIndex(), newIndex, amount); + } +} + +void InventoryHandler::moveItem(int oldIndex, int newIndex) +{ + if (oldIndex == newIndex) + return; + + // TODO fix me! + Net::GameServer::Player::moveItem(oldIndex, newIndex, -1); } void InventoryHandler::openStorage() diff --git a/src/net/tmwserv/inventoryhandler.h b/src/net/tmwserv/inventoryhandler.h index c70b10c0..9ae37c10 100644 --- a/src/net/tmwserv/inventoryhandler.h +++ b/src/net/tmwserv/inventoryhandler.h @@ -34,15 +34,19 @@ class InventoryHandler : public MessageHandler, Net::InventoryHandler void handleMessage(MessageIn &msg); - void equipItem(Item *item); + void equipItem(const Item *item); - void unequipItem(Item *item); + void unequipItem(const Item *item); - void useItem(Item *item); + void useItem(const Item *item); - void dropItem(Item *item, int amount); + void dropItem(const Item *item, int amount); - void splitItem(Item *item, int amount); + bool canSplit(const Item *item); + + void splitItem(const Item *item, int amount); + + void moveItem(int oldIndex, int newIndex); void openStorage(); |