]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Add GrantContainedActions() (#21206)
authorLeon Friedrich <60421075+ElectroJr@users.noreply.github.com>
Tue, 24 Oct 2023 00:53:27 +0000 (11:53 +1100)
committerGitHub <noreply@github.com>
Tue, 24 Oct 2023 00:53:27 +0000 (20:53 -0400)
Content.Shared/Actions/SharedActionsSystem.cs

index 9ad155081acc8491177d30e90d0b6d522d757fd6..00a17ace250988b5284707624f29cfaee4434734 100644 (file)
@@ -494,6 +494,9 @@ public abstract class SharedActionsSystem : EntitySystem
                           (TryComp(action.Container, out ActionsContainerComponent? containerComp)
                            && containerComp.Container.Contains(actionId)));
 
+        if (action.AttachedEntity != null)
+            RemoveAction(action.AttachedEntity.Value, actionId, action: action);
+
         DebugTools.AssertOwner(performer, comp);
         comp ??= EnsureComp<ActionsComponent>(performer);
         action.AttachedEntity = performer;
@@ -532,6 +535,26 @@ public abstract class SharedActionsSystem : EntitySystem
         }
     }
 
+    /// <summary>
+    ///     Grants all actions currently contained in some action-container. If the target entity has no action
+    /// component, this will give them one.
+    /// </summary>
+    /// <param name="performer">Entity to receive the actions</param>
+    /// <param name="container">The entity that contains thee actions.</param>
+    public void GrantContainedActions(Entity<ActionsComponent?> performer, Entity<ActionsContainerComponent?> container)
+    {
+        if (!Resolve(container, ref container.Comp))
+            return;
+
+        performer.Comp ??= EnsureComp<ActionsComponent>(performer);
+
+        foreach (var actionId in container.Comp.Container.ContainedEntities)
+        {
+            if (TryGetActionData(actionId, out var action))
+                AddActionDirect(performer, actionId, performer.Comp, action);
+        }
+    }
+
     public IEnumerable<(EntityUid Id, BaseActionComponent Comp)> GetActions(EntityUid holderId, ActionsComponent? actions = null)
     {
         if (!Resolve(holderId, ref actions, false))