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;
|
2022-05-17 19:11:47 +01:00
|
|
|
using Content.Shared.Tag;
|
2021-02-11 01:13:03 -08:00
|
|
|
using Robust.Server.Player;
|
2021-02-01 16:49:43 -08:00
|
|
|
using Robust.Shared.Console;
|
2020-12-03 03:40:47 +01:00
|
|
|
using Robust.Shared.Map;
|
|
|
|
|
|
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}";
|
|
|
|
|
|
2023-08-13 20:26:59 -04:00
|
|
|
[ValidatePrototypeId<ContentTileDefinition>]
|
2022-10-30 02:48:53 -04:00
|
|
|
public const string TilePrototypeId = "Plating";
|
2023-08-13 20:26:59 -04:00
|
|
|
|
|
|
|
|
[ValidatePrototypeId<TagPrototype>]
|
2022-05-17 19:11:47 +01:00
|
|
|
public const string WallTag = "Wall";
|
|
|
|
|
|
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>();
|
2022-06-20 12:14:35 +12:00
|
|
|
EntityUid? gridId;
|
2020-12-03 03:40:47 +01:00
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-20 12:14:35 +12:00
|
|
|
gridId = entityManager.GetComponent<TransformComponent>(playerEntity).GridUid;
|
2020-12-03 03:40:47 +01:00
|
|
|
break;
|
|
|
|
|
case 1:
|
2022-06-11 18:54:41 -07:00
|
|
|
if (!EntityUid.TryParse(args[0], out var id))
|
2020-12-03 03:40:47 +01:00
|
|
|
{
|
2022-06-11 18:54:41 -07:00
|
|
|
shell.WriteLine($"{args[0]} is not a valid entity.");
|
2020-12-03 03:40:47 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-11 18:54:41 -07:00
|
|
|
gridId = id;
|
2020-12-03 03:40:47 +01:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-12 14:59:02 +11:00
|
|
|
if (!entityManager.EntityExists(grid.Owner))
|
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>();
|
2022-10-30 02:48:53 -04:00
|
|
|
var tagSystem = entityManager.EntitySysManager.GetEntitySystem<TagSystem>();
|
|
|
|
|
var underplating = tileDefinitionManager[TilePrototypeId];
|
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;
|
2022-12-12 14:59:02 +11:00
|
|
|
foreach (var child in entityManager.GetComponent<TransformComponent>(grid.Owner).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;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-17 19:11:47 +01:00
|
|
|
if (!tagSystem.HasTag(child, WallTag))
|
2020-12-03 03:40:47 +01:00
|
|
|
{
|
|
|
|
|
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-10-30 02:48:53 -04:00
|
|
|
if (tileDef.ID == TilePrototypeId)
|
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
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|