00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "net/tmwserv/npchandler.h"
00023
00024 #include "net/tmwserv/connection.h"
00025 #include "net/tmwserv/protocol.h"
00026
00027 #include "net/tmwserv/gameserver/internal.h"
00028 #include "net/tmwserv/gameserver/player.h"
00029
00030 #include "net/messagein.h"
00031 #include "net/messageout.h"
00032
00033 #include "beingmanager.h"
00034 #include "npc.h"
00035
00036 #include "gui/npclistdialog.h"
00037 #include "gui/npcpostdialog.h"
00038 #include "gui/npc_text.h"
00039
00040 Net::NpcHandler *npcHandler;
00041
00042 namespace TmwServ {
00043
00044 NpcHandler::NpcHandler()
00045 {
00046 static const Uint16 _messages[] = {
00047 GPMSG_NPC_CHOICE,
00048 GPMSG_NPC_POST,
00049 GPMSG_NPC_MESSAGE,
00050 GPMSG_NPC_ERROR,
00051 0
00052 };
00053 handledMessages = _messages;
00054 npcHandler = this;
00055 }
00056
00057 void NpcHandler::handleMessage(MessageIn &msg)
00058 {
00059 Being *being = beingManager->findBeing(msg.readInt16());
00060 if (!being || being->getType() != Being::NPC)
00061 {
00062 return;
00063 }
00064
00065 current_npc = being->getId();
00066
00067 switch (msg.getId())
00068 {
00069 case GPMSG_NPC_CHOICE:
00070 npcListDialog->reset();
00071 while (msg.getUnreadLength())
00072 {
00073 npcListDialog->addItem(msg.readString());
00074 }
00075 npcListDialog->setVisible(true);
00076 break;
00077
00078 case GPMSG_NPC_POST:
00079 npcTextDialog->setVisible(false);
00080 npcPostDialog->clear();
00081 npcPostDialog->setVisible(true);
00082 break;
00083
00084 case GPMSG_NPC_ERROR:
00085 current_npc = NULL;
00086 case GPMSG_NPC_MESSAGE:
00087 npcTextDialog->addText(msg.readString(msg.getUnreadLength()));
00088 npcListDialog->setVisible(false);
00089 npcTextDialog->setVisible(true);
00090 npcPostDialog->setVisible(false);
00091 break;
00092 }
00093 }
00094
00095 void NpcHandler::talk(int npcId)
00096 {
00097 MessageOut msg(PGMSG_NPC_TALK);
00098 msg.writeInt16(npcId);
00099 Net::GameServer::connection->send(msg);
00100 }
00101
00102 void NpcHandler::nextDialog(int npcId)
00103 {
00104 MessageOut msg(PGMSG_NPC_TALK_NEXT);
00105 msg.writeInt16(npcId);
00106 Net::GameServer::connection->send(msg);
00107 }
00108
00109 void NpcHandler::closeDialog(int npcId)
00110 {
00111
00112 }
00113
00114 void NpcHandler::listInput(int npcId, int value)
00115 {
00116 MessageOut msg(PGMSG_NPC_SELECT);
00117 msg.writeInt16(npcId);
00118 msg.writeInt8(value);
00119 Net::GameServer::connection->send(msg);
00120 }
00121
00122 void NpcHandler::integerInput(int npcId, int value)
00123 {
00124
00125 }
00126
00127 void NpcHandler::stringInput(int npcId, const std::string &value)
00128 {
00129
00130 }
00131
00132 void NpcHandler::sendLetter(int npcId, const std::string &recipient,
00133 const std::string &text)
00134 {
00135 MessageOut msg(PGMSG_NPC_POST_SEND);
00136 msg.writeString(recipient);
00137 msg.writeString(text);
00138 Net::GameServer::connection->send(msg);
00139 }
00140
00141 void NpcHandler::startShopping(int beingId)
00142 {
00143
00144 }
00145
00146 void NpcHandler::buy(int beingId)
00147 {
00148
00149 }
00150
00151 void NpcHandler::sell(int beingId)
00152 {
00153
00154 }
00155
00156 void NpcHandler::buyItem(int beingId, int itemId, int amount)
00157 {
00158 MessageOut msg(PGMSG_NPC_BUYSELL);
00159 msg.writeInt16(itemId);
00160 msg.writeInt16(amount);
00161 Net::GameServer::connection->send(msg);
00162 }
00163
00164 void NpcHandler::sellItem(int beingId, int itemId, int amount)
00165 {
00166 MessageOut msg(PGMSG_NPC_BUYSELL);
00167 msg.writeInt16(itemId);
00168 msg.writeInt16(amount);
00169 Net::GameServer::connection->send(msg);
00170 }
00171
00172 void NpcHandler::endShopping(int beingId)
00173 {
00174
00175 }
00176
00177 }