diff options
author | Jared Adams <jaxad0127@gmail.com> | 2010-08-12 19:43:51 -0600 |
---|---|---|
committer | Jared Adams <jaxad0127@gmail.com> | 2010-08-12 20:07:04 -0600 |
commit | 2293b1c5ef0bb7378140bf73f1fef03a4504bdd2 (patch) | |
tree | b3df7512fd0e48e8b1b3a0ed3cbd6d5e9d149ad2 /src/net/manaserv | |
parent | 71595e5db41f503f06401c59090748b46e9731f0 (diff) | |
download | mana-2293b1c5ef0bb7378140bf73f1fef03a4504bdd2.tar.gz mana-2293b1c5ef0bb7378140bf73f1fef03a4504bdd2.tar.bz2 mana-2293b1c5ef0bb7378140bf73f1fef03a4504bdd2.tar.xz mana-2293b1c5ef0bb7378140bf73f1fef03a4504bdd2.zip |
Replace most of Net::NpcHandler with events
Reviewed-by: Chuck Miller
Diffstat (limited to 'src/net/manaserv')
-rw-r--r-- | src/net/manaserv/npchandler.cpp | 97 | ||||
-rw-r--r-- | src/net/manaserv/npchandler.h | 20 |
2 files changed, 51 insertions, 66 deletions
diff --git a/src/net/manaserv/npchandler.cpp b/src/net/manaserv/npchandler.cpp index 09dccffe..9f63c837 100644 --- a/src/net/manaserv/npchandler.cpp +++ b/src/net/manaserv/npchandler.cpp @@ -51,6 +51,8 @@ NpcHandler::NpcHandler() }; handledMessages = _messages; npcHandler = this; + + Mana::EventManager::bind(this, "NPC"); } void NpcHandler::handleMessage(Net::MessageIn &msg) @@ -127,58 +129,51 @@ void NpcHandler::handleMessage(Net::MessageIn &msg) delete event; } -void NpcHandler::talk(int npcId) -{ - MessageOut msg(PGMSG_NPC_TALK); - msg.writeInt16(npcId); - gameServerConnection->send(msg); -} - -void NpcHandler::nextDialog(int npcId) -{ - MessageOut msg(PGMSG_NPC_TALK_NEXT); - msg.writeInt16(npcId); - gameServerConnection->send(msg); -} - -void NpcHandler::closeDialog(int npcId) -{ - MessageOut msg(PGMSG_NPC_TALK_NEXT); - msg.writeInt16(npcId); - gameServerConnection->send(msg); -} - -void NpcHandler::listInput(int npcId, int value) -{ - MessageOut msg(PGMSG_NPC_SELECT); - msg.writeInt16(npcId); - msg.writeInt8(value); - gameServerConnection->send(msg); -} - -void NpcHandler::integerInput(int npcId, int value) -{ - MessageOut msg(PGMSG_NPC_NUMBER); - msg.writeInt16(npcId); - msg.writeInt32(value); - gameServerConnection->send(msg); -} - -void NpcHandler::stringInput(int npcId, const std::string &value) -{ - MessageOut msg(PGMSG_NPC_STRING); - msg.writeInt16(npcId); - msg.writeString(value); - gameServerConnection->send(msg); -} - -void NpcHandler::sendLetter(int npcId, const std::string &recipient, - const std::string &text) +void NpcHandler::event(const std::string &channel, const Mana::Event &event) { - MessageOut msg(PGMSG_NPC_POST_SEND); - msg.writeString(recipient); - msg.writeString(text); - gameServerConnection->send(msg); + if (channel == "NPC") + { + if (event.getName() == "doTalk") + { + MessageOut msg(PGMSG_NPC_TALK); + msg.writeInt16(event.getInt("npcId")); + gameServerConnection->send(msg); + } + else if (event.getName() == "doNext" || event.getName() == "doClose") + { + MessageOut msg(PGMSG_NPC_TALK_NEXT); + msg.writeInt16(event.getInt("npcId")); + gameServerConnection->send(msg); + } + else if (event.getName() == "doMenu") + { + MessageOut msg(PGMSG_NPC_SELECT); + msg.writeInt16(event.getInt("npcId")); + msg.writeInt8(event.getInt("choice")); + gameServerConnection->send(msg); + } + else if (event.getName() == "doIntegerInput") + { + MessageOut msg(PGMSG_NPC_NUMBER); + msg.writeInt16(event.getInt("npcId")); + msg.writeInt32(event.getInt("value")); + gameServerConnection->send(msg); + } + else if (event.getName() == "doStringInput") + { + MessageOut msg(PGMSG_NPC_STRING); + msg.writeInt16(event.getInt("npcId")); + msg.writeString(event.getString("value")); + gameServerConnection->send(msg); + } + else if (event.getName() == "doSendLetter") + { + MessageOut msg(PGMSG_NPC_POST_SEND); + msg.writeString(event.getString("recipient")); + msg.writeString(event.getString("text")); + gameServerConnection->send(msg); + } + } } void NpcHandler::startShopping(int beingId) diff --git a/src/net/manaserv/npchandler.h b/src/net/manaserv/npchandler.h index d66c1a48..14e8a50a 100644 --- a/src/net/manaserv/npchandler.h +++ b/src/net/manaserv/npchandler.h @@ -22,6 +22,8 @@ #ifndef NET_MANASERV_NPCHANDLER_H #define NET_MANASERV_NPCHANDLER_H +#include "listener.h" + #include "net/npchandler.h" #include "net/manaserv/messagehandler.h" @@ -30,27 +32,15 @@ namespace ManaServ { -class NpcHandler : public MessageHandler, public Net::NpcHandler +class NpcHandler : public MessageHandler, public Net::NpcHandler, + public Mana::Listener { public: NpcHandler(); void handleMessage(Net::MessageIn &msg); - void talk(int npcId); - - void nextDialog(int npcId); - - void closeDialog(int npcId); - - void listInput(int npcId, int value); - - void integerInput(int npcId, int value); - - void stringInput(int npcId, const std::string &value); - - void sendLetter(int npcId, const std::string &recipient, - const std::string &text); + void event(const std::string &channel, const Mana::Event &event); void startShopping(int beingId); |