summaryrefslogtreecommitdiff
path: root/src/net/eathena/vendinghandler.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2016-08-25 02:55:51 +0300
committerAndrei Karas <akaras@inbox.ru>2016-08-25 02:55:51 +0300
commit1ad3e55c431b61e6fe6638ee0afc5e8f4c14496c (patch)
treec198baa8b7c57b2a4b118e6d740961a126d0e528 /src/net/eathena/vendinghandler.cpp
parent290ae8ba45bb706f32da15978459022e633aa626 (diff)
downloadmanaverse-1ad3e55c431b61e6fe6638ee0afc5e8f4c14496c.tar.gz
manaverse-1ad3e55c431b61e6fe6638ee0afc5e8f4c14496c.tar.bz2
manaverse-1ad3e55c431b61e6fe6638ee0afc5e8f4c14496c.tar.xz
manaverse-1ad3e55c431b61e6fe6638ee0afc5e8f4c14496c.zip
Allow buy more than one item at vending shop at once.
Diffstat (limited to 'src/net/eathena/vendinghandler.cpp')
-rw-r--r--src/net/eathena/vendinghandler.cpp35
1 files changed, 35 insertions, 0 deletions
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<ShopItem*> &items) const
+{
+ int cnt = 0;
+ const int pairSize = 4;
+
+ FOR_EACH (std::vector<ShopItem*>::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<ShopItem*>::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,