using System.Linq; using Content.Server.Administration; using Content.Server.GameTicking.Rules; using Content.Shared.Administration; using Robust.Shared.Prototypes; using Robust.Shared.Toolshed; namespace Content.Server.GameTicking.Commands; [ToolshedCommand, AdminCommand(AdminFlags.Round)] public sealed class DynamicRuleCommand : ToolshedCommand { private DynamicRuleSystem? _dynamicRuleSystem; [CommandImplementation("list")] public IEnumerable List() { _dynamicRuleSystem ??= GetSys(); return _dynamicRuleSystem.GetDynamicRules(); } [CommandImplementation("get")] public EntityUid Get() { _dynamicRuleSystem ??= GetSys(); return _dynamicRuleSystem.GetDynamicRules().FirstOrDefault(); } [CommandImplementation("budget")] public IEnumerable Budget([PipedArgument] IEnumerable input) => input.Select(Budget); [CommandImplementation("budget")] public float? Budget([PipedArgument] EntityUid input) { _dynamicRuleSystem ??= GetSys(); return _dynamicRuleSystem.GetRuleBudget(input); } [CommandImplementation("adjust")] public IEnumerable Adjust([PipedArgument] IEnumerable input, float value) => input.Select(i => Adjust(i,value)); [CommandImplementation("adjust")] public float? Adjust([PipedArgument] EntityUid input, float value) { _dynamicRuleSystem ??= GetSys(); return _dynamicRuleSystem.AdjustBudget(input, value); } [CommandImplementation("set")] public IEnumerable Set([PipedArgument] IEnumerable input, float value) => input.Select(i => Set(i,value)); [CommandImplementation("set")] public float? Set([PipedArgument] EntityUid input, float value) { _dynamicRuleSystem ??= GetSys(); return _dynamicRuleSystem.SetBudget(input, value); } [CommandImplementation("dryrun")] public IEnumerable> DryRun([PipedArgument] IEnumerable input) => input.Select(DryRun); [CommandImplementation("dryrun")] public IEnumerable DryRun([PipedArgument] EntityUid input) { _dynamicRuleSystem ??= GetSys(); return _dynamicRuleSystem.DryRun(input); } [CommandImplementation("executenow")] public IEnumerable> ExecuteNow([PipedArgument] IEnumerable input) => input.Select(ExecuteNow); [CommandImplementation("executenow")] public IEnumerable ExecuteNow([PipedArgument] EntityUid input) { _dynamicRuleSystem ??= GetSys(); return _dynamicRuleSystem.ExecuteNow(input); } [CommandImplementation("rules")] public IEnumerable> Rules([PipedArgument] IEnumerable input) => input.Select(Rules); [CommandImplementation("rules")] public IEnumerable Rules([PipedArgument] EntityUid input) { _dynamicRuleSystem ??= GetSys(); return _dynamicRuleSystem.Rules(input); } }