From 290c2fd502af9fcb23b96377eb2d1550b0f6e74b Mon Sep 17 00:00:00 2001 From: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Date: Sat, 30 Sep 2023 01:01:47 +1000 Subject: [PATCH] Organ fixes (#20488) --- Content.Server/Body/Systems/BrainSystem.cs | 15 --------- .../Body/Events/MechanismBodyEvents.cs | 32 ++----------------- .../Body/Systems/SharedBodySystem.Body.cs | 2 +- .../Body/Systems/SharedBodySystem.Organs.cs | 8 +++-- .../Body/Systems/SharedBodySystem.Parts.cs | 16 +++++++++- 5 files changed, 24 insertions(+), 49 deletions(-) diff --git a/Content.Server/Body/Systems/BrainSystem.cs b/Content.Server/Body/Systems/BrainSystem.cs index 629db0a1fb..16a2a6737b 100644 --- a/Content.Server/Body/Systems/BrainSystem.cs +++ b/Content.Server/Body/Systems/BrainSystem.cs @@ -19,25 +19,10 @@ namespace Content.Server.Body.Systems { base.Initialize(); - SubscribeLocalEvent((uid, _, args) => HandleMind(args.Body, uid)); - SubscribeLocalEvent((uid, _, args) => HandleMind(args.Part, uid)); SubscribeLocalEvent((uid, _, args) => HandleMind(args.Body, uid)); - SubscribeLocalEvent(OnRemovedFromBody); - SubscribeLocalEvent((uid, _, args) => HandleMind(uid, args.Old)); SubscribeLocalEvent((uid, _, args) => HandleMind(args.OldBody, uid)); } - private void OnRemovedFromBody(EntityUid uid, BrainComponent component, RemovedFromBodyEvent args) - { - // This one needs to be special, okay? - if (!EntityManager.TryGetComponent(uid, out OrganComponent? organ)) - { - return; - } - - HandleMind(uid, args.Old); - } - private void HandleMind(EntityUid newEntity, EntityUid oldEntity) { EnsureComp(newEntity); diff --git a/Content.Shared/Body/Events/MechanismBodyEvents.cs b/Content.Shared/Body/Events/MechanismBodyEvents.cs index 917d687a0f..b52a333613 100644 --- a/Content.Shared/Body/Events/MechanismBodyEvents.cs +++ b/Content.Shared/Body/Events/MechanismBodyEvents.cs @@ -3,19 +3,6 @@ // All of these events are raised on a mechanism entity when added/removed to a body in different // ways. - /// - /// Raised on a mechanism when it is added to a body. - /// - public sealed class AddedToBodyEvent : EntityEventArgs - { - public EntityUid Body; - - public AddedToBodyEvent(EntityUid body) - { - Body = body; - } - } - /// /// Raised on a mechanism when it is added to a body part. /// @@ -44,29 +31,16 @@ } } - /// - /// Raised on a mechanism when it is removed from a body. - /// - public sealed class RemovedFromBodyEvent : EntityEventArgs - { - public EntityUid Old; - - public RemovedFromBodyEvent(EntityUid old) - { - Old = old; - } - } - /// /// Raised on a mechanism when it is removed from a body part. /// public sealed class RemovedFromPartEvent : EntityEventArgs { - public EntityUid Old; + public EntityUid OldPart; - public RemovedFromPartEvent(EntityUid old) + public RemovedFromPartEvent(EntityUid oldPart) { - Old = old; + OldPart = oldPart; } } diff --git a/Content.Shared/Body/Systems/SharedBodySystem.Body.cs b/Content.Shared/Body/Systems/SharedBodySystem.Body.cs index 072826f08b..9cdeb8dcfa 100644 --- a/Content.Shared/Body/Systems/SharedBodySystem.Body.cs +++ b/Content.Shared/Body/Systems/SharedBodySystem.Body.cs @@ -74,7 +74,7 @@ public partial class SharedBodySystem if (TryComp(entity, out OrganComponent? organ)) { - RemoveOrgan(entity, uid, uid, organ); + RemoveOrgan(entity, uid, organ); } } diff --git a/Content.Shared/Body/Systems/SharedBodySystem.Organs.cs b/Content.Shared/Body/Systems/SharedBodySystem.Organs.cs index 7ee39da00b..d2a7b7256a 100644 --- a/Content.Shared/Body/Systems/SharedBodySystem.Organs.cs +++ b/Content.Shared/Body/Systems/SharedBodySystem.Organs.cs @@ -12,7 +12,7 @@ public partial class SharedBodySystem private void AddOrgan(EntityUid uid, EntityUid bodyUid, EntityUid parentPartUid, OrganComponent component) { component.Body = bodyUid; - RaiseLocalEvent(uid, new AddedToPartEvent(bodyUid)); + RaiseLocalEvent(uid, new AddedToPartEvent(parentPartUid)); if (component.Body != null) RaiseLocalEvent(uid, new AddedToPartInBodyEvent(component.Body.Value, parentPartUid)); @@ -20,12 +20,14 @@ public partial class SharedBodySystem Dirty(uid, component); } - private void RemoveOrgan(EntityUid uid, EntityUid bodyUid, EntityUid parentPartUid, OrganComponent component) + private void RemoveOrgan(EntityUid uid, EntityUid parentPartUid, OrganComponent component) { - RaiseLocalEvent(uid, new RemovedFromPartEvent(bodyUid)); + RaiseLocalEvent(uid, new RemovedFromPartEvent(parentPartUid)); if (component.Body != null) + { RaiseLocalEvent(uid, new RemovedFromPartInBodyEvent(component.Body.Value, parentPartUid)); + } component.Body = null; Dirty(uid, component); diff --git a/Content.Shared/Body/Systems/SharedBodySystem.Parts.cs b/Content.Shared/Body/Systems/SharedBodySystem.Parts.cs index 2d96c14863..d2ec8c7f18 100644 --- a/Content.Shared/Body/Systems/SharedBodySystem.Parts.cs +++ b/Content.Shared/Body/Systems/SharedBodySystem.Parts.cs @@ -1,6 +1,7 @@ using System.Diagnostics.CodeAnalysis; using System.Linq; using Content.Shared.Body.Components; +using Content.Shared.Body.Events; using Content.Shared.Body.Organ; using Content.Shared.Body.Part; using Content.Shared.Damage; @@ -61,7 +62,7 @@ public partial class SharedBodySystem if (TryComp(entity, out OrganComponent? organ)) { - RemoveOrgan(entity, organ); + RemoveOrgan(entity, uid, organ); } } @@ -85,7 +86,20 @@ public partial class SharedBodySystem { if (TryComp(organ, out OrganComponent? organComp)) { + var oldBody = organComp.Body; organComp.Body = bodyUid; + + if (bodyUid != null) + { + var ev = new AddedToPartInBodyEvent(bodyUid.Value, children.Id); + RaiseLocalEvent(organ, ev); + } + else if (oldBody != null) + { + var ev = new RemovedFromPartInBodyEvent(oldBody.Value, children.Id); + RaiseLocalEvent(organ, ev); + } + Dirty(organ, organComp); } }