]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Organ fixes (#20488)
authormetalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Fri, 29 Sep 2023 15:01:47 +0000 (01:01 +1000)
committerGitHub <noreply@github.com>
Fri, 29 Sep 2023 15:01:47 +0000 (08:01 -0700)
Content.Server/Body/Systems/BrainSystem.cs
Content.Shared/Body/Events/MechanismBodyEvents.cs
Content.Shared/Body/Systems/SharedBodySystem.Body.cs
Content.Shared/Body/Systems/SharedBodySystem.Organs.cs
Content.Shared/Body/Systems/SharedBodySystem.Parts.cs

index 629db0a1fb11cc86664a0e996ee5b7a3bceb8966..16a2a6737b065e7abeb10d9a9a37c96058b24a47 100644 (file)
@@ -19,25 +19,10 @@ namespace Content.Server.Body.Systems
         {
             base.Initialize();
 
-            SubscribeLocalEvent<BrainComponent, AddedToBodyEvent>((uid, _, args) => HandleMind(args.Body, uid));
-            SubscribeLocalEvent<BrainComponent, AddedToPartEvent>((uid, _, args) => HandleMind(args.Part, uid));
             SubscribeLocalEvent<BrainComponent, AddedToPartInBodyEvent>((uid, _, args) => HandleMind(args.Body, uid));
-            SubscribeLocalEvent<BrainComponent, RemovedFromBodyEvent>(OnRemovedFromBody);
-            SubscribeLocalEvent<BrainComponent, RemovedFromPartEvent>((uid, _, args) => HandleMind(uid, args.Old));
             SubscribeLocalEvent<BrainComponent, RemovedFromPartInBodyEvent>((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<MindContainerComponent>(newEntity);
index 917d687a0facba1762f38e346f22d47beea39a4b..b52a333613f5246f04dce06c0c53f1e3e03e5736 100644 (file)
@@ -3,19 +3,6 @@
     // All of these events are raised on a mechanism entity when added/removed to a body in different
     // ways.
 
-    /// <summary>
-    ///     Raised on a mechanism when it is added to a body.
-    /// </summary>
-    public sealed class AddedToBodyEvent : EntityEventArgs
-    {
-        public EntityUid Body;
-
-        public AddedToBodyEvent(EntityUid body)
-        {
-            Body = body;
-        }
-    }
-
     /// <summary>
     ///     Raised on a mechanism when it is added to a body part.
     /// </summary>
         }
     }
 
-    /// <summary>
-    ///     Raised on a mechanism when it is removed from a body.
-    /// </summary>
-    public sealed class RemovedFromBodyEvent : EntityEventArgs
-    {
-        public EntityUid Old;
-
-        public RemovedFromBodyEvent(EntityUid old)
-        {
-            Old = old;
-        }
-    }
-
     /// <summary>
     ///     Raised on a mechanism when it is removed from a body part.
     /// </summary>
     public sealed class RemovedFromPartEvent : EntityEventArgs
     {
-        public EntityUid Old;
+        public EntityUid OldPart;
 
-        public RemovedFromPartEvent(EntityUid old)
+        public RemovedFromPartEvent(EntityUid oldPart)
         {
-            Old = old;
+            OldPart = oldPart;
         }
     }
 
index 072826f08b36108f3df94f2ea82e07d9cc7e4935..9cdeb8dcfad44ae7e00915c2bb4429cee2b035b3 100644 (file)
@@ -74,7 +74,7 @@ public partial class SharedBodySystem
 
         if (TryComp(entity, out OrganComponent? organ))
         {
-            RemoveOrgan(entity, uid, uid, organ);
+            RemoveOrgan(entity, uid, organ);
         }
     }
 
index 7ee39da00ba90060b0a5e6cf61fcc0f14ed68e06..d2a7b7256ae85bd16a7b0e252c453e654b0922f7 100644 (file)
@@ -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);
index 2d96c1486372096d52e073e76a5e9f49b4940a9e..d2ec8c7f18ec46b8595cbbcab391911009ffdcc1 100644 (file)
@@ -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);
                         }
                     }