diff --git a/Content.Server/Backmen/Administration/Commands/BkmFtlCommand.cs b/Content.Server/Backmen/Administration/Commands/BkmFtlCommand.cs new file mode 100644 index 00000000000..f34157a5dde --- /dev/null +++ b/Content.Server/Backmen/Administration/Commands/BkmFtlCommand.cs @@ -0,0 +1,154 @@ +using System.Numerics; +using Content.Server.Shuttles; +using Content.Server.Shuttles.Components; +using Content.Server.Shuttles.Events; +using Content.Server.Shuttles.Systems; +using Content.Shared.Administration; +using Content.Shared.Mobs; +using Content.Shared.Mobs.Components; +using Content.Shared.Shuttles.Components; +using Robust.Server.GameObjects; +using Robust.Shared.Console; +using Robust.Shared.Map; +using Robust.Shared.Physics.Components; + +namespace Content.Server.Backmen.Administration.Commands; + +[AnyCommand] +public sealed class BkmFtlCommand : IConsoleCommand +{ + [Dependency] private readonly IEntityManager _entityManager = default!; + + public string Command => "bkm_ftl"; + public string Description => "ftl helper"; + public string Help => "bkm_ftl "; + public void Execute(IConsoleShell shell, string argStr, string[] args) + { + if (shell.Player?.AttachedEntity == null) + { + shell.WriteLine(Loc.GetString("shell-wrong-invalid-player")); + return; + } + + if (!_entityManager.TryGetComponent(shell.Player.AttachedEntity.Value, + out var mobStateComponent) || mobStateComponent.CurrentState != MobState.Alive) + { + shell.WriteLine(Loc.GetString("shell-wrong-not-alive")); + return; + } + + if(args.Length != 1) + { + shell.WriteLine(Loc.GetString("shell-wrong-arguments-number")); + return; + } + + if (!int.TryParse(args[0], out var ftlInt)) + { + shell.WriteLine(Loc.GetString("shell-entity-uid-must-be-number")); + return; + } + + var gridNet = new NetEntity(ftlInt); + + if (!_entityManager.TryGetEntity(gridNet, out var gridUid)) + { + shell.WriteLine(Loc.GetString("shell-invalid-entity-id")); + return; + } + + var ftl = _entityManager.GetComponentOrNull(gridUid); + + if (ftl == null || !ftl.Enabled || ftl.Whitelist != null || !ftl.BeaconsOnly) + { + shell.WriteLine(Loc.GetString("shell-invalid-ftl-destination")); + return; + } + var ftlTransform = _entityManager.GetComponent(gridUid.Value); + + var performer = shell.Player.AttachedEntity.Value; + + if (!_entityManager.TryGetComponent(performer, out var pilotComponent) || pilotComponent.Console == null) + { + shell.WriteLine(Loc.GetString("shell-invalid-no-pilot")); + return; + } + + var grid = _entityManager.GetComponent(performer); + if (grid.GridUid == null || ftlTransform.MapUid == null) + { + shell.WriteLine(Loc.GetString("shell-invalid-grid")); + return; + } + + Entity shuttle; + + if (_entityManager.TryGetComponent(pilotComponent.Console, out var droneConsoleComponent) && + droneConsoleComponent.Entity != null) + { + shell.WriteLine(Loc.GetString("shell-cant-remote-pilot")); + return; + //shuttle = (droneConsoleComponent.Entity.Value,_entityManager.GetComponent(droneConsoleComponent.Entity.Value)); + } + else + { + shuttle = (grid.GridUid.Value,_entityManager.GetComponent(grid.GridUid.Value)); + } + + if (shuttle.Comp.GridUid == null) + { + shell.WriteLine(Loc.GetString("shell-invalid-shuttle-grid")); + return; + } + + var shuttleSystem = _entityManager.System(); + + if (!shuttleSystem.CanFTL(shuttle.Comp.GridUid.Value, out var reason)) + { + shell.WriteLine(reason); + return; + } + + var transformSystem = _entityManager.System(); + + var targetMap = transformSystem.GetMapCoordinates(gridUid.Value,ftlTransform); + + // Check shuttle can FTL to this target. + if (!shuttleSystem.CanFTLTo(shuttle, targetMap.MapId)) + { + shell.WriteLine(Loc.GetString("shell-invalid-mapid")); + return; + } + + if (!_entityManager.TryGetComponent(shuttle, out PhysicsComponent? shuttlePhysics)) + { + return; + } + + var targetCoordinates = new EntityCoordinates(ftlTransform.MapUid.Value, transformSystem.GetWorldPosition(ftlTransform)); + var targetAngle = Angle.Zero; + + // Client sends the "adjusted" coordinates and we adjust it back to get the actual transform coordinates. + var adjustedCoordinates = targetCoordinates.Offset(targetAngle.RotateVec(-shuttlePhysics.LocalCenter)); + + var tagEv = new FTLTagEvent(); + _entityManager.EventBus.RaiseLocalEvent(shuttle, ref tagEv); + + var ev = new ShuttleConsoleFTLTravelStartEvent(pilotComponent.Console.Value); + _entityManager.EventBus.RaiseEvent(EventSource.Local, ref ev); + + shuttleSystem.FTLToCoordinates(shuttle, + _entityManager.GetComponent(shuttle), + adjustedCoordinates, + targetAngle); + + shell.WriteLine("OK!"); + } + + public CompletionResult GetCompletion(IConsoleShell shell, string[] args) + { + return CompletionResult.FromHintOptions( + CompletionHelper.Components(args[0], _entityManager), + "Точка назначения"); + } +} diff --git a/Content.Server/Backmen/Arrivals/CentcommSystem.cs b/Content.Server/Backmen/Arrivals/CentcommSystem.cs index d878f560318..03c053052d1 100644 --- a/Content.Server/Backmen/Arrivals/CentcommSystem.cs +++ b/Content.Server/Backmen/Arrivals/CentcommSystem.cs @@ -358,13 +358,13 @@ private void OnFtlActionUsed(EntityUid uid, ActorComponent component, CentcomFtl _popup.PopupEntity(Loc.GetString("centcom-ftl-action-no-station"), args.Performer, args.Performer); return; } - +/* if (shuttle.MapUid == centcomm.MapEntity) { _popup.PopupEntity(Loc.GetString("centcom-ftl-action-at-centcomm"), args.Performer, args.Performer); return; } - +*/ if (!_shuttleSystem.CanFTL(shuttle.GridUid.Value, out var reason)) { _popup.PopupEntity(reason, args.Performer, args.Performer);