From 3a788dd8d48dbfed6ceeac8735af6739f6de6163 Mon Sep 17 00:00:00 2001 From: keronshb <54602815+keronshb@users.noreply.github.com> Date: Fri, 3 Nov 2023 19:55:32 -0400 Subject: [PATCH] Mind Action Container (#21336) --- Content.Client/Actions/ActionsSystem.cs | 1 + .../Actions/ActionContainerSystem.cs | 23 +++++++++++++++++++ Content.Shared/Actions/BaseActionComponent.cs | 8 +++++++ Content.Shared/Actions/SharedActionsSystem.cs | 11 ++++++--- Content.Shared/Mind/MindComponent.cs | 3 ++- 5 files changed, 42 insertions(+), 4 deletions(-) diff --git a/Content.Client/Actions/ActionsSystem.cs b/Content.Client/Actions/ActionsSystem.cs index a487e5d8d8ab96..d9fc20d78ce72b 100644 --- a/Content.Client/Actions/ActionsSystem.cs +++ b/Content.Client/Actions/ActionsSystem.cs @@ -92,6 +92,7 @@ private void BaseHandleState(EntityUid uid, BaseActionComponent component, Ba component.ClientExclusive = state.ClientExclusive; component.Priority = state.Priority; component.AttachedEntity = EnsureEntity(state.AttachedEntity, uid); + component.RaiseOnUser = state.RaiseOnUser; component.AutoPopulate = state.AutoPopulate; component.Temporary = state.Temporary; component.ItemIconStyle = state.ItemIconStyle; diff --git a/Content.Shared/Actions/ActionContainerSystem.cs b/Content.Shared/Actions/ActionContainerSystem.cs index d7c02ffd6328ae..21e3f79f2ba4a2 100644 --- a/Content.Shared/Actions/ActionContainerSystem.cs +++ b/Content.Shared/Actions/ActionContainerSystem.cs @@ -1,5 +1,8 @@ using System.Diagnostics.CodeAnalysis; using System.Linq; +using Content.Shared.Ghost; +using Content.Shared.Mind; +using Content.Shared.Mind.Components; using Robust.Shared.Containers; using Robust.Shared.Network; using Robust.Shared.Timing; @@ -17,6 +20,7 @@ public sealed class ActionContainerSystem : EntitySystem [Dependency] private readonly SharedActionsSystem _actions = default!; [Dependency] private readonly INetManager _netMan = default!; [Dependency] private readonly SharedTransformSystem _transform = default!; + [Dependency] private readonly SharedMindSystem _mind = default!; public override void Initialize() { @@ -26,6 +30,25 @@ public override void Initialize() SubscribeLocalEvent(OnShutdown); SubscribeLocalEvent(OnEntityRemoved); SubscribeLocalEvent(OnEntityInserted); + SubscribeLocalEvent(OnMindAdded); + SubscribeLocalEvent(OnMindRemoved); + } + + private void OnMindAdded(EntityUid uid, ActionsContainerComponent component, MindAddedMessage args) + { + if(!_mind.TryGetMind(uid, out var mindId, out _)) + return; + + if (!TryComp(mindId, out var mindActionContainerComp)) + return; + + if (!HasComp(uid) && mindActionContainerComp.Container.ContainedEntities.Count > 0 ) + _actions.GrantContainedActions(uid, mindId); + } + + private void OnMindRemoved(EntityUid uid, ActionsContainerComponent component, MindRemovedMessage args) + { + _actions.RemoveProvidedActions(uid, args.Mind); } /// diff --git a/Content.Shared/Actions/BaseActionComponent.cs b/Content.Shared/Actions/BaseActionComponent.cs index a21b801d3cc9a2..0eccdddc4c246e 100644 --- a/Content.Shared/Actions/BaseActionComponent.cs +++ b/Content.Shared/Actions/BaseActionComponent.cs @@ -120,6 +120,12 @@ public EntityUid? EntityIcon /// [ViewVariables] public EntityUid? AttachedEntity; + /// + /// If true, this will cause the the action event to always be raised directed at the action performer/user instead of the action's container/provider. + /// + [DataField] + public bool RaiseOnUser; + /// /// Whether or not to automatically add this action to the action bar when it becomes available. /// @@ -159,6 +165,7 @@ public abstract class BaseActionComponentState : ComponentState public bool ClientExclusive; public int Priority; public NetEntity? AttachedEntity; + public bool RaiseOnUser; public bool AutoPopulate; public bool Temporary; public ItemActionIconStyle ItemIconStyle; @@ -169,6 +176,7 @@ protected BaseActionComponentState(BaseActionComponent component, IEntityManager Container = entManager.GetNetEntity(component.Container); EntityIcon = entManager.GetNetEntity(component.EntIcon); AttachedEntity = entManager.GetNetEntity(component.AttachedEntity); + RaiseOnUser = component.RaiseOnUser; Icon = component.Icon; IconOn = component.IconOn; IconColor = component.IconColor; diff --git a/Content.Shared/Actions/SharedActionsSystem.cs b/Content.Shared/Actions/SharedActionsSystem.cs index 7384ab30b17092..d035e6ccfbf6cd 100644 --- a/Content.Shared/Actions/SharedActionsSystem.cs +++ b/Content.Shared/Actions/SharedActionsSystem.cs @@ -7,6 +7,7 @@ using Content.Shared.Hands; using Content.Shared.Interaction; using Content.Shared.Inventory.Events; +using Content.Shared.Mind; using Robust.Shared.Containers; using Robust.Shared.GameStates; using Robust.Shared.Map; @@ -221,7 +222,6 @@ private void OnActionRequest(RequestPerformActionEvent ev, EntitySessionEventArg return; DebugTools.Assert(action.AttachedEntity == user); - if (!action.Enabled) return; @@ -369,7 +369,7 @@ public void PerformAction(EntityUid performer, ActionsComponent? component, Enti var toggledBefore = action.Toggled; - // Note that attached entity is allowed to be null here. + // Note that attached entity and attached container are allowed to be null here. if (action.AttachedEntity != null && action.AttachedEntity != performer) { Log.Error($"{ToPrettyString(performer)} is attempting to perform an action {ToPrettyString(actionId)} that is attached to another entity {ToPrettyString(action.AttachedEntity.Value)}"); @@ -380,7 +380,12 @@ public void PerformAction(EntityUid performer, ActionsComponent? component, Enti { // This here is required because of client-side prediction (RaisePredictiveEvent results in event re-use). actionEvent.Handled = false; - RaiseLocalEvent(action.Container ?? performer, (object) actionEvent, broadcast: true); + var target = performer; + + if (!action.RaiseOnUser && action.Container != null && !HasComp(action.Container)) + target = action.Container.Value; + + RaiseLocalEvent(target, (object) actionEvent, broadcast: true); handled = actionEvent.Handled; } diff --git a/Content.Shared/Mind/MindComponent.cs b/Content.Shared/Mind/MindComponent.cs index b147a2dbbe7e10..51a174c8465c86 100644 --- a/Content.Shared/Mind/MindComponent.cs +++ b/Content.Shared/Mind/MindComponent.cs @@ -1,4 +1,5 @@ -using Content.Shared.GameTicking; +using Content.Shared.Actions; +using Content.Shared.GameTicking; using Content.Shared.Mind.Components; using Robust.Shared.GameStates; using Robust.Shared.Network;