using Content.Shared.Alert;
using Robust.Shared.Prototypes;
using Robust.Shared.Timing;
namespace Content.Shared.EntityEffects.Effects;
///
/// Adjusts a given alert on this entity.
///
///
public sealed partial class AdjustAlertEntityEffectSysten : EntityEffectSystem
{
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly AlertsSystem _alerts = default!;
protected override void Effect(Entity entity, ref EntityEffectEvent args)
{
var time = args.Effect.Time;
var clear = args.Effect.Clear;
var type = args.Effect.AlertType;
if (clear && time <= TimeSpan.Zero)
{
_alerts.ClearAlert(entity.AsNullable(), type);
}
else
{
(TimeSpan, TimeSpan)? cooldown = null;
if ((args.Effect.ShowCooldown || clear) && args.Effect.Time >= TimeSpan.Zero)
cooldown = (_timing.CurTime, _timing.CurTime + time);
_alerts.ShowAlert(entity.AsNullable(), type, cooldown: cooldown, autoRemove: clear, showCooldown: args.Effect.ShowCooldown);
}
}
}
///
public sealed partial class AdjustAlert : EntityEffectBase
{
///
/// The specific Alert that will be adjusted
///
[DataField(required: true)]
public ProtoId AlertType;
///
/// If true, the alert is removed after Time seconds. If Time was not specified the alert is removed immediately.
///
[DataField]
public bool Clear;
///
/// Visually display cooldown progress over the alert icon.
///
[DataField]
public bool ShowCooldown;
///
/// The length of the cooldown or delay before removing the alert (in seconds).
///
[DataField]
public TimeSpan Time;
}