1
0

TilePryCommand.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. using System.Numerics;
  2. using Content.Server.Administration;
  3. using Content.Shared.Administration;
  4. using Content.Shared.Maps;
  5. using Robust.Shared.Console;
  6. using Robust.Shared.Map;
  7. using Robust.Shared.Map.Components;
  8. namespace Content.Server.Interaction;
  9. [AdminCommand(AdminFlags.Debug)]
  10. public sealed class TilePryCommand : IConsoleCommand
  11. {
  12. [Dependency] private readonly IEntityManager _entities = default!;
  13. public string Command => "tilepry";
  14. public string Description => "Pries up all tiles in a radius around the user.";
  15. public string Help => $"Usage: {Command} <radius>";
  16. public void Execute(IConsoleShell shell, string argStr, string[] args)
  17. {
  18. var player = shell.Player;
  19. if (player?.AttachedEntity is not { } attached)
  20. {
  21. return;
  22. }
  23. if (args.Length != 1)
  24. {
  25. shell.WriteLine(Help);
  26. return;
  27. }
  28. if (!int.TryParse(args[0], out var radius))
  29. {
  30. shell.WriteError($"{args[0]} isn't a valid integer.");
  31. return;
  32. }
  33. if (radius < 0)
  34. {
  35. shell.WriteError("Radius must be positive.");
  36. return;
  37. }
  38. var mapSystem = _entities.System<SharedMapSystem>();
  39. var xform = _entities.GetComponent<TransformComponent>(attached);
  40. var playerGrid = xform.GridUid;
  41. if (!_entities.TryGetComponent<MapGridComponent>(playerGrid, out var mapGrid))
  42. return;
  43. var playerPosition = xform.Coordinates;
  44. var tileDefinitionManager = IoCManager.Resolve<ITileDefinitionManager>();
  45. for (var i = -radius; i <= radius; i++)
  46. {
  47. for (var j = -radius; j <= radius; j++)
  48. {
  49. var tile = mapSystem.GetTileRef(playerGrid.Value, mapGrid, playerPosition.Offset(new Vector2(i, j)));
  50. var coordinates = mapSystem.GridTileToLocal(playerGrid.Value, mapGrid, tile.GridIndices);
  51. var tileDef = (ContentTileDefinition)tileDefinitionManager[tile.Tile.TypeId];
  52. if (!tileDef.CanCrowbar) continue;
  53. var plating = tileDefinitionManager["Plating"];
  54. mapSystem.SetTile(playerGrid.Value, mapGrid, coordinates, new Tile(plating.TileId));
  55. }
  56. }
  57. }
  58. }