From be44a9b715875b18616097fd026f845afa27d333 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Wed, 10 Sep 2014 17:44:20 +0300 Subject: eathena: simplify function moveItem2. --- src/net/eathena/inventoryhandler.cpp | 56 +++++++++++++++++------------------- 1 file changed, 26 insertions(+), 30 deletions(-) diff --git a/src/net/eathena/inventoryhandler.cpp b/src/net/eathena/inventoryhandler.cpp index 7bf1d7d07..958866650 100644 --- a/src/net/eathena/inventoryhandler.cpp +++ b/src/net/eathena/inventoryhandler.cpp @@ -201,44 +201,40 @@ void InventoryHandler::closeStorage(const int type A_UNUSED) const MessageOut outMsg(CMSG_CLOSE_STORAGE); } -void InventoryHandler::moveItem2(const int source, const int slot, - const int amount, const int destination) const +void InventoryHandler::moveItem2(const int source, + const int slot, + const int amount, + const int destination) const { - if (source == Inventory::INVENTORY && destination == Inventory::STORAGE) + int packet = 0; + int offset = INVENTORY_OFFSET; + if (source == Inventory::INVENTORY) { - MessageOut outMsg(CMSG_MOVE_TO_STORAGE); - outMsg.writeInt16(static_cast(slot + INVENTORY_OFFSET)); - outMsg.writeInt32(amount); - } - else if (source == Inventory::STORAGE - && destination == Inventory::INVENTORY) - { - MessageOut outMsg(CSMG_MOVE_FROM_STORAGE); - outMsg.writeInt16(static_cast(slot + STORAGE_OFFSET)); - outMsg.writeInt32(amount); - } - else if (source == Inventory::INVENTORY && destination == Inventory::CART) - { - MessageOut outMsg(CMSG_MOVE_TO_CART); - outMsg.writeInt16(static_cast(slot + INVENTORY_OFFSET)); - outMsg.writeInt32(amount); + if (destination == Inventory::STORAGE) + packet = CMSG_MOVE_TO_STORAGE; + else if (destination == Inventory::CART) + packet = CMSG_MOVE_TO_CART; } - else if (source == Inventory::CART && destination == Inventory::INVENTORY) + else if (source == Inventory::STORAGE) { - MessageOut outMsg(CMSG_MOVE_FROM_CART); - outMsg.writeInt16(static_cast(slot + INVENTORY_OFFSET)); - outMsg.writeInt32(amount); + offset = STORAGE_OFFSET; + if (destination == Inventory::INVENTORY) + packet = CSMG_MOVE_FROM_STORAGE; + else if (destination == Inventory::CART) + packet = CMSG_MOVE_FROM_STORAGE_TO_CART; } - else if (source == Inventory::CART && destination == Inventory::STORAGE) + else if (source == Inventory::CART) { - MessageOut outMsg(CMSG_MOVE_FROM_CART_TO_STORAGE); - outMsg.writeInt16(static_cast(slot + INVENTORY_OFFSET)); - outMsg.writeInt32(amount); + if (destination == Inventory::INVENTORY) + packet = CMSG_MOVE_FROM_CART; + else if (destination == Inventory::STORAGE) + packet = CMSG_MOVE_FROM_CART_TO_STORAGE; } - else if (source == Inventory::STORAGE && destination == Inventory::CART) + + if (packet) { - MessageOut outMsg(CMSG_MOVE_FROM_STORAGE_TO_CART); - outMsg.writeInt16(static_cast(slot + STORAGE_OFFSET)); + MessageOut outMsg(packet); + outMsg.writeInt16(static_cast(slot + offset)); outMsg.writeInt32(amount); } } -- cgit v1.2.3-70-g09d2