72 lines
2.2 KiB
C#
72 lines
2.2 KiB
C#
using System.Collections.Generic;
|
|
using Cielonos.MainGame.Characters;
|
|
using Sirenix.OdinInspector;
|
|
using UnityEngine;
|
|
|
|
namespace Cielonos.MainGame.Inventory
|
|
{
|
|
public class FunctionSubmodule : SubmoduleBase<ItemBase>
|
|
{
|
|
[ReadOnly]
|
|
public Dictionary<string, RuntimeFunctionUnit> functionUnits;
|
|
|
|
public RuntimeFunctionUnit this[string functionName] => functionUnits.ContainsKey(functionName) ? functionUnits[functionName] : null;
|
|
|
|
public FunctionSubmodule(ItemBase owner, FunctionData data) : base(owner)
|
|
{
|
|
functionUnits = new Dictionary<string, RuntimeFunctionUnit>();
|
|
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<FunctionSubmodule>
|
|
{
|
|
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;
|
|
}
|
|
}
|
|
} |