]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Fix health alert not being updated when a system overrides the current state through...
authorDrSmugleaf <DrSmugleaf@users.noreply.github.com>
Thu, 23 Nov 2023 00:43:12 +0000 (16:43 -0800)
committerGitHub <noreply@github.com>
Thu, 23 Nov 2023 00:43:12 +0000 (19:43 -0500)
Content.Shared/Mobs/Systems/MobThresholdSystem.cs

index f34240d8fe3738fd360083e8c957cc9e4cad31d0..59d9fb4c2390384f8625a3018887923332df3f07 100644 (file)
@@ -22,6 +22,7 @@ public sealed class MobThresholdSystem : EntitySystem
         SubscribeLocalEvent<MobThresholdsComponent, ComponentStartup>(MobThresholdStartup);
         SubscribeLocalEvent<MobThresholdsComponent, DamageChangedEvent>(OnDamaged);
         SubscribeLocalEvent<MobThresholdsComponent, UpdateMobStateEvent>(OnUpdateMobState);
+        SubscribeLocalEvent<MobThresholdsComponent, MobStateChangedEvent>(OnThresholdsMobState);
     }
 
     private void OnGetState(EntityUid uid, MobThresholdsComponent component, ref ComponentGetState args)
@@ -424,9 +425,7 @@ public sealed class MobThresholdSystem : EntitySystem
         if (!TryComp<MobStateComponent>(target, out var mobState) || !TryComp<DamageableComponent>(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<MobThresholdsComponent, MobStateComponent?, DamageableComponent?> 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<MobThresholdsComponent> ent, ref MobStateChangedEvent args)
+    {
+        UpdateAllEffects((ent, ent, null, null), args.NewMobState);
+    }
+
     #endregion
 }