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/markethandler.cpp | |
parent | cd636f7e367cfb7fa2c348d00071301a480d62c3 (diff) | |
download | ManaVerse-2288a403ad4377fbb552243e805aaf0b5a4f5a0d.tar.gz ManaVerse-2288a403ad4377fbb552243e805aaf0b5a4f5a0d.tar.bz2 ManaVerse-2288a403ad4377fbb552243e805aaf0b5a4f5a0d.tar.xz ManaVerse-2288a403ad4377fbb552243e805aaf0b5a4f5a0d.zip |
Allow buy from npc shop or from market more than one of item at one transaction.
Diffstat (limited to 'src/net/eathena/markethandler.cpp')
-rw-r--r-- | src/net/eathena/markethandler.cpp | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/src/net/eathena/markethandler.cpp b/src/net/eathena/markethandler.cpp index b96e5b588..47aa05418 100644 --- a/src/net/eathena/markethandler.cpp +++ b/src/net/eathena/markethandler.cpp @@ -18,6 +18,8 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ +#include "shopitem.h" + #include "net/eathena/markethandler.h" #include "net/eathena/marketrecv.h" @@ -62,4 +64,54 @@ void MarketHandler::buyItem(const int itemId, } } +void MarketHandler::buyItems(std::vector<ShopItem*> &items) const +{ + int cnt = 0; + const int pairSize = 6; + + 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_MARKET_BUY); + 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->increaseQuantity(usedQuantity); + 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>(item->getId()), + "item id"); + outMsg.writeInt32(static_cast<int16_t>(1), "amount"); + } + } + else + { + outMsg.writeInt16(static_cast<int16_t>(item->getId()), "item id"); + outMsg.writeInt32(static_cast<int16_t>(usedQuantity), "amount"); + } + } +} + } // namespace EAthena |