fighter/FighterAura.cs
using System;
using Sandbox;
public sealed class FighterAura : Component
{
[Property, Group( "Aura" )] public float StartingAura { get; set; } = 20f;
[Property, Group( "Aura" )] public float CurrentAura { get; set; } = 20f;
[Property, Group( "Aura" )] public float AuraDecayRate { get; set; } = 0.35f;
[Property, Group( "Aura" )] public float DecayDelay { get; set; } = 5.0f;
private TimeSince _timeSinceAction = 0f;
private Fighter _fighter;
protected override void OnAwake()
{
_fighter = Components.Get<Fighter>();
if ( CurrentAura <= 0f && StartingAura > 0f )
{
CurrentAura = StartingAura;
}
}
protected override void OnStart()
{
GameManager.OnPhaseChanged += HandlePhaseChanged;
}
protected override void OnDestroy()
{
GameManager.OnPhaseChanged -= HandlePhaseChanged;
}
private void HandlePhaseChanged( GamePhase phase )
{
// Réinitialise le délai à chaque début de combat pour ne pas drainer immédiatement
if ( phase == GamePhase.RoundActive )
{
_timeSinceAction = 0f;
}
}
protected override void OnUpdate()
{
if ( _fighter != null && _fighter.IsDead ) return;
// Le drain ne s'applique STRICTEMENT QUE pendant le combat actif
if ( GameManager.Instance == null || GameManager.Instance.CurrentPhase != GamePhase.RoundActive )
{
_timeSinceAction = 0f;
return;
}
if ( _timeSinceAction > DecayDelay && CurrentAura > 0f )
{
CurrentAura = MathF.Max( 0f, CurrentAura - (AuraDecayRate * Time.Delta) );
}
}
public void ApplyAuraDelta( float delta )
{
CurrentAura = Math.Clamp( CurrentAura + delta, 0f, 100f );
_timeSinceAction = 0f;
Log.Info( $"🏛️ [{GameObject.Name}] Aura: {CurrentAura:F1}% (Delta: {delta:+0;-#})" );
}
}