110 lines
4.0 KiB
C#
110 lines
4.0 KiB
C#
using Content.Server.Administration;
|
|
using Content.Server.Window;
|
|
using Content.Server.Power.Components;
|
|
using Content.Shared.Administration;
|
|
using Content.Shared.Construction;
|
|
using Content.Shared.Tag;
|
|
using Robust.Server.Player;
|
|
using Robust.Shared.Console;
|
|
using Robust.Shared.GameObjects;
|
|
using Robust.Shared.IoC;
|
|
using Robust.Shared.Map;
|
|
using Robust.Shared.Maths;
|
|
|
|
namespace Content.Server.Construction.Commands
|
|
{
|
|
[AdminCommand(AdminFlags.Mapping)]
|
|
class FixRotationsCommand : IConsoleCommand
|
|
{
|
|
// ReSharper disable once StringLiteralTypo
|
|
public string Command => "fixrotations";
|
|
public string Description => "Sets the rotation of all occluders, low walls and windows to south.";
|
|
public string Help => $"Usage: {Command} <gridId> | {Command}";
|
|
|
|
public void Execute(IConsoleShell shell, string argsOther, string[] args)
|
|
{
|
|
var player = shell.Player as IPlayerSession;
|
|
|
|
GridId gridId;
|
|
|
|
switch (args.Length)
|
|
{
|
|
case 0:
|
|
if (player?.AttachedEntity == null)
|
|
{
|
|
shell.WriteLine("Only a player can run this command.");
|
|
return;
|
|
}
|
|
|
|
gridId = IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(player.AttachedEntity).GridID;
|
|
break;
|
|
case 1:
|
|
if (!int.TryParse(args[0], out var id))
|
|
{
|
|
shell.WriteLine($"{args[0]} is not a valid integer.");
|
|
return;
|
|
}
|
|
|
|
gridId = new GridId(id);
|
|
break;
|
|
default:
|
|
shell.WriteLine(Help);
|
|
return;
|
|
}
|
|
|
|
var mapManager = IoCManager.Resolve<IMapManager>();
|
|
if (!mapManager.TryGetGrid(gridId, out var grid))
|
|
{
|
|
shell.WriteLine($"No grid exists with id {gridId}");
|
|
return;
|
|
}
|
|
|
|
var entityManager = IoCManager.Resolve<IEntityManager>();
|
|
if (!entityManager.TryGetEntity(grid.GridEntityId, out var gridEntity))
|
|
{
|
|
shell.WriteLine($"Grid {gridId} doesn't have an associated grid entity.");
|
|
return;
|
|
}
|
|
|
|
var changed = 0;
|
|
foreach (var childUid in IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(gridEntity).ChildEntityUids)
|
|
{
|
|
if (!entityManager.TryGetEntity(childUid, out var childEntity))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
var valid = false;
|
|
|
|
// Occluders should only count if the state of it right now is enabled.
|
|
// This prevents issues with edge firelocks.
|
|
if (entityManager.TryGetComponent<OccluderComponent>(childUid, out var occluder))
|
|
{
|
|
valid |= occluder.Enabled;
|
|
}
|
|
// low walls & grilles
|
|
valid |= IoCManager.Resolve<IEntityManager>().HasComponent<SharedCanBuildWindowOnTopComponent>(childEntity);
|
|
// cables
|
|
valid |= IoCManager.Resolve<IEntityManager>().HasComponent<CableComponent>(childEntity);
|
|
// anything else that might need this forced
|
|
valid |= childEntity.HasTag("ForceFixRotations");
|
|
// override
|
|
valid &= !childEntity.HasTag("ForceNoFixRotations");
|
|
|
|
if (!valid)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
if (IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(childEntity).LocalRotation != Angle.Zero)
|
|
{
|
|
IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(childEntity).LocalRotation = Angle.Zero;
|
|
changed++;
|
|
}
|
|
}
|
|
|
|
shell.WriteLine($"Changed {changed} entities. If things seem wrong, reconnect.");
|
|
}
|
|
}
|
|
}
|