Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Rxup committed Mar 13, 2024
1 parent d0547c6 commit 03c8558
Show file tree
Hide file tree
Showing 2 changed files with 156 additions and 2 deletions.
154 changes: 154 additions & 0 deletions Content.Server/Backmen/Administration/Commands/BkmFtlCommand.cs
Original file line number Diff line number Diff line change
@@ -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 <desinationUid>";
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<MobStateComponent>(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<FTLDestinationComponent>(gridUid);

if (ftl == null || !ftl.Enabled || ftl.Whitelist != null || !ftl.BeaconsOnly)
{
shell.WriteLine(Loc.GetString("shell-invalid-ftl-destination"));
return;
}
var ftlTransform = _entityManager.GetComponent<TransformComponent>(gridUid.Value);

var performer = shell.Player.AttachedEntity.Value;

if (!_entityManager.TryGetComponent<PilotComponent>(performer, out var pilotComponent) || pilotComponent.Console == null)
{
shell.WriteLine(Loc.GetString("shell-invalid-no-pilot"));
return;
}

var grid = _entityManager.GetComponent<TransformComponent>(performer);
if (grid.GridUid == null || ftlTransform.MapUid == null)
{
shell.WriteLine(Loc.GetString("shell-invalid-grid"));
return;
}

Entity<TransformComponent> shuttle;

if (_entityManager.TryGetComponent<DroneConsoleComponent>(pilotComponent.Console, out var droneConsoleComponent) &&
droneConsoleComponent.Entity != null)
{
shell.WriteLine(Loc.GetString("shell-cant-remote-pilot"));
return;
//shuttle = (droneConsoleComponent.Entity.Value,_entityManager.GetComponent<TransformComponent>(droneConsoleComponent.Entity.Value));
}
else
{
shuttle = (grid.GridUid.Value,_entityManager.GetComponent<TransformComponent>(grid.GridUid.Value));
}

if (shuttle.Comp.GridUid == null)
{
shell.WriteLine(Loc.GetString("shell-invalid-shuttle-grid"));
return;
}

var shuttleSystem = _entityManager.System<ShuttleSystem>();

if (!shuttleSystem.CanFTL(shuttle.Comp.GridUid.Value, out var reason))
{
shell.WriteLine(reason);
return;
}

var transformSystem = _entityManager.System<TransformSystem>();

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<ShuttleComponent>(shuttle),
adjustedCoordinates,
targetAngle);

shell.WriteLine("OK!");
}

public CompletionResult GetCompletion(IConsoleShell shell, string[] args)
{
return CompletionResult.FromHintOptions(
CompletionHelper.Components<FTLDestinationComponent>(args[0], _entityManager),
"Точка назначения");
}
}
4 changes: 2 additions & 2 deletions Content.Server/Backmen/Arrivals/CentcommSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 03c8558

Please sign in to comment.