diff options
author | Jared Adams <jaxad0127@gmail.com> | 2010-02-13 15:04:58 -0700 |
---|---|---|
committer | Jared Adams <jaxad0127@gmail.com> | 2010-02-13 15:08:54 -0700 |
commit | 8bc425ff48b7a874ca0fb9d2285044c75f3010ab (patch) | |
tree | 5904c7f53cde9ffbe7df2a63f088561141e06b66 /src/net/manaserv/npchandler.cpp | |
parent | 28c9cec5d39c9a1b98694eba9a28281cf111e34a (diff) | |
download | mana-client-8bc425ff48b7a874ca0fb9d2285044c75f3010ab.tar.gz mana-client-8bc425ff48b7a874ca0fb9d2285044c75f3010ab.tar.bz2 mana-client-8bc425ff48b7a874ca0fb9d2285044c75f3010ab.tar.xz mana-client-8bc425ff48b7a874ca0fb9d2285044c75f3010ab.zip |
Make NPC dialogs instance instead of global
This change allows players to talk to multiple NPCs at a time (if the server agrees). Manaserv's netcode allows multiple commerce instances too. eAthena's is limited to one commerce instance, due to protocol limitations.
Diffstat (limited to 'src/net/manaserv/npchandler.cpp')
-rw-r--r-- | src/net/manaserv/npchandler.cpp | 52 |
1 files changed, 36 insertions, 16 deletions
diff --git a/src/net/manaserv/npchandler.cpp b/src/net/manaserv/npchandler.cpp index 4e1a4f95..00f3a338 100644 --- a/src/net/manaserv/npchandler.cpp +++ b/src/net/manaserv/npchandler.cpp @@ -62,16 +62,29 @@ void NpcHandler::handleMessage(Net::MessageIn &msg) return; } - current_npc = being->getId(); - npcDialog->setNpc(current_npc); + int npcId = being->getId(); + NpcDialogs::iterator diag = mNpcDialogs.find(npcId); + NpcDialog *dialog; + + if (diag == mNpcDialogs.end()) + { + dialog = new NpcDialog(npcId); + Wrapper wrap; + wrap.dialog = dialog; + mNpcDialogs[npcId] = wrap; + } + else + { + dialog = diag->second.dialog; + } switch (msg.getId()) { case GPMSG_NPC_CHOICE: - npcDialog->choiceRequest(); + dialog->choiceRequest(); while (msg.getUnreadLength()) { - npcDialog->addChoice(msg.readString()); + dialog->addChoice(msg.readString()); } break; @@ -79,32 +92,35 @@ void NpcHandler::handleMessage(Net::MessageIn &msg) { int min_num = msg.readInt32(); int max_num = msg.readInt32(); - npcDialog->integerRequest(msg.readInt32(), min_num, max_num); + dialog->integerRequest(msg.readInt32(), min_num, max_num); break; } case GPMSG_NPC_STRING: - npcDialog->textRequest(""); + dialog->textRequest(""); break; case GPMSG_NPC_POST: - npcDialog->setVisible(false); - npcPostDialog->clear(); - npcPostDialog->setVisible(true); + { + new NpcPostDialog(npcId); break; + } case GPMSG_NPC_ERROR: - current_npc = NULL; + dialog->close(); + if (diag != mNpcDialogs.end()) + { + mNpcDialogs.erase(diag); + } break; case GPMSG_NPC_MESSAGE: - npcDialog->addText(msg.readString(msg.getUnreadLength())); - npcDialog->showNextButton(); - npcDialog->setVisible(true); + dialog->addText(msg.readString(msg.getUnreadLength())); + dialog->showNextButton(); break; case GPMSG_NPC_CLOSE: - npcDialog->showCloseButton(); + dialog->showCloseButton(); break; } } @@ -129,8 +145,12 @@ void NpcHandler::closeDialog(int npcId) msg.writeInt16(npcId); gameServerConnection->send(msg); - npcDialog->setVisible(false); - npcDialog->setText(""); + NpcDialogs::iterator it = mNpcDialogs.find(npcId); + if (it != mNpcDialogs.end()) + { + (*it).second.dialog->close(); + mNpcDialogs.erase(it); + } } void NpcHandler::listInput(int npcId, int value) |