diff options
author | Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> | 2012-03-27 00:18:31 +0200 |
---|---|---|
committer | Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> | 2012-04-14 12:21:58 +0200 |
commit | 387a04cf3c38e19fd8050e39d0f219e5f07257fd (patch) | |
tree | 0dbdeb2679a5c58303b6e48766bee7fa4520a174 /src/game-server/monster.cpp | |
parent | dcd66debbe519403d3b8f7bf30313fbdee71fe6c (diff) | |
download | manaserv-387a04cf3c38e19fd8050e39d0f219e5f07257fd.tar.gz manaserv-387a04cf3c38e19fd8050e39d0f219e5f07257fd.tar.bz2 manaserv-387a04cf3c38e19fd8050e39d0f219e5f07257fd.tar.xz manaserv-387a04cf3c38e19fd8050e39d0f219e5f07257fd.zip |
Introduced a Timeout class for counting down without counting
The timeout remembers a reference point of time against which it can check
how much time is remaining.
Reviewed-by: Erik Schilling
Reviewed-by: Yohann Ferreira
Diffstat (limited to 'src/game-server/monster.cpp')
-rw-r--r-- | src/game-server/monster.cpp | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/src/game-server/monster.cpp b/src/game-server/monster.cpp index ec9db792..30c38da9 100644 --- a/src/game-server/monster.cpp +++ b/src/game-server/monster.cpp @@ -122,13 +122,13 @@ void Monster::update() { Being::update(); - if (isTimerJustFinished(T_M_KILLSTEAL_PROTECTED)) + if (mKillStealProtectedTimeout.justFinished()) mOwner = NULL; // If dead, remove it if (mAction == DEAD) { - if (!isTimerRunning(T_M_DECAY)) + if (mDecayTimeout.expired()) GameState::enqueueRemove(this); return; @@ -144,7 +144,7 @@ void Monster::update() } // Cancel the rest when we are currently performing an attack - if (isTimerRunning(T_M_ATTACK_TIME)) + if (!mAttackTimeout.expired()) return; refreshTarget(); @@ -152,9 +152,9 @@ void Monster::update() if (!mTarget) { // We have no target - let's wander around - if (!isTimerRunning(T_M_STROLL) && getPosition() == getDestination()) + if (mStrollTimeout.expired() && getPosition() == getDestination()) { - if (!isTimerRunning(T_M_KILLSTEAL_PROTECTED)) + if (mKillStealProtectedTimeout.expired()) { unsigned range = mSpecy->getStrollRange(); if (range) @@ -168,7 +168,7 @@ void Monster::update() if (randomPos.x >= 0 && randomPos.y >= 0) setDestination(randomPos); } - setTimerHard(T_M_STROLL, 10 + rand() % 10); + mStrollTimeout.set(10 + rand() % 10); } } } @@ -293,8 +293,8 @@ void Monster::processAttack() if (!mCurrentAttack) return; - setTimerHard(T_M_ATTACK_TIME, mCurrentAttack->aftDelay - + mCurrentAttack->preDelay); + mAttackTimeout.set(mCurrentAttack->aftDelay + + mCurrentAttack->preDelay); float damageFactor = mCurrentAttack->damageFactor; @@ -421,13 +421,12 @@ int Monster::damage(Actor *source, const Damage &damage) Character *s = static_cast< Character * >(source); mExpReceivers[s].insert(damage.skill); - if (!isTimerRunning(T_M_KILLSTEAL_PROTECTED) || mOwner == s + if (mKillStealProtectedTimeout.expired() || mOwner == s || mOwner->getParty() == s->getParty()) { mOwner = s; mLegalExpReceivers.insert(s); - setTimerHard(T_M_KILLSTEAL_PROTECTED, - KILLSTEAL_PROTECTION_TIME); + mKillStealProtectedTimeout.set(KILLSTEAL_PROTECTION_TIME); } } @@ -451,7 +450,7 @@ void Monster::died() if (mAction == DEAD) return; Being::died(); - setTimerHard(T_M_DECAY, Monster::DECAY_TIME); + mDecayTimeout.set(DECAY_TIME); if (mExpReceivers.size() > 0) { |