diff options
author | Andrei Karas <akaras@inbox.ru> | 2015-11-04 02:03:03 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2015-11-04 02:40:04 +0300 |
commit | 5cfc73dc5c0093a96c45f604a028ecca21a01af8 (patch) | |
tree | 4916b602dfa9b5caee28252515a45215008b8d71 /src/net | |
parent | 2288a403ad4377fbb552243e805aaf0b5a4f5a0d (diff) | |
download | manaplus-5cfc73dc5c0093a96c45f604a028ecca21a01af8.tar.gz manaplus-5cfc73dc5c0093a96c45f604a028ecca21a01af8.tar.bz2 manaplus-5cfc73dc5c0093a96c45f604a028ecca21a01af8.tar.xz manaplus-5cfc73dc5c0093a96c45f604a028ecca21a01af8.zip |
Allow sell to npc many items at one time (hercules).halloween2015
Diffstat (limited to 'src/net')
-rw-r--r-- | src/net/eathena/npchandler.cpp | 33 | ||||
-rw-r--r-- | src/net/eathena/npchandler.h | 2 | ||||
-rw-r--r-- | src/net/npchandler.h | 2 | ||||
-rw-r--r-- | src/net/tmwa/npchandler.cpp | 4 | ||||
-rw-r--r-- | src/net/tmwa/npchandler.h | 2 |
5 files changed, 42 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, 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<ShopItem*> &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<int16_t>(amount), "amount"); } +void NpcHandler::sellItems(std::vector<ShopItem*> &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<ShopItem*> &items) const override final; + void completeProgressBar() const override final; BeingId getNpc(Net::MessageIn &msg, |