diff options
author | Chuck Miller <shadowmil@gmail.com> | 2010-11-12 20:58:30 -0500 |
---|---|---|
committer | Chuck Miller <shadowmil@gmail.com> | 2010-11-12 21:16:08 -0500 |
commit | 009cfa4b2959bf89370e9d271f2244ef5446f3a0 (patch) | |
tree | 88f9185140a636b8c6fc3badfdec55cfee826290 /src/net/tmwa | |
parent | 9ac7645f10d1e419703bdd35b276ce6e4eaf8152 (diff) | |
download | mana-009cfa4b2959bf89370e9d271f2244ef5446f3a0.tar.gz mana-009cfa4b2959bf89370e9d271f2244ef5446f3a0.tar.bz2 mana-009cfa4b2959bf89370e9d271f2244ef5446f3a0.tar.xz mana-009cfa4b2959bf89370e9d271f2244ef5446f3a0.zip |
Change NPC handling in the net code
Instead of using events to invoke netcode,
invoke netcode directly and have it send events
Reviewed-by: Freeyorp
Diffstat (limited to 'src/net/tmwa')
-rw-r--r-- | src/net/tmwa/npchandler.cpp | 121 | ||||
-rw-r--r-- | src/net/tmwa/npchandler.h | 21 |
2 files changed, 92 insertions, 50 deletions
diff --git a/src/net/tmwa/npchandler.cpp b/src/net/tmwa/npchandler.cpp index 1b12b63f..337226a9 100644 --- a/src/net/tmwa/npchandler.cpp +++ b/src/net/tmwa/npchandler.cpp @@ -68,8 +68,6 @@ NpcHandler::NpcHandler() }; handledMessages = _messages; npcHandler = this; - - listen(CHANNEL_NPC); } void NpcHandler::handleMessage(Net::MessageIn &msg) @@ -133,50 +131,6 @@ void NpcHandler::handleMessage(Net::MessageIn &msg) player_node->setAction(Being::STAND); } -void NpcHandler::event(Channels channel, const Mana::Event &event) -{ - if (channel == CHANNEL_NPC) - { - if (event.getName() == EVENT_DOTALK) - { - MessageOut outMsg(CMSG_NPC_TALK); - outMsg.writeInt32(event.getInt("npcId")); - outMsg.writeInt8(0); // Unused - } - else if (event.getName() == EVENT_DONEXT) - { - MessageOut outMsg(CMSG_NPC_NEXT_REQUEST); - outMsg.writeInt32(event.getInt("npcId")); - } - else if (event.getName() == EVENT_DOCLOSE) - { - MessageOut outMsg(CMSG_NPC_CLOSE); - outMsg.writeInt32(event.getInt("npcId")); - } - else if (event.getName() == EVENT_DOMENU) - { - MessageOut outMsg(CMSG_NPC_LIST_CHOICE); - outMsg.writeInt32(event.getInt("npcId")); - outMsg.writeInt8(event.getInt("choice")); - } - else if (event.getName() == EVENT_DOINTEGERINPUT) - { - MessageOut outMsg(CMSG_NPC_INT_RESPONSE); - outMsg.writeInt32(event.getInt("npcId")); - outMsg.writeInt32(event.getInt("value")); - } - else if (event.getName() == EVENT_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) { // TODO @@ -217,4 +171,79 @@ void NpcHandler::endShopping(int beingId) // TODO } +void NpcHandler::talk(int npcId) +{ + MessageOut outMsg(CMSG_NPC_TALK); + outMsg.writeInt32(npcId); + outMsg.writeInt8(0); // Unused + + Mana::Event event(EVENT_TALKSENT); + event.setInt("npcId", npcId); + event.trigger(CHANNEL_NPC); +} + +void NpcHandler::nextDialog(int npcId) +{ + MessageOut outMsg(CMSG_NPC_NEXT_REQUEST); + outMsg.writeInt32(npcId); + + Mana::Event event(EVENT_NEXTSENT); + event.setInt("npcId", npcId); + event.trigger(CHANNEL_NPC); +} + +void NpcHandler::closeDialog(int npcId) +{ + MessageOut outMsg(CMSG_NPC_CLOSE); + outMsg.writeInt32(npcId); + + Mana::Event event(EVENT_CLOSESENT); + event.setInt("npcId", npcId); + event.trigger(CHANNEL_NPC); +} + +void NpcHandler::menuSelect(int npcId, int choice) +{ + MessageOut outMsg(CMSG_NPC_LIST_CHOICE); + outMsg.writeInt32(npcId); + outMsg.writeInt8(choice); + + Mana::Event event(EVENT_MENUSENT); + event.setInt("npcId", npcId); + event.setInt("choice", choice); + event.trigger(CHANNEL_NPC); +} + +void NpcHandler::integerInput(int npcId, int value) +{ + MessageOut outMsg(CMSG_NPC_INT_RESPONSE); + outMsg.writeInt32(npcId); + outMsg.writeInt32(value); + + Mana::Event event(EVENT_INTEGERINPUTSENT); + event.setInt("npcId", npcId); + event.setInt("value", value); + event.trigger(CHANNEL_NPC); +} + +void NpcHandler::stringInput(int npcId, const std::string &value) +{ + 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 + + Mana::Event event(EVENT_STRINGINPUTSENT); + event.setInt("npcId", npcId); + event.setString("value", value); + event.trigger(CHANNEL_NPC); +} + +void NpcHandler::sendLetter(int npcId, const std::string &recipient, + const std::string &text) +{ + //NOTE: eA doesn't have letters +} + } // namespace TmwAthena diff --git a/src/net/tmwa/npchandler.h b/src/net/tmwa/npchandler.h index 9fcb0041..1e933418 100644 --- a/src/net/tmwa/npchandler.h +++ b/src/net/tmwa/npchandler.h @@ -32,16 +32,13 @@ namespace TmwAthena { -class NpcHandler : public MessageHandler, public Net::NpcHandler, - public Mana::Listener +class NpcHandler : public MessageHandler, public Net::NpcHandler { public: NpcHandler(); void handleMessage(Net::MessageIn &msg); - void event(Channels channel, const Mana::Event &event); - void startShopping(int beingId); void buy(int beingId); @@ -53,6 +50,22 @@ class NpcHandler : public MessageHandler, public Net::NpcHandler, void sellItem(int beingId, int itemId, int amount); void endShopping(int beingId); + + void talk(int npcId); + + void nextDialog(int npcId); + + void closeDialog(int npcId); + + void menuSelect(int npcId, int choice); + + 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); + }; } // namespace TmwAthena |