using System; using System.Collections; using System.Collections.Generic; using UnityEngine; public class BattleParticipant { public delegate void BattleParticipantUpdateAction(BattleParticipant participant); public event BattleParticipantUpdateAction OnHit; public event BattleParticipantUpdateAction OnDeath; public event BattleParticipantUpdateAction OnStatusChanged; public event BattleParticipantUpdateAction OnBuffsChanged; protected TeamChoice team; protected string displayName; protected int hp; protected int maxHP; protected int block; protected bool dead; protected Dictionary statuses; public BattleParticipant(TeamChoice team) { this.team = team; this.statuses = new Dictionary(); } 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) { if (!IsAlive()) { return 0; } int blockedDamage = Math.Min(damage, this.block); if (blockedDamage > 0) { this.block -= blockedDamage; damage -= blockedDamage; } damage = Math.Min(this.hp, damage); this.hp -= damage; TriggerOnHit(); return damage; } public void CheckState() { if (!IsAlive()) { return; } if (this.hp <= 0) { this.dead = true; WipeStatus(); 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) { if (!IsAlive()) { return; } this.block += block; } public void ResetBlock() { if (!IsAlive()) { return; } this.block = 0; } public int GetBlock() { return this.block; } public TeamChoice Team { get => this.team; } public void IncreaseMaxHP(int amount) { if (!IsAlive()) { return; } this.maxHP += amount; if (this.hp > 0) { this.hp += amount; } } private void TriggerOnHit() { if (this.OnHit != null) { this.OnHit(this); } } private void TriggerOnDeath() { if (this.OnDeath != null) { this.OnDeath(this); } } public int AddStatus(BattleStatus status, int amount) { if (amount <= 0) { return 0; } int currentAmount; this.statuses.TryGetValue(status, out currentAmount); this.statuses[status] = currentAmount + amount; TriggerOnStatusChanged(); return amount; } public void TickStatuses() { if (this.statuses.Count > 0) { Dictionary newStatuses = new Dictionary(); foreach (KeyValuePair pair in this.statuses) { if (pair.Value > 1) { newStatuses[pair.Key] = pair.Value - 1; } } this.statuses = newStatuses; TriggerOnStatusChanged(); } } public void WipeStatus() { if (this.statuses.Count > 0) { this.statuses = new Dictionary(); TriggerOnStatusChanged(); } } public bool CanUseCard(BaseCard card) { return IsAlive() && !HasStatus(BattleStatus.Stun); } public bool CanUseDefault() { return IsAlive() && !HasStatus(BattleStatus.Stun); } public bool HasStatus(BattleStatus status) { return this.statuses.ContainsKey(status); } public int GetStatusAmount(BattleStatus status) { if (!this.statuses.ContainsKey(status)) { return 0; } else { return this.statuses[status]; } } private void TriggerOnStatusChanged() { if (this.OnStatusChanged != null) { this.OnStatusChanged(this); } } public void TriggerOnBuffsChanged() { if (this.OnBuffsChanged != null) { this.OnBuffsChanged(this); } } }