SubscribeLocalEvent<PolymorphedEntityComponent, BeforeFullySlicedEvent>(OnBeforeFullySliced);
SubscribeLocalEvent<PolymorphedEntityComponent, DestructionEventArgs>(OnDestruction);
+ SubscribeLocalEvent<PolymorphedEntityComponent, EntityTerminatingEvent>(OnPolymorphedTerminating);
InitializeMap();
}
}
}
+ 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>
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);
[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>