summaryrefslogtreecommitdiff
path: root/src/net/eathena
diff options
context:
space:
mode:
Diffstat (limited to 'src/net/eathena')
-rw-r--r--src/net/eathena/cashshophandler.cpp5
-rw-r--r--src/net/eathena/cashshophandler.h2
-rw-r--r--src/net/eathena/markethandler.cpp52
-rw-r--r--src/net/eathena/markethandler.h2
-rw-r--r--src/net/eathena/npchandler.cpp51
-rw-r--r--src/net/eathena/npchandler.h2
-rw-r--r--src/net/eathena/serverfeatures.cpp5
-rw-r--r--src/net/eathena/serverfeatures.h2
8 files changed, 121 insertions, 0 deletions
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<int16_t>(itemId), "item id");
}
+void CashShopHandler::buyItems(std::vector<ShopItem*> &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<ShopItem*> &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 <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
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<ShopItem*> &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<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
{
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<ShopItem*> &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