Files
tbd-station-14/Content.Server/Administration/Commands/BQL/ForAllCommand.cs
moonheart08 89bbb71f75 ForAll command! (#4982)
* ForAll command!
Implements "Bad Query Language", which has a few specifiers you can use for badminning, namely:
named <regex>
prototyped <prototype name>
with <component name>
tagged <tag name>
parented_to <parent entity uid>

For example: forall prototyped MobHuman parented_to 855 do explode $WX $WY 1 1 1 1; addcomp $ID Item

* oops

* fix a silent parsing bug, make parser louder.

* cleanup

* rename shit
2021-10-23 19:15:40 +02:00

39 lines
1.2 KiB
C#

using System;
using System.Linq;
using Content.Server.Commands;
using Content.Shared.Administration;
using Robust.Shared.Console;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
namespace Content.Server.Administration.Commands.BQL
{
[AdminCommand(AdminFlags.Admin)]
public class ForAllCommand : IConsoleCommand
{
public string Command => "forall";
public string Description => "Runs a command over all entities with a given component";
public string Help => "Usage: forall <comp> <command...>";
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
if (args.Length < 2)
{
shell.WriteLine(Help);
return;
}
var entityManager = IoCManager.Resolve<IEntityManager>();
var (command, entities) = BqlParser.DoEntityQuery(argStr[6..], entityManager);
foreach (var ent in entities.ToList())
{
var cmds = CommandUtils.SubstituteEntityDetails(shell, ent, command).Split(";");
foreach (var cmd in cmds)
{
shell.ExecuteCommand(cmd);
}
}
}
}
}