[DataField(required: true)]
public EntityUid? Parent;
+ /// <summary>
+ /// Whether this polymorph has been reverted.
+ /// </summary>
+ [DataField]
+ public bool Reverted;
+
/// <summary>
/// The amount of time that has passed since the entity was created
/// used for tracking the duration
private void OnBeforeFullySliced(Entity<PolymorphedEntityComponent> ent, ref BeforeFullySlicedEvent args)
{
- var (_, comp) = ent;
- if (comp.Configuration.RevertOnEat)
- {
- args.Cancel();
- Revert((ent, ent));
- }
+ if (ent.Comp.Reverted || !ent.Comp.Configuration.RevertOnEat)
+ return;
+
+ args.Cancel();
+ Revert((ent, ent));
}
/// <summary>
/// </summary>
private void OnDestruction(Entity<PolymorphedEntityComponent> ent, ref DestructionEventArgs args)
{
- if (ent.Comp.Configuration.RevertOnDeath)
- {
- Revert((ent, ent));
- }
+ if (ent.Comp.Reverted || !ent.Comp.Configuration.RevertOnDeath)
+ return;
+
+ Revert((ent, ent));
}
private void OnPolymorphedTerminating(Entity<PolymorphedEntityComponent> ent, ref EntityTerminatingEvent args)
{
+ if (ent.Comp.Reverted)
+ return;
+
if (ent.Comp.Configuration.RevertOnDelete)
Revert(ent.AsNullable());
if (component.Parent is not { } parent)
return null;
- // Clear our reference to the original entity
- component.Parent = null;
if (Deleted(parent))
return null;
_transform.SetParent(parent, parentXform, uidXform.ParentUid);
_transform.SetCoordinates(parent, parentXform, uidXform.Coordinates, uidXform.LocalRotation);
+ component.Reverted = true;
+
if (component.Configuration.TransferDamage &&
TryComp<DamageableComponent>(parent, out var damageParent) &&
_mobThreshold.GetScaledDamage(uid, parent, out var damage) &&