From: Leon Friedrich <60421075+ElectroJr@users.noreply.github.com> Date: Tue, 24 Oct 2023 00:53:27 +0000 (+1100) Subject: Add GrantContainedActions() (#21206) X-Git-Url: https://git.smokeofanarchy.ru/gitweb.cgi?a=commitdiff_plain;h=472381c0db6cd3088fe757975d96a70ac652f584;p=space-station-14.git Add GrantContainedActions() (#21206) --- 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))