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
This commit is contained in:
moonheart08
2021-10-23 12:15:40 -05:00
committed by GitHub
parent 328b3b2b6a
commit 89bbb71f75
3 changed files with 238 additions and 0 deletions

View File

@@ -0,0 +1,38 @@
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);
}
}
}
}
}