From 5cfc73dc5c0093a96c45f604a028ecca21a01af8 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Wed, 4 Nov 2015 02:03:03 +0300 Subject: Allow sell to npc many items at one time (hercules). --- src/net/eathena/npchandler.cpp | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'src/net/eathena/npchandler.cpp') 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(itemId + INVENTORY_OFFSET), - "item id"); + "item index"); outMsg.writeInt16(static_cast(amount), "amount"); } +void NpcHandler::sellItems(std::vector &items) const +{ + const int pairSize = 4; + int cnt = 0; + + FOR_EACH (std::vector::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(4 + pairSize * cnt), "len"); + FOR_EACH (std::vector::iterator, it, items) + { + ShopItem *const item = *it; + const int usedQuantity = item->getUsedQuantity(); + if (!usedQuantity) + continue; + item->increaseUsedQuantity(-usedQuantity); + item->update(); + outMsg.writeInt16(static_cast( + item->getCurrentInvIndex() + INVENTORY_OFFSET), + "item index"); + outMsg.writeInt16(static_cast(usedQuantity), "amount"); + } +} + void NpcHandler::completeProgressBar() const { createOutPacket(CMSG_NPC_COMPLETE_PROGRESS_BAR); -- cgit v1.2.3-60-g2f50