From: DrSmugleaf Date: Thu, 23 Nov 2023 00:43:12 +0000 (-0800) Subject: Fix health alert not being updated when a system overrides the current state through... X-Git-Url: https://git.smokeofanarchy.ru/gitweb.cgi?a=commitdiff_plain;h=4be03591b94d58d34f97ab6236760bd064f7b0f9;p=space-station-14.git Fix health alert not being updated when a system overrides the current state through UpdateMobStateEvent (#21741) --- diff --git a/Content.Shared/Mobs/Systems/MobThresholdSystem.cs b/Content.Shared/Mobs/Systems/MobThresholdSystem.cs index f34240d8fe..59d9fb4c23 100644 --- a/Content.Shared/Mobs/Systems/MobThresholdSystem.cs +++ b/Content.Shared/Mobs/Systems/MobThresholdSystem.cs @@ -22,6 +22,7 @@ public sealed class MobThresholdSystem : EntitySystem SubscribeLocalEvent(MobThresholdStartup); SubscribeLocalEvent(OnDamaged); SubscribeLocalEvent(OnUpdateMobState); + SubscribeLocalEvent(OnThresholdsMobState); } private void OnGetState(EntityUid uid, MobThresholdsComponent component, ref ComponentGetState args) @@ -424,9 +425,7 @@ public sealed class MobThresholdSystem : EntitySystem if (!TryComp(target, out var mobState) || !TryComp(target, out var damageable)) return; CheckThresholds(target, mobState, thresholds, damageable); - var ev = new MobThresholdChecked(target, mobState, thresholds, damageable); - RaiseLocalEvent(target, ref ev, true); - UpdateAlerts(target, mobState.CurrentState, thresholds, damageable); + UpdateAllEffects((target, thresholds, mobState, damageable), mobState.CurrentState); } private void MobThresholdShutdown(EntityUid target, MobThresholdsComponent component, ComponentShutdown args) @@ -447,6 +446,23 @@ public sealed class MobThresholdSystem : EntitySystem } } + private void UpdateAllEffects(Entity ent, MobState currentState) + { + var (_, thresholds, mobState, damageable) = ent; + if (Resolve(ent, ref thresholds, ref mobState, ref damageable)) + { + var ev = new MobThresholdChecked(ent, mobState, thresholds, damageable); + RaiseLocalEvent(ent, ref ev, true); + } + + UpdateAlerts(ent, currentState, thresholds, damageable); + } + + private void OnThresholdsMobState(Entity ent, ref MobStateChangedEvent args) + { + UpdateAllEffects((ent, ent, null, null), args.NewMobState); + } + #endregion }