refactor: mob move lock (Castle)

This commit is contained in:
2021-11-29 16:36:27 +01:00
parent f0115166c0
commit adeddee09d
2 changed files with 11 additions and 4 deletions

View File

@@ -76,7 +76,7 @@ const MobStats* getMobStats(MobType type, std::uint8_t level);
const TowerImmunities& getMobTowerImmunities(MobType type, std::uint8_t level);
const EffectImmunities& getMobEffectImmunities(MobType type, std::uint8_t level);
class Mob : public utils::shape::Rectangle{
class Mob : public utils::shape::Rectangle {
protected:
float m_Health;
private:
@@ -86,6 +86,7 @@ private:
Direction m_Direction;
std::vector<EffectDuration> m_Effects;
const Tower* m_LastDamage; // the last tower that damaged the mob
bool m_HasReachedCastle; // if true, no need to walk anymore
utils::Timer m_EffectFireTimer;
utils::Timer m_EffectPoisonTimer;
@@ -93,7 +94,8 @@ private:
public:
Mob(MobID id, MobLevel level, PlayerID sender) : m_Sender(sender), m_Level(level),
m_EffectFireTimer(1000), m_EffectPoisonTimer(1000), m_EffectHealTimer(1000) {
m_HasReachedCastle(false), m_EffectFireTimer(1000), m_EffectPoisonTimer(1000),
m_EffectHealTimer(1000) {
}
@@ -112,9 +114,11 @@ public:
bool isDead() const { return m_Health <= 0; }
bool isAlive() const { return m_Health > 0; }
const Tower* getLastDamageTower() { return m_LastDamage; }
bool hasReachedEnemyCastle() { return m_HasReachedCastle; }
void damage(float dmg, const Tower* damager) { m_Health = std::max(0.0f, m_Health - dmg); m_LastDamage = damager; }
void heal(float heal) { m_Health = std::min(static_cast<float>(getStats()->getMaxLife()), m_Health + heal); }
void setMobReachedCastle() { m_HasReachedCastle = true; } // used when mob is in front of the castle
bool isImmuneTo(TowerType type);

View File

@@ -137,6 +137,8 @@ void World::moveMobs(std::uint64_t delta) {
mob->setDirection(walkTile->direction);
}
if (mob->hasReachedEnemyCastle()) continue;
moveMob(mob, delta);
TeamColor mobTeam = m_Game->getPlayerById(mob->getSender()).getTeamColor();
@@ -151,6 +153,7 @@ void World::moveMobs(std::uint64_t delta) {
if (isMobTouchingCastle(mob, *enemyCastle)) {
moveBackMob(mob, *enemyCastle);
mob->setMobReachedCastle();
}
}
}