Skip to content

Commit

Permalink
Zombies keep their anomalies on zombification (space-wizards#33867)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
pcaessayrs authored Dec 17, 2024
1 parent 67e5cc2 commit 8f2d16a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Content.Server/Anomaly/Effects/InnerBodyAnomalySystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,11 @@ private void OnMobStateChanged(Entity<InnerBodyAnomalyComponent> 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
}

Expand Down
10 changes: 10 additions & 0 deletions Content.Server/Zombies/ZombieSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -64,10 +65,19 @@ public override void Initialize()
SubscribeLocalEvent<ZombieComponent, GetCharactedDeadIcEvent>(OnGetCharacterDeadIC);

SubscribeLocalEvent<PendingZombieComponent, MapInitEvent>(OnPendingMapInit);
SubscribeLocalEvent<PendingZombieComponent, BeforeRemoveAnomalyOnDeathEvent>(OnBeforeRemoveAnomalyOnDeath);

SubscribeLocalEvent<IncurableZombieComponent, MapInitEvent>(OnPendingMapInit);

SubscribeLocalEvent<ZombifyOnDeathComponent, MobStateChangedEvent>(OnDamageChanged);

}

private void OnBeforeRemoveAnomalyOnDeath(Entity<PendingZombieComponent> 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,11 @@ public sealed partial class InnerBodyAnomalyComponent : Component
[DataField]
public string LayerMap = "inner_anomaly_layer";
}

/// <summary>
/// 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.
/// </summary>
[ByRefEvent]
public record struct BeforeRemoveAnomalyOnDeathEvent(bool Cancelled = false);

0 comments on commit 8f2d16a

Please sign in to comment.