]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Fix nuke disk getting lost when polymorphed holder is deleted (#36058)
authorTayrtahn <tayrtahn@gmail.com>
Wed, 20 Aug 2025 07:02:41 +0000 (03:02 -0400)
committerGitHub <noreply@github.com>
Wed, 20 Aug 2025 07:02:41 +0000 (00:02 -0700)
* Delete original entity when polymorph is deleted

* Switch to EntityTerminatingEvent

* Add RevertOnDelete option to PolymorphPrototype

* Fix error on server shutdown while polymorphed

* Set RevertOnDelete to false by default

* AsNullable

* Revert "Set RevertOnDelete to false by default"

This reverts commit 087c43fbb923c9369c61c9d001e18814b3de3aca.

* Use pattern matching instead of .Value

Content.Server/Polymorph/Components/PolymorphedEntityComponent.cs
Content.Server/Polymorph/Systems/PolymorphSystem.cs
Content.Shared/Polymorph/PolymorphPrototype.cs

index 7620203a862b070e2a3f22b5c29e56630ef62ca0..7e3437a908cf5c0ec93627fd5b8c45d15c9c3a6e 100644 (file)
@@ -18,7 +18,7 @@ public sealed partial class PolymorphedEntityComponent : Component
     /// The original entity that the player will revert back into
     /// </summary>
     [DataField(required: true)]
-    public EntityUid Parent;
+    public EntityUid? Parent;
 
     /// <summary>
     /// The amount of time that has passed since the entity was created
index d0f8b4e8fc4389b340f86024e313a3eb555c5cb1..aabc0366cd6998bf68f3cd7deb1d4b4e9f239747 100644 (file)
@@ -55,6 +55,7 @@ public sealed partial class PolymorphSystem : EntitySystem
 
         SubscribeLocalEvent<PolymorphedEntityComponent, BeforeFullySlicedEvent>(OnBeforeFullySliced);
         SubscribeLocalEvent<PolymorphedEntityComponent, DestructionEventArgs>(OnDestruction);
+        SubscribeLocalEvent<PolymorphedEntityComponent, EntityTerminatingEvent>(OnPolymorphedTerminating);
 
         InitializeMap();
     }
@@ -147,6 +148,16 @@ public sealed partial class PolymorphSystem : EntitySystem
         }
     }
 
+    private void OnPolymorphedTerminating(Entity<PolymorphedEntityComponent> ent, ref EntityTerminatingEvent args)
+    {
+        if (ent.Comp.Configuration.RevertOnDelete)
+            Revert(ent.AsNullable());
+
+        // Remove our original entity too
+        // Note that Revert will set Parent to null, so reverted entities will not be deleted
+        QueueDel(ent.Comp.Parent);
+    }
+
     /// <summary>
     /// Polymorphs the target entity into the specific polymorph prototype
     /// </summary>
@@ -284,13 +295,21 @@ public sealed partial class PolymorphSystem : EntitySystem
         if (Deleted(uid))
             return null;
 
-        var parent = component.Parent;
+        if (component.Parent is not { } parent)
+            return null;
+
+        // Clear our reference to the original entity
+        component.Parent = null;
         if (Deleted(parent))
             return null;
 
         var uidXform = Transform(uid);
         var parentXform = Transform(parent);
 
+        // Don't swap back onto a terminating grid
+        if (TerminatingOrDeleted(uidXform.ParentUid))
+            return null;
+
         if (component.Configuration.ExitPolymorphSound != null)
             _audio.PlayPvs(component.Configuration.ExitPolymorphSound, uidXform.Coordinates);
 
index 0978d7119a3c8ec799106f20f176d4ed105b54c6..26637431f0d5ad738a5c7bfbb548d19e80b46207 100644 (file)
@@ -105,6 +105,12 @@ public sealed partial record PolymorphConfiguration
     [DataField(serverOnly: true)]
     public bool RevertOnDeath = true;
 
+    /// <summary>
+    /// Whether or not the polymorph reverts when the entity is deleted.
+    /// </summary>
+    [DataField(serverOnly: true)]
+    public bool RevertOnDelete = true;
+
     /// <summary>
     /// Whether or not the polymorph reverts when the entity is eaten or fully sliced.
     /// </summary>