示例#1
0
 private static void RefreshMovementSpeed(SharedPullerComponent component)
 {
     // Before changing how this is updated, please see SharedPullerComponent
     if (component.Owner.TryGetComponent <MovementSpeedModifierComponent>(out var speed))
     {
         speed.RefreshMovementSpeedModifiers();
     }
 }
示例#2
0
        private void OnPullerMove(EntityUid uid, SharedPullerComponent component, ref MoveEvent args)
        {
            if (component.Pulling == null ||
                !TryComp <SharedPullableComponent>(component.Pulling.Value, out var pullable))
            {
                return;
            }

            _pullableSystem.StopMoveTo(pullable);
        }
示例#3
0
        private void PullerHandlePullStarted(
            EntityUid uid,
            SharedPullerComponent component,
            PullStartedMessage args)
        {
            if (args.Puller.Owner != uid)
            {
                return;
            }

            _alertsSystem.ShowAlert(component.Owner, AlertType.Pulling);

            RefreshMovementSpeed(component);
        }
        private static void PullerHandlePullStopped(
            EntityUid uid,
            SharedPullerComponent component,
            PullStoppedMessage args)
        {
            if (args.Puller.Owner.Uid != uid)
            {
                return;
            }

            if (component.Owner.TryGetComponent(out SharedAlertsComponent? alerts))
            {
                alerts.ClearAlert(AlertType.Pulling);
            }
        }
示例#5
0
        private void OnVirtualItemDeleted(EntityUid uid, SharedPullerComponent component, VirtualItemDeletedEvent args)
        {
            if (component.Pulling == null)
            {
                return;
            }

            if (component.Pulling == EntityManager.GetEntity(args.BlockingEntity))
            {
                if (EntityManager.TryGetComponent <SharedPullableComponent>(args.BlockingEntity, out var comp))
                {
                    _pullSystem.TryStopPull(comp, EntityManager.GetEntity(uid));
                }
            }
        }
示例#6
0
        private void PullerHandlePullStopped(
            EntityUid uid,
            SharedPullerComponent component,
            PullStoppedMessage args)
        {
            if (args.Puller.Owner != uid)
            {
                return;
            }

            var euid = component.Owner;

            _alertsSystem.ClearAlert(euid, AlertType.Pulling);

            RefreshMovementSpeed(component);
        }
示例#7
0
        private static void PullerHandlePullStarted(
            EntityUid uid,
            SharedPullerComponent component,
            PullStartedMessage args)
        {
            if (args.Puller.Owner.Uid != uid)
            {
                return;
            }

            if (component.Owner.TryGetComponent(out SharedAlertsComponent? alerts))
            {
                alerts.ShowAlert(AlertType.Pulling);
            }

            RefreshMovementSpeed(component);
        }
        private void OnPullerMove(EntityUid uid, SharedPullerComponent component, ref MoveEvent args)
        {
            if (component.Pulling == null ||
                !TryComp <SharedPullableComponent>(component.Pulling.Value, out var pullable))
            {
                return;
            }

            UpdatePulledRotation(uid, pullable.Owner);

            if (TryComp <PhysicsComponent>(pullable.Owner, out var physics))
            {
                physics.WakeBody();
            }

            _pullableSystem.StopMoveTo(pullable);
        }
