Aetheria/Assets/Scripts/ServerShared/Behaviors/Cooldown.cs

42 lines
1.3 KiB
C#
Raw Normal View History

2026-06-13 04:56:50 +01:00
/* 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/. */
2026-06-21 09:37:54 +01:00
using static CultMath.math;
public class Cooldown : Behavior, IAlwaysUpdatedBehavior, IProgressBehavior
{
private readonly PerformanceStat _cooldownDuration;
private float _cooldown; // Normalized
public float Progress => saturate(_cooldown);
2026-06-15 19:06:13 +01:00
public Cooldown(RuntimeBehaviorDefinition definition, EquippedItem item) : base(definition, item)
{
2026-06-15 19:06:13 +01:00
_cooldownDuration = definition.PerformanceStat(1, new PerformanceStat());
RegisterPerformanceStat(nameof(Cooldown), _cooldownDuration);
}
2026-06-15 19:06:13 +01:00
public Cooldown(RuntimeBehaviorDefinition definition, ConsumableItemEffect item) : base(definition, item)
{
2026-06-15 19:06:13 +01:00
_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);
}
}