diff options
Diffstat (limited to 'src/net')
-rw-r--r-- | src/net/buysellhandler.cpp | 3 | ||||
-rw-r--r-- | src/net/equipmenthandler.cpp | 19 | ||||
-rw-r--r-- | src/net/inventoryhandler.cpp | 38 | ||||
-rw-r--r-- | src/net/tradehandler.cpp | 4 |
4 files changed, 44 insertions, 20 deletions
diff --git a/src/net/buysellhandler.cpp b/src/net/buysellhandler.cpp index d7f063a7..26261664 100644 --- a/src/net/buysellhandler.cpp +++ b/src/net/buysellhandler.cpp @@ -29,6 +29,7 @@ #include "protocol.h" #include "../beingmanager.h" +#include "../inventory.h" #include "../item.h" #include "../localplayer.h" #include "../npc.h" @@ -99,7 +100,7 @@ void BuySellHandler::handleMessage(MessageIn *msg) Sint32 value = msg->readInt32(); msg->readInt32(); // OCvalue - Item *item = player_node->getInvItem(index); + Item *item = player_node->getInventory()->getItem(index); if (item && !(item->isEquipped())) { sellDialog->addItem(item, value); } diff --git a/src/net/equipmenthandler.cpp b/src/net/equipmenthandler.cpp index 69f24d80..85790b42 100644 --- a/src/net/equipmenthandler.cpp +++ b/src/net/equipmenthandler.cpp @@ -28,6 +28,7 @@ #include "../beingmanager.h" #include "../equipment.h" +#include "../inventory.h" #include "../item.h" #include "../localplayer.h" #include "../log.h" @@ -54,6 +55,7 @@ void EquipmentHandler::handleMessage(MessageIn *msg) Sint8 type; int mask, position; Item *item; + Inventory *inventory = player_node->getInventory(); switch (msg->getId()) { @@ -73,7 +75,7 @@ void EquipmentHandler::handleMessage(MessageIn *msg) msg->readInt8(); // refine msg->skip(8); // card - player_node->addInvItem(index, itemId, 1, true); + inventory->setItem(index, itemId, 1, true); if (equipPoint) { @@ -84,7 +86,7 @@ void EquipmentHandler::handleMessage(MessageIn *msg) mask <<= 1; position++; } - item = player_node->getInvItem(index); + item = inventory->getItem(index); player_node->mEquipment->setEquipment(position, item); } } @@ -120,7 +122,7 @@ void EquipmentHandler::handleMessage(MessageIn *msg) item->setEquipped(false); } - item = player_node->getInvItem(index); + item = inventory->getItem(index); player_node->mEquipment->setEquipment(position, item); break; @@ -146,8 +148,7 @@ void EquipmentHandler::handleMessage(MessageIn *msg) position++; } - item = player_node->getInvItem(index); - + item = inventory->getItem(index); if (!item) break; @@ -181,18 +182,18 @@ void EquipmentHandler::handleMessage(MessageIn *msg) break; case SMSG_PLAYER_ARROW_EQUIP: - itemId = msg->readInt16(); + index = msg->readInt16(); - if (itemId <= 1) + if (index <= 1) break; - item = player_node->getInvItem(itemId); + item = inventory->getItem(index); if (!item) break; item->setEquipped(true); player_node->mEquipment->setArrows(item); - logger->log("Arrows equipped: %i", itemId); + logger->log("Arrows equipped: %i", index); break; } } diff --git a/src/net/inventoryhandler.cpp b/src/net/inventoryhandler.cpp index a2190c1e..48cf18ff 100644 --- a/src/net/inventoryhandler.cpp +++ b/src/net/inventoryhandler.cpp @@ -32,9 +32,13 @@ #include "../item.h" #include "../itemshortcut.h" #include "../localplayer.h" +#include "../log.h" +#include "../inventory.h" #include "../gui/chat.h" +#include "../utils/tostring.h" + InventoryHandler::InventoryHandler() { static const Uint16 _messages[] = { @@ -52,13 +56,14 @@ void InventoryHandler::handleMessage(MessageIn *msg) { Sint32 number; Sint16 index, amount, itemId, equipType; + Inventory *inventory = player_node->getInventory(); switch (msg->getId()) { case SMSG_PLAYER_INVENTORY: // Only called on map load / warp. First reset all items // to not load them twice on map change. - player_node->clearInventory(); + inventory->clear(); msg->readInt16(); // length number = (msg->getLength() - 4) / 18; @@ -72,12 +77,13 @@ void InventoryHandler::handleMessage(MessageIn *msg) msg->skip(2); // unknown msg->skip(8); // card (4 shorts) - player_node->addInvItem(index, itemId, amount, false); + inventory->setItem(index, itemId, amount, false); // Trick because arrows are not considered equipment if (itemId == 1199 || itemId == 529) { - player_node->getInvItem(index)->setEquipment(true); + if (Item *item = inventory->getItem(index)) + item->setEquipment(true); } } break; @@ -93,20 +99,32 @@ void InventoryHandler::handleMessage(MessageIn *msg) equipType = msg->readInt16(); msg->readInt8(); // type - if (msg->readInt8()> 0) { + if (msg->readInt8() > 0) { chatWindow->chatLog("Unable to pick up item", BY_SERVER); } else { const ItemInfo &itemInfo = ItemDB::get(itemId); - chatWindow->chatLog("You picked up a " + + const std::string amountStr = + (amount > 1) ? toString(amount) : "a"; + chatWindow->chatLog("You picked up " + amountStr + " " + itemInfo.getName(), BY_SERVER); - player_node->addInvItem(index, itemId, amount, equipType != 0); + + if (Item *item = inventory->getItem(index)) { + item->setId(itemId); + item->increaseQuantity(amount); + } else { + inventory->setItem(index, itemId, amount, equipType != 0); + } } break; case SMSG_PLAYER_INVENTORY_REMOVE: index = msg->readInt16(); amount = msg->readInt16(); - player_node->getInvItem(index)->increaseQuantity(-amount); + if (Item *item = inventory->getItem(index)) { + item->increaseQuantity(-amount); + if (item->getQuantity() == 0) + inventory->removeItemAt(index); + } break; case SMSG_PLAYER_INVENTORY_USE: @@ -116,7 +134,8 @@ void InventoryHandler::handleMessage(MessageIn *msg) amount = msg->readInt16(); msg->readInt8(); // type - player_node->getInvItem(index)->setQuantity(amount); + if (Item *item = inventory->getItem(index)) + item->setQuantity(amount); break; case SMSG_ITEM_USE_RESPONSE: @@ -126,7 +145,8 @@ void InventoryHandler::handleMessage(MessageIn *msg) if (msg->readInt8() == 0) { chatWindow->chatLog("Failed to use item", BY_SERVER); } else { - player_node->getInvItem(index)->setQuantity(amount); + if (Item *item = inventory->getItem(index)) + item->setQuantity(amount); } break; } diff --git a/src/net/tradehandler.cpp b/src/net/tradehandler.cpp index 9b3c590e..85ab65c1 100644 --- a/src/net/tradehandler.cpp +++ b/src/net/tradehandler.cpp @@ -26,6 +26,7 @@ #include "messagein.h" #include "protocol.h" +#include "../inventory.h" #include "../item.h" #include "../localplayer.h" #include "../player_relations.h" @@ -157,7 +158,8 @@ void TradeHandler::handleMessage(MessageIn *msg) case SMSG_TRADE_ITEM_ADD_RESPONSE: // Trade: New Item add response (was 0x00ea, now 01b1) { - Item *item = player_node->getInvItem(msg->readInt16()); + const int index = msg->readInt16(); + Item *item = player_node->getInventory()->getItem(index); Sint16 quantity = msg->readInt16(); switch (msg->readInt8()) |