diff options
author | Jared Adams <jaxad0127@gmail.com> | 2009-02-25 13:38:55 -0700 |
---|---|---|
committer | Jared Adams <jaxad0127@gmail.com> | 2009-02-25 13:38:55 -0700 |
commit | f04a8713ffc83db8b3dc4a472b28aad25a2b2bd1 (patch) | |
tree | 1822aa7cecfbe4ef38b55216ab82b686e3b636c7 /src/net | |
parent | 9673149ea3c28f42f38fc9989faf76d68e72bd20 (diff) | |
download | mana-f04a8713ffc83db8b3dc4a472b28aad25a2b2bd1.tar.gz mana-f04a8713ffc83db8b3dc4a472b28aad25a2b2bd1.tar.bz2 mana-f04a8713ffc83db8b3dc4a472b28aad25a2b2bd1.tar.xz mana-f04a8713ffc83db8b3dc4a472b28aad25a2b2bd1.zip |
Fix NPC handling to not need a handle on the NPC
The Being ID is used instead, as that is all that was ever really
needed.
Diffstat (limited to 'src/net')
-rw-r--r-- | src/net/beinghandler.cpp | 14 | ||||
-rw-r--r-- | src/net/buysellhandler.cpp | 4 | ||||
-rw-r--r-- | src/net/npchandler.cpp | 27 | ||||
-rw-r--r-- | src/net/playerhandler.cpp | 4 |
4 files changed, 24 insertions, 25 deletions
diff --git a/src/net/beinghandler.cpp b/src/net/beinghandler.cpp index 3e746eb5..982667d1 100644 --- a/src/net/beinghandler.cpp +++ b/src/net/beinghandler.cpp @@ -35,6 +35,10 @@ #include "../npc.h" #include "../player_relations.h" +#include "../gui/npc_text.h" + +extern NpcTextDialog *npcTextDialog; + const int EMOTION_TIME = 150; /**< Duration of emotion icon */ BeingHandler::BeingHandler(bool enableSync): @@ -204,7 +208,12 @@ void BeingHandler::handleMessage(MessageIn *msg) case SMSG_BEING_REMOVE: // A being should be removed or has died - dstBeing = beingManager->findBeing(msg->readInt32()); + id = msg->readInt32(); + + if (id == current_npc) + npcTextDialog->showCloseButton(); + + dstBeing = beingManager->findBeing(id); if (!dstBeing) break; @@ -213,9 +222,6 @@ void BeingHandler::handleMessage(MessageIn *msg) if (dstBeing == player_node->getTarget()) player_node->stopAttack(); - if (dstBeing == current_npc) - current_npc->handleDeath(); - if (msg->readInt8() == 1) dstBeing->setAction(Being::DEAD); else diff --git a/src/net/buysellhandler.cpp b/src/net/buysellhandler.cpp index a2442d70..714bc0ea 100644 --- a/src/net/buysellhandler.cpp +++ b/src/net/buysellhandler.cpp @@ -65,7 +65,7 @@ void BuySellHandler::handleMessage(MessageIn *msg) sellDialog->setVisible(false); sellDialog->reset(); buySellDialog->setVisible(true); - current_npc = dynamic_cast<NPC*>(beingManager->findBeing(msg->readInt32())); + current_npc = msg->readInt32(); break; case SMSG_NPC_BUY: @@ -107,7 +107,7 @@ void BuySellHandler::handleMessage(MessageIn *msg) } else { chatWindow->chatLog(_("Nothing to sell"), BY_SERVER); - if (current_npc) current_npc->handleDeath(); + current_npc = 0; } break; diff --git a/src/net/npchandler.cpp b/src/net/npchandler.cpp index ae521bd5..405217bb 100644 --- a/src/net/npchandler.cpp +++ b/src/net/npchandler.cpp @@ -54,24 +54,21 @@ NPCHandler::NPCHandler() void NPCHandler::handleMessage(MessageIn *msg) { int id; - NPC *temporaryNPC; switch (msg->getId()) { case SMSG_NPC_CHOICE: msg->readInt16(); // length - id = msg->readInt32(); + current_npc = msg->readInt32(); player_node->setAction(LocalPlayer::STAND); - current_npc = dynamic_cast<NPC*>(beingManager->findBeing(id)); npcListDialog->parseItems(msg->readString(msg->getLength() - 8)); npcListDialog->setVisible(true); break; case SMSG_NPC_MESSAGE: msg->readInt16(); // length - id = msg->readInt32(); + current_npc = msg->readInt32(); player_node->setAction(LocalPlayer::STAND); - current_npc = dynamic_cast<NPC*>(beingManager->findBeing(id)); npcTextDialog->addText(msg->readString(msg->getLength() - 8)); npcListDialog->setVisible(false); npcTextDialog->setVisible(true); @@ -79,30 +76,28 @@ void NPCHandler::handleMessage(MessageIn *msg) case SMSG_NPC_CLOSE: id = msg->readInt32(); - temporaryNPC = dynamic_cast<NPC*>(beingManager->findBeing(id)); // If we're talking to that NPC, show the close button - if (temporaryNPC == current_npc) + if (id == current_npc) npcTextDialog->showCloseButton(); // Otherwise, move on as an empty dialog doesn't help else - temporaryNPC->nextDialog(); + npcTextDialog->nextDialog(id); break; case SMSG_NPC_NEXT: id = msg->readInt32(); - temporaryNPC = dynamic_cast<NPC*>(beingManager->findBeing(id)); // If we're talking to that NPC, show the next button - if (temporaryNPC == current_npc) + if (id == current_npc) npcTextDialog->showNextButton(); - else if (temporaryNPC) // Otherwise, move on as an empty dialog doesn't help - temporaryNPC->nextDialog(); + else + npcTextDialog->nextDialog(id); break; case SMSG_NPC_INT_INPUT: // Request for an integer - id = msg->readInt32(); - current_npc = dynamic_cast<NPC*>(beingManager->findBeing(id)); + current_npc = msg->readInt32(); + player_node->setAction(LocalPlayer::STAND); npcIntegerDialog->setRange(0, 2147483647); npcIntegerDialog->setDefaultValue(0); npcIntegerDialog->setVisible(true); @@ -111,8 +106,8 @@ void NPCHandler::handleMessage(MessageIn *msg) case SMSG_NPC_STR_INPUT: // Request for a string - id = msg->readInt32(); - current_npc = dynamic_cast<NPC*>(beingManager->findBeing(id)); + current_npc = msg->readInt32(); + player_node->setAction(LocalPlayer::STAND); npcStringDialog->setValue(""); npcStringDialog->setVisible(true); npcStringDialog->requestFocus(); diff --git a/src/net/playerhandler.cpp b/src/net/playerhandler.cpp index ee1b2fd9..550753b7 100644 --- a/src/net/playerhandler.cpp +++ b/src/net/playerhandler.cpp @@ -93,7 +93,7 @@ namespace { buyDialog->setVisible(false); sellDialog->setVisible(false); buySellDialog->setVisible(false); - if (current_npc) current_npc->handleDeath(); + current_npc = 0; } } deathListener; } @@ -147,8 +147,6 @@ void PlayerHandler::handleMessage(MessageIn *msg) // Switch the actual map, deleting the previous one if necessary engine->changeMap(mapPath); - if (current_npc) current_npc->handleDeath(); - float scrollOffsetX = 0.0f; float scrollOffsetY = 0.0f; |