diff options
author | Ira Rice <irarice@gmail.com> | 2008-10-28 01:27:57 +0000 |
---|---|---|
committer | Ira Rice <irarice@gmail.com> | 2008-10-28 01:27:57 +0000 |
commit | 89d67a3c0f222529e61207891ae320a5a5babcdf (patch) | |
tree | 7e7615e72848a49c1ddcd6153857cebbc7320b15 /src/localplayer.cpp | |
parent | 9cd73fb8c9d4890336d0d0ccf290d45084155c2d (diff) | |
download | mana-client-89d67a3c0f222529e61207891ae320a5a5babcdf.tar.gz mana-client-89d67a3c0f222529e61207891ae320a5a5babcdf.tar.bz2 mana-client-89d67a3c0f222529e61207891ae320a5a5babcdf.tar.xz mana-client-89d67a3c0f222529e61207891ae320a5a5babcdf.zip |
Fixed attacking so that it will actually continue to attack in
succession like it's intended to if it's given a true keep flag, or just
do one attack if that flag isn't set. Since most people seem to prefer to
continue to attack when attacking, shift will be used for when someone only
wants to hit the target once.
Diffstat (limited to 'src/localplayer.cpp')
-rw-r--r-- | src/localplayer.cpp | 72 |
1 files changed, 43 insertions, 29 deletions
diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 85030eb7..a63ec18a 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -107,30 +107,37 @@ void LocalPlayer::logic() mFrame = (get_elapsed_time(mWalkTime) * frames) / mAttackSpeed; if (mFrame >= frames) { nextStep(); - attack(); } break; } - // Actions are allowed twice per second - if (get_elapsed_time(mLastAction) >= 500) { + // Actions are allowed once per second + if (get_elapsed_time(mLastAction) >= 1000) { mLastAction = -1; } + // Targeting allowed 4 times a second + if (get_elapsed_time(mLastTarget) >= 250) { + mLastTarget = -1; + } + // Remove target if its been on a being for more than a minute if (get_elapsed_time(mTargetTime) >= 60000) { mTargetTime = -1; setTarget(mTarget); - mLastAction = -1; + mLastTarget = -1; } if (mTarget) { if (mTarget->mAction == DEAD) { - setTarget(mTarget); - mLastAction = -1; + stopAttack(); + } + if (mKeepAttacking && mTarget) + { + attack(mTarget, true); } } @@ -279,27 +286,19 @@ void LocalPlayer::walk(unsigned char dir) void LocalPlayer::setTarget(Being *target) { - if (mLastAction != -1) + if (mLastTarget != -1 || target == this) return; - mLastAction = tick_time; + mLastTarget = tick_time; if (target) { mTargetTime = tick_time; } - if (target == mTarget) + if ((target == NULL) || target == mTarget) { - if (mTarget) - { - if (mTarget->getType() == Being::MONSTER) - { - static_cast<Monster *>(mTarget)->showName(false); - } - mTarget->mTargetCursor = NULL; - mTarget = NULL; - } - return; + target = NULL; + mKeepAttacking = false; } if (mTarget && mTarget->getType() == Being::MONSTER) { @@ -444,22 +443,25 @@ bool LocalPlayer::tradeRequestOk() const void LocalPlayer::attack(Being *target, bool keep) { - // Can only attack when standing still - if (mAction != STAND) + mKeepAttacking = keep; + + if (!target) return; - if (keep && (mTarget != target)) + if ((mTarget != target) || !mTarget) { - mLastAction = -1; + mLastTarget = -1; setTarget(target); } - if (!target) - return; - int dist_x = target->mX - mX; int dist_y = target->mY - mY; + // Must be standing and be within attack range to continue + if ((mAction != STAND) || (mAttackRange < abs(dist_x)) || + (mAttackRange < abs(dist_y))) + return; + if (abs(dist_y) >= abs(dist_x)) { if (dist_y > 0) @@ -478,9 +480,10 @@ void LocalPlayer::attack(Being *target, bool keep) // Implement charging attacks here mLastAttackTime = 0; - setAction(ATTACK); mWalkTime = tick_time; + setAction(ATTACK); + if (mEquippedWeapon) { std::string soundFile = mEquippedWeapon->getSound(EQUIP_EVENT_STRIKE); @@ -494,11 +497,22 @@ void LocalPlayer::attack(Being *target, bool keep) outMsg.writeInt16(0x0089); outMsg.writeInt32(target->getId()); outMsg.writeInt8(0); + + if (!keep) + { + stopAttack(); + } } void LocalPlayer::stopAttack() { - setTarget(NULL); + if (mTarget) + { + setAction(STAND); + mLastTarget = -1; + setTarget(NULL); + mLastTarget = -1; + } } Being* LocalPlayer::getTarget() const @@ -541,7 +555,7 @@ bool LocalPlayer::withinAttackRange(Being *target) void LocalPlayer::setGotoTarget(Being *target) { - mLastAction = -1; + mLastTarget = -1; setTarget(target); mGoingToTarget = true; setDestination(target->mX, target->mY); |