diff --git a/Content.Server/Shuttles/ShuttleConsoleSystem.cs b/Content.Server/Shuttles/ShuttleConsoleSystem.cs index c899549fce..cbcbe867ef 100644 --- a/Content.Server/Shuttles/ShuttleConsoleSystem.cs +++ b/Content.Server/Shuttles/ShuttleConsoleSystem.cs @@ -10,6 +10,8 @@ using Content.Shared.Tag; using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Localization; +using Robust.Shared.Log; +using Robust.Shared.Physics; using Robust.Shared.Utility; namespace Content.Server.Shuttles @@ -72,7 +74,16 @@ namespace Content.Server.Shuttles /// private void HandlePilotMove(EntityUid uid, PilotComponent component, ref MoveEvent args) { - if (component.Console == null) return; + if (component.Console == null || component.Position == null) + { + DebugTools.Assert(component.Position == null && component.Console == null); + EntityManager.RemoveComponent(uid); + return; + } + + if (args.NewPosition.TryDistance(EntityManager, component.Position.Value, out var distance) && + distance < PilotComponent.BreakDistance) return; + RemovePilot(component); } @@ -138,6 +149,7 @@ namespace Content.Server.Shuttles entity.PopupMessage(Loc.GetString("shuttle-pilot-start")); pilotComponent.Console = component; + pilotComponent.Position = EntityManager.GetComponent(entity.Uid).Coordinates; pilotComponent.Dirty(); } @@ -148,6 +160,7 @@ namespace Content.Server.Shuttles if (console is not ShuttleConsoleComponent helmsman) return; pilotComponent.Console = null; + pilotComponent.Position = null; if (!helmsman.SubscribedPilots.Remove(pilotComponent)) return; @@ -157,7 +170,9 @@ namespace Content.Server.Shuttles } pilotComponent.Owner.PopupMessage(Loc.GetString("shuttle-pilot-end")); - EntityManager.RemoveComponent(pilotComponent.Owner.Uid); + + if (pilotComponent.LifeStage < ComponentLifeStage.Stopping) + EntityManager.RemoveComponent(pilotComponent.Owner.Uid); } public void RemovePilot(IEntity entity) diff --git a/Content.Shared/Shuttles/PilotComponent.cs b/Content.Shared/Shuttles/PilotComponent.cs index 04241d8e46..889a618140 100644 --- a/Content.Shared/Shuttles/PilotComponent.cs +++ b/Content.Shared/Shuttles/PilotComponent.cs @@ -2,6 +2,7 @@ using System; using Robust.Shared.GameObjects; using Robust.Shared.GameStates; using Robust.Shared.Log; +using Robust.Shared.Map; using Robust.Shared.Players; using Robust.Shared.Serialization; using Robust.Shared.ViewVariables; @@ -12,12 +13,19 @@ namespace Content.Shared.Shuttles /// Stores what shuttle this entity is currently piloting. /// [RegisterComponent] - [NetworkedComponent()] + [NetworkedComponent] public sealed class PilotComponent : Component { public override string Name => "Pilot"; [ViewVariables] public SharedShuttleConsoleComponent? Console { get; set; } + /// + /// Where we started piloting from to check if we should break from moving too far. + /// + [ViewVariables] public EntityCoordinates? Position { get; set; } + + public const float BreakDistance = 0.25f; + public override void HandleComponentState(ComponentState? curState, ComponentState? nextState) { base.HandleComponentState(curState, nextState);