/// <summary> /// Polymorphs the target entity into the specific polymorph prototype /// </summary> /// <param name="target">The entity that will be transformed</param> /// <param name="proto">The polymorph prototype</param> public EntityUid?PolymorphEntity(EntityUid target, PolymorphPrototype proto) { /// This is the big papa function. This handles the transformation, moving the old entity /// logic and conditions specified in the prototype, and everything else that may be needed. /// I am clinically insane - emo // mostly just for vehicles if (TryComp <BuckleComponent>(target, out var buckle)) { buckle.TryUnbuckle(target, true); } var targetTransformComp = Transform(target); var child = Spawn(proto.Entity, targetTransformComp.Coordinates); MakeSentientCommand.MakeSentient(child, EntityManager); var comp = EnsureComp <PolymorphedEntityComponent>(child); comp.Parent = target; comp.Prototype = proto; RaiseLocalEvent(child, new PolymorphComponentSetupEvent(), true); var childXform = Transform(child); childXform.LocalRotation = targetTransformComp.LocalRotation; if (_container.TryGetContainingContainer(target, out var cont)) { cont.Insert(child); } //Transfers all damage from the original to the new one if (proto.TransferDamage && TryComp <DamageableComponent>(child, out var damageParent) && _damageable.GetScaledDamage(target, child, out var damage) && damage != null) { _damageable.SetDamage(damageParent, damage); } if (proto.Inventory == PolymorphInventoryChange.Transfer) { _inventory.TransferEntityInventories(target, child); foreach (var hand in _sharedHands.EnumerateHeld(target)) { hand.TryRemoveFromContainer(); _sharedHands.TryPickupAnyHand(child, hand); } } else if (proto.Inventory == PolymorphInventoryChange.Drop) { if (_inventory.TryGetContainerSlotEnumerator(target, out var enumerator)) { while (enumerator.MoveNext(out var slot)) { slot.EmptyContainer(); } } foreach (var hand in _sharedHands.EnumerateHeld(target)) { hand.TryRemoveFromContainer(); } } if (proto.TransferName && TryComp <MetaDataComponent>(target, out var targetMeta) && TryComp <MetaDataComponent>(child, out var childMeta)) { childMeta.EntityName = targetMeta.EntityName; } if (proto.TransferHumanoidAppearance && TryComp <HumanoidAppearanceComponent>(target, out var targetHuApp) && TryComp <HumanoidAppearanceComponent>(child, out var childHuApp)) { _sharedHuApp.UpdateAppearance(child, targetHuApp.Appearance); _sharedHuApp.ForceAppearanceUpdate(child); } if (TryComp <MindComponent>(target, out var mind) && mind.Mind != null) { mind.Mind.TransferTo(child); } //Ensures a map to banish the entity to EnsurePausesdMap(); if (PausedMap != null) { targetTransformComp.AttachParent(Transform(PausedMap.Value)); } return(child); }
public PolymorphActionEvent(PolymorphPrototype prototype) { Prototype = prototype; }