From 2288a403ad4377fbb552243e805aaf0b5a4f5a0d Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 3 Nov 2015 21:54:44 +0300 Subject: Allow buy from npc shop or from market more than one of item at one transaction. --- src/net/eathena/npchandler.cpp | 51 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) (limited to 'src/net/eathena/npchandler.cpp') diff --git a/src/net/eathena/npchandler.cpp b/src/net/eathena/npchandler.cpp index c84c0cab6..dc01d512c 100644 --- a/src/net/eathena/npchandler.cpp +++ b/src/net/eathena/npchandler.cpp @@ -22,6 +22,8 @@ #include "net/eathena/npchandler.h" +#include "shopitem.h" + #include "being/localplayer.h" #include "gui/windows/npcdialog.h" @@ -130,6 +132,55 @@ void NpcHandler::buyItem(const BeingId beingId A_UNUSED, outMsg.writeInt16(static_cast(itemId), "item id"); } +void NpcHandler::buyItems(std::vector &items) const +{ + int cnt = 0; + const int pairSize = 4; + + FOR_EACH (std::vector::iterator, it, items) + { + ShopItem *const item = *it; + const int usedQuantity = item->getUsedQuantity(); + const int type = item->getType(); + if (!usedQuantity) + continue; + if (type == 4 || type == 5 || type == 7 || type == 8) + cnt += item->getUsedQuantity(); + else + cnt ++; + } + + if (cnt > 100) + return; + + createOutPacket(CMSG_NPC_BUY_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(); + const int type = item->getType(); + if (type == 4 || type == 5 || type == 7 || type == 8) + { + for (int f = 0; f < usedQuantity; f ++) + { + outMsg.writeInt16(static_cast(1), "amount"); + outMsg.writeInt16(static_cast(item->getId()), + "item id"); + } + } + else + { + outMsg.writeInt16(static_cast(usedQuantity), "amount"); + outMsg.writeInt16(static_cast(item->getId()), "item id"); + } + } +} + void NpcHandler::sellItem(const BeingId beingId A_UNUSED, const int itemId, const int amount) const { -- cgit v1.2.3-60-g2f50