using System.Linq; using Content.Shared.Alert; using Content.Shared.FixedPoint; using Robust.Shared.Prototypes; namespace Content.Shared._Offbrand.Wounds; public sealed class ShockAlertsSystem : EntitySystem { [Dependency] private readonly AlertsSystem _alerts = default!; [Dependency] private readonly PainSystem _pain = default!; public override void Initialize() { base.Initialize(); SubscribeLocalEvent(OnMapInit); SubscribeLocalEvent(OnComponentShutdown); SubscribeLocalEvent(OnAfterShockChange); } private ProtoId? DetermineThreshold(Entity ent) { var shock = FixedPoint2.Max(_pain.GetShock(ent.Owner), FixedPoint2.Zero); if (Comp(ent).Suppressed) return ent.Comp.SuppressedAlert; return ent.Comp.Thresholds.HighestMatch(shock); } private void UpdateAlert(Entity ent) { var targetEffect = DetermineThreshold(ent); if (targetEffect == ent.Comp.CurrentThresholdState) return; ent.Comp.CurrentThresholdState = targetEffect; if (targetEffect is { } effect) { _alerts.ShowAlert(ent.Owner, effect); } else { _alerts.ClearAlertCategory(ent.Owner, ent.Comp.AlertCategory); } } private void OnMapInit(Entity ent, ref MapInitEvent args) { UpdateAlert(ent); } private void OnComponentShutdown(Entity ent, ref ComponentShutdown args) { _alerts.ClearAlertCategory(ent.Owner, ent.Comp.AlertCategory); } private void OnAfterShockChange(Entity ent, ref AfterShockChangeEvent args) { UpdateAlert(ent); } }