]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Commands for adding and removing actions (#38317)
authorScarKy0 <106310278+ScarKy0@users.noreply.github.com>
Mon, 16 Jun 2025 10:25:44 +0000 (12:25 +0200)
committerGitHub <noreply@github.com>
Mon, 16 Jun 2025 10:25:44 +0000 (13:25 +0300)
Content.Server/Actions/Commands/AddActionCommand.cs [new file with mode: 0644]
Content.Server/Actions/Commands/RemoveActionCommand.cs [new file with mode: 0644]
Content.Shared/Actions/SharedActionsSystem.cs
Resources/Locale/en-US/actions/commands/addaction.ftl [new file with mode: 0644]
Resources/Locale/en-US/actions/commands/rmaction.ftl [new file with mode: 0644]

diff --git a/Content.Server/Actions/Commands/AddActionCommand.cs b/Content.Server/Actions/Commands/AddActionCommand.cs
new file mode 100644 (file)
index 0000000..c2c471e
--- /dev/null
@@ -0,0 +1,75 @@
+using System.Linq;
+using Content.Server.Administration;
+using Content.Shared.Actions;
+using Content.Shared.Actions.Components;
+using Content.Shared.Administration;
+using Content.Shared.Prototypes;
+using Robust.Shared.Console;
+using Robust.Shared.Prototypes;
+
+namespace Content.Server.Actions.Commands;
+
+[AdminCommand(AdminFlags.Debug)]
+public sealed class AddActionCommand : LocalizedEntityCommands
+{
+    [Dependency] private readonly IPrototypeManager _prototypes = default!;
+    [Dependency] private readonly SharedActionsSystem _actions = default!;
+    [Dependency] private readonly IPrototypeManager _prototypeManager = default!;
+
+    public override string Command => "addaction";
+
+    public override void Execute(IConsoleShell shell, string argStr, string[] args)
+    {
+        if (args.Length != 2)
+        {
+            shell.WriteError(Loc.GetString(Loc.GetString("cmd-addaction-invalid-args")));
+            return;
+        }
+
+        if (!NetEntity.TryParse(args[0], out var targetUidNet) || !EntityManager.TryGetEntity(targetUidNet, out var targetEntity))
+        {
+            shell.WriteLine(Loc.GetString("shell-entity-uid-must-be-number"));
+            return;
+        }
+
+        if (!EntityManager.HasComponent<ActionsComponent>(targetEntity))
+        {
+            shell.WriteError(Loc.GetString("cmd-addaction-actions-not-found"));
+            return;
+        }
+
+        if (!_prototypes.TryIndex<EntityPrototype>(args[1], out var proto) ||
+            !proto.HasComponent<ActionComponent>())
+        {
+            shell.WriteError(Loc.GetString("cmd-addaction-action-not-found", ("action", args[1])));
+            return;
+        }
+
+        if (_actions.AddAction(targetEntity.Value, args[1]) == null)
+        {
+            shell.WriteError(Loc.GetString("cmd-addaction-adding-failed"));
+        }
+    }
+
+    public override CompletionResult GetCompletion(IConsoleShell shell, string[] args)
+    {
+        if (args.Length == 1)
+        {
+            return CompletionResult.FromHintOptions(
+                CompletionHelper.Components<ActionsComponent>(args[0]),
+                Loc.GetString("cmd-addaction-player-completion"));
+        }
+
+        if (args.Length != 2)
+            return CompletionResult.Empty;
+
+        var actionPrototypes = _prototypeManager.EnumeratePrototypes<EntityPrototype>()
+            .Where(p => p.HasComponent<ActionComponent>())
+            .Select(p => p.ID)
+            .Order();
+
+        return CompletionResult.FromHintOptions(
+            actionPrototypes,
+            Loc.GetString("cmd-addaction-action-completion"));
+    }
+}
diff --git a/Content.Server/Actions/Commands/RemoveActionCommand.cs b/Content.Server/Actions/Commands/RemoveActionCommand.cs
new file mode 100644 (file)
index 0000000..541f8f8
--- /dev/null
@@ -0,0 +1,84 @@
+using Content.Server.Administration;
+using Content.Shared.Actions;
+using Content.Shared.Actions.Components;
+using Content.Shared.Administration;
+using Robust.Shared.Console;
+
+namespace Content.Server.Actions.Commands;
+
+[AdminCommand(AdminFlags.Debug)]
+public sealed class RemoveActionCommand : LocalizedEntityCommands
+{
+    [Dependency] private readonly SharedActionsSystem _actions = default!;
+
+    public override string Command => "rmaction";
+
+    public override void Execute(IConsoleShell shell, string argStr, string[] args)
+    {
+        if (args.Length != 2)
+        {
+            shell.WriteError(Loc.GetString(Loc.GetString("cmd-rmaction-invalid-args")));
+            return;
+        }
+
+        if (!NetEntity.TryParse(args[0], out var targetUidNet) || !EntityManager.TryGetEntity(targetUidNet, out var targetEntity))
+        {
+            shell.WriteLine(Loc.GetString("shell-could-not-find-entity-with-uid", ("uid", args[0])));
+            return;
+        }
+
+        if (!NetEntity.TryParse(args[1], out var targetActionUidNet) || !EntityManager.TryGetEntity(targetActionUidNet, out var targetActionEntity))
+        {
+            shell.WriteLine(Loc.GetString("shell-could-not-find-entity-with-uid", ("uid", args[1])));
+            return;
+        }
+
+        if (!EntityManager.HasComponent<ActionsComponent>(targetEntity))
+        {
+            shell.WriteError(Loc.GetString("cmd-rmaction-actions-not-found"));
+            return;
+        }
+
+        if (_actions.GetAction(targetActionEntity) is not { } ent)
+        {
+            shell.WriteError(Loc.GetString("cmd-rmaction-not-an-action"));
+            return;
+        }
+
+        _actions.SetTemporary(ent.Owner, true);
+
+        _actions.RemoveAction(ent.Owner);
+    }
+
+    public override CompletionResult GetCompletion(IConsoleShell shell, string[] args)
+    {
+        if (args.Length == 1)
+        {
+            return CompletionResult.FromHintOptions(
+                CompletionHelper.Components<ActionsComponent>(args[0]),
+                Loc.GetString("cmd-rmaction-player-completion"));
+        }
+
+        if (args.Length == 2)
+        {
+            if (!NetEntity.TryParse(args[0], out var targetUidNet) || !EntityManager.TryGetEntity(targetUidNet, out var targetEntity))
+                return CompletionResult.Empty;
+
+            if (!EntityManager.HasComponent<ActionsComponent>(targetEntity))
+                return CompletionResult.Empty;
+
+            var actions = _actions.GetActions(targetEntity.Value);
+
+            var options = new List<CompletionOption>();
+            foreach (var action in actions)
+            {
+                var hint = Loc.GetString("cmd-rmaction-action-info", ("action", action));
+                options.Add(new CompletionOption(action.Owner.ToString(), hint));
+            }
+
+            return CompletionResult.FromHintOptions(options, Loc.GetString("cmd-rmaction-action-completion"));
+        }
+
+        return CompletionResult.Empty;
+    }
+}
index 583bd177dcebc40927b5768aa8df14525432350e..ad93d6c99843bd5966f9127cb785ff2cd3325140 100644 (file)
@@ -1019,4 +1019,17 @@ public abstract class SharedActionsSystem : EntitySystem
         // TODO: Check for charge recovery timer
         return action.Cooldown.HasValue && action.Cooldown.Value.End > curTime;
     }
