1
0
Fork 0
Bildschirmflausch-LD41/Assets/Scripts/Entities/Mob.cs

71 lines
1.7 KiB
C#
Raw Normal View History

using Assets.Scripts.Entities.Attack;
2018-04-23 01:25:50 +02:00
using UnityEngine;
public abstract class Mob : Entity {
protected readonly int maxHP;
protected int currentHP;
protected bool isDead;
protected IAttack attack;
2018-04-21 16:55:39 +02:00
/// <summary>
/// Creates a new Mob instance with the given HP.
/// </summary>
/// <param name="maxHP"></param>
public Mob(int maxHP) {
this.maxHP = maxHP;
currentHP = maxHP;
isDead = false;
}
public void SetAttack(IAttack attack) {
this.attack = attack;
}
/// <summary>
/// Inflicts damage to this mob.
/// </summary>
/// <param name="damage"></param>
public void InflictDamage(int damage) {
2018-04-23 01:25:50 +02:00
Debug.Log(tag + " received " + damage + " Damage");
currentHP -= damage;
if ( !isDead && currentHP <= 0 ) {
isDead = true;
Death();
}
}
/// <summary>
/// This is called when a mob dies.
/// </summary>
protected virtual void Death() {
if ( objective != null )
objective.RemoveEntity(this);
Destroy(gameObject);
}
/// <summary>
/// Heals the mob.
/// </summary>
/// <param name="healAmount"></param>
public void Heal(int healAmount) {
if ( !isDead )
currentHP = ( currentHP + healAmount > currentHP ) ? maxHP : currentHP + healAmount;
}
/// <summary>
/// Gets the current HP.
/// </summary>
/// <returns></returns>
2018-04-22 16:20:25 +02:00
public int GetHealth() {
2018-04-22 11:45:12 +02:00
return currentHP;
}
/// <summary>
/// Gets the maximum HP.
/// </summary>
/// <returns></returns>
2018-04-22 16:20:25 +02:00
public int GetMaxHealth() {
return maxHP;
}
2018-04-21 16:55:39 +02:00
}