Files
OldThink/Content.Server/Construction/Commands/FixRotationsCommand.cs

111 lines
3.9 KiB
C#
Raw Normal View History

using Content.Server.Administration;
using Content.Server.Power.Components;
using Content.Shared.Administration;
2021-06-09 22:19:39 +02:00
using Content.Shared.Construction;
using Content.Shared.Tag;
2021-02-12 11:47:14 +01:00
using Robust.Server.Player;
using Robust.Shared.Console;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Maths;
2021-06-09 22:19:39 +02:00
namespace Content.Server.Construction.Commands
{
[AdminCommand(AdminFlags.Mapping)]
sealed 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;
2021-12-05 18:09:01 +01:00
var entityManager = IoCManager.Resolve<IEntityManager>();
GridId gridId;
2022-02-08 14:08:11 +11:00
var xformQuery = entityManager.GetEntityQuery<TransformComponent>();
switch (args.Length)
{
case 0:
2021-12-05 18:09:01 +01:00
if (player?.AttachedEntity is not {Valid: true} playerEntity)
{
2022-02-08 14:08:11 +11:00
shell.WriteError("Only a player can run this command.");
return;
}
2022-02-08 14:08:11 +11:00
gridId = xformQuery.GetComponent(playerEntity).GridID;
break;
case 1:
if (!int.TryParse(args[0], out var id))
{
2022-02-08 14:08:11 +11:00
shell.WriteError($"{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))
{
2022-02-08 14:08:11 +11:00
shell.WriteError($"No grid exists with id {gridId}");
return;
}
2021-12-05 18:09:01 +01:00
if (!entityManager.EntityExists(grid.GridEntityId))
{
2022-02-08 14:08:11 +11:00
shell.WriteError($"Grid {gridId} doesn't have an associated grid entity.");
return;
}
var changed = 0;
2022-02-08 14:08:11 +11:00
var tagSystem = EntitySystem.Get<TagSystem>();
foreach (var child in xformQuery.GetComponent(grid.GridEntityId).ChildEntities)
{
2021-12-05 18:09:01 +01:00
if (!entityManager.EntityExists(child))
{
continue;
}
var valid = false;
// Occluders should only count if the state of it right now is enabled.
// This prevents issues with edge firelocks.
2021-12-05 18:09:01 +01:00
if (entityManager.TryGetComponent<OccluderComponent>(child, out var occluder))
{
valid |= occluder.Enabled;
}
// low walls & grilles
2021-12-05 18:09:01 +01:00
valid |= entityManager.HasComponent<SharedCanBuildWindowOnTopComponent>(child);
// cables
2021-12-05 18:09:01 +01:00
valid |= entityManager.HasComponent<CableComponent>(child);
// anything else that might need this forced
2022-02-08 14:08:11 +11:00
valid |= tagSystem.HasTag(child, "ForceFixRotations");
// override
2022-02-08 14:08:11 +11:00
valid &= !tagSystem.HasTag(child, "ForceNoFixRotations");
if (!valid)
continue;
2022-02-08 14:08:11 +11:00
var childXform = xformQuery.GetComponent(child);
if (childXform.LocalRotation != Angle.Zero)
{
2022-02-08 14:08:11 +11:00
childXform.LocalRotation = Angle.Zero;
changed++;
}
}
shell.WriteLine($"Changed {changed} entities. If things seem wrong, reconnect.");
}
}
}