00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "net/ea/buysellhandler.h"
00023
00024 #include "net/ea/protocol.h"
00025
00026 #include "net/messagein.h"
00027
00028 #include "beingmanager.h"
00029 #include "inventory.h"
00030 #include "item.h"
00031 #include "localplayer.h"
00032 #include "npc.h"
00033
00034 #include "gui/buy.h"
00035 #include "gui/buysell.h"
00036 #include "gui/sell.h"
00037
00038 #include "gui/widgets/chattab.h"
00039
00040 #include "utils/gettext.h"
00041
00042 namespace EAthena {
00043
00044 BuySellHandler::BuySellHandler()
00045 {
00046 static const Uint16 _messages[] = {
00047 SMSG_NPC_BUY_SELL_CHOICE,
00048 SMSG_NPC_BUY,
00049 SMSG_NPC_SELL,
00050 SMSG_NPC_BUY_RESPONSE,
00051 SMSG_NPC_SELL_RESPONSE,
00052 0
00053 };
00054 handledMessages = _messages;
00055 }
00056
00057 void BuySellHandler::handleMessage(MessageIn &msg)
00058 {
00059 int n_items;
00060 switch (msg.getId())
00061 {
00062 case SMSG_NPC_BUY_SELL_CHOICE:
00063 buyDialog->setVisible(false);
00064 buyDialog->reset();
00065 sellDialog->setVisible(false);
00066 sellDialog->reset();
00067 current_npc = msg.readInt32();
00068 buySellDialog->setVisible(true);
00069 break;
00070
00071 case SMSG_NPC_BUY:
00072 msg.readInt16();
00073 n_items = (msg.getLength() - 4) / 11;
00074 buyDialog->reset();
00075 buyDialog->setMoney(player_node->getMoney());
00076 buyDialog->setVisible(true);
00077
00078 for (int k = 0; k < n_items; k++)
00079 {
00080 int value = msg.readInt32();
00081 msg.readInt32();
00082 msg.readInt8();
00083 int itemId = msg.readInt16();
00084 buyDialog->addItem(itemId, 0, value);
00085 }
00086 break;
00087
00088 case SMSG_NPC_SELL:
00089 msg.readInt16();
00090 n_items = (msg.getLength() - 4) / 10;
00091 if (n_items > 0)
00092 {
00093 sellDialog->setMoney(player_node->getMoney());
00094 sellDialog->reset();
00095 sellDialog->setVisible(true);
00096
00097 for (int k = 0; k < n_items; k++)
00098 {
00099 int index = msg.readInt16() - INVENTORY_OFFSET;
00100 int value = msg.readInt32();
00101 msg.readInt32();
00102
00103 Item *item = player_node->getInventory()->getItem(index);
00104
00105 if (item && !(item->isEquipped()))
00106 sellDialog->addItem(item, value);
00107 }
00108 }
00109 else
00110 {
00111 localChatTab->chatLog(_("Nothing to sell"), BY_SERVER);
00112 current_npc = 0;
00113 }
00114 break;
00115
00116 case SMSG_NPC_BUY_RESPONSE:
00117 if (msg.readInt8() == 0)
00118 {
00119 localChatTab->chatLog(_("Thanks for buying"), BY_SERVER);
00120 }
00121 else
00122 {
00123
00124
00125 buyDialog->setMoney(player_node->getMoney());
00126 localChatTab->chatLog(_("Unable to buy"), BY_SERVER);
00127 }
00128 break;
00129
00130 case SMSG_NPC_SELL_RESPONSE:
00131 if (msg.readInt8() == 0)
00132 localChatTab->chatLog(_("Thanks for selling"), BY_SERVER);
00133 else
00134 localChatTab->chatLog(_("Unable to sell"), BY_SERVER);
00135
00136 break;
00137 }
00138 }
00139
00140 }