Only alive participants can act

This commit is contained in:
henriquenakashima 2020-09-20 16:02:13 -04:00
parent a5a96edf25
commit adc84f9aba
5 changed files with 44 additions and 8 deletions

View file

@ -5,11 +5,15 @@ using UnityEngine;
public class BattleParticipant
{
public delegate void DeathAction(BattleParticipant participant);
public event DeathAction OnDeath;
protected bool isHero;
protected string displayName;
protected int hp;
protected int maxHP;
protected int block;
protected bool dead;
public BattleParticipant(bool isHero) {
this.isHero = isHero;
@ -32,7 +36,7 @@ public class BattleParticipant
}
public bool IsAlive() {
return this.hp > 0;
return !this.dead;
}
public int DealDamage(int damage) {
@ -43,6 +47,10 @@ public class BattleParticipant
}
damage = Math.Min(this.hp, damage);
this.hp -= damage;
if (this.hp <= 0) {
this.dead = true;
TriggerOnDeath();
}
return damage;
}
@ -78,4 +86,10 @@ public class BattleParticipant
this.hp += amount;
}
}
private void TriggerOnDeath() {
if (this.OnDeath != null) {
this.OnDeath(this);
}
}
}