Add command to add underplating to all walls on a grid (#1644)
This commit is contained in:
@@ -6,10 +6,15 @@ using Content.Server.Interfaces.GameTicking;
|
||||
using Content.Server.Players;
|
||||
using Content.Shared.BodySystem;
|
||||
using Content.Shared.Jobs;
|
||||
using Content.Shared.Maps;
|
||||
using Robust.Server.Interfaces.Console;
|
||||
using Robust.Server.Interfaces.Player;
|
||||
using Robust.Shared.GameObjects.Components.Transform;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Interfaces.Map;
|
||||
using Robust.Shared.Interfaces.Random;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Network;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Random;
|
||||
@@ -377,7 +382,7 @@ namespace Content.Server.GameTicking
|
||||
{
|
||||
if (player == null)
|
||||
{
|
||||
shell.SendText(player, "Only a player can run this command.");
|
||||
shell.SendText((IPlayerSession) null, "Only a player can run this command.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -400,4 +405,102 @@ namespace Content.Server.GameTicking
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class TileWallsCommand : IClientCommand
|
||||
{
|
||||
// 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}";
|
||||
|
||||
public void Execute(IConsoleShell shell, IPlayerSession player, string[] args)
|
||||
{
|
||||
GridId gridId;
|
||||
|
||||
switch (args.Length)
|
||||
{
|
||||
case 0:
|
||||
if (player?.AttachedEntity == null)
|
||||
{
|
||||
shell.SendText((IPlayerSession) null, "Only a player can run this command.");
|
||||
return;
|
||||
}
|
||||
|
||||
gridId = player.AttachedEntity.Transform.GridID;
|
||||
break;
|
||||
case 1:
|
||||
if (!int.TryParse(args[0], out var id))
|
||||
{
|
||||
shell.SendText(player, $"{args[0]} is not a valid integer.");
|
||||
return;
|
||||
}
|
||||
|
||||
gridId = new GridId(id);
|
||||
break;
|
||||
default:
|
||||
shell.SendText(player, Help);
|
||||
return;
|
||||
}
|
||||
|
||||
var mapManager = IoCManager.Resolve<IMapManager>();
|
||||
if (!mapManager.TryGetGrid(gridId, out var grid))
|
||||
{
|
||||
shell.SendText(player, $"No grid exists with id {gridId}");
|
||||
return;
|
||||
}
|
||||
|
||||
var entityManager = IoCManager.Resolve<IEntityManager>();
|
||||
if (!entityManager.TryGetEntity(grid.GridEntityId, out var gridEntity))
|
||||
{
|
||||
shell.SendText(player, $"Grid {gridId} doesn't have an associated grid entity.");
|
||||
return;
|
||||
}
|
||||
|
||||
var tileDefinitionManager = IoCManager.Resolve<ITileDefinitionManager>();
|
||||
var underplating = tileDefinitionManager["underplating"];
|
||||
var underplatingTile = new Tile(underplating.TileId);
|
||||
var changed = 0;
|
||||
foreach (var childUid in gridEntity.Transform.ChildEntityUids)
|
||||
{
|
||||
if (!entityManager.TryGetEntity(childUid, out var childEntity))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var prototype = childEntity.Prototype;
|
||||
while (true)
|
||||
{
|
||||
if (prototype?.Parent == null)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
prototype = prototype.Parent;
|
||||
}
|
||||
|
||||
if (prototype?.ID != "base_wall")
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!childEntity.TryGetComponent(out SnapGridComponent snapGrid))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var tile = grid.GetTileRef(childEntity.Transform.GridPosition);
|
||||
var tileDef = (ContentTileDefinition) tileDefinitionManager[tile.Tile.TypeId];
|
||||
|
||||
if (tileDef.Name == "underplating")
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
grid.SetTile(childEntity.Transform.GridPosition, underplatingTile);
|
||||
changed++;
|
||||
}
|
||||
|
||||
shell.SendText(player, $"Changed {changed} tiles.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,6 +92,7 @@
|
||||
- anchor
|
||||
- unanchor
|
||||
- tubeconnections
|
||||
- tilewalls
|
||||
CanViewVar: true
|
||||
CanAdminPlace: true
|
||||
|
||||
@@ -179,6 +180,7 @@
|
||||
- clearatmos
|
||||
- settemp
|
||||
- setatmostemp
|
||||
- tilewalls
|
||||
CanViewVar: true
|
||||
CanAdminPlace: true
|
||||
CanScript: true
|
||||
|
||||
Reference in New Issue
Block a user