29 lines
828 B
C#
29 lines
828 B
C#
using UnityEngine;
|
|
|
|
[System.Serializable]
|
|
public class AbilitySlot
|
|
{
|
|
public Ability ability;
|
|
[HideInInspector] public float cdTimer; // counts down at runtime
|
|
|
|
public bool IsOnCooldown => cdTimer > 0f;
|
|
public float CooldownRatio => ability && ability.cooldown > 0 ? Mathf.Clamp01(cdTimer / ability.cooldown) : 0f;
|
|
|
|
public bool TryUse(AbilityUser user)
|
|
{
|
|
if (!ability || IsOnCooldown) return false;
|
|
if (user && user.mana && user.mana.Has(ability.manaCost) == false) return false;
|
|
if (!ability.CanActivate(user)) return false;
|
|
|
|
if (user && !user.TrySpendMana(ability.manaCost)) return false;
|
|
|
|
ability.Activate(user);
|
|
cdTimer = ability.cooldown;
|
|
return true;
|
|
}
|
|
|
|
public void Tick(float dt)
|
|
{
|
|
if (cdTimer > 0f) cdTimer -= dt;
|
|
}
|
|
} |