Add minimum distance for pilot breaking (#5232)
This commit is contained in:
@@ -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
|
||||
/// </summary>
|
||||
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<PilotComponent>(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<TransformComponent>(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>(pilotComponent.Owner.Uid);
|
||||
|
||||
if (pilotComponent.LifeStage < ComponentLifeStage.Stopping)
|
||||
EntityManager.RemoveComponent<PilotComponent>(pilotComponent.Owner.Uid);
|
||||
}
|
||||
|
||||
public void RemovePilot(IEntity entity)
|
||||
|
||||
@@ -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.
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
[NetworkedComponent()]
|
||||
[NetworkedComponent]
|
||||
public sealed class PilotComponent : Component
|
||||
{
|
||||
public override string Name => "Pilot";
|
||||
[ViewVariables] public SharedShuttleConsoleComponent? Console { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Where we started piloting from to check if we should break from moving too far.
|
||||
/// </summary>
|
||||
[ViewVariables] public EntityCoordinates? Position { get; set; }
|
||||
|
||||
public const float BreakDistance = 0.25f;
|
||||
|
||||
public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
|
||||
{
|
||||
base.HandleComponentState(curState, nextState);
|
||||
|
||||
Reference in New Issue
Block a user