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/npchandler.h"
00023
00024 #include "net/ea/protocol.h"
00025
00026 #include "net/messagein.h"
00027 #include "net/messageout.h"
00028 #include "net/net.h"
00029 #include "net/npchandler.h"
00030
00031 #include "beingmanager.h"
00032 #include "localplayer.h"
00033 #include "npc.h"
00034
00035 #include "gui/npc_text.h"
00036 #include "gui/npcintegerdialog.h"
00037 #include "gui/npclistdialog.h"
00038 #include "gui/npcstringdialog.h"
00039
00040 #include <SDL_types.h>
00041
00042 Net::NpcHandler *npcHandler;
00043
00044 namespace EAthena {
00045
00046 NpcHandler::NpcHandler()
00047 {
00048 static const Uint16 _messages[] = {
00049 SMSG_NPC_CHOICE,
00050 SMSG_NPC_MESSAGE,
00051 SMSG_NPC_NEXT,
00052 SMSG_NPC_CLOSE,
00053 SMSG_NPC_INT_INPUT,
00054 SMSG_NPC_STR_INPUT,
00055 0
00056 };
00057 handledMessages = _messages;
00058 npcHandler = this;
00059 }
00060
00061 void NpcHandler::handleMessage(MessageIn &msg)
00062 {
00063 int id;
00064
00065 switch (msg.getId())
00066 {
00067 case SMSG_NPC_CHOICE:
00068 msg.readInt16();
00069 current_npc = msg.readInt32();
00070 player_node->setAction(LocalPlayer::STAND);
00071 npcListDialog->parseItems(msg.readString(msg.getLength() - 8));
00072 npcListDialog->setVisible(true);
00073 npcListDialog->requestFocus();
00074 break;
00075
00076 case SMSG_NPC_MESSAGE:
00077 msg.readInt16();
00078 current_npc = msg.readInt32();
00079 player_node->setAction(LocalPlayer::STAND);
00080 npcTextDialog->addText(msg.readString(msg.getLength() - 8));
00081 npcTextDialog->setVisible(true);
00082 npcTextDialog->requestFocus();
00083 break;
00084
00085 case SMSG_NPC_CLOSE:
00086 id = msg.readInt32();
00087
00088 if (id == current_npc)
00089 npcTextDialog->showCloseButton();
00090
00091 else
00092 npcTextDialog->closeDialog(id);
00093 break;
00094
00095 case SMSG_NPC_NEXT:
00096 id = msg.readInt32();
00097
00098 if (id == current_npc)
00099 npcTextDialog->showNextButton();
00100
00101 else
00102 npcTextDialog->nextDialog(id);
00103 break;
00104
00105 case SMSG_NPC_INT_INPUT:
00106
00107 current_npc = msg.readInt32();
00108 player_node->setAction(LocalPlayer::STAND);
00109 npcIntegerDialog->setRange(0, 2147483647);
00110 npcIntegerDialog->setDefaultValue(0);
00111 npcIntegerDialog->setVisible(true);
00112 npcIntegerDialog->requestFocus();
00113 break;
00114
00115 case SMSG_NPC_STR_INPUT:
00116
00117 current_npc = msg.readInt32();
00118 player_node->setAction(LocalPlayer::STAND);
00119 npcStringDialog->setValue("");
00120 npcStringDialog->setVisible(true);
00121 npcStringDialog->requestFocus();
00122 break;
00123 }
00124 }
00125
00126 void NpcHandler::talk(int npcId)
00127 {
00128 MessageOut outMsg(CMSG_NPC_TALK);
00129 outMsg.writeInt32(npcId);
00130 outMsg.writeInt8(0);
00131 }
00132
00133 void NpcHandler::nextDialog(int npcId)
00134 {
00135 MessageOut outMsg(CMSG_NPC_NEXT_REQUEST);
00136 outMsg.writeInt32(npcId);
00137 }
00138
00139 void NpcHandler::closeDialog(int npcId)
00140 {
00141 MessageOut outMsg(CMSG_NPC_CLOSE);
00142 outMsg.writeInt32(npcId);
00143 }
00144
00145 void NpcHandler::listInput(int npcId, int value)
00146 {
00147 MessageOut outMsg(CMSG_NPC_LIST_CHOICE);
00148 outMsg.writeInt32(npcId);
00149 outMsg.writeInt8(value);
00150 }
00151
00152 void NpcHandler::integerInput(int npcId, int value)
00153 {
00154 MessageOut outMsg(CMSG_NPC_INT_RESPONSE);
00155 outMsg.writeInt32(npcId);
00156 outMsg.writeInt32(value);
00157 }
00158
00159 void NpcHandler::stringInput(int npcId, const std::string &value)
00160 {
00161 MessageOut outMsg(CMSG_NPC_STR_RESPONSE);
00162 outMsg.writeInt16(value.length() + 9);
00163 outMsg.writeInt32(npcId);
00164 outMsg.writeString(value, value.length());
00165 outMsg.writeInt8(0);
00166 }
00167
00168 void NpcHandler::sendLetter(int npcId, const std::string &recipient,
00169 const std::string &text)
00170 {
00171
00172 }
00173
00174 void NpcHandler::startShopping(int beingId)
00175 {
00176
00177 }
00178
00179 void NpcHandler::buy(int beingId)
00180 {
00181 MessageOut outMsg(CMSG_NPC_BUY_SELL_REQUEST);
00182 outMsg.writeInt32(beingId);
00183 outMsg.writeInt8(0);
00184 }
00185
00186 void NpcHandler::sell(int beingId)
00187 {
00188 MessageOut outMsg(CMSG_NPC_BUY_SELL_REQUEST);
00189 outMsg.writeInt32(beingId);
00190 outMsg.writeInt8(1);
00191 }
00192
00193 void NpcHandler::buyItem(int beingId, int itemId, int amount)
00194 {
00195 MessageOut outMsg(CMSG_NPC_BUY_REQUEST);
00196 outMsg.writeInt16(8);
00197 outMsg.writeInt16(amount);
00198 outMsg.writeInt16(itemId);
00199 }
00200
00201 void NpcHandler::sellItem(int beingId, int itemId, int amount)
00202 {
00203 MessageOut outMsg(CMSG_NPC_SELL_REQUEST);
00204 outMsg.writeInt16(8);
00205 outMsg.writeInt16(itemId + INVENTORY_OFFSET);
00206 outMsg.writeInt16(amount);
00207 }
00208
00209 void NpcHandler::endShopping(int beingId)
00210 {
00211
00212 }
00213
00214 }