using Assets.Scripts.Entities.Attack; using UnityEngine; public abstract class Mob : Entity { protected readonly int maxHP; protected int currentHP; protected bool isDead; protected IAttack attack; /// /// Creates a new Mob instance with the given HP. /// /// public Mob(int maxHP) { this.maxHP = maxHP; currentHP = maxHP; isDead = false; } public void SetAttack(IAttack attack) { this.attack = attack; } /// /// Inflicts damage to this mob. /// /// public void InflictDamage(int damage) { Debug.Log(tag + " received " + damage + " Damage"); currentHP -= damage; if ( !isDead && currentHP <= 0 ) { isDead = true; Death(); } else if (! isDead) { GameController.instance.GetAudioControl().SfxPlay(AudioControl.Sfx.mobattack); } } /// /// This is called when a mob dies. /// protected virtual void Death() { if ( objective != null ) objective.RemoveEntity(this); GameController.instance.GetAudioControl().SfxPlay(AudioControl.Sfx.explosion); Destroy(gameObject); } /// /// Heals the mob. /// /// public void Heal(int healAmount) { if ( !isDead ) currentHP = ( currentHP + healAmount > currentHP ) ? maxHP : currentHP + healAmount; } /// /// Gets the current HP. /// /// public int GetHealth() { return currentHP; } /// /// Gets the maximum HP. /// /// public int GetMaxHealth() { return maxHP; } }