summaryrefslogtreecommitdiff
path: root/src/net
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2015-11-03 21:54:44 +0300
committerAndrei Karas <akaras@inbox.ru>2015-11-04 02:14:03 +0300
commit2288a403ad4377fbb552243e805aaf0b5a4f5a0d (patch)
treead081047290fb6cc101f43833de6f565a368cf29 /src/net
parentcd636f7e367cfb7fa2c348d00071301a480d62c3 (diff)
downloadmanaverse-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')
-rw-r--r--src/net/cashshophandler.h5
-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
-rw-r--r--src/net/markethandler.h5
-rw-r--r--src/net/npchandler.h6
-rw-r--r--src/net/serverfeatures.h2
-rw-r--r--src/net/tmwa/cashshophandler.cpp4
-rw-r--r--src/net/tmwa/cashshophandler.h2
-rw-r--r--src/net/tmwa/markethandler.cpp4
-rw-r--r--src/net/tmwa/markethandler.h2
-rw-r--r--src/net/tmwa/npchandler.cpp4
-rw-r--r--src/net/tmwa/npchandler.h2
-rw-r--r--src/net/tmwa/serverfeatures.cpp5
-rw-r--r--src/net/tmwa/serverfeatures.h2
20 files changed, 164 insertions, 0 deletions
diff --git a/src/net/cashshophandler.h b/src/net/cashshophandler.h
index 1577aa543..9ff528404 100644
--- a/src/net/cashshophandler.h
+++ b/src/net/cashshophandler.h
@@ -26,9 +26,12 @@
#include "enums/simpletypes/itemcolor.h"
#include <string>
+#include <vector>
#include "localconsts.h"
+class ShopItem;
+
namespace Net
{
@@ -43,6 +46,8 @@ class CashShopHandler notfinal
const ItemColor color,
const int amount) const = 0;
+ virtual void buyItems(std::vector<ShopItem*> &items) const = 0;
+
virtual void close() const = 0;
virtual void requestPoints() const = 0;
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
diff --git a/src/net/markethandler.h b/src/net/markethandler.h
index 13027024e..2037d95cf 100644
--- a/src/net/markethandler.h
+++ b/src/net/markethandler.h
@@ -26,9 +26,12 @@
#include "enums/simpletypes/itemcolor.h"
#include <string>
+#include <vector>
#include "localconsts.h"
+class ShopItem;
+
namespace Net
{
@@ -44,6 +47,8 @@ class MarketHandler notfinal
const int type,
const ItemColor color,
const int amount) const = 0;
+
+ virtual void buyItems(std::vector<ShopItem*> &items) const = 0;
};
} // namespace Net
diff --git a/src/net/npchandler.h b/src/net/npchandler.h
index e3ef4ab23..cb7a088f1 100644
--- a/src/net/npchandler.h
+++ b/src/net/npchandler.h
@@ -32,8 +32,12 @@
#include "enums/simpletypes/beingid.h"
#include "enums/simpletypes/itemcolor.h"
+#include <vector>
+
#include "localconsts.h"
+class ShopItem;
+
namespace Net
{
@@ -72,6 +76,8 @@ class NpcHandler notfinal
const ItemColor color,
const int amount) const = 0;
+ virtual void buyItems(std::vector<ShopItem*> &items) const = 0;
+
virtual void sellItem(const BeingId beingId,
const int itemId,
const int amount) const = 0;
diff --git a/src/net/serverfeatures.h b/src/net/serverfeatures.h
index c03d409af..5926d9d3a 100644
--- a/src/net/serverfeatures.h
+++ b/src/net/serverfeatures.h
@@ -114,6 +114,8 @@ class ServerFeatures notfinal
virtual bool haveAdvancedSprites() const = 0;
virtual bool haveExtendedRiding() const = 0;
+
+ virtual bool haveAdvancedBuySell() const = 0;
};
} // namespace Net
diff --git a/src/net/tmwa/cashshophandler.cpp b/src/net/tmwa/cashshophandler.cpp
index a0b6d64cd..e940d2a54 100644
--- a/src/net/tmwa/cashshophandler.cpp
+++ b/src/net/tmwa/cashshophandler.cpp
@@ -39,6 +39,10 @@ void CashShopHandler::buyItem(const int points A_UNUSED,
{
}
+void CashShopHandler::buyItems(std::vector<ShopItem*> &items A_UNUSED) const
+{
+}
+
void CashShopHandler::close() const
{
}
diff --git a/src/net/tmwa/cashshophandler.h b/src/net/tmwa/cashshophandler.h
index 7d90067c8..c81ed394e 100644
--- a/src/net/tmwa/cashshophandler.h
+++ b/src/net/tmwa/cashshophandler.h
@@ -40,6 +40,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/tmwa/markethandler.cpp b/src/net/tmwa/markethandler.cpp
index b9dbfa4bb..4eb36c841 100644
--- a/src/net/tmwa/markethandler.cpp
+++ b/src/net/tmwa/markethandler.cpp
@@ -43,4 +43,8 @@ void MarketHandler::buyItem(const int itemId A_UNUSED,
{
}
+void MarketHandler::buyItems(std::vector<ShopItem*> &items A_UNUSED) const
+{
+}
+
} // namespace TmwAthena
diff --git a/src/net/tmwa/markethandler.h b/src/net/tmwa/markethandler.h
index 7bbf04aea..9cd4b0b8b 100644
--- a/src/net/tmwa/markethandler.h
+++ b/src/net/tmwa/markethandler.h
@@ -40,6 +40,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 TmwAthena
diff --git a/src/net/tmwa/npchandler.cpp b/src/net/tmwa/npchandler.cpp
index 4b24bce1f..57ad5850f 100644
--- a/src/net/tmwa/npchandler.cpp
+++ b/src/net/tmwa/npchandler.cpp
@@ -130,6 +130,10 @@ void NpcHandler::buyItem(const BeingId beingId A_UNUSED,
outMsg.writeInt16(static_cast<int16_t>(itemId), "item id");
}
+void NpcHandler::buyItems(std::vector<ShopItem*> &items A_UNUSED) const
+{
+}
+
void NpcHandler::sellItem(const BeingId beingId A_UNUSED,
const int itemId,
const int amount) const
diff --git a/src/net/tmwa/npchandler.h b/src/net/tmwa/npchandler.h
index 3a3cb1969..6eed8e81f 100644
--- a/src/net/tmwa/npchandler.h
+++ b/src/net/tmwa/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/tmwa/serverfeatures.cpp b/src/net/tmwa/serverfeatures.cpp
index 566bcc983..a2d60675a 100644
--- a/src/net/tmwa/serverfeatures.cpp
+++ b/src/net/tmwa/serverfeatures.cpp
@@ -244,4 +244,9 @@ bool ServerFeatures::haveExtendedRiding() const
return false;
}
+bool ServerFeatures::haveAdvancedBuySell() const
+{
+ return false;
+}
+
} // namespace TmwAthena
diff --git a/src/net/tmwa/serverfeatures.h b/src/net/tmwa/serverfeatures.h
index 33eb1457d..7a0008583 100644
--- a/src/net/tmwa/serverfeatures.h
+++ b/src/net/tmwa/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 TmwAthena