summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorYohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer>2011-06-24 01:49:58 +0200
committerYohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer>2011-06-24 01:49:58 +0200
commitb4589749217c550db0849b439b6687ff4f5822d7 (patch)
tree7e23d1b1e3397cf3bdc8f45c3fa2aab244fb003b /src
parentbb7033e0247ab1d3a526a5d68f9c482f6ff01ba7 (diff)
downloadmanaserv-b4589749217c550db0849b439b6687ff4f5822d7.tar.gz
manaserv-b4589749217c550db0849b439b6687ff4f5822d7.tar.bz2
manaserv-b4589749217c550db0849b439b6687ff4f5822d7.tar.xz
manaserv-b4589749217c550db0849b439b6687ff4f5822d7.zip
Fixed autoattacks basic handling.
The server is now using the autoattacks system to perform damage based on the attack's timer. I also added a default bare knuckle attack when the character is unequipped. As a result, maggots can be killed again with bare hands now. Known issues left: This isn't tested against equipment changes for now, and the client isn't in sync with the attacks speed. Reviewed-by: Crush.
Diffstat (limited to 'src')
-rw-r--r--src/game-server/autoattack.cpp12
-rw-r--r--src/game-server/autoattack.h12
-rw-r--r--src/game-server/being.cpp4
-rw-r--r--src/game-server/character.cpp46
4 files changed, 59 insertions, 15 deletions
diff --git a/src/game-server/autoattack.cpp b/src/game-server/autoattack.cpp
index d433b421..d8425d50 100644
--- a/src/game-server/autoattack.cpp
+++ b/src/game-server/autoattack.cpp
@@ -47,7 +47,11 @@ void AutoAttacks::start()
for (std::list<AutoAttack>::iterator it = mAutoAttacks.begin();
it != mAutoAttacks.end(); ++it)
{
- it->softReset();
+ // If the attack is inactive, we hard reset it.
+ if (!it->getTimer())
+ it->reset();
+ else
+ it->softReset();
}
mActive = true;
}
@@ -57,13 +61,15 @@ void AutoAttacks::tick(std::list<AutoAttack> *ret)
for (std::list<AutoAttack>::iterator it = mAutoAttacks.begin();
it != mAutoAttacks.end(); ++it)
{
- if (it->tick()) {
+ if (it->tick())
+ {
if (mActive)
it->reset();
else
it->halt();
}
- else if (ret && it->isReady())
+
+ if (ret && it->isReady())
{
ret->push_back(*it);
}
diff --git a/src/game-server/autoattack.h b/src/game-server/autoattack.h
index 268f429c..2e891fa9 100644
--- a/src/game-server/autoattack.h
+++ b/src/game-server/autoattack.h
@@ -143,6 +143,18 @@ class AutoAttacks
void stop(); // If the character does some action other than attacking, reset all warmups (NOT cooldowns!)
void tick(std::list<AutoAttack> *ret = 0);
+ /**
+ * Tells the number of attacks available
+ */
+ unsigned getAutoAttacksNumber()
+ { return mAutoAttacks.size(); }
+
+ /**
+ * Tells whether the autoattacks are active.
+ */
+ bool areActive()
+ { return mActive; }
+
private:
/**
* Marks whether or not to keep auto-attacking. Cooldowns still need
diff --git a/src/game-server/being.cpp b/src/game-server/being.cpp
index f7206e4d..4058a4ad 100644
--- a/src/game-server/being.cpp
+++ b/src/game-server/being.cpp
@@ -430,6 +430,10 @@ int Being::performAttack(Being *target, const Damage &damage)
void Being::setAction(BeingAction action)
{
+ // Stops the auto-attacks when changing action
+ if (mAction == ATTACK && action != ATTACK)
+ mAutoAttacks.stop();
+
mAction = action;
if (action != ATTACK && // The players are informed about these actions
action != WALK) // by other messages
diff --git a/src/game-server/character.cpp b/src/game-server/character.cpp
index 46f9eade..bbe26bd6 100644
--- a/src/game-server/character.cpp
+++ b/src/game-server/character.cpp
@@ -143,25 +143,47 @@ void Character::update()
void Character::perform()
{
- if (mAction != ATTACK || mTarget == NULL) return;
+ // Ticks attacks even when not attacking to permit cooldowns and warmups.
+ std::list<AutoAttack> attacksReady;
+ mAutoAttacks.tick(&attacksReady);
- // wait before next attack
- // Note: The auto-attack system will handle the delay between two attacks.
- // TODO: Remove this condition when it's done.
- if (mMoveTime > WORLD_TICK_MS)
+ if (mAction != ATTACK || mTarget == NULL)
{
- mMoveTime -= WORLD_TICK_MS;
+ mAutoAttacks.stop();
return;
}
- std::list<AutoAttack> attacks;
- mAutoAttacks.tick(&attacks);
- if (attacks.empty())
- return; // TODO: Install default attack?
+ // Deal with the ATTACK action.
+
+ // Install default bare knuckle attack if no attacks were added from config.
+ // TODO: Get this from configuration.
+ if (!mAutoAttacks.getAutoAttacksNumber())
+ {
+ int damageBase = getModifiedAttribute(ATTR_STR);
+ int damageDelta = damageBase / 2;
+ Damage knuckleDamage(damageBase, damageDelta, 2, ELEMENT_NEUTRAL,
+ DAMAGE_PHYSICAL,
+ (getSize() < DEFAULT_TILE_LENGTH) ?
+ DEFAULT_TILE_LENGTH : getSize());
+
+ AutoAttack knuckleAttack(knuckleDamage, 7, 3);
+ mAutoAttacks.add(knuckleAttack);
+ }
+
+ if (attacksReady.empty())
+ {
+ if (!mAutoAttacks.areActive())
+ mAutoAttacks.start();
+ }
else
- for (std::list<AutoAttack>::iterator it = attacks.begin();
- it != attacks.end(); ++it)
+ {
+ // Performs all ready attacks.
+ for (std::list<AutoAttack>::iterator it = attacksReady.begin();
+ it != attacksReady.end(); ++it)
+ {
performAttack(mTarget, it->getDamage());
+ }
+ }
}
void Character::died()