refactor: moved mob functions
This commit is contained in:
@@ -46,8 +46,8 @@ public:
|
||||
const PlayerList& getPlayers() const { return m_Players; }
|
||||
PlayerList& getPlayers() { return m_Players; }
|
||||
|
||||
const Player& getPlayerById(PlayerID id) const { return m_Players.find(id)->second; }
|
||||
Player& getPlayerById(PlayerID id) { return m_Players.find(id)->second; }
|
||||
const Player* getPlayerById(PlayerID id) const;
|
||||
Player* getPlayerById(PlayerID id);
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
namespace td {
|
||||
namespace game {
|
||||
|
||||
struct WalkableTile;
|
||||
|
||||
enum class EffectType : std::uint8_t {
|
||||
Slowness = 0,
|
||||
Stun,
|
||||
@@ -88,22 +90,24 @@ 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;
|
||||
utils::Timer m_EffectHealTimer;
|
||||
|
||||
TeamCastle* m_CastleTarget;
|
||||
utils::CooldownTimer m_AttackTimer;
|
||||
|
||||
public:
|
||||
Mob(MobID id, MobLevel level, PlayerID sender) : m_Sender(sender), m_Level(level),
|
||||
m_HasReachedCastle(false), m_EffectFireTimer(1000), m_EffectPoisonTimer(1000),
|
||||
m_EffectHealTimer(1000) {
|
||||
m_EffectFireTimer(1000), m_EffectPoisonTimer(1000),
|
||||
m_EffectHealTimer(1000), m_CastleTarget(nullptr), m_AttackTimer(1000) {
|
||||
|
||||
}
|
||||
|
||||
virtual MobType getType() const = 0;
|
||||
|
||||
virtual void tick(std::uint64_t delta);
|
||||
virtual void tick(std::uint64_t delta, World* world);
|
||||
|
||||
virtual bool OnDeath(World* world) { return true; }
|
||||
|
||||
@@ -116,11 +120,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; }
|
||||
bool hasReachedEnemyCastle() { return m_CastleTarget != nullptr; }
|
||||
|
||||
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
|
||||
void setMobReachedCastle(TeamCastle* castle) { m_CastleTarget = castle; } // used when mob is in front of the castle
|
||||
|
||||
bool isImmuneTo(TowerType type);
|
||||
|
||||
@@ -140,6 +144,12 @@ protected:
|
||||
}
|
||||
private:
|
||||
void updateEffects(std::uint64_t delta);
|
||||
void attackCastle(std::uint64_t delta, World* world);
|
||||
void move(std::uint64_t delta, World* world);
|
||||
void walk(std::uint64_t delta, World* world);
|
||||
void moveBack(const TeamCastle& castle, World* world);
|
||||
void changeDirection(const WalkableTile& tile, World* world);
|
||||
bool isTouchingCastle(const TeamCastle& castle) const;
|
||||
EffectDuration& getEffect(EffectType type);
|
||||
};
|
||||
|
||||
@@ -227,8 +237,8 @@ public:
|
||||
|
||||
virtual void OnMobDamage(MobPtr target, float damage, Tower* damager) {}
|
||||
|
||||
virtual void OnMobTouchCastle(MobPtr damager, TeamCastle* enemyCastle) {}
|
||||
virtual void OnMobCastleDamage(MobPtr damager, TeamCastle* enemyCastle) {}
|
||||
virtual void OnMobTouchCastle(Mob* damager, TeamCastle* enemyCastle) {}
|
||||
virtual void OnMobCastleDamage(Mob* damager, TeamCastle* enemyCastle, float damage) {}
|
||||
};
|
||||
|
||||
typedef utils::ObjectNotifier<MobListener> MobNotifier;
|
||||
|
||||
@@ -208,6 +208,8 @@ public:
|
||||
const TowerList& getTowers() const { return m_Towers; };
|
||||
TowerPtr getTowerById(TowerID tower);
|
||||
|
||||
const Player* getPlayerById(PlayerID id) const;
|
||||
|
||||
WorldNotifier& getWorldNotifier() { return m_WorldNotifier; }
|
||||
MobNotifier& getMobNotifier() { return m_MobNotifier; }
|
||||
|
||||
@@ -222,11 +224,6 @@ public:
|
||||
|
||||
virtual void OnMobDamage(MobPtr target, float damage, Tower* source);
|
||||
private:
|
||||
void moveMobs(std::uint64_t delta);
|
||||
void moveMob(MobPtr mob, std::uint64_t delta);
|
||||
void moveBackMob(MobPtr mob, const TeamCastle& castle);
|
||||
void changeMobDirection(MobPtr mob, WalkableTilePtr tile);
|
||||
bool isMobTouchingCastle(MobPtr mob, const TeamCastle& castle) const;
|
||||
void tickMobs(std::uint64_t delta);
|
||||
void cleanDeadMobs();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user