using System.Collections; using System.Collections.Generic; using UnityEngine; public class Unit : MonoBehaviour { public UnitPosition position; public UnitHealth health; public UnitStats stats; private List activeEffects; void Awake() { position = GetComponent(); health = GetComponent(); stats = GetComponent(); } public void Heal(int amount) { activeEffects.ForEach(delegate (GenericEffect effect) { effect.BeforeHeal(this, amount); }); if (health != null) { health.Heal(amount); } activeEffects.ForEach(delegate (GenericEffect effect) { effect.AfterHeal(this, amount); }); } public void Damage(int amount) { activeEffects.ForEach(delegate (GenericEffect effect) { effect.BeforeDamage(this, amount); }); if (health != null) { health.Damage(amount); if (health.currentHealth == 0) { Kill(); } } activeEffects.ForEach(delegate (GenericEffect effect) { effect.AfterDamage(this, amount); }); } public void Kill() { bool deathPrevented = activeEffects.TrueForAll(delegate (GenericEffect effect) { return effect.BeforeDeath(this); }); if(deathPrevented) { if(health.currentHealth <= 0) { health.currentHealth = 1; } return; } //Die. For real. } public void StepTo(MapPosition mapPosition) { position.StepTo(mapPosition); //TODO } public void ApplyNewEffect(GenericEffect newEffect) { activeEffects.ForEach(delegate (GenericEffect existingEffect) { existingEffect.BeforeNewEffect(this, newEffect); }); activeEffects.Add(newEffect); activeEffects.ForEach(delegate (GenericEffect existingEffect) { existingEffect.AfterNewEffect(this, newEffect); }); } }