From c8c51d7550adf9c952a4be54398df7e7a6f341a8 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sun, 1 Feb 2015 18:07:14 +0300 Subject: add buy dialog for vending shop. --- src/actions/actions.cpp | 9 +++++++-- src/net/eathena/vendinghandler.cpp | 28 +++++++++++++++++++++++----- src/net/eathena/vendinghandler.h | 4 ++++ 3 files changed, 34 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/actions/actions.cpp b/src/actions/actions.cpp index 036f107b8..6290c0d37 100644 --- a/src/actions/actions.cpp +++ b/src/actions/actions.cpp @@ -80,7 +80,9 @@ #include "net/mercenaryhandler.h" #include "net/npchandler.h" #include "net/playerhandler.h" +#include "net/serverfeatures.h" #include "net/uploadcharinfo.h" +#include "net/vendinghandler.h" #include "net/tradehandler.h" #include "resources/iteminfo.h" @@ -605,7 +607,7 @@ impHandler(buy) { const std::string args = event.args; Being *being = findBeing(args); - if (!being) + if (!being && !serverFeatures->haveVending()) { const std::set &players = whoIsOnline->getOnlineNicks(); if (players.find(args) != players.end()) @@ -623,7 +625,10 @@ impHandler(buy) } else if (being->getType() == ActorType::Player) { - buySellHandler->requestSellList(being->getName()); + if (serverFeatures->haveVending()) + vendingHandler->open(being); + else + buySellHandler->requestSellList(being->getName()); return true; } return false; diff --git a/src/net/eathena/vendinghandler.cpp b/src/net/eathena/vendinghandler.cpp index ec765d559..25bec7c68 100644 --- a/src/net/eathena/vendinghandler.cpp +++ b/src/net/eathena/vendinghandler.cpp @@ -23,7 +23,12 @@ #include "actormanager.h" #include "shopitem.h" +#include "enums/being/attributes.h" + #include "being/being.h" +#include "being/playerinfo.h" + +#include "gui/windows/buydialog.h" #include "listeners/vendingslotslistener.h" @@ -39,6 +44,8 @@ extern Net::VendingHandler *vendingHandler; namespace EAthena { +BuyDialog *VendingHandler::mBuyDialog = nullptr; + VendingHandler::VendingHandler() : MessageHandler() { @@ -54,6 +61,7 @@ VendingHandler::VendingHandler() : }; handledMessages = _messages; vendingHandler = this; + mBuyDialog = nullptr; } void VendingHandler::handleMessage(Net::MessageIn &msg) @@ -117,22 +125,32 @@ void VendingHandler::processHideBoard(Net::MessageIn &msg) void VendingHandler::processItemsList(Net::MessageIn &msg) { + const int count = (msg.readInt16("len") - 12) / 22; - msg.readInt32("id"); + const int id = msg.readInt32("id"); + Being *const being = actorManager->findBeing(id); + if (!being) + return; + mBuyDialog = new BuyDialog(being->getName()); + mBuyDialog->setMoney(PlayerInfo::getAttribute(Attributes::MONEY)); msg.readInt32("vender id"); for (int f = 0; f < count; f ++) { - msg.readInt32("price"); - msg.readInt16("amount"); + const int value = msg.readInt32("price"); + const int amount = msg.readInt16("amount"); msg.readInt16("inv index"); - msg.readUInt8("item type"); - msg.readInt16("item id"); + const int type = msg.readUInt8("item type"); + const int itemId = msg.readInt16("item id"); msg.readUInt8("identify"); msg.readUInt8("attribute"); msg.readUInt8("refine"); for (int d = 0; d < 4; d ++) msg.readInt16("card"); + + const unsigned char color = 1; + mBuyDialog->addItem(itemId, type, color, amount, value); } + mBuyDialog->sort(); } void VendingHandler::processBuyAck(Net::MessageIn &msg) diff --git a/src/net/eathena/vendinghandler.h b/src/net/eathena/vendinghandler.h index 30e9f50e2..ba7059071 100644 --- a/src/net/eathena/vendinghandler.h +++ b/src/net/eathena/vendinghandler.h @@ -25,6 +25,8 @@ #include "net/eathena/messagehandler.h" +class BuyDialog; + namespace EAthena { class VendingHandler final : public MessageHandler, @@ -68,6 +70,8 @@ class VendingHandler final : public MessageHandler, static void processOpen(Net::MessageIn &msg); static void processReport(Net::MessageIn &msg); + + static BuyDialog *mBuyDialog; }; } // namespace EAthena -- cgit v1.2.3-60-g2f50