From 472381c0db6cd3088fe757975d96a70ac652f584 Mon Sep 17 00:00:00 2001 From: Leon Friedrich <60421075+ElectroJr@users.noreply.github.com> Date: Tue, 24 Oct 2023 11:53:27 +1100 Subject: [PATCH] Add GrantContainedActions() (#21206) --- Content.Shared/Actions/SharedActionsSystem.cs | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/Content.Shared/Actions/SharedActionsSystem.cs b/Content.Shared/Actions/SharedActionsSystem.cs index 9ad155081a..00a17ace25 100644 --- a/Content.Shared/Actions/SharedActionsSystem.cs +++ b/Content.Shared/Actions/SharedActionsSystem.cs @@ -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(performer); action.AttachedEntity = performer; @@ -532,6 +535,26 @@ public abstract class SharedActionsSystem : EntitySystem } } + /// + /// Grants all actions currently contained in some action-container. If the target entity has no action + /// component, this will give them one. + /// + /// Entity to receive the actions + /// The entity that contains thee actions. + public void GrantContainedActions(Entity performer, Entity container) + { + if (!Resolve(container, ref container.Comp)) + return; + + performer.Comp ??= EnsureComp(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)) -- 2.51.2