summaryrefslogtreecommitdiff
path: root/src/net/ea/npchandler.cpp
diff options
context:
space:
mode:
authorJared Adams <jaxad0127@gmail.com>2010-02-13 15:04:58 -0700
committerJared Adams <jaxad0127@gmail.com>2010-02-13 15:08:54 -0700
commit8bc425ff48b7a874ca0fb9d2285044c75f3010ab (patch)
tree5904c7f53cde9ffbe7df2a63f088561141e06b66 /src/net/ea/npchandler.cpp
parent28c9cec5d39c9a1b98694eba9a28281cf111e34a (diff)
downloadmana-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/ea/npchandler.cpp')
-rw-r--r--src/net/ea/npchandler.cpp97
1 files changed, 50 insertions, 47 deletions
diff --git a/src/net/ea/npchandler.cpp b/src/net/ea/npchandler.cpp
index 48cc6125..6fb719a1 100644
--- a/src/net/ea/npchandler.cpp
+++ b/src/net/ea/npchandler.cpp
@@ -57,72 +57,70 @@ NpcHandler::NpcHandler()
void NpcHandler::handleMessage(Net::MessageIn &msg)
{
- int id;
- bool resetPlayer = false;
+ bool resetPlayer = true;
+
+ if (msg.getId() == SMSG_NPC_CHOICE || msg.getId() == SMSG_NPC_MESSAGE)
+ {
+ msg.readInt16(); // length
+ }
+
+ int npcId = msg.readInt32();
+ NpcDialogs::iterator diag = mNpcDialogs.find(npcId);
+ NpcDialog *dialog;
+
+ if (diag == mNpcDialogs.end())
+ {
+ // Empty dialogs don't help
+ if (msg.getId() == SMSG_NPC_CLOSE)
+ {
+ closeDialog(npcId);
+ }
+ else if (msg.getId() == SMSG_NPC_NEXT)
+ {
+ nextDialog(npcId);
+ }
+ else
+ {
+ dialog = new NpcDialog(npcId);
+ Wrapper wrap;
+ wrap.dialog = dialog;
+ mNpcDialogs[npcId] = wrap;
+ }
+ }
+ else
+ {
+ dialog = diag->second.dialog;
+ }
switch (msg.getId())
{
case SMSG_NPC_CHOICE:
- msg.readInt16(); // length
- current_npc = msg.readInt32();
- npcDialog->setNpc(current_npc);
- npcDialog->choiceRequest();
- npcDialog->parseListItems(msg.readString(msg.getLength() - 8));
- npcDialog->setVisible(true);
- resetPlayer = true;
+ dialog->choiceRequest();
+ dialog->parseListItems(msg.readString(msg.getLength() - 8));
break;
case SMSG_NPC_MESSAGE:
- msg.readInt16(); // length
- current_npc = msg.readInt32();
- npcDialog->setNpc(current_npc);
- npcDialog->addText(msg.readString(msg.getLength() - 8));
- npcDialog->setVisible(true);
- resetPlayer = true;
+ dialog->addText(msg.readString(msg.getLength() - 8));
break;
case SMSG_NPC_CLOSE:
- id = msg.readInt32();
- // If we're talking to that NPC, show the close button
- if (id == current_npc)
- {
- npcDialog->showCloseButton();
- resetPlayer = true;
- }
- // Otherwise, move on as an empty dialog doesn't help
- else
- closeDialog(id);
+ // Show the close button
+ dialog->showCloseButton();
break;
case SMSG_NPC_NEXT:
- id = msg.readInt32();
- // If we're talking to that NPC, show the next button
- if (id == current_npc)
- {
- npcDialog->showNextButton();
- resetPlayer = true;
- }
- // Otherwise, move on as an empty dialog doesn't help
- else
- nextDialog(id);
+ // Show the next button
+ dialog->showNextButton();
break;
case SMSG_NPC_INT_INPUT:
// Request for an integer
- current_npc = msg.readInt32();
- npcDialog->setNpc(current_npc);
- npcDialog->integerRequest(0);
- npcDialog->setVisible(true);
- resetPlayer = true;
+ dialog->integerRequest(0);
break;
case SMSG_NPC_STR_INPUT:
// Request for a string
- current_npc = msg.readInt32();
- npcDialog->setNpc(current_npc);
- npcDialog->textRequest("");
- npcDialog->setVisible(true);
- resetPlayer = true;
+ dialog->textRequest("");
break;
}
@@ -147,8 +145,13 @@ void NpcHandler::closeDialog(int npcId)
{
MessageOut outMsg(CMSG_NPC_CLOSE);
outMsg.writeInt32(npcId);
- npcDialog->setText("");
- npcDialog->setVisible(false);
+
+ NpcDialogs::iterator it = mNpcDialogs.find(npcId);
+ if (it != mNpcDialogs.end())
+ {
+ (*it).second.dialog->close();
+ mNpcDialogs.erase(it);
+ }
}
void NpcHandler::listInput(int npcId, int value)