コード例 #1
0
        /// <summary>
        /// Reverts a polymorphed entity back into its original form
        /// </summary>
        /// <param name="uid">The entityuid of the entity being reverted</param>
        public void Revert(EntityUid uid)
        {
            if (Deleted(uid))
            {
                return;
            }

            if (!TryComp <PolymorphedEntityComponent>(uid, out var component))
            {
                return;
            }

            if (Deleted(component.Parent))
            {
                return;
            }

            var proto = component.Prototype;

            var uidXform    = Transform(uid);
            var parentXform = Transform(component.Parent);

            parentXform.AttachParent(uidXform.ParentUid);
            parentXform.Coordinates   = uidXform.Coordinates;
            parentXform.LocalRotation = uidXform.LocalRotation;

            if (_container.TryGetContainingContainer(uid, out var cont))
            {
                cont.Insert(component.Parent);
            }

            if (component.Prototype.TransferDamage &&
                TryComp <DamageableComponent>(component.Parent, out var damageParent) &&
                _damageable.GetScaledDamage(uid, component.Parent, out var damage) &&
                damage != null)
            {
                _damageable.SetDamage(damageParent, damage);
            }

            if (proto.Inventory == PolymorphInventoryChange.Transfer)
            {
                _inventory.TransferEntityInventories(uid, component.Parent);
                foreach (var hand in _sharedHands.EnumerateHeld(component.Parent))
                {
                    hand.TryRemoveFromContainer();
                    _sharedHands.TryPickupAnyHand(component.Parent, hand);
                }
            }
            else if (proto.Inventory == PolymorphInventoryChange.Drop)
            {
                if (_inventory.TryGetContainerSlotEnumerator(uid, out var enumerator))
                {
                    while (enumerator.MoveNext(out var slot))
                    {
                        slot.EmptyContainer();
                    }
                }

                foreach (var hand in _sharedHands.EnumerateHeld(uid))
                {
                    hand.TryRemoveFromContainer();
                }
            }

            if (TryComp <MindComponent>(uid, out var mind) && mind.Mind != null)
            {
                mind.Mind.TransferTo(component.Parent);
            }

            _popup.PopupEntity(Loc.GetString("polymorph-revert-popup-generic", ("parent", uid), ("child", component.Parent)), component.Parent, Filter.Pvs(component.Parent));
            QueueDel(uid);
        }
コード例 #2
0
        /// <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);
        }