From 957198ff4fcd42431f2c352e21e9cbd3dabaed3a Mon Sep 17 00:00:00 2001 From: Yohann Ferreira Date: Mon, 6 Feb 2012 22:43:36 +0100 Subject: Hopefully fixed two issues in the go and attack playflow MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Fixed the player attacking when clicking on a monster, and then walking near using the keyboard. - Fixed the walking glitch seen in tile path mode by letting the character reach its nearest tile path node. Reviewed-by: Thorbjørn Lindeijer --- src/localplayer.cpp | 38 +++++++++++++++++++++++++------------- src/localplayer.h | 9 +++++++++ 2 files changed, 34 insertions(+), 13 deletions(-) diff --git a/src/localplayer.cpp b/src/localplayer.cpp index eb92fbab..92fea956 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -153,22 +153,30 @@ void LocalPlayer::logic() { stopAttack(); } - else if (mGoingToTarget && !withinAttackRange - && getPath().empty()) + else if (mGoingToTarget) { - setDestination(mTarget->getPosition()); - mKeepAttacking = true; - } - else if (withinAttackRange) - { - mGoingToTarget = false; - if (!getPath().empty()) + if (!withinAttackRange && getPath().empty()) { - stopWalking(); + setDestination(mTarget->getPosition()); + } + else if (withinAttackRange) + { + // Truncate the path to terminate at the next node. + // This permits to avoid a walking glitch in tile path + // mode. + if (!mPath.empty()) + { + pathSetByMouse(); + setDestination(mPath.front()); + } + mKeepAttacking = true; + mGoingToTarget = false; } - if (mKeepAttacking) - attack(mTarget, true); + } + else if (withinAttackRange && mKeepAttacking) + { + attack(mTarget, true); } break; } @@ -616,6 +624,8 @@ void LocalPlayer::pickUp(FloorItem *item) if (!item) return; + cancelGoToTarget(); + if (withinRange(item, Net::getGameHandler()->getPickupRange())) { Net::getPlayerHandler()->pickUp(item); @@ -746,6 +756,8 @@ void LocalPlayer::setWalkingDir(int dir) else if (!dir) return; + cancelGoToTarget(); + mWalkingDir = dir; // If we're not already walking, start walking. @@ -886,7 +898,7 @@ void LocalPlayer::stopAttack() setTarget(0); } mLastTargetTime = -1; - mKeepAttacking = false; + cancelGoToTarget(); } void LocalPlayer::pickedUp(const ItemInfo &itemInfo, int amount, diff --git a/src/localplayer.h b/src/localplayer.h index 64e37fee..0d7b6077 100644 --- a/src/localplayer.h +++ b/src/localplayer.h @@ -130,6 +130,8 @@ class LocalPlayer : public Being virtual void setDestination(int x, int y); virtual void setDestination(const Vector &dest) { setDestination((int)dest.x, (int)dest.y); } + virtual void setDestination(const Position &dest) + { setDestination(dest.x, dest.y); } /** * Sets a new direction to keep walking in, when using the keyboard @@ -148,6 +150,13 @@ class LocalPlayer : public Being */ void setGotoTarget(Being *target); + /** + * Cancel a possible target destination in progress, + * but not the targeting. + */ + void cancelGoToTarget() + { mGoingToTarget = mKeepAttacking = false; } + /** * Returns whether the target is in range (in pixels). */ -- cgit v1.2.3-70-g09d2