using Content.Server.Shuttles.Events; using Content.Server.Station.Systems; using Content.Shared.DeltaV.Shuttles.Components; using Content.Shared.DeltaV.Shuttles.Systems; using Content.Shared.Shuttles.Components; using Content.Shared.Station.Components; using Content.Shared.Whitelist; using Robust.Shared.Map.Components; using System.Linq; namespace Content.Server.DeltaV.Shuttles.Systems; public sealed class DockingShuttleSystem : SharedDockingShuttleSystem { [Dependency] private readonly DockingConsoleSystem _console = default!; [Dependency] private readonly EntityWhitelistSystem _whitelist = default!; [Dependency] private readonly StationSystem _station = default!; public override void Initialize() { base.Initialize(); SubscribeLocalEvent(OnMapInit); SubscribeLocalEvent(OnFTLStarted); SubscribeLocalEvent(OnFTLCompleted); SubscribeLocalEvent(OnStationGridAdded); } private void OnMapInit(Entity ent, ref MapInitEvent args) { // add any whitelisted destinations that it can FTL to // since it needs a whitelist, this excludes the station var query = EntityQueryEnumerator(); while (query.MoveNext(out var mapUid, out var dest, out var map)) { if (!dest.Enabled || _whitelist.IsWhitelistFailOrNull(dest.Whitelist, ent)) continue; ent.Comp.Destinations.Add(new DockingDestination() { Name = Name(mapUid), Map = map.MapId }); } } private void OnFTLStarted(Entity ent, ref FTLStartedEvent args) { _console.UpdateConsolesUsing(ent); } private void OnFTLCompleted(Entity ent, ref FTLCompletedEvent args) { _console.UpdateConsolesUsing(ent); } private void OnStationGridAdded(StationGridAddedEvent args) { var uid = args.GridId; if (!TryComp(uid, out var comp)) return; // only add the destination once if (comp.Station != null) return; if (_station.GetOwningStation(uid) is not {} station || !TryComp(station, out var data)) return; // add the source station as a destination comp.Station = station; comp.Destinations.Add(new DockingDestination() { Name = Name(station), Map = Transform(data.Grids.First()).MapID }); } }