diff options
Diffstat (limited to 'src/localplayer.cpp')
-rw-r--r-- | src/localplayer.cpp | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 0ed23892..2aae199e 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -48,7 +48,8 @@ LocalPlayer::LocalPlayer(Uint32 id, Uint16 job, Map *map): mInventory(new Inventory), mXp(0), mNetwork(0), mTarget(NULL), mPickUpTarget(NULL), - mTrading(false), mLastAction(-1), + mTrading(false), mGoingToTarget(false), + mLastAction(-1), mWalkingDir(0), mDestX(0), mDestY(0) { } @@ -104,6 +105,16 @@ void LocalPlayer::nextStep() { walk(mWalkingDir); } + + } + + if (mGoingToTarget && mTarget && withinAttackRange(mTarget)) + { + mAction = Being::STAND; + attack(mTarget, true); + mGoingToTarget = false; + mPath.clear(); + return; } Player::nextStep(); @@ -453,3 +464,23 @@ void LocalPlayer::setXp(int xp) } mXp = xp; } + +bool LocalPlayer::withinAttackRange(Being *target) +{ + int dist_x = abs(target->mX - mX); + int dist_y = abs(target->mY - mY); + + if (dist_x > getAttackRange() || dist_y > getAttackRange()) + { + return false; + } + + return true; +} + +void LocalPlayer::setGotoTarget(Being *target) +{ + mTarget = target; + mGoingToTarget = true; + setDestination(target->mX, target->mY); +} |