diff options
Diffstat (limited to 'src/net/eathena')
-rw-r--r-- | src/net/eathena/npchandler.cpp | 33 | ||||
-rw-r--r-- | src/net/eathena/npchandler.h | 2 |
2 files changed, 34 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); diff --git a/src/net/eathena/npchandler.h b/src/net/eathena/npchandler.h index 608c7d775..34855c802 100644 --- a/src/net/eathena/npchandler.h +++ b/src/net/eathena/npchandler.h @@ -65,6 +65,8 @@ class NpcHandler final : public Ea::NpcHandler const int itemId, const int amount) const override final; + void sellItems(std::vector<ShopItem*> &items) const override final; + void completeProgressBar() const override final; void produceMix(const int nameId, |