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 ++++++++++++++++++++++++++++++++- src/net/eathena/npchandler.h | 2 ++ src/net/npchandler.h | 2 ++ src/net/tmwa/npchandler.cpp | 4 ++++ src/net/tmwa/npchandler.h | 2 ++ 5 files changed, 42 insertions(+), 1 deletion(-) (limited to 'src/net') 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); 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 &items) const override final; + void completeProgressBar() const override final; void produceMix(const int nameId, diff --git a/src/net/npchandler.h b/src/net/npchandler.h index cb7a088f1..5e5a674e5 100644 --- a/src/net/npchandler.h +++ b/src/net/npchandler.h @@ -82,6 +82,8 @@ class NpcHandler notfinal const int itemId, const int amount) const = 0; + virtual void sellItems(std::vector &items) const = 0; + virtual void completeProgressBar() const = 0; virtual void produceMix(const int nameId, diff --git a/src/net/tmwa/npchandler.cpp b/src/net/tmwa/npchandler.cpp index 57ad5850f..71b5ce1d2 100644 --- a/src/net/tmwa/npchandler.cpp +++ b/src/net/tmwa/npchandler.cpp @@ -145,6 +145,10 @@ void NpcHandler::sellItem(const BeingId beingId A_UNUSED, outMsg.writeInt16(static_cast(amount), "amount"); } +void NpcHandler::sellItems(std::vector &items A_UNUSED) const +{ +} + void NpcHandler::completeProgressBar() const { } diff --git a/src/net/tmwa/npchandler.h b/src/net/tmwa/npchandler.h index 6eed8e81f..5275feeb4 100644 --- a/src/net/tmwa/npchandler.h +++ b/src/net/tmwa/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 &items) const override final; + void completeProgressBar() const override final; BeingId getNpc(Net::MessageIn &msg, -- cgit v1.2.3-70-g09d2