private void OnParentChanged(EntityUid uid, BlockingUserComponent component, ref EntParentChangedMessage args)
 {
     if (TryComp <BlockingComponent>(component.BlockingItem, out var blockComp) && blockComp.IsBlocking)
     {
         _blockingSystem.StopBlocking(component.BlockingItem.Value, blockComp, uid);
     }
 }
        // Eject entities from their parent container if the parent change is done by the transform only.
        private static void HandleParentChanged(EntParentChangedMessage message)
        {
            var oldParentEntity = message.OldParent;

            if (oldParentEntity == null || !oldParentEntity.IsValid())
                return;

            if (oldParentEntity.TryGetComponent(out IContainerManager? containerManager))
                containerManager.ForceRemove(message.Entity);
        }
 private void OnAlertsParentChange(EntityUid uid, AlertsComponent component, ref EntParentChangedMessage args)
 {
     if (IsWeightless(component.Owner))
     {
         _alerts.ShowAlert(uid, AlertType.Weightless);
     }
     else
     {
         _alerts.ClearAlert(uid, AlertType.Weightless);
     }
 }
Esempio n. 4
0
        // Eject entities from their parent container if the parent change is done by the transform only.
        private void HandleParentChanged(ref EntParentChangedMessage message)
        {
            var oldParentEntity = message.OldParent;

            if (oldParentEntity == null || !EntityManager.EntityExists(oldParentEntity !.Value))
            {
                return;
            }

            if (EntityManager.TryGetComponent(oldParentEntity !.Value, out IContainerManager? containerManager))
            {
                containerManager.ForceRemove(message.Entity);
            }
        }
        private void EntParentChanged(EntParentChangedMessage ev)
        {
            if (!ev.Entity.TryGetComponent(out ServerAlertsComponent status))
            {
                return;
            }

            if (ev.OldParent != null &&
                ev.OldParent.TryGetComponent(out IMapGridComponent mapGrid))
            {
                var oldGrid = mapGrid.GridIndex;

                if (_alerts.TryGetValue(oldGrid, out var oldStatuses))
                {
                    oldStatuses.Remove(status);
                }
            }

            var newGrid     = ev.Entity.Transform.GridID;
            var newStatuses = _alerts.GetOrNew(newGrid);

            newStatuses.Add(status);
        }
 private void OnParentChanged(EntityUid uid, ActivatableUIComponent aui, ref EntParentChangedMessage args)
 {
     CloseAll(uid, aui);
 }
 private void OnDeviceParentChanged(EntityUid uid, AtmosDeviceComponent component, EntParentChangedMessage args)
 {
     RejoinAtmosphere(component);
 }
Esempio n. 8
0
 private void EntParentChanged(EntParentChangedMessage ev)
 {
     UpdateEntity(ev.Entity);
 }
Esempio n. 9
0
 private void OnParentChange(ref EntParentChangedMessage ev)
 {
     RefreshVisibility(ev.Entity);
 }
    private void OnJetpackUserEntParentChanged(EntityUid uid, JetpackUserComponent component, ref EntParentChangedMessage args)
    {
        if (TryComp <JetpackComponent>(component.Jetpack, out var jetpack) &&
            !CanEnableOnGrid(args.Transform.GridUid))
        {
            SetEnabled(jetpack, false, uid);

            if (_timing.IsFirstTimePredicted && _network.IsClient)
            {
                _popups.PopupEntity(Loc.GetString("jetpack-to-grid"), uid, Filter.Entities(uid));
            }
        }
    }
        private void OnParentChanged(EntityUid uid, GravityGeneratorComponent component, ref EntParentChangedMessage args)
        {
            // TODO consider stations with more than one generator.
            if (component.GravityActive && TryComp(args.OldParent, out GravityComponent? gravity))
            {
                _gravitySystem.DisableGravity(gravity);
            }

            UpdateGravityActive(component, false);
        }
    private void HandleParentChangeVelocity(EntityUid uid, PhysicsComponent physics, ref EntParentChangedMessage args, TransformComponent xform)
    {
        if (physics.LifeStage != ComponentLifeStage.Running)
        {
            return;
        }

        if (_container.IsEntityInContainer(uid, xform))
        {
            return;
        }

        // When transferring bodies, we will preserve map angular and linear velocities. For this purpose, we simply
        // modify the velocities so that the map value remains unchanged.

        // TODO currently this causes issues when the parent changes due to teleportation or something like that. Though
        // I guess the question becomes, what do you do with conservation of momentum in that case. I guess its the job
        // of the teleporter to select a velocity at the after the parent has changed.

        var xformQuery   = EntityManager.GetEntityQuery <TransformComponent>();
        var physicsQuery = EntityManager.GetEntityQuery <PhysicsComponent>();

        // for the new velocities (that need to be updated), we can just use the existing function:
        var(newLinear, newAngular) = GetMapVelocities(uid, physics, xform, xformQuery, physicsQuery);

        // for the old velocities, we need to re-implement this function while using the old parent and old local position:
        if (args.OldParent is not EntityUid {
            Valid : true
        } parent)
        {
            // no previous parent --> simple
            physics.LinearVelocity  += physics.LinearVelocity - newLinear;
            physics.AngularVelocity += physics.AngularVelocity - newAngular;
            return;
        }

        TransformComponent?parentXform = xformQuery.GetComponent(parent);
        var localPos = parentXform.InvWorldMatrix.Transform(xform.WorldPosition);

        var     oldLinear  = physics.LinearVelocity;
        var     oldAngular = physics.AngularVelocity;
        Vector2 linearAngularContribution = Vector2.Zero;

        do
        {
            if (physicsQuery.TryGetComponent(parent, out var body))
            {
                oldAngular += body.AngularVelocity;

                // add linear velocity of parent relative to it's own parent (again, in map coordinates)
                oldLinear += body.LinearVelocity;

                // add the component of the linear velocity that results from the parent's rotation. This is NOT in map
                // coordinates, this is the velocity in the parentXform.Parent's frame.
                linearAngularContribution += Vector2.Cross(body.AngularVelocity, localPos - body.LocalCenter);
                linearAngularContribution  = parentXform.LocalRotation.RotateVec(linearAngularContribution);
            }

            localPos = parentXform.LocalPosition + parentXform.LocalRotation.RotateVec(localPos);
            parent   = parentXform.ParentUid;
        } while (parent.IsValid() && xformQuery.TryGetComponent(parent, out parentXform));

        oldLinear += linearAngularContribution;

        // Finally we can update the Velocities. linear velocity is already in terms of map-coordinates, so no
        // world-rotation is required
        physics.LinearVelocity  += oldLinear - newLinear;
        physics.AngularVelocity += oldAngular - newAngular;
    }