using Kryz.CharacterStats.Examples; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Events; public class SpiritPower : Resource { CharacterStats character; public UnityEvent onMaxSpiritPowerChanged = new UnityEvent(); private bool noCost = false; public bool NoCost => noCost; public UnityEvent OnNoSpiritPowerCostStateChanged = new UnityEvent(); private void Awake() { character = GetComponent(); baseFlatRegen = flatRegen; character.onUpdateStatValues.AddListener(CalculateMaxValueBasedOnStat); } protected override void Start() { canRegen = false; base.Start(); } public void SetNoCostState(bool noManaCost) { RPC_SetNoCostState(noManaCost); } public void RPC_SetNoCostState(bool noManaCost) { noCost = noManaCost; OnNoSpiritPowerCostStateChanged.Invoke(noCost); } public override void ChangeValue(float value) { if (noCost && value < 0) return; currentValue += value; currentValue = Mathf.Clamp(currentValue, 0, maxValue); onResourceChanged.Invoke(currentValue); } public override float GetMaxValue() { return base.GetMaxValue(); } public bool EnoughSpiritPower(float cost) { if (noCost) return true; return cost <= currentValue; } public void ReserveSpiritPower(float cost) { currentValue -= cost; currentValue = Mathf.Clamp(currentValue, 0, maxValue); onResourceChanged.Invoke(currentValue); } public void ReleaseSpiritPower(float cost) { currentValue += cost; currentValue = Mathf.Clamp(currentValue, 0, maxValue); onResourceChanged.Invoke(currentValue); } public void CalculateMaxValueBasedOnStat() { maxValue = baseMaxValue + character.Spirit.Value * GameConstants.CharacterStatsBalancing.SpiritToSpiritPowerRate; CalculateRegenValueBasedOnStat(); onMaxSpiritPowerChanged.Invoke(maxValue); } public void CalculateRegenValueBasedOnStat() { flatRegen = baseFlatRegen + (character.Spirit.Value - character.Spirit.BaseValue) * GameConstants.CharacterStatsBalancing.BonusSpiritToFlatRegenRate; //percentRegen = (character.Spirit.Value - character.Spirit.BaseValue) * GameConstants.CharacterBalancing.BonusSpiritToPercentRegenRate; } public override void SetMaxValue(float value) { base.SetMaxValue(value); onMaxSpiritPowerChanged.Invoke(maxValue); } }