diff options
author | Andrei Karas <akaras@inbox.ru> | 2015-11-03 21:54:44 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2015-11-04 02:14:03 +0300 |
commit | 2288a403ad4377fbb552243e805aaf0b5a4f5a0d (patch) | |
tree | ad081047290fb6cc101f43833de6f565a368cf29 /src/net/eathena/npchandler.cpp | |
parent | cd636f7e367cfb7fa2c348d00071301a480d62c3 (diff) | |
download | manaplus-2288a403ad4377fbb552243e805aaf0b5a4f5a0d.tar.gz manaplus-2288a403ad4377fbb552243e805aaf0b5a4f5a0d.tar.bz2 manaplus-2288a403ad4377fbb552243e805aaf0b5a4f5a0d.tar.xz manaplus-2288a403ad4377fbb552243e805aaf0b5a4f5a0d.zip |
Allow buy from npc shop or from market more than one of item at one transaction.
Diffstat (limited to 'src/net/eathena/npchandler.cpp')
-rw-r--r-- | src/net/eathena/npchandler.cpp | 51 |
1 files changed, 51 insertions, 0 deletions
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<int16_t>(itemId), "item id"); } +void NpcHandler::buyItems(std::vector<ShopItem*> &items) const +{ + int cnt = 0; + const int pairSize = 4; + + FOR_EACH (std::vector<ShopItem*>::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<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(); + 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<int16_t>(1), "amount"); + outMsg.writeInt16(static_cast<int16_t>(item->getId()), + "item id"); + } + } + else + { + outMsg.writeInt16(static_cast<int16_t>(usedQuantity), "amount"); + outMsg.writeInt16(static_cast<int16_t>(item->getId()), "item id"); + } + } +} + void NpcHandler::sellItem(const BeingId beingId A_UNUSED, const int itemId, const int amount) const { |