From cc8458f23c539189da5dbf70d7fc6bccfc137d92 Mon Sep 17 00:00:00 2001 From: 20kdc Date: Fri, 12 Feb 2021 10:13:32 +0000 Subject: [PATCH] Add "fixrotations" command to fix rotations of walls/windows/low walls (#3069) * Add "fixrotations" command to fix rotations of walls/windows/low walls * fixrotations: Migrate command to new command structure --- .../GameTicking/FixRotationsCommand.cs | 100 ++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 Content.Server/Commands/GameTicking/FixRotationsCommand.cs diff --git a/Content.Server/Commands/GameTicking/FixRotationsCommand.cs b/Content.Server/Commands/GameTicking/FixRotationsCommand.cs new file mode 100644 index 0000000000..683f3346eb --- /dev/null +++ b/Content.Server/Commands/GameTicking/FixRotationsCommand.cs @@ -0,0 +1,100 @@ +using Content.Server.Administration; +using Content.Shared.GameObjects.Components; +using Content.Server.GameObjects.Components; +using Content.Shared.Administration; +using Content.Shared.Maps; +using Robust.Server.Interfaces.Player; +using Robust.Shared.Console; +using Robust.Shared.GameObjects.Components.Transform; +using Robust.Shared.GameObjects; +using Robust.Shared.Interfaces.GameObjects; +using Robust.Shared.Interfaces.Map; +using Robust.Shared.IoC; +using Robust.Shared.Map; +using Robust.Shared.Maths; + +namespace Content.Server.Commands.GameTicking +{ + [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} | {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 = player.AttachedEntity.Transform.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(); + if (!mapManager.TryGetGrid(gridId, out var grid)) + { + shell.WriteLine($"No grid exists with id {gridId}"); + return; + } + + var entityManager = IoCManager.Resolve(); + 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 gridEntity.Transform.ChildEntityUids) + { + if (!entityManager.TryGetEntity(childUid, out var childEntity)) + { + continue; + } + + var valid = false; + + valid |= childEntity.HasComponent(); + valid |= childEntity.HasComponent(); + valid |= childEntity.HasComponent(); + + if (!valid) + { + continue; + } + + if (childEntity.Transform.LocalRotation != Angle.South) + { + childEntity.Transform.LocalRotation = Angle.South; + changed++; + } + } + + shell.WriteLine($"Changed {changed} entities. If things seem wrong, reconnect."); + } + } +}