public abstract class Mob : Entity {
readonly int maxHP;
int currentHP;
bool isDead;
int damage;
///
/// Creates a new Mob instance with the given HP.
///
///
public Mob(int maxHP) {
this.maxHP = maxHP;
currentHP = maxHP;
isDead = false;
}
///
/// Inflicts damage to this mob.
///
///
public void InflictDamage(int damage) {
currentHP -= damage;
if ( !isDead && currentHP <= 0 ) {
isDead = true;
Death();
}
}
///
/// This is called when a mob dies.
///
protected virtual void Death() {
if ( objective != null )
objective.RemoveEntity(this);
Destroy(gameObject);
}
///
/// Heals the mob.
///
///
public void Heal(int healAmount) {
if ( !isDead )
currentHP = ( currentHP + healAmount > currentHP ) ? maxHP : currentHP + healAmount;
}
///
/// Sets the damage value of a mobs attack.
///
///
public void SetDamage(int dmg) {
damage = dmg;
}
///
/// Gets the damage value og a mobs attack.
///
///
public int GetDamage() {
return damage;
}
///
/// Gets the current HP.
///
///
public int GetHealth() {
return currentHP;
}
///
/// Gets the maximum HP.
///
///
public int GetMaxHealth() {
return maxHP;
}
}