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;
|
||||
|
||||
@@ -12,14 +12,14 @@ class Player {
|
||||
private:
|
||||
game::TeamColor m_TeamColor;
|
||||
|
||||
std::uint32_t m_Gold = 0;
|
||||
std::uint32_t m_EXP = 0;
|
||||
std::uint32_t m_Gold;
|
||||
std::uint32_t m_EXP;
|
||||
std::string m_Name;
|
||||
std::uint8_t m_ID;
|
||||
|
||||
std::uint8_t m_GoldPerSecond = 5;
|
||||
std::uint8_t m_GoldPerSecond;
|
||||
public:
|
||||
Player(std::uint8_t id = 0) : m_TeamColor(game::TeamColor::None), m_ID(id) {}
|
||||
Player(std::uint8_t id = 0) : m_TeamColor(game::TeamColor::None), m_Gold(0), m_EXP(0), m_ID(id), m_GoldPerSecond(5) {}
|
||||
|
||||
const std::string& getName() const { return m_Name; }
|
||||
void setName(const std::string& name) { m_Name = name; }
|
||||
@@ -32,9 +32,13 @@ public:
|
||||
|
||||
std::uint32_t getGold() const { return m_Gold; }
|
||||
void setGold(std::uint32_t gold) { m_Gold = gold; }
|
||||
void addGold(std::uint32_t gold) { m_Gold += gold; }
|
||||
void removeGold(std::uint32_t gold) { m_Gold -= gold; }
|
||||
|
||||
std::uint32_t getEXP() const { return m_EXP; }
|
||||
void setEXP(std::uint32_t exp) { m_EXP = exp; }
|
||||
void addEXP(std::uint32_t exp) { m_EXP += exp; }
|
||||
void removeEXP(std::uint32_t exp) { m_EXP -= exp; }
|
||||
|
||||
std::uint8_t getID() const { return m_ID; }
|
||||
};
|
||||
|
||||
@@ -115,6 +115,7 @@ public:
|
||||
std::uint16_t getY() const { return m_Y; }
|
||||
const TowerLevel& getLevel() const { return m_Level; }
|
||||
const TowerStats* getStats() const { return getTowerStats(m_Type, m_Level); }
|
||||
PlayerID getBuilder() const { return m_Builder; }
|
||||
|
||||
bool isMobInRange(MobPtr mob);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user