2023-07-08 14:08:32 +10:00
|
|
|
using System.Numerics;
|
2020-12-03 03:40:47 +01:00
|
|
|
using Content.Server.Administration;
|
|
|
|
|
using Content.Shared.Administration;
|
|
|
|
|
using Content.Shared.Maps;
|
2021-02-01 16:49:43 -08:00
|
|
|
using Robust.Shared.Console;
|
2020-12-03 03:40:47 +01:00
|
|
|
using Robust.Shared.Map;
|
2024-03-22 03:08:40 -04:00
|
|
|
using Robust.Shared.Map.Components;
|
2025-06-17 05:39:42 -04:00
|
|
|
using Robust.Shared.Prototypes;
|
2020-12-03 03:40:47 +01:00
|
|
|
|
2024-08-22 18:10:13 -07:00
|
|
|
namespace Content.Server.Interaction;
|
|
|
|
|
|
|
|
|
|
[AdminCommand(AdminFlags.Debug)]
|
2025-06-17 05:39:42 -04:00
|
|
|
public sealed class TilePryCommand : LocalizedEntityCommands
|
2020-12-03 03:40:47 +01:00
|
|
|
{
|
2025-06-17 05:39:42 -04:00
|
|
|
[Dependency] private readonly ITileDefinitionManager _tileDefinitionManager = default!;
|
|
|
|
|
[Dependency] private readonly SharedMapSystem _mapSystem = default!;
|
2021-12-05 21:02:04 +01:00
|
|
|
|
2025-06-17 05:39:42 -04:00
|
|
|
private readonly string _platingId = "Plating";
|
2020-12-03 03:40:47 +01:00
|
|
|
|
2025-06-17 05:39:42 -04:00
|
|
|
public override string Command => "tilepry";
|
|
|
|
|
|
|
|
|
|
public override void Execute(IConsoleShell shell, string argStr, string[] args)
|
2024-08-22 18:10:13 -07:00
|
|
|
{
|
|
|
|
|
var player = shell.Player;
|
|
|
|
|
if (player?.AttachedEntity is not { } attached)
|
2020-12-03 03:40:47 +01:00
|
|
|
{
|
2024-08-22 18:10:13 -07:00
|
|
|
return;
|
|
|
|
|
}
|
2020-12-03 03:40:47 +01:00
|
|
|
|
2024-08-22 18:10:13 -07:00
|
|
|
if (args.Length != 1)
|
|
|
|
|
{
|
|
|
|
|
shell.WriteLine(Help);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-12-03 03:40:47 +01:00
|
|
|
|
2024-08-22 18:10:13 -07:00
|
|
|
if (!int.TryParse(args[0], out var radius))
|
|
|
|
|
{
|
2025-06-17 05:39:42 -04:00
|
|
|
shell.WriteError(Loc.GetString($"cmd-tilepry-arg-must-be-number", ("arg", args[0])));
|
2024-08-22 18:10:13 -07:00
|
|
|
return;
|
|
|
|
|
}
|
2020-12-03 03:40:47 +01:00
|
|
|
|
2024-08-22 18:10:13 -07:00
|
|
|
if (radius < 0)
|
|
|
|
|
{
|
2025-06-17 05:39:42 -04:00
|
|
|
shell.WriteError(Loc.GetString($"cmd-tilepry-radius-must-be-positive"));
|
2024-08-22 18:10:13 -07:00
|
|
|
return;
|
|
|
|
|
}
|
2020-12-03 03:40:47 +01:00
|
|
|
|
2025-06-17 05:39:42 -04:00
|
|
|
var xform = EntityManager.GetComponent<TransformComponent>(attached);
|
2022-06-20 12:14:35 +12:00
|
|
|
|
2024-08-22 18:10:13 -07:00
|
|
|
var playerGrid = xform.GridUid;
|
2022-06-20 12:14:35 +12:00
|
|
|
|
2025-06-17 05:39:42 -04:00
|
|
|
if (!EntityManager.TryGetComponent<MapGridComponent>(playerGrid, out var mapGrid))
|
2024-08-22 18:10:13 -07:00
|
|
|
return;
|
2020-12-03 03:40:47 +01:00
|
|
|
|
2024-08-22 18:10:13 -07:00
|
|
|
var playerPosition = xform.Coordinates;
|
|
|
|
|
|
|
|
|
|
for (var i = -radius; i <= radius; i++)
|
|
|
|
|
{
|
|
|
|
|
for (var j = -radius; j <= radius; j++)
|
2020-12-03 03:40:47 +01:00
|
|
|
{
|
2025-06-17 05:39:42 -04:00
|
|
|
var tile = _mapSystem.GetTileRef(playerGrid.Value, mapGrid, playerPosition.Offset(new Vector2(i, j)));
|
|
|
|
|
var coordinates = _mapSystem.GridTileToLocal(playerGrid.Value, mapGrid, tile.GridIndices);
|
|
|
|
|
var tileDef = (ContentTileDefinition)_tileDefinitionManager[tile.Tile.TypeId];
|
2020-12-03 03:40:47 +01:00
|
|
|
|
2025-06-17 05:39:42 -04:00
|
|
|
if (!tileDef.CanCrowbar)
|
|
|
|
|
continue;
|
2020-12-03 03:40:47 +01:00
|
|
|
|
2025-06-17 05:39:42 -04:00
|
|
|
var plating = _tileDefinitionManager[_platingId];
|
|
|
|
|
_mapSystem.SetTile(playerGrid.Value, mapGrid, coordinates, new Tile(plating.TileId));
|
2020-12-03 03:40:47 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|