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/tmwa/npchandler.cpp | |
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/tmwa/npchandler.cpp')
-rw-r--r-- | src/net/tmwa/npchandler.cpp | 88 |
1 files changed, 43 insertions, 45 deletions
diff --git a/src/net/tmwa/npchandler.cpp b/src/net/tmwa/npchandler.cpp index 485a8ff7..b61dc520 100644 --- a/src/net/tmwa/npchandler.cpp +++ b/src/net/tmwa/npchandler.cpp @@ -68,6 +68,8 @@ NpcHandler::NpcHandler() }; handledMessages = _messages; npcHandler = this; + + Mana::EventManager::bind(this, "NPC"); } void NpcHandler::handleMessage(Net::MessageIn &msg) @@ -131,52 +133,48 @@ void NpcHandler::handleMessage(Net::MessageIn &msg) player_node->setAction(Being::STAND); } -void NpcHandler::talk(int npcId) -{ - MessageOut outMsg(CMSG_NPC_TALK); - outMsg.writeInt32(npcId); - outMsg.writeInt8(0); // Unused -} - -void NpcHandler::nextDialog(int npcId) -{ - MessageOut outMsg(CMSG_NPC_NEXT_REQUEST); - outMsg.writeInt32(npcId); -} - -void NpcHandler::closeDialog(int npcId) -{ - MessageOut outMsg(CMSG_NPC_CLOSE); - outMsg.writeInt32(npcId); -} - -void NpcHandler::listInput(int npcId, int value) -{ - MessageOut outMsg(CMSG_NPC_LIST_CHOICE); - outMsg.writeInt32(npcId); - outMsg.writeInt8(value); -} - -void NpcHandler::integerInput(int npcId, int value) -{ - MessageOut outMsg(CMSG_NPC_INT_RESPONSE); - outMsg.writeInt32(npcId); - outMsg.writeInt32(value); -} - -void NpcHandler::stringInput(int npcId, const std::string &value) +void NpcHandler::event(const std::string &channel, const Mana::Event &event) { - MessageOut outMsg(CMSG_NPC_STR_RESPONSE); - outMsg.writeInt16(value.length() + 9); - outMsg.writeInt32(npcId); - outMsg.writeString(value, value.length()); - outMsg.writeInt8(0); // Prevent problems with string reading -} - -void NpcHandler::sendLetter(int npcId, const std::string &recipient, - const std::string &text) -{ - // TODO + if (channel == "NPC") + { + if (event.getName() == "doTalk") + { + MessageOut outMsg(CMSG_NPC_TALK); + outMsg.writeInt32(event.getInt("npcId")); + outMsg.writeInt8(0); // Unused + } + else if (event.getName() == "doNext") + { + MessageOut outMsg(CMSG_NPC_NEXT_REQUEST); + outMsg.writeInt32(event.getInt("npcId")); + } + else if (event.getName() == "doClose") + { + MessageOut outMsg(CMSG_NPC_CLOSE); + outMsg.writeInt32(event.getInt("npcId")); + } + else if (event.getName() == "doMenu") + { + MessageOut outMsg(CMSG_NPC_LIST_CHOICE); + outMsg.writeInt32(event.getInt("npcId")); + outMsg.writeInt8(event.getInt("choice")); + } + else if (event.getName() == "doIntegerInput") + { + MessageOut outMsg(CMSG_NPC_INT_RESPONSE); + outMsg.writeInt32(event.getInt("npcId")); + outMsg.writeInt32(event.getInt("value")); + } + else if (event.getName() == "doStringInput") + { + const std::string &value = event.getString("value"); + MessageOut outMsg(CMSG_NPC_STR_RESPONSE); + outMsg.writeInt16(value.length() + 9); + outMsg.writeInt32(event.getInt("npcId")); + outMsg.writeString(value, value.length()); + outMsg.writeInt8(0); // Prevent problems with string reading + } + } } void NpcHandler::startShopping(int beingId) |