summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIra Rice <irarice@gmail.com>2008-10-28 01:27:57 +0000
committerIra Rice <irarice@gmail.com>2008-10-28 01:27:57 +0000
commit89d67a3c0f222529e61207891ae320a5a5babcdf (patch)
tree7e7615e72848a49c1ddcd6153857cebbc7320b15
parent9cd73fb8c9d4890336d0d0ccf290d45084155c2d (diff)
downloadmana-89d67a3c0f222529e61207891ae320a5a5babcdf.tar.gz
mana-89d67a3c0f222529e61207891ae320a5a5babcdf.tar.bz2
mana-89d67a3c0f222529e61207891ae320a5a5babcdf.tar.xz
mana-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.
-rw-r--r--src/game.cpp2
-rw-r--r--src/gui/viewport.cpp2
-rw-r--r--src/localplayer.cpp72
-rw-r--r--src/localplayer.h2
4 files changed, 47 insertions, 31 deletions
diff --git a/src/game.cpp b/src/game.cpp
index 2fc23a53..86427a7a 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -801,7 +801,7 @@ void Game::handleInput()
{
Being *target = beingManager->findNearestLivingBeing(x, y, 20, Being::MONSTER);
- bool newTarget = keyboard.isKeyActive(keyboard.KEY_TARGET);
+ bool newTarget = !keyboard.isKeyActive(keyboard.KEY_TARGET);
// A set target has highest priority
if (newTarget || !player_node->getTarget())
{
diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp
index ef3f0dff..6f89f639 100644
--- a/src/gui/viewport.cpp
+++ b/src/gui/viewport.cpp
@@ -303,7 +303,7 @@ void Viewport::mousePressed(gcn::MouseEvent &event)
if (player_node->withinAttackRange(being) || keyboard.isKeyActive(keyboard.KEY_ATTACK))
{
player_node->setGotoTarget(being);
- player_node->attack(being, true);
+ player_node->attack(being, !keyboard.isKeyActive(keyboard.KEY_TARGET));
}
else
{
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);
diff --git a/src/localplayer.h b/src/localplayer.h
index dcdcbeec..1eebabb6 100644
--- a/src/localplayer.h
+++ b/src/localplayer.h
@@ -236,8 +236,10 @@ class LocalPlayer : public Player
bool mTrading;
bool mInStorage; /**< Whether storage is currently accessible */
bool mGoingToTarget;
+ bool mKeepAttacking;/** Whether or not to continue to attack */
int mTargetTime; /** How long the being has been targeted **/
int mLastAction; /**< Time stamp of the last action, -1 if none. */
+ int mLastTarget; /** Time stamp of last targeting action, -1 if none. */
int mWalkingDir; /**< The direction the player is walking in. */
int mDestX; /**< X coordinate of destination. */
int mDestY; /**< Y coordinate of destination. */