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 +++++++++++++++++++++++++++++++++++ src/net/eathena/vendinghandler.h | 4 ++++ src/net/eathena/vendingrecv.cpp | 2 +- 3 files changed, 40 insertions(+), 1 deletion(-) (limited to 'src/net/eathena') 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, diff --git a/src/net/eathena/vendinghandler.h b/src/net/eathena/vendinghandler.h index b824a8d8e..307c93ad9 100644 --- a/src/net/eathena/vendinghandler.h +++ b/src/net/eathena/vendinghandler.h @@ -45,6 +45,10 @@ class VendingHandler final : public Net::VendingHandler const int index, const int amount) const override final; + void buyItems(const Being *const being, + const std::vector &items) const + override final; + void createShop(const std::string &name, const bool flag, const std::vector &items) const diff --git a/src/net/eathena/vendingrecv.cpp b/src/net/eathena/vendingrecv.cpp index 468143dfd..d3b625159 100644 --- a/src/net/eathena/vendingrecv.cpp +++ b/src/net/eathena/vendingrecv.cpp @@ -98,7 +98,7 @@ void VendingRecv::processItemsList(Net::MessageIn &msg) if (!being) return; int cards[maxCards]; - CREATEWIDGETV(mBuyDialog, BuyDialog, being->getName()); + CREATEWIDGETV(mBuyDialog, BuyDialog, being); mBuyDialog->setMoney(PlayerInfo::getAttribute(Attributes::MONEY)); if (msg.getVersion() >= 20100105) msg.readInt32("vender id"); -- cgit v1.2.3-60-g2f50