+
+    /// <summary>
+    /// Marks the action as temporary.
+    /// Temporary actions get deleted upon being removed from an entity.
+    /// </summary>
+    public void SetTemporary(Entity<ActionComponent?> ent, bool temporary)
+    {
+        if (!Resolve(ent.Owner, ref ent.Comp, false))
+            return;
+
+        ent.Comp.Temporary = temporary;
+        Dirty(ent);
+    }
 }
diff --git a/Resources/Locale/en-US/actions/commands/addaction.ftl b/Resources/Locale/en-US/actions/commands/addaction.ftl
new file mode 100644 (file)
index 0000000..be1cbf2
--- /dev/null
@@ -0,0 +1,11 @@
+# addaction
+cmd-addaction-desc = Adds an action to the target entity. The action will not work if the target requires an additional component on their entity (such as Dragon's Devour).
+cmd-addaction-help = addaction <EntityUid> <ActionPrototype>
+
+cmd-addaction-invalid-args = Expected exactly 2 arguments.
+cmd-addaction-actions-not-found = Target entity cannot use actions.
+cmd-addaction-action-not-found = Can't find matching action prototype {$action}.
+cmd-addaction-adding-failed = Failed to add the action.
+
+cmd-addaction-player-completion = <EntityUid>
+cmd-addaction-action-completion = <ActionProto>
diff --git a/Resources/Locale/en-US/actions/commands/rmaction.ftl b/Resources/Locale/en-US/actions/commands/rmaction.ftl
new file mode 100644 (file)
index 0000000..0226d3d
--- /dev/null
@@ -0,0 +1,12 @@
+# rmaction
+cmd-rmaction-desc = Removes an action from an entity.
+cmd-rmaction-help = rmaction <EntityUid> <ActionUid>
+
+cmd-rmaction-invalid-args = Expected exactly 2 arguments.
+cmd-rmaction-actions-not-found = Target entity cannot use actions.
+cmd-rmaction-not-an-action = Target entity is not an action.
+
+cmd-rmaction-player-completion = <EntityUid>
+cmd-rmaction-action-completion = <ActionUid>
+
+cmd-rmaction-action-info = {$action}