public void ForceSetMovingTo(SharedPullableComponent pullable, MapCoordinates?movingTo) { if (pullable.MovingTo == movingTo) { return; } // Don't allow setting a MovingTo if there's no puller. // The other half of this guarantee (shutting down a MovingTo if the puller goes away) is enforced in ForceRelationship. if ((pullable.Puller == null) && (movingTo != null)) { return; } pullable.MovingTo = movingTo; if (movingTo == null) { RaiseLocalEvent(pullable.Owner.Uid, new PullableStopMovingMessage()); } else { RaiseLocalEvent(pullable.Owner.Uid, new PullableMoveMessage()); } }
private void OnShutdown(EntityUid uid, SharedPullableComponent component, ComponentShutdown args) { if (component.Puller != null) { ForceRelationship(null, component); } }
// -- Core attempted actions -- public bool TryStopPull(SharedPullableComponent pullable, EntityUid?user = null) { if (!pullable.BeingPulled) { return(false); } var msg = new StopPullingEvent(user); RaiseLocalEvent(pullable.Owner, msg, true); if (msg.Cancelled) { return(false); } // Stop pulling confirmed! if (TryComp <PhysicsComponent>(pullable.Owner, out var pullablePhysics)) { pullablePhysics.FixedRotation = pullable.PrevFixedRotation; } _pullSm.ForceRelationship(null, pullable); return(true); }
public bool TogglePull(EntityUid puller, SharedPullableComponent pullable) { if (pullable.Puller == puller) { return(TryStopPull(pullable)); } return(TryStartPull(puller, pullable.Owner)); }
private void OnRelayMoveInput(EntityUid uid, SharedPullableComponent component, RelayMoveInputEvent args) { var entity = args.Session.AttachedEntity; if (entity == null || !_blocker.CanMove(entity.Value)) { return; } _pullSystem.TryStopPull(component); }
private void OnRelayMoveInput(EntityUid uid, SharedPullableComponent component, ref MoveInputEvent args) { var entity = args.Entity; if (_mobState.IsIncapacitated(entity) || !_blocker.CanMove(entity)) { return; } _pullSystem.TryStopPull(component); }
private void OnRelayMoveInput(EntityUid uid, SharedPullableComponent component, RelayMoveInputEvent args) { var entity = args.Session.AttachedEntity; if (entity == null || !_blocker.CanMove(entity.Value)) { return; } if (TryComp <MobStateComponent>(component.Owner, out var mobState) && mobState.IsIncapacitated()) { return; } _pullSystem.TryStopPull(component); }
public bool TryMoveTo(SharedPullableComponent pullable, EntityCoordinates to) { if (pullable.Puller == null) { return(false); } if (!EntityManager.HasComponent <PhysicsComponent>(pullable.Owner)) { return(false); } _pullSm.ForceSetMovingTo(pullable, to); return(true); }
// -- Core attempted actions -- public bool TryStopPull(SharedPullableComponent pullable, EntityUid?user = null) { if (!pullable.BeingPulled) { return(false); } var msg = new StopPullingEvent(user); RaiseLocalEvent(pullable.Owner, msg); if (msg.Cancelled) { return(false); } _pullSm.ForceRelationship(null, pullable); return(true); }
// 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 ForceDisconnectPullable(SharedPullableComponent pullable) { // DO NOT ADD ADDITIONAL LOGIC IN THIS FUNCTION. Do it in ForceRelationship. ForceRelationship(null, pullable); }
public void StopMoveTo(SharedPullableComponent pullable) { _pullSm.ForceSetMovingTo(pullable, null); }
// 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); }