Only alive participants can act
This commit is contained in:
parent
a5a96edf25
commit
adc84f9aba
5 changed files with 44 additions and 8 deletions
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue