2021-07-21 21:15:12 +10:00
|
|
|
using System;
|
|
|
|
|
using Robust.Shared.GameObjects;
|
|
|
|
|
using Robust.Shared.GameStates;
|
2021-12-03 11:11:52 +01:00
|
|
|
using Robust.Shared.IoC;
|
2021-07-21 21:15:12 +10:00
|
|
|
using Robust.Shared.Log;
|
2021-11-11 18:42:34 +11:00
|
|
|
using Robust.Shared.Map;
|
2021-07-21 21:15:12 +10:00
|
|
|
using Robust.Shared.Serialization;
|
|
|
|
|
using Robust.Shared.ViewVariables;
|
|
|
|
|
|
2021-11-21 17:09:49 +11:00
|
|
|
namespace Content.Shared.Shuttles.Components
|
2021-07-21 21:15:12 +10:00
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Stores what shuttle this entity is currently piloting.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[RegisterComponent]
|
2021-11-11 18:42:34 +11:00
|
|
|
[NetworkedComponent]
|
2021-07-21 21:15:12 +10:00
|
|
|
public sealed class PilotComponent : Component
|
|
|
|
|
{
|
|
|
|
|
[ViewVariables] public SharedShuttleConsoleComponent? Console { get; set; }
|
|
|
|
|
|
2021-11-11 18:42:34 +11:00
|
|
|
/// <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;
|
|
|
|
|
|
2021-07-21 21:15:12 +10:00
|
|
|
public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
|
|
|
|
|
{
|
|
|
|
|
base.HandleComponentState(curState, nextState);
|
|
|
|
|
if (curState is not PilotComponentState state) return;
|
|
|
|
|
|
2021-12-05 18:09:01 +01:00
|
|
|
var console = state.Console.GetValueOrDefault();
|
|
|
|
|
if (!console.IsValid())
|
2021-07-21 21:15:12 +10:00
|
|
|
{
|
|
|
|
|
Console = null;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-04 14:14:22 +01:00
|
|
|
var entityManager = IoCManager.Resolve<IEntityManager>();
|
|
|
|
|
|
2021-12-05 18:09:01 +01:00
|
|
|
if (!entityManager.TryGetComponent(console, out SharedShuttleConsoleComponent? shuttleConsoleComponent))
|
2021-07-21 21:15:12 +10:00
|
|
|
{
|
2021-12-05 18:09:01 +01:00
|
|
|
Logger.Warning($"Unable to set Helmsman console to {console}");
|
2021-07-21 21:15:12 +10:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Console = shuttleConsoleComponent;
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-30 15:20:38 +01:00
|
|
|
public override ComponentState GetComponentState()
|
2021-07-21 21:15:12 +10:00
|
|
|
{
|
2021-12-04 12:47:09 +01:00
|
|
|
return Console == null ? new PilotComponentState(null) : new PilotComponentState(Console.Owner);
|
2021-07-21 21:15:12 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Serializable, NetSerializable]
|
|
|
|
|
private sealed class PilotComponentState : ComponentState
|
|
|
|
|
{
|
|
|
|
|
public EntityUid? Console { get; }
|
|
|
|
|
|
|
|
|
|
public PilotComponentState(EntityUid? uid)
|
|
|
|
|
{
|
|
|
|
|
Console = uid;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|