98 lines
1.9 KiB
C#
98 lines
1.9 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
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;
|
|
}
|
|
|
|
public void Init() {
|
|
this.hp = this.maxHP;
|
|
}
|
|
|
|
public string GetDisplayName() {
|
|
return this.displayName;
|
|
}
|
|
|
|
public int GetHP() {
|
|
return this.hp;
|
|
}
|
|
|
|
public int GetMaxHP() {
|
|
return this.maxHP;
|
|
}
|
|
|
|
public bool IsAlive() {
|
|
return !this.dead;
|
|
}
|
|
|
|
public int DealDamage(int damage) {
|
|
int blockedDamage = Math.Min(damage, this.block);
|
|
if (blockedDamage > 0) {
|
|
this.block -= blockedDamage;
|
|
damage -= blockedDamage;
|
|
}
|
|
damage = Math.Min(this.hp, damage);
|
|
this.hp -= damage;
|
|
return damage;
|
|
}
|
|
|
|
public void CheckState() {
|
|
if (this.hp <= 0) {
|
|
this.dead = true;
|
|
TriggerOnDeath();
|
|
}
|
|
}
|
|
|
|
public int Heal(int amount) {
|
|
if (!IsAlive()) {
|
|
return 0;
|
|
}
|
|
|
|
amount = Math.Min(this.maxHP - this.hp, amount);
|
|
this.hp += amount;
|
|
return amount;
|
|
}
|
|
|
|
public void AddBlock(int block) {
|
|
this.block += block;
|
|
}
|
|
|
|
public void ResetBlock() {
|
|
this.block = 0;
|
|
}
|
|
|
|
public int GetBlock() {
|
|
return this.block;
|
|
}
|
|
|
|
public bool IsHero() {
|
|
return this.isHero;
|
|
}
|
|
|
|
public void IncreaseMaxHP(int amount) {
|
|
this.maxHP += amount;
|
|
if (this.hp > 0) {
|
|
this.hp += amount;
|
|
}
|
|
}
|
|
|
|
private void TriggerOnDeath() {
|
|
if (this.OnDeath != null) {
|
|
this.OnDeath(this);
|
|
}
|
|
}
|
|
}
|