feat: add kill reward + effect damages
This commit is contained in:
@@ -36,7 +36,6 @@ typedef std::uint32_t MobID;
|
||||
typedef std::uint8_t MobLevel;
|
||||
typedef std::vector<TowerType> TowerImmunities;
|
||||
typedef std::vector<EffectType> EffectImmunities;
|
||||
typedef std::pair<EffectType, float> EffectDuration;
|
||||
|
||||
class MobStats {
|
||||
private:
|
||||
@@ -62,6 +61,12 @@ public:
|
||||
std::uint16_t getMaxLife() const { return m_MaxLife; }
|
||||
};
|
||||
|
||||
struct EffectDuration{
|
||||
EffectType type;
|
||||
float duration; // in seconds
|
||||
const Tower* tower; // the tower that gived the effect
|
||||
};
|
||||
|
||||
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);
|
||||
@@ -75,10 +80,16 @@ private:
|
||||
MobLevel m_Level;
|
||||
Direction m_Direction;
|
||||
std::vector<EffectDuration> m_Effects;
|
||||
const Tower* m_KillTower; // the tower that killed the mob
|
||||
|
||||
utils::Timer m_EffectFireTimer;
|
||||
utils::Timer m_EffectPoisonTimer;
|
||||
utils::Timer m_EffectHealTimer;
|
||||
|
||||
float m_X = 0, m_Y = 0;
|
||||
public:
|
||||
Mob(MobID id, MobLevel level, PlayerID sender) : m_Sender(sender), m_Level(level) {
|
||||
Mob(MobID id, MobLevel level, PlayerID sender) : m_Sender(sender), m_Level(level),
|
||||
m_EffectFireTimer(1000), m_EffectPoisonTimer(1000), m_EffectHealTimer(1000) {
|
||||
|
||||
}
|
||||
|
||||
@@ -86,13 +97,18 @@ public:
|
||||
|
||||
virtual void tick(std::uint64_t delta);
|
||||
|
||||
virtual void OnDeath(World* world){}
|
||||
|
||||
const TowerImmunities& getTowerImmunities() const { return getMobTowerImmunities(getType(), m_Level); }
|
||||
const EffectImmunities& getEffectImmunities() const { return getMobEffectImmunities(getType(), m_Level); }
|
||||
PlayerID getSender() const { return m_Sender; }
|
||||
MobLevel getLevel() const { return m_Level; }
|
||||
const MobStats* getStats() const { return getMobStats(getType(), m_Level); }
|
||||
float getHealth() const { return m_Health; }
|
||||
bool isDead() const { return m_Health <= 0; }
|
||||
bool isAlive() const { return m_Health > 0; }
|
||||
const Tower* getKillTower() { return m_KillTower; }
|
||||
void setKillTower(const Tower* killTower) { m_KillTower = killTower; }
|
||||
|
||||
void damage(float dmg) { m_Health -= dmg; }
|
||||
void heal(float heal) { m_Health = std::min((float)getStats()->getMaxLife(), m_Health + heal); }
|
||||
@@ -106,7 +122,7 @@ public:
|
||||
bool isImmuneTo(TowerType type);
|
||||
|
||||
bool isImmuneTo(EffectType type);
|
||||
void addEffect(EffectType type, float durationSec);
|
||||
void addEffect(EffectType type, float durationSec, const Tower* tower);
|
||||
bool hasEffect(EffectType type);
|
||||
|
||||
|
||||
@@ -116,6 +132,7 @@ protected:
|
||||
void initHealth() { m_Health = (float)getStats()->getMaxLife(); }
|
||||
private:
|
||||
void updateEffects(std::uint64_t delta);
|
||||
EffectDuration& getEffect(EffectType type);
|
||||
};
|
||||
|
||||
typedef std::shared_ptr<Mob> MobPtr;
|
||||
|
||||
Reference in New Issue
Block a user