Add LightFootedEffect and StatusManager for player capabilities management
This commit is contained in:
50
Assets/Scripts/Core/Domain/Status/StatusManager.cs
Normal file
50
Assets/Scripts/Core/Domain/Status/StatusManager.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Core.Domain.Status
|
||||
{
|
||||
public class StatusManager
|
||||
{
|
||||
private readonly List<IStatusEffect> _activeEffects = new();
|
||||
|
||||
public PlayerCapabilities CurrentCapabilities { get; private set; }
|
||||
|
||||
public StatusManager()
|
||||
{
|
||||
Recalculate();
|
||||
}
|
||||
|
||||
public void AddEffect(IStatusEffect effect)
|
||||
{
|
||||
_activeEffects.Add(effect);
|
||||
effect.OnApply();
|
||||
Recalculate();
|
||||
}
|
||||
|
||||
public void Tick(float deltaTime)
|
||||
{
|
||||
for (var i = _activeEffects.Count - 1; i >= 0; i--)
|
||||
{
|
||||
var effect = _activeEffects[i];
|
||||
effect.Tick(deltaTime);
|
||||
|
||||
if (!effect.IsExpired) continue;
|
||||
|
||||
effect.OnRemove();
|
||||
_activeEffects.RemoveAt(i);
|
||||
Recalculate();
|
||||
}
|
||||
}
|
||||
|
||||
private void Recalculate()
|
||||
{
|
||||
var caps = PlayerCapabilities.Default;
|
||||
|
||||
foreach (var effect in _activeEffects)
|
||||
{
|
||||
effect.ModifyCapabilities(ref caps);
|
||||
}
|
||||
|
||||
CurrentCapabilities = caps;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user