summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2014-12-22 14:14:26 +0300
committerAndrei Karas <akaras@inbox.ru>2014-12-22 14:14:26 +0300
commitc860fb83abb48b98f98e20fc19ac1591d03b61d1 (patch)
tree6da6ce13302fe00f061ce54a1eabcb694ee37ecd
parentb3f39e67e4bf45f526a6a1867e72e2b35092528b (diff)
downloadmv-c860fb83abb48b98f98e20fc19ac1591d03b61d1.tar.gz
mv-c860fb83abb48b98f98e20fc19ac1591d03b61d1.tar.bz2
mv-c860fb83abb48b98f98e20fc19ac1591d03b61d1.tar.xz
mv-c860fb83abb48b98f98e20fc19ac1591d03b61d1.zip
Add support for show and buy from market.
-rw-r--r--src/gui/windows/buydialog.cpp16
-rw-r--r--src/net/eathena/markethandler.cpp35
-rw-r--r--src/net/eathena/markethandler.h4
3 files changed, 47 insertions, 8 deletions
diff --git a/src/gui/windows/buydialog.cpp b/src/gui/windows/buydialog.cpp
index dbc6dd59b..61b5d7233 100644
--- a/src/gui/windows/buydialog.cpp
+++ b/src/gui/windows/buydialog.cpp
@@ -45,6 +45,7 @@
#include "net/adminhandler.h"
#include "net/buysellhandler.h"
+#include "net/markethandler.h"
#include "net/npchandler.h"
#include "resources/iteminfo.h"
@@ -439,8 +440,19 @@ void BuyDialog::action(const ActionEvent &event)
else if (mNpcId != -1)
{
const ShopItem *const item = mShopItems->at(selectedItem);
- npcHandler->buyItem(mNpcId, item->getId(),
- item->getColor(), mAmountItems);
+ if (mNpcId != -3)
+ {
+ npcHandler->buyItem(mNpcId,
+ item->getId(),
+ item->getColor(),
+ mAmountItems);
+ }
+ else
+ {
+ marketHandler->buyItem(item->getId(),
+ item->getColor(),
+ mAmountItems);
+ }
// Update money and adjust the max number of items
// that can be bought
diff --git a/src/net/eathena/markethandler.cpp b/src/net/eathena/markethandler.cpp
index da3180f90..fbd0e0987 100644
--- a/src/net/eathena/markethandler.cpp
+++ b/src/net/eathena/markethandler.cpp
@@ -20,9 +20,18 @@
#include "net/eathena/markethandler.h"
+#include "notifymanager.h"
+
+#include "being/attributes.h"
+#include "being/playerinfo.h"
+
+#include "gui/windows/buydialog.h"
+
#include "net/eathena/messageout.h"
#include "net/eathena/protocol.h"
+#include "resources/notifytypes.h"
+
#include "debug.h"
extern Net::MarketHandler *marketHandler;
@@ -30,6 +39,8 @@ extern Net::MarketHandler *marketHandler;
namespace EAthena
{
+BuyDialog *MarketHandler::mBuyDialog = nullptr;
+
MarketHandler::MarketHandler() :
MessageHandler()
{
@@ -41,6 +52,7 @@ MarketHandler::MarketHandler() :
};
handledMessages = _messages;
marketHandler = this;
+ mBuyDialog = nullptr;
}
void MarketHandler::handleMessage(Net::MessageIn &msg)
@@ -63,25 +75,36 @@ void MarketHandler::handleMessage(Net::MessageIn &msg)
void MarketHandler::processMarketOpen(Net::MessageIn &msg)
{
const int len = (msg.readInt16("len") - 4) / 13;
+
+ mBuyDialog = new BuyDialog(-3);
+ mBuyDialog->setMoney(PlayerInfo::getAttribute(Attributes::MONEY));
+
for (int f = 0; f < len; f ++)
{
- msg.readInt16("item id");
+ const int itemId = msg.readInt16("item id");
msg.readUInt8("type");
- msg.readInt32("price");
- msg.readInt32("amount");
+ const int value = msg.readInt32("price");
+ const int amount = msg.readInt32("amount");
msg.readInt16("view");
+ const unsigned char color = 1;
+ mBuyDialog->addItem(itemId, color, amount, value);
}
}
void MarketHandler::processMarketBuyAck(Net::MessageIn &msg)
{
- const int len = (msg.readInt16("len") - 4) / 8;
+ const int len = (msg.readInt16("len") - 5) / 8;
+ const int res = msg.readUInt8("result");
for (int f = 0; f < len; f ++)
{
msg.readInt16("item id");
msg.readInt16("amount");
msg.readInt32("price");
}
+ if (res)
+ NotifyManager::notify(NotifyTypes::BUY_DONE);
+ else
+ NotifyManager::notify(NotifyTypes::BUY_FAILED);
}
void MarketHandler::close()
@@ -94,9 +117,9 @@ void MarketHandler::buyItem(const int itemId,
const int amount) const
{
createOutPacket(CMSG_NPC_MARKET_BUY);
- outMsg.writeInt16(8, "len");
+ outMsg.writeInt16(10, "len");
outMsg.writeInt16(static_cast<int16_t>(itemId), "item id");
- outMsg.writeInt16(static_cast<int16_t>(amount), "amount");
+ outMsg.writeInt32(static_cast<int16_t>(amount), "amount");
}
} // namespace EAthena
diff --git a/src/net/eathena/markethandler.h b/src/net/eathena/markethandler.h
index d199790e4..055023038 100644
--- a/src/net/eathena/markethandler.h
+++ b/src/net/eathena/markethandler.h
@@ -25,6 +25,8 @@
#include "net/eathena/messagehandler.h"
+class BuyDialog;
+
namespace EAthena
{
class MarketHandler final : public MessageHandler,
@@ -47,6 +49,8 @@ class MarketHandler final : public MessageHandler,
void processMarketOpen(Net::MessageIn &msg);
void processMarketBuyAck(Net::MessageIn &msg);
+
+ static BuyDialog *mBuyDialog;
};
} // namespace EAthena