using System.Collections.Generic; using Cielonos.MainGame.Characters; using Sirenix.OdinInspector; using UnityEngine; namespace Cielonos.MainGame.Inventory { public class FunctionSubmodule : SubmoduleBase { [ReadOnly] public Dictionary functionUnits; public RuntimeFunctionUnit this[string functionName] => functionUnits.ContainsKey(functionName) ? functionUnits[functionName] : null; public FunctionSubmodule(ItemBase owner, FunctionData data) : base(owner) { functionUnits = new Dictionary(); foreach (var kvp in data.functionUnits) { functionUnits[kvp.Key] = new RuntimeFunctionUnit(this, kvp.Value); } } public void Update(float deltaTime) { foreach (var unit in functionUnits.Values) { unit.Update(deltaTime); } } } public class RuntimeFunctionUnit : SubmoduleBase { private CharacterBase character => owner.owner.player; public ItemFunctionUnit data; public float currentCooldown; public float maxCooldown; public RuntimeFunctionUnit(FunctionSubmodule owner, ItemFunctionUnit data) : base(owner) { this.data = data; maxCooldown = data.interval; currentCooldown = 0f; } public void Update(float deltaTime) { currentCooldown -= deltaTime; } public bool IsAvailable() { bool cooldownAvailable = currentCooldown <= 0f; bool energyAvailable = character.attributeSm["Energy"] >= data.energyCost; return cooldownAvailable && energyAvailable; } public RuntimeFunctionUnit ResetCooldown() { currentCooldown = maxCooldown; return this; } public RuntimeFunctionUnit ConsumeEnergy() { character.attributeSm["CurrentEnergy"] -= data.energyCost; return this; } } }