From 2288a403ad4377fbb552243e805aaf0b5a4f5a0d Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 3 Nov 2015 21:54:44 +0300 Subject: Allow buy from npc shop or from market more than one of item at one transaction. --- src/net/eathena/cashshophandler.cpp | 5 ++++ src/net/eathena/cashshophandler.h | 2 ++ src/net/eathena/markethandler.cpp | 52 +++++++++++++++++++++++++++++++++++++ src/net/eathena/markethandler.h | 2 ++ src/net/eathena/npchandler.cpp | 51 ++++++++++++++++++++++++++++++++++++ src/net/eathena/npchandler.h | 2 ++ src/net/eathena/serverfeatures.cpp | 5 ++++ src/net/eathena/serverfeatures.h | 2 ++ 8 files changed, 121 insertions(+) (limited to 'src/net/eathena') diff --git a/src/net/eathena/cashshophandler.cpp b/src/net/eathena/cashshophandler.cpp index 5bb54b119..9dcbe208a 100644 --- a/src/net/eathena/cashshophandler.cpp +++ b/src/net/eathena/cashshophandler.cpp @@ -50,6 +50,11 @@ void CashShopHandler::buyItem(const int points, outMsg.writeInt16(static_cast(itemId), "item id"); } +void CashShopHandler::buyItems(std::vector &items A_UNUSED) const +{ + // +++ probably need impliment buy many items at same time +} + void CashShopHandler::close() const { createOutPacket(CMSG_NPC_CASH_SHOP_CLOSE); diff --git a/src/net/eathena/cashshophandler.h b/src/net/eathena/cashshophandler.h index 099aa3e92..132d019b8 100644 --- a/src/net/eathena/cashshophandler.h +++ b/src/net/eathena/cashshophandler.h @@ -39,6 +39,8 @@ class CashShopHandler final : public Net::CashShopHandler const ItemColor color, const int amount) const override final; + void buyItems(std::vector &items) const override final; + void close() const override final; void requestPoints() const override final; 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 . */ +#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 &items) const +{ + int cnt = 0; + const int pairSize = 6; + + FOR_EACH (std::vector::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(4 + pairSize * cnt), "len"); + FOR_EACH (std::vector::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(item->getId()), + "item id"); + outMsg.writeInt32(static_cast(1), "amount"); + } + } + else + { + outMsg.writeInt16(static_cast(item->getId()), "item id"); + outMsg.writeInt32(static_cast(usedQuantity), "amount"); + } + } +} + } // namespace EAthena diff --git a/src/net/eathena/markethandler.h b/src/net/eathena/markethandler.h index 30d1eb2b1..bcc59e351 100644 --- a/src/net/eathena/markethandler.h +++ b/src/net/eathena/markethandler.h @@ -39,6 +39,8 @@ class MarketHandler final : public Net::MarketHandler const int type, const ItemColor color, const int amount) const override final; + + void buyItems(std::vector &items) const override final; }; } // namespace EAthena 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(itemId), "item id"); } +void NpcHandler::buyItems(std::vector &items) const +{ + int cnt = 0; + const int pairSize = 4; + + FOR_EACH (std::vector::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(4 + pairSize * cnt), "len"); + FOR_EACH (std::vector::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(1), "amount"); + outMsg.writeInt16(static_cast(item->getId()), + "item id"); + } + } + else + { + outMsg.writeInt16(static_cast(usedQuantity), "amount"); + outMsg.writeInt16(static_cast(item->getId()), "item id"); + } + } +} + void NpcHandler::sellItem(const BeingId beingId A_UNUSED, const int itemId, const int amount) const { diff --git a/src/net/eathena/npchandler.h b/src/net/eathena/npchandler.h index b1ef9128d..608c7d775 100644 --- a/src/net/eathena/npchandler.h +++ b/src/net/eathena/npchandler.h @@ -59,6 +59,8 @@ class NpcHandler final : public Ea::NpcHandler const ItemColor color, const int amount) const override final; + void buyItems(std::vector &items) const override final; + void sellItem(const BeingId beingId, const int itemId, const int amount) const override final; diff --git a/src/net/eathena/serverfeatures.cpp b/src/net/eathena/serverfeatures.cpp index b3f4b7814..fbc97b97e 100644 --- a/src/net/eathena/serverfeatures.cpp +++ b/src/net/eathena/serverfeatures.cpp @@ -245,4 +245,9 @@ bool ServerFeatures::haveExtendedRiding() const return serverVersion >= 9; } +bool ServerFeatures::haveAdvancedBuySell() const +{ + return true; +} + } // namespace EAthena diff --git a/src/net/eathena/serverfeatures.h b/src/net/eathena/serverfeatures.h index b1fc7c74e..6bb2176ae 100644 --- a/src/net/eathena/serverfeatures.h +++ b/src/net/eathena/serverfeatures.h @@ -117,6 +117,8 @@ class ServerFeatures final : public Net::ServerFeatures bool haveAdvancedSprites() const override final; bool haveExtendedRiding() const override final; + + bool haveAdvancedBuySell() const override final; }; } // namespace EAthena -- cgit v1.2.3-60-g2f50