Underplating, go away (#8138)
This commit is contained in:
88
Content.Server/Construction/Commands/TileReplaceCommand.cs
Normal file
88
Content.Server/Construction/Commands/TileReplaceCommand.cs
Normal file
@@ -0,0 +1,88 @@
|
||||
using Content.Server.Administration;
|
||||
using Content.Shared.Administration;
|
||||
using Content.Shared.Maps;
|
||||
using Content.Shared.Tag;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.Console;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Server.Construction.Commands;
|
||||
|
||||
[AdminCommand(AdminFlags.Mapping)]
|
||||
sealed class TileReplaceCommand : IConsoleCommand
|
||||
{
|
||||
// ReSharper disable once StringLiteralTypo
|
||||
public string Command => "tilereplace";
|
||||
public string Description => "Replaces one tile with another.";
|
||||
public string Help => $"Usage: {Command} [<gridId>] <src> <dst>";
|
||||
|
||||
public void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||
{
|
||||
var player = shell.Player as IPlayerSession;
|
||||
var entityManager = IoCManager.Resolve<IEntityManager>();
|
||||
GridId gridId;
|
||||
string tileIdA = "";
|
||||
string tileIdB = "";
|
||||
|
||||
switch (args.Length)
|
||||
{
|
||||
case 2:
|
||||
if (player?.AttachedEntity is not {Valid: true} playerEntity)
|
||||
{
|
||||
shell.WriteLine("Only a player can run this command without a grid ID.");
|
||||
return;
|
||||
}
|
||||
|
||||
gridId = entityManager.GetComponent<TransformComponent>(playerEntity).GridID;
|
||||
tileIdA = args[0];
|
||||
tileIdB = args[1];
|
||||
break;
|
||||
case 3:
|
||||
if (!int.TryParse(args[0], out var id))
|
||||
{
|
||||
shell.WriteLine($"{args[0]} is not a valid integer.");
|
||||
return;
|
||||
}
|
||||
|
||||
gridId = new GridId(id);
|
||||
tileIdA = args[1];
|
||||
tileIdB = args[2];
|
||||
break;
|
||||
default:
|
||||
shell.WriteLine(Help);
|
||||
return;
|
||||
}
|
||||
|
||||
var tileDefinitionManager = IoCManager.Resolve<ITileDefinitionManager>();
|
||||
var tileA = tileDefinitionManager[tileIdA];
|
||||
var tileB = tileDefinitionManager[tileIdB];
|
||||
|
||||
var mapManager = IoCManager.Resolve<IMapManager>();
|
||||
if (!mapManager.TryGetGrid(gridId, out var grid))
|
||||
{
|
||||
shell.WriteLine($"No grid exists with id {gridId}");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!entityManager.EntityExists(grid.GridEntityId))
|
||||
{
|
||||
shell.WriteLine($"Grid {gridId} doesn't have an associated grid entity.");
|
||||
return;
|
||||
}
|
||||
|
||||
var changed = 0;
|
||||
foreach (var tile in grid.GetAllTiles())
|
||||
{
|
||||
var tileContent = tile.Tile;
|
||||
if (tileContent.TypeId == tileA.TileId)
|
||||
{
|
||||
grid.SetTile(tile.GridIndices, new Tile(tileB.TileId));
|
||||
changed++;
|
||||
}
|
||||
}
|
||||
|
||||
shell.WriteLine($"Changed {changed} tiles.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Content.Server.Administration;
|
||||
using Content.Shared.Administration;
|
||||
using Content.Shared.Maps;
|
||||
using Content.Shared.Tag;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.Console;
|
||||
using Robust.Shared.Map;
|
||||
@@ -16,6 +17,9 @@ namespace Content.Server.Construction.Commands
|
||||
public string Description => "Puts an underplating tile below every wall on a grid.";
|
||||
public string Help => $"Usage: {Command} <gridId> | {Command}";
|
||||
|
||||
public const string TilePrototypeID = "plating";
|
||||
public const string WallTag = "Wall";
|
||||
|
||||
public void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||
{
|
||||
var player = shell.Player as IPlayerSession;
|
||||
@@ -61,8 +65,8 @@ namespace Content.Server.Construction.Commands
|
||||
}
|
||||
|
||||
var tileDefinitionManager = IoCManager.Resolve<ITileDefinitionManager>();
|
||||
var prototypeManager = IoCManager.Resolve<IPrototypeManager>();
|
||||
var underplating = tileDefinitionManager["underplating"];
|
||||
var tagSystem = EntitySystem.Get<TagSystem>();
|
||||
var underplating = tileDefinitionManager[TilePrototypeID];
|
||||
var underplatingTile = new Tile(underplating.TileId);
|
||||
var changed = 0;
|
||||
foreach (var child in entityManager.GetComponent<TransformComponent>(grid.GridEntityId).ChildEntities)
|
||||
@@ -72,18 +76,7 @@ namespace Content.Server.Construction.Commands
|
||||
continue;
|
||||
}
|
||||
|
||||
var prototype = entityManager.GetComponent<MetaDataComponent>(child).EntityPrototype;
|
||||
while (true)
|
||||
{
|
||||
if (prototype?.Parent == null)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
prototype = prototypeManager.Index<EntityPrototype>(prototype.Parent);
|
||||
}
|
||||
|
||||
if (prototype?.ID != "base_wall")
|
||||
if (!tagSystem.HasTag(child, WallTag))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -98,7 +91,7 @@ namespace Content.Server.Construction.Commands
|
||||
var tile = grid.GetTileRef(childTransform.Coordinates);
|
||||
var tileDef = (ContentTileDefinition) tileDefinitionManager[tile.Tile.TypeId];
|
||||
|
||||
if (tileDef.ID == "underplating")
|
||||
if (tileDef.ID == TilePrototypeID)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user