using Kryz.CharacterStats.Examples; using System.Collections; using System.Collections.Generic; using System.Threading.Tasks; using UnityEngine; public class MinionSpiritPowerDrainController : MonoBehaviour { [SerializeField] private bool shouldDrainMana; public SpiritPower OwnerSpiritPower; public Health minionHealth; public CharacterStats minionStats; private bool isDead; private void Awake() { minionHealth = GetComponentInParent(); minionStats = GetComponentInParent(); minionHealth.onDeath.AddListener(() => isDead = true); } private void Start() { isDead = false; TryDrainMana(); } public async void TryDrainMana() { if (isDead) return; if (EnoughManaToDrain()) DrainMana(); else LoseHealth(); await Task.Delay(1000); TryDrainMana(); } private bool EnoughManaToDrain() { return OwnerSpiritPower.GetCurrentValue() - (minionStats.GetRelativePowerLevel() * GameConstants.CharacterStatsBalancing.RelativePowerToSpiritCostPercent) >= 0f; } private void DrainMana() { OwnerSpiritPower.ChangeValue(-(minionStats.GetRelativePowerLevel() * GameConstants.CharacterStatsBalancing.RelativePowerToSpiritCostPercent)); } private void LoseHealth() { minionHealth.ChangeValueDirect(-(minionHealth.GetMaxValue() * GameConstants.CharacterStatsBalancing.HealthDecayOnSpiritExhaustion)); } }