Add FTL destinations (#9685)

This commit is contained in:
metalgearsloth
2022-07-15 14:11:41 +10:00
committed by GitHub
parent 5e1d019f17
commit 1251b3aeda
34 changed files with 9133 additions and 227 deletions

View File

@@ -6,7 +6,6 @@ using Content.Server.Shuttles.Events;
using Content.Server.UserInterface;
using Content.Shared.ActionBlocker;
using Content.Shared.Alert;
using Content.Shared.Light;
using Content.Shared.Popups;
using Content.Shared.Shuttles.BUIStates;
using Content.Shared.Shuttles.Components;
@@ -15,15 +14,19 @@ using Content.Shared.Shuttles.Systems;
using Content.Shared.Tag;
using Robust.Server.GameObjects;
using Robust.Shared.GameStates;
using Robust.Shared.Map;
using Robust.Shared.Player;
using Robust.Shared.Timing;
using Robust.Shared.Utility;
namespace Content.Server.Shuttles.Systems
{
public sealed class ShuttleConsoleSystem : SharedShuttleConsoleSystem
{
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly ActionBlockerSystem _blocker = default!;
[Dependency] private readonly AlertsSystem _alertsSystem = default!;
[Dependency] private readonly SharedPopupSystem _popup = default!;
[Dependency] private readonly ShuttleSystem _shuttle = default!;
[Dependency] private readonly TagSystem _tags = default!;
[Dependency] private readonly UserInterfaceSystem _ui = default!;
@@ -36,7 +39,9 @@ namespace Content.Server.Shuttles.Systems
SubscribeLocalEvent<ShuttleConsoleComponent, AnchorStateChangedEvent>(OnConsoleAnchorChange);
SubscribeLocalEvent<ShuttleConsoleComponent, ActivatableUIOpenAttemptEvent>(OnConsoleUIOpenAttempt);
SubscribeLocalEvent<ShuttleConsoleComponent, ShuttleModeRequestMessage>(OnModeRequest);
SubscribeLocalEvent<ShuttleConsoleComponent, ShuttleConsoleDestinationMessage>(OnDestinationMessage);
SubscribeLocalEvent<ShuttleConsoleComponent, BoundUIClosedEvent>(OnConsoleUIClose);
SubscribeLocalEvent<DockEvent>(OnDock);
SubscribeLocalEvent<UndockEvent>(OnUndock);
@@ -44,6 +49,46 @@ namespace Content.Server.Shuttles.Systems
SubscribeLocalEvent<PilotComponent, ComponentGetState>(OnGetState);
}
private void OnDestinationMessage(EntityUid uid, ShuttleConsoleComponent component, ShuttleConsoleDestinationMessage args)
{
if (!TryComp<FTLDestinationComponent>(args.Destination, out var dest)) return;
if (!dest.Enabled) return;
EntityUid? entity = component.Owner;
var getShuttleEv = new ConsoleShuttleEvent
{
Console = uid,
};
RaiseLocalEvent(entity.Value, ref getShuttleEv);
entity = getShuttleEv.Console;
if (entity == null || dest.Whitelist?.IsValid(entity.Value, EntityManager) == false) return;
if (!TryComp<TransformComponent>(entity, out var xform) ||
!TryComp<ShuttleComponent>(xform.GridUid, out var shuttle)) return;
if (HasComp<FTLComponent>(xform.GridUid))
{
if (args.Session.AttachedEntity != null)
_popup.PopupCursor(Loc.GetString("shuttle-console-in-ftl"), Filter.Entities(args.Session.AttachedEntity.Value));
return;
}
if (!_shuttle.CanFTL(shuttle.Owner, out var reason))
{
if (args.Session.AttachedEntity != null)
_popup.PopupCursor(reason, Filter.Entities(args.Session.AttachedEntity.Value));
return;
}
_shuttle.FTLTravel(shuttle, args.Destination, hyperspaceTime: _shuttle.TransitTime);
}
private void OnDock(DockEvent ev)
{
RefreshShuttleConsoles();
@@ -54,12 +99,17 @@ namespace Content.Server.Shuttles.Systems
RefreshShuttleConsoles();
}
public void RefreshShuttleConsoles(EntityUid uid)
{
// TODO: Should really call this per shuttle in some instances.
RefreshShuttleConsoles();
}
/// <summary>
/// Refreshes all of the data for shuttle consoles.
/// </summary>
public void RefreshShuttleConsoles()
{
// TODO: Should really call this per shuttle in some instances.
var docks = GetAllDocks();
foreach (var comp in EntityQuery<ShuttleConsoleComponent>(true))
@@ -87,7 +137,7 @@ namespace Content.Server.Shuttles.Systems
private void OnConsoleUIOpenAttempt(EntityUid uid, ShuttleConsoleComponent component, ActivatableUIOpenAttemptEvent args)
{
if (!component.CanPilot || !TryPilot(args.User, uid))
if (!TryPilot(args.User, uid))
args.Cancel();
}
@@ -174,7 +224,7 @@ namespace Content.Server.Shuttles.Systems
if (!this.IsPowered(consoleComponent.Owner, EntityManager) ||
!Resolve(consoleComponent.Owner, ref consoleXform) ||
!consoleXform.Anchored ||
consoleXform.GridID != Transform(shuttleComponent.Owner).GridID)
consoleXform.GridUid != Transform(shuttleComponent.Owner).GridUid)
{
return;
}
@@ -228,7 +278,7 @@ namespace Content.Server.Shuttles.Systems
Console = entity,
};
RaiseLocalEvent(entity.Value, ref getShuttleEv, false);
RaiseLocalEvent(entity.Value, ref getShuttleEv);
entity = getShuttleEv.Console;
TryComp<TransformComponent>(entity, out var consoleXform);
@@ -236,14 +286,64 @@ namespace Content.Server.Shuttles.Systems
var range = radar?.MaxRange ?? 0f;
TryComp<ShuttleComponent>(consoleXform?.GridUid, out var shuttle);
component.CanPilot = shuttle is { CanPilot: true };
var mode = shuttle?.Mode ?? ShuttleMode.Cruise;
var destinations = new List<(EntityUid, string, bool)>();
var ftlState = FTLState.Available;
var ftlTime = TimeSpan.Zero;
if (TryComp<FTLComponent>(shuttle?.Owner, out var shuttleFtl))
{
ftlState = shuttleFtl.State;
ftlTime = _timing.CurTime + TimeSpan.FromSeconds(shuttleFtl.Accumulator);
}
// Mass too large
if (entity != null && shuttle?.Owner != null && (!TryComp<PhysicsComponent>(shuttle?.Owner, out var shuttleBody) ||
shuttleBody.Mass < 1000f))
{
var metaQuery = GetEntityQuery<MetaDataComponent>();
// Can't go anywhere when in FTL.
var locked = shuttleFtl != null || Paused(shuttle!.Owner);
// Can't cache it because it may have a whitelist for the particular console.
// Include paused as we still want to show centcomm.
foreach (var comp in EntityQuery<FTLDestinationComponent>(true))
{
// Can't warp to itself or if it's not on the whitelist.
if (comp.Owner == shuttle?.Owner ||
comp.Whitelist?.IsValid(entity.Value) == false) continue;
var meta = metaQuery.GetComponent(comp.Owner);
var name = meta.EntityName;
if (string.IsNullOrEmpty(name))
name = Loc.GetString("shuttle-console-unknown");
var canTravel = !locked &&
comp.Enabled &&
!Paused(comp.Owner, meta) &&
(!TryComp<FTLComponent>(comp.Owner, out var ftl) || ftl.State == FTLState.Cooldown);
// Can't travel to same map.
if (canTravel && consoleXform?.MapUid == Transform(comp.Owner).MapUid)
{
canTravel = false;
}
destinations.Add((comp.Owner, name, canTravel));
}
}
docks ??= GetAllDocks();
_ui.GetUiOrNull(component.Owner, ShuttleConsoleUiKey.Key)
?.SetState(new ShuttleConsoleBoundInterfaceState(
ftlState,
ftlTime,
mode,
destinations,
range,
consoleXform?.Coordinates,
consoleXform?.LocalRotation,