示例#9
0
        private void PullerHandlePullStopped(
            EntityUid uid,
            SharedPullerComponent component,
            PullStoppedMessage args)
        {
            if (args.Puller.Owner != uid)
            {
                return;
            }

            if (EntityManager.TryGetComponent(component.Owner, out SharedAlertsComponent? alerts))
            {
                alerts.ClearAlert(AlertType.Pulling);
            }

            RefreshMovementSpeed(component);
        }
        private void OnPullerMove(EntityUid uid, SharedPullerComponent component, ref MoveEvent args)
        {
            if (component.Pulling == null ||
                !TryComp <SharedPullableComponent>(component.Pulling.Value, out var pullable))
            {
                return;
            }

            UpdatePulledRotation(uid, pullable.Owner);

            if (args.NewPosition.EntityId == args.OldPosition.EntityId &&
                (args.NewPosition.Position - args.OldPosition.Position).LengthSquared < MinimumMovementDistance * MinimumMovementDistance)
            {
                return;
            }

            if (TryComp <PhysicsComponent>(pullable.Owner, out var physics))
            {
                physics.WakeBody();
            }

            _pullableSystem.StopMoveTo(pullable);
        }
        // A WARNING:
        // The following 2 functions are the most internal part of the pulling system's relationship management.
        // They do not expect to be cancellable.
        private void ForceDisconnect(SharedPullerComponent puller, SharedPullableComponent pullable)
        {
            var pullerPhysics   = puller.Owner.GetComponent <PhysicsComponent>();
            var pullablePhysics = pullable.Owner.GetComponent <PhysicsComponent>();

            // MovingTo shutdown
            ForceSetMovingTo(pullable, null);

            // Joint shutdown
            if (puller.Owner.TryGetComponent <JointComponent>(out var jointComp))
            {
                if (jointComp.GetJoints.Contains(pullable.PullJoint !))
                {
                    _jointSystem.RemoveJoint(pullable.PullJoint !);
                }
            }
            pullable.PullJoint = null;

            // State shutdown
            puller.Pulling  = null;
            pullable.Puller = null;

            // Messaging
            var message = new PullStoppedMessage(pullerPhysics, pullablePhysics);

            RaiseLocalEvent(puller.Owner.Uid, message, broadcast: false);

            if (pullable.Owner.LifeStage <= EntityLifeStage.MapInitialized)
            {
                RaiseLocalEvent(pullable.Owner.Uid, message);
            }

            // Networking
            puller.Dirty();
            pullable.Dirty();
        }
 // For OnRemove use only.
 public void ForceDisconnectPuller(SharedPullerComponent puller)
 {
     // DO NOT ADD ADDITIONAL LOGIC IN THIS FUNCTION. Do it in ForceRelationship.
     ForceRelationship(puller, null);
 }
示例#13
0
        // The main "start pulling" function.
        public bool TryStartPull(SharedPullerComponent puller, SharedPullableComponent pullable)
        {
            if (puller.Pulling == pullable.Owner)
            {
                return(true);
            }

            // Pulling a new object : Perform sanity checks.

            if (!CanPull(puller.Owner, pullable.Owner))
            {
                return(false);
            }

            if (!EntityManager.TryGetComponent <PhysicsComponent?>(puller.Owner, out var pullerPhysics))
            {
                return(false);
            }

            if (!EntityManager.TryGetComponent <PhysicsComponent?>(pullable.Owner, out var pullablePhysics))
            {
                return(false);
            }

            // Ensure that the puller is not currently pulling anything.
            // If this isn't done, then it happens too late, and the start/stop messages go out of order,
            //  and next thing you know it thinks it's not pulling anything even though it is!

            var oldPullable = puller.Pulling;

            if (oldPullable != null)
            {
                if (EntityManager.TryGetComponent <SharedPullableComponent?>(oldPullable.Value, out var oldPullableComp))
                {
                    if (!TryStopPull(oldPullableComp))
                    {
                        return(false);
                    }
                }
                else
                {
                    Logger.WarningS("c.go.c.pulling", "Well now you've done it, haven't you? Someone transferred pulling (onto {0}) while presently pulling something that has no Pullable component (on {1})!", pullable.Owner, oldPullable);
                    return(false);
                }
            }

            // Ensure that the pullable is not currently being pulled.
            // Same sort of reasons as before.

            var oldPuller = pullable.Puller;

            if (oldPuller != null)
            {
                if (!TryStopPull(pullable))
                {
                    return(false);
                }
            }

            // Continue with pulling process.

            var pullAttempt = new PullAttemptMessage(pullerPhysics, pullablePhysics);

            RaiseLocalEvent(puller.Owner, pullAttempt, broadcast: false);

            if (pullAttempt.Cancelled)
            {
                return(false);
            }

            RaiseLocalEvent(pullable.Owner, pullAttempt);

            if (pullAttempt.Cancelled)
            {
                return(false);
            }

            _pullSm.ForceRelationship(puller, pullable);
            return(true);
        }
示例#14
0
 private void RefreshMovementSpeed(SharedPullerComponent component)
 {
     _movementSpeedModifierSystem.RefreshMovementSpeedModifiers((component).Owner);
 }
示例#15
0
 private void OnRefreshMovespeed(EntityUid uid, SharedPullerComponent component, RefreshMovementSpeedModifiersEvent args)
 {
     args.ModifySpeed(component.WalkSpeedModifier, component.SprintSpeedModifier);
 }