Aetheria/Assets/Scripts/ServerShared/Behaviors/Cooldown.cs
2026-06-15 19:06:13 +01:00

45 lines
1.3 KiB
C#

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System;
using System.Linq;
using Unity.Mathematics;
using static Unity.Mathematics.math;
public class Cooldown : Behavior, IAlwaysUpdatedBehavior, IProgressBehavior
{
private readonly PerformanceStat _cooldownDuration;
private float _cooldown; // Normalized
public float Progress => saturate(_cooldown);
public Cooldown(RuntimeBehaviorDefinition definition, EquippedItem item) : base(definition, item)
{
_cooldownDuration = definition.PerformanceStat(1, new PerformanceStat());
RegisterPerformanceStat(nameof(Cooldown), _cooldownDuration);
}
public Cooldown(RuntimeBehaviorDefinition definition, ConsumableItemEffect item) : base(definition, item)
{
_cooldownDuration = definition.PerformanceStat(1, new PerformanceStat());
RegisterPerformanceStat(nameof(Cooldown), _cooldownDuration);
}
public override bool Execute(float dt)
{
if (_cooldown < 0)
{
_cooldown = 1;
return true;
}
return false;
}
public void Update(float delta)
{
_cooldown -= delta / Evaluate(_cooldownDuration);
}
}