diff options
author | Yohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer> | 2012-02-03 13:06:21 +0100 |
---|---|---|
committer | Yohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer> | 2012-02-03 14:44:43 +0100 |
commit | 024088d76569ef07be7f166f22f3f5e22592a586 (patch) | |
tree | d72732228963c969f86ec0d5f4f96fc703bb71f5 /src | |
parent | e2f9e7cf25d3dd2b239496945a83a0d7c6c4e86e (diff) | |
download | mana-024088d76569ef07be7f166f22f3f5e22592a586.tar.gz mana-024088d76569ef07be7f166f22f3f5e22592a586.tar.bz2 mana-024088d76569ef07be7f166f22f3f5e22592a586.tar.xz mana-024088d76569ef07be7f166f22f3f5e22592a586.zip |
Fixed the go and attack mouse click
I first removed the keep attacking and pickup targetting unset
statements in the setdestination() function
since it was messing with all the rest of the logic,
and put those targetting logic where they belonged more.
I also changed the gotoTarget function to properly call the setTarget
function which permitted to properly unset the previous target
in that case.
I also finished the logic built around the mGoingToTarget member
(until then actually unused) to make it all work again.
At last, I also removed a now false comment
in the startWalking() function.
Reviewed-by: Erik Schilling
Diffstat (limited to 'src')
-rw-r--r-- | src/localplayer.cpp | 73 | ||||
-rw-r--r-- | src/localplayer.h | 2 |
2 files changed, 51 insertions, 24 deletions
diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 99cdca0d..353f75c7 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -132,23 +132,48 @@ void LocalPlayer::logic() if (mTarget) { - if (mTarget->getType() == ActorSprite::NPC) + ActorSprite::Type targetType = mTarget->getType(); + switch (targetType) { - mTarget->setTargetType( - withinRange(mTarget, - Net::getGameHandler()->getNpcTalkRange()) ? - TCT_IN_RANGE : TCT_NORMAL); - } - else - { - mTarget->setTargetType(withinRange(mTarget, getAttackRange()) ? - TCT_IN_RANGE : TCT_NORMAL); - - if (!mTarget->isAlive()) - stopAttack(); + case ActorSprite::NPC: + mTarget->setTargetType( + withinRange(mTarget, + Net::getGameHandler()->getNpcTalkRange()) ? + TCT_IN_RANGE : TCT_NORMAL); + break; + case ActorSprite::MONSTER: + case ActorSprite::PLAYER: + { + // Dealing with attacks + bool withinAttackRange = withinRange(mTarget, getAttackRange()); + mTarget->setTargetType(withinAttackRange ? + TCT_IN_RANGE : TCT_NORMAL); - if (mKeepAttacking && mTarget) - attack(mTarget, true); + if (!mTarget->isAlive()) + { + stopAttack(); + } + else if (mGoingToTarget && !withinAttackRange + && getPath().empty()) + { + setDestination(mTarget->getPosition()); + mKeepAttacking = true; + } + else if (withinAttackRange) + { + mGoingToTarget = false; + if (!getPath().empty()) + { + stopWalking(); + mKeepAttacking = true; + } + if (mKeepAttacking) + attack(mTarget, true); + } + break; + } + default: + break; } } else if (mPickUpTarget @@ -692,9 +717,6 @@ void LocalPlayer::setDestination(int x, int y) if (srcX == dstX && srcY == dstY) Net::getPlayerHandler()->setDestination(x, y, mDirection); } - - mPickUpTarget = 0; - mKeepAttacking = false; } void LocalPlayer::setWalkingDir(int dir) @@ -736,8 +758,6 @@ void LocalPlayer::setWalkingDir(int dir) void LocalPlayer::startWalking(unsigned char dir) { - // This function is called by setWalkingDir(), - // but also by nextTile() for TMW-Athena... if (!mMap || !dir) return; @@ -764,7 +784,7 @@ void LocalPlayer::startWalking(unsigned char dir) void LocalPlayer::stopWalking(bool sendToServer) { - if (mAction == MOVE && mWalkingDir) + if (mAction == MOVE) { mWalkingDir = 0; @@ -863,6 +883,7 @@ void LocalPlayer::stopAttack() setTarget(0); } mLastTargetTime = -1; + mKeepAttacking = false; } void LocalPlayer::pickedUp(const ItemInfo &itemInfo, int amount, @@ -950,13 +971,17 @@ bool LocalPlayer::withinRange(Actor *target, int range) const void LocalPlayer::setGotoTarget(Being *target) { + if (!target) + return; + mLastTargetTime = -1; - mTarget = target; + setTarget(target); mGoingToTarget = true; - const Vector &targetPos = target->getPosition(); + mKeepAttacking = true; + pathSetByMouse(); - setDestination(targetPos.x, targetPos.y); + setDestination(target->getPosition()); } void LocalPlayer::addMessageToQueue(const std::string &message, int color) diff --git a/src/localplayer.h b/src/localplayer.h index 8e5795c3..64e37fee 100644 --- a/src/localplayer.h +++ b/src/localplayer.h @@ -128,6 +128,8 @@ class LocalPlayer : public Being * Sets a new destination for this being to walk to. */ virtual void setDestination(int x, int y); + virtual void setDestination(const Vector &dest) + { setDestination((int)dest.x, (int)dest.y); } /** * Sets a new direction to keep walking in, when using the keyboard |