Files
OldThink/Content.Server/Administration/Commands/VariantizeCommand.cs

50 lines
1.5 KiB
C#
Raw Normal View History

using Content.Shared.Administration;
2022-03-09 13:59:44 -06:00
using Content.Shared.Maps;
using Robust.Shared.Console;
using Robust.Shared.Map;
using Robust.Shared.Map.Components;
2022-03-09 13:59:44 -06:00
using Robust.Shared.Random;
namespace Content.Server.Administration.Commands;
[AdminCommand(AdminFlags.Mapping)]
public sealed class VariantizeCommand : IConsoleCommand
{
public string Command => "variantize";
public string Description => Loc.GetString("variantize-command-description");
public string Help => Loc.GetString("variantize-command-help-text");
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
if (args.Length != 1)
{
shell.WriteError(Loc.GetString("shell-wrong-arguments-number"));
return;
}
var entMan = IoCManager.Resolve<IEntityManager>();
2022-03-09 13:59:44 -06:00
var random = IoCManager.Resolve<IRobustRandom>();
2022-07-02 20:29:47 -05:00
if (!EntityUid.TryParse(args[0], out var euid))
2022-03-09 13:59:44 -06:00
{
shell.WriteError($"Failed to parse euid '{args[0]}'.");
2022-03-09 13:59:44 -06:00
return;
}
if (!entMan.TryGetComponent(euid, out MapGridComponent? gridComp))
2022-03-09 13:59:44 -06:00
{
shell.WriteError($"Euid '{euid}' does not exist or is not a grid.");
2022-03-09 13:59:44 -06:00
return;
}
foreach (var tile in gridComp.GetAllTiles())
2022-03-09 13:59:44 -06:00
{
var def = tile.GetContentTileDefinition();
var newTile = new Tile(tile.Tile.TypeId, tile.Tile.Flags, def.PickVariant(random));
gridComp.SetTile(tile.GridIndices, newTile);
2022-03-09 13:59:44 -06:00
}
}
}