From 8f2d16aabf8fd29e077f59099ccbc9f5a5402d4d Mon Sep 17 00:00:00 2001 From: Patrik Caes-Sayrs Date: Tue, 17 Dec 2024 04:56:47 -0700 Subject: [PATCH] Zombies keep their anomalies on zombification (#33867) * Zombies keep their anomalies on zombification * Refactor anombies to isolate anomalies and zombies InnerBodyAnomalies now send an event when the host dies. Zombies cancels this event if the host is turning into a zombie. * Anomazombies: deprecate CancellableEntityEventArgs CancellableEntityEventArgs is deprecated. Use structs with bool Cancelled instead. --- .../Anomaly/Effects/InnerBodyAnomalySystem.cs | 5 +++++ Content.Server/Zombies/ZombieSystem.cs | 10 ++++++++++ .../Anomaly/Components/InnerBodyAnomalyComponent.cs | 8 ++++++++ 3 files changed, 23 insertions(+) diff --git a/Content.Server/Anomaly/Effects/InnerBodyAnomalySystem.cs b/Content.Server/Anomaly/Effects/InnerBodyAnomalySystem.cs index 38c4c51d8745f9..b75be376383faf 100644 --- a/Content.Server/Anomaly/Effects/InnerBodyAnomalySystem.cs +++ b/Content.Server/Anomaly/Effects/InnerBodyAnomalySystem.cs @@ -186,6 +186,11 @@ private void OnMobStateChanged(Entity ent, ref MobSta if (args.NewMobState != MobState.Dead) return; + var ev = new BeforeRemoveAnomalyOnDeathEvent(); + RaiseLocalEvent(args.Target, ref ev); + if (ev.Cancelled) + return; + _anomaly.ChangeAnomalyHealth(ent, -2); //Shutdown it } diff --git a/Content.Server/Zombies/ZombieSystem.cs b/Content.Server/Zombies/ZombieSystem.cs index 371c6f1222aeaa..ec50e11a0caf9b 100644 --- a/Content.Server/Zombies/ZombieSystem.cs +++ b/Content.Server/Zombies/ZombieSystem.cs @@ -5,6 +5,7 @@ using Content.Server.Chat.Systems; using Content.Server.Emoting.Systems; using Content.Server.Speech.EntitySystems; +using Content.Shared.Anomaly.Components; using Content.Shared.Bed.Sleep; using Content.Shared.Cloning; using Content.Shared.Damage; @@ -64,10 +65,19 @@ public override void Initialize() SubscribeLocalEvent(OnGetCharacterDeadIC); SubscribeLocalEvent(OnPendingMapInit); + SubscribeLocalEvent(OnBeforeRemoveAnomalyOnDeath); SubscribeLocalEvent(OnPendingMapInit); SubscribeLocalEvent(OnDamageChanged); + + } + + private void OnBeforeRemoveAnomalyOnDeath(Entity ent, ref BeforeRemoveAnomalyOnDeathEvent args) + { + // Pending zombies (e.g. infected non-zombies) do not remove their hosted anomaly on death. + // Current zombies DO remove the anomaly on death. + args.Cancelled = true; } private void OnPendingMapInit(EntityUid uid, IncurableZombieComponent component, MapInitEvent args) diff --git a/Content.Shared/Anomaly/Components/InnerBodyAnomalyComponent.cs b/Content.Shared/Anomaly/Components/InnerBodyAnomalyComponent.cs index e88cedb18ef2aa..a7e07ae2b504c7 100644 --- a/Content.Shared/Anomaly/Components/InnerBodyAnomalyComponent.cs +++ b/Content.Shared/Anomaly/Components/InnerBodyAnomalyComponent.cs @@ -70,3 +70,11 @@ public sealed partial class InnerBodyAnomalyComponent : Component [DataField] public string LayerMap = "inner_anomaly_layer"; } + +/// +/// Event broadcast when an anomaly is being removed because the host is dying. +/// Raised directed at the host entity with the anomaly. +/// Cancel this if you want to prevent the host from losing their anomaly on death. +/// +[ByRefEvent] +public record struct BeforeRemoveAnomalyOnDeathEvent(bool Cancelled = false);