Fix nuke disk getting lost when polymorphed holder is deleted (#36058)
* 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
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user