diff options
Diffstat (limited to 'src/net/eathena/npchandler.cpp')
-rw-r--r-- | src/net/eathena/npchandler.cpp | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/src/net/eathena/npchandler.cpp b/src/net/eathena/npchandler.cpp index dc01d512c..9b09d8799 100644 --- a/src/net/eathena/npchandler.cpp +++ b/src/net/eathena/npchandler.cpp @@ -187,10 +187,41 @@ void NpcHandler::sellItem(const BeingId beingId A_UNUSED, createOutPacket(CMSG_NPC_SELL_REQUEST); outMsg.writeInt16(8, "len"); outMsg.writeInt16(static_cast<int16_t>(itemId + INVENTORY_OFFSET), - "item id"); + "item index"); outMsg.writeInt16(static_cast<int16_t>(amount), "amount"); } +void NpcHandler::sellItems(std::vector<ShopItem*> &items) const +{ + const int pairSize = 4; + int cnt = 0; + + FOR_EACH (std::vector<ShopItem*>::iterator, it, items) + { + ShopItem *const item = *it; + const int usedQuantity = item->getUsedQuantity(); + if (!usedQuantity) + continue; + cnt ++; + } + + createOutPacket(CMSG_NPC_SELL_REQUEST); + outMsg.writeInt16(static_cast<int16_t>(4 + pairSize * cnt), "len"); + FOR_EACH (std::vector<ShopItem*>::iterator, it, items) + { + ShopItem *const item = *it; + const int usedQuantity = item->getUsedQuantity(); + if (!usedQuantity) + continue; + item->increaseUsedQuantity(-usedQuantity); + item->update(); + outMsg.writeInt16(static_cast<int16_t>( + item->getCurrentInvIndex() + INVENTORY_OFFSET), + "item index"); + outMsg.writeInt16(static_cast<int16_t>(usedQuantity), "amount"); + } +} + void NpcHandler::completeProgressBar() const { createOutPacket(CMSG_NPC_COMPLETE_PROGRESS_BAR); |