summaryrefslogtreecommitdiff
path: root/src/net
diff options
context:
space:
mode:
Diffstat (limited to 'src/net')
-rw-r--r--src/net/eathena/markethandler.cpp35
-rw-r--r--src/net/eathena/markethandler.h4
2 files changed, 33 insertions, 6 deletions
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