2021-02-01 16:49:43 -08:00
|
|
|
using Content.Server.Administration;
|
2020-12-03 03:40:47 +01:00
|
|
|
using Content.Shared.Administration;
|
|
|
|
|
using Content.Shared.Maps;
|
2021-02-11 01:13:03 -08:00
|
|
|
using Robust.Server.Player;
|
2021-02-01 16:49:43 -08:00
|
|
|
using Robust.Shared.Console;
|
2021-02-11 01:13:03 -08:00
|
|
|
using Robust.Shared.GameObjects;
|
2020-12-03 03:40:47 +01:00
|
|
|
using Robust.Shared.IoC;
|
|
|
|
|
using Robust.Shared.Map;
|
2021-03-05 01:08:38 +01:00
|
|
|
using Robust.Shared.Prototypes;
|
2020-12-03 03:40:47 +01:00
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Server.Construction.Commands
|
2020-12-03 03:40:47 +01:00
|
|
|
{
|
|
|
|
|
[AdminCommand(AdminFlags.Mapping)]
|
2022-02-16 00:23:23 -07:00
|
|
|
sealed class TileWallsCommand : IConsoleCommand
|
2020-12-03 03:40:47 +01:00
|
|
|
{
|
|
|
|
|
// ReSharper disable once StringLiteralTypo
|
|
|
|
|
public string Command => "tilewalls";
|
|
|
|
|
public string Description => "Puts an underplating tile below every wall on a grid.";
|
|
|
|
|
public string Help => $"Usage: {Command} <gridId> | {Command}";
|
|
|
|
|
|
2021-02-01 16:49:43 -08:00
|
|
|
public void Execute(IConsoleShell shell, string argStr, string[] args)
|
2020-12-03 03:40:47 +01:00
|
|
|
{
|
2021-02-01 16:49:43 -08:00
|
|
|
var player = shell.Player as IPlayerSession;
|
2021-12-05 18:09:01 +01:00
|
|
|
var entityManager = IoCManager.Resolve<IEntityManager>();
|
2020-12-03 03:40:47 +01:00
|
|
|
GridId gridId;
|
|
|
|
|
|
|
|
|
|
switch (args.Length)
|
|
|
|
|
{
|
|
|
|
|
case 0:
|
2021-12-05 18:09:01 +01:00
|
|
|
if (player?.AttachedEntity is not {Valid: true} playerEntity)
|
2020-12-03 03:40:47 +01:00
|
|
|
{
|
2021-02-01 16:49:43 -08:00
|
|
|
shell.WriteLine("Only a player can run this command.");
|
2020-12-03 03:40:47 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-05 18:09:01 +01:00
|
|
|
gridId = entityManager.GetComponent<TransformComponent>(playerEntity).GridID;
|
2020-12-03 03:40:47 +01:00
|
|
|
break;
|
|
|
|
|
case 1:
|
|
|
|
|
if (!int.TryParse(args[0], out var id))
|
|
|
|
|
{
|
2021-02-01 16:49:43 -08:00
|
|
|
shell.WriteLine($"{args[0]} is not a valid integer.");
|
2020-12-03 03:40:47 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gridId = new GridId(id);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
2021-02-01 16:49:43 -08:00
|
|
|
shell.WriteLine(Help);
|
2020-12-03 03:40:47 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var mapManager = IoCManager.Resolve<IMapManager>();
|
|
|
|
|
if (!mapManager.TryGetGrid(gridId, out var grid))
|
|
|
|
|
{
|
2021-02-01 16:49:43 -08:00
|
|
|
shell.WriteLine($"No grid exists with id {gridId}");
|
2020-12-03 03:40:47 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-05 18:09:01 +01:00
|
|
|
if (!entityManager.EntityExists(grid.GridEntityId))
|
2020-12-03 03:40:47 +01:00
|
|
|
{
|
2021-02-01 16:49:43 -08:00
|
|
|
shell.WriteLine($"Grid {gridId} doesn't have an associated grid entity.");
|
2020-12-03 03:40:47 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var tileDefinitionManager = IoCManager.Resolve<ITileDefinitionManager>();
|
2021-03-05 01:08:38 +01:00
|
|
|
var prototypeManager = IoCManager.Resolve<IPrototypeManager>();
|
2020-12-03 03:40:47 +01:00
|
|
|
var underplating = tileDefinitionManager["underplating"];
|
2021-12-05 18:09:01 +01:00
|
|
|
var underplatingTile = new Tile(underplating.TileId);
|
2020-12-03 03:40:47 +01:00
|
|
|
var changed = 0;
|
2021-12-05 18:09:01 +01:00
|
|
|
foreach (var child in entityManager.GetComponent<TransformComponent>(grid.GridEntityId).ChildEntities)
|
2020-12-03 03:40:47 +01:00
|
|
|
{
|
2021-12-05 18:09:01 +01:00
|
|
|
if (!entityManager.EntityExists(child))
|
2020-12-03 03:40:47 +01:00
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-08 17:04:21 +01:00
|
|
|
var prototype = entityManager.GetComponent<MetaDataComponent>(child).EntityPrototype;
|
2020-12-03 03:40:47 +01:00
|
|
|
while (true)
|
|
|
|
|
{
|
|
|
|
|
if (prototype?.Parent == null)
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-05 01:08:38 +01:00
|
|
|
prototype = prototypeManager.Index<EntityPrototype>(prototype.Parent);
|
2020-12-03 03:40:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (prototype?.ID != "base_wall")
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-08 17:04:21 +01:00
|
|
|
var childTransform = entityManager.GetComponent<TransformComponent>(child);
|
|
|
|
|
|
|
|
|
|
if (!childTransform.Anchored)
|
2020-12-03 03:40:47 +01:00
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-08 17:04:21 +01:00
|
|
|
var tile = grid.GetTileRef(childTransform.Coordinates);
|
2020-12-03 03:40:47 +01:00
|
|
|
var tileDef = (ContentTileDefinition) tileDefinitionManager[tile.Tile.TypeId];
|
|
|
|
|
|
2022-01-04 16:26:07 -08:00
|
|
|
if (tileDef.ID == "underplating")
|
2020-12-03 03:40:47 +01:00
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-08 17:04:21 +01:00
|
|
|
grid.SetTile(childTransform.Coordinates, underplatingTile);
|
2020-12-03 03:40:47 +01:00
|
|
|
changed++;
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-01 16:49:43 -08:00
|
|
|
shell.WriteLine($"Changed {changed} tiles.");
|
2020-12-03 03:40:47 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|