summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/localplayer.cpp10
-rw-r--r--src/localplayer.h8
-rw-r--r--src/npc.cpp14
3 files changed, 16 insertions, 16 deletions
diff --git a/src/localplayer.cpp b/src/localplayer.cpp
index 2487ab54..70e42f88 100644
--- a/src/localplayer.cpp
+++ b/src/localplayer.cpp
@@ -329,6 +329,11 @@ void LocalPlayer::walk(unsigned char dir)
}
}
+Being* LocalPlayer::getTarget() const
+{
+ return mTarget;
+}
+
void LocalPlayer::setTarget(Being *target)
{
if (mLastTarget != -1 || target == this)
@@ -563,11 +568,6 @@ void LocalPlayer::stopAttack()
mLastTarget = -1;
}
-Being* LocalPlayer::getTarget() const
-{
- return mTarget;
-}
-
void LocalPlayer::revive()
{
MessageOut outMsg(mNetwork);
diff --git a/src/localplayer.h b/src/localplayer.h
index 4d0a05be..5f02de4f 100644
--- a/src/localplayer.h
+++ b/src/localplayer.h
@@ -141,8 +141,6 @@ class LocalPlayer : public Player
void stopAttack();
- Being* getTarget() const;
-
/**
* Overridden to do nothing. The attacks of the local player are
* displayed as soon as the player attacks, not when the server says
@@ -154,6 +152,12 @@ class LocalPlayer : public Player
virtual void handleAttack(Being *victim, int damage) {}
/**
+ * Returns the current target of the player. Returns 0 if no being is
+ * currently targeted.
+ */
+ Being* getTarget() const;
+
+ /**
* Sets the target being of the player.
*/
void setTarget(Being* target);
diff --git a/src/npc.cpp b/src/npc.cpp
index 70b3ce13..9aa7ad15 100644
--- a/src/npc.cpp
+++ b/src/npc.cpp
@@ -72,21 +72,17 @@ NPC::NPC(Uint32 id, Uint16 job, Map *map, Network *network):
NPC::~NPC()
{
- if (mName)
- {
- delete mName;
+ delete mName;
+
+ if (player_node->getTarget() == this)
player_node->setTarget(NULL);
- }
}
void NPC::setName(const std::string &name)
{
- if (mName)
- {
- delete mName;
- }
- std::string displayName = name.substr(0, name.find('#', 0));
+ const std::string displayName = name.substr(0, name.find('#', 0));
+ delete mName;
mName = new Text(displayName, mPx + NAME_X_OFFSET, mPy + NAME_Y_OFFSET,
gcn::Graphics::CENTER, gcn::Color(200, 200, 255));
Being::setName(displayName + " (NPC)");