From 1ad3e55c431b61e6fe6638ee0afc5e8f4c14496c Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Thu, 25 Aug 2016 02:55:51 +0300 Subject: Allow buy more than one item at vending shop at once. --- src/net/eathena/vendinghandler.cpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'src/net/eathena/vendinghandler.cpp') diff --git a/src/net/eathena/vendinghandler.cpp b/src/net/eathena/vendinghandler.cpp index 739f39acd..35e77f954 100644 --- a/src/net/eathena/vendinghandler.cpp +++ b/src/net/eathena/vendinghandler.cpp @@ -73,6 +73,41 @@ void VendingHandler::buy(const Being *const being, outMsg.writeInt16(CAST_S16(index), "index"); } +void VendingHandler::buyItems(const Being *const being, + const std::vector &items) const +{ + int cnt = 0; + const int pairSize = 4; + + FOR_EACH (std::vector::const_iterator, it, items) + { + ShopItem *const item = *it; + const int usedQuantity = item->getUsedQuantity(); + if (!usedQuantity) + continue; + cnt ++; + } + + if (cnt > 100) + return; + + createOutPacket(CMSG_VENDING_BUY); + outMsg.writeInt16(CAST_S16(4 + 4 + pairSize * cnt), "len"); + outMsg.writeBeingId(being->getId(), "account id"); + FOR_EACH (std::vector::const_iterator, it, items) + { + ShopItem *const item = *it; + const int usedQuantity = item->getUsedQuantity(); + if (!usedQuantity) + continue; + item->increaseQuantity(usedQuantity); + item->increaseUsedQuantity(-usedQuantity); + item->update(); + outMsg.writeInt16(CAST_S16(usedQuantity), "amount"); + outMsg.writeInt16(CAST_S16(item->getInvIndex()), "index"); + } +} + void VendingHandler::buy2(const Being *const being, const int vendId, const int index, -- cgit v1.2.3-70-g09d2