Mind Action Container (#21336)
This commit is contained in:
@@ -92,6 +92,7 @@ namespace Content.Client.Actions
|
|||||||
component.ClientExclusive = state.ClientExclusive;
|
component.ClientExclusive = state.ClientExclusive;
|
||||||
component.Priority = state.Priority;
|
component.Priority = state.Priority;
|
||||||
component.AttachedEntity = EnsureEntity<T>(state.AttachedEntity, uid);
|
component.AttachedEntity = EnsureEntity<T>(state.AttachedEntity, uid);
|
||||||
|
component.RaiseOnUser = state.RaiseOnUser;
|
||||||
component.AutoPopulate = state.AutoPopulate;
|
component.AutoPopulate = state.AutoPopulate;
|
||||||
component.Temporary = state.Temporary;
|
component.Temporary = state.Temporary;
|
||||||
component.ItemIconStyle = state.ItemIconStyle;
|
component.ItemIconStyle = state.ItemIconStyle;
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using Content.Shared.Ghost;
|
||||||
|
using Content.Shared.Mind;
|
||||||
|
using Content.Shared.Mind.Components;
|
||||||
using Robust.Shared.Containers;
|
using Robust.Shared.Containers;
|
||||||
using Robust.Shared.Network;
|
using Robust.Shared.Network;
|
||||||
using Robust.Shared.Timing;
|
using Robust.Shared.Timing;
|
||||||
@@ -17,6 +20,7 @@ public sealed class ActionContainerSystem : EntitySystem
|
|||||||
[Dependency] private readonly SharedActionsSystem _actions = default!;
|
[Dependency] private readonly SharedActionsSystem _actions = default!;
|
||||||
[Dependency] private readonly INetManager _netMan = default!;
|
[Dependency] private readonly INetManager _netMan = default!;
|
||||||
[Dependency] private readonly SharedTransformSystem _transform = default!;
|
[Dependency] private readonly SharedTransformSystem _transform = default!;
|
||||||
|
[Dependency] private readonly SharedMindSystem _mind = default!;
|
||||||
|
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
@@ -26,6 +30,25 @@ public sealed class ActionContainerSystem : EntitySystem
|
|||||||
SubscribeLocalEvent<ActionsContainerComponent, ComponentShutdown>(OnShutdown);
|
SubscribeLocalEvent<ActionsContainerComponent, ComponentShutdown>(OnShutdown);
|
||||||
SubscribeLocalEvent<ActionsContainerComponent, EntRemovedFromContainerMessage>(OnEntityRemoved);
|
SubscribeLocalEvent<ActionsContainerComponent, EntRemovedFromContainerMessage>(OnEntityRemoved);
|
||||||
SubscribeLocalEvent<ActionsContainerComponent, EntInsertedIntoContainerMessage>(OnEntityInserted);
|
SubscribeLocalEvent<ActionsContainerComponent, EntInsertedIntoContainerMessage>(OnEntityInserted);
|
||||||
|
SubscribeLocalEvent<ActionsContainerComponent, MindAddedMessage>(OnMindAdded);
|
||||||
|
SubscribeLocalEvent<ActionsContainerComponent, MindRemovedMessage>(OnMindRemoved);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnMindAdded(EntityUid uid, ActionsContainerComponent component, MindAddedMessage args)
|
||||||
|
{
|
||||||
|
if(!_mind.TryGetMind(uid, out var mindId, out _))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!TryComp<ActionsContainerComponent>(mindId, out var mindActionContainerComp))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!HasComp<GhostComponent>(uid) && mindActionContainerComp.Container.ContainedEntities.Count > 0 )
|
||||||
|
_actions.GrantContainedActions(uid, mindId);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnMindRemoved(EntityUid uid, ActionsContainerComponent component, MindRemovedMessage args)
|
||||||
|
{
|
||||||
|
_actions.RemoveProvidedActions(uid, args.Mind);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -120,6 +120,12 @@ public abstract partial class BaseActionComponent : Component
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
[ViewVariables] public EntityUid? AttachedEntity;
|
[ViewVariables] public EntityUid? AttachedEntity;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 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.
|
||||||
|
/// </summary>
|
||||||
|
[DataField]
|
||||||
|
public bool RaiseOnUser;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Whether or not to automatically add this action to the action bar when it becomes available.
|
/// Whether or not to automatically add this action to the action bar when it becomes available.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -159,6 +165,7 @@ public abstract class BaseActionComponentState : ComponentState
|
|||||||
public bool ClientExclusive;
|
public bool ClientExclusive;
|
||||||
public int Priority;
|
public int Priority;
|
||||||
public NetEntity? AttachedEntity;
|
public NetEntity? AttachedEntity;
|
||||||
|
public bool RaiseOnUser;
|
||||||
public bool AutoPopulate;
|
public bool AutoPopulate;
|
||||||
public bool Temporary;
|
public bool Temporary;
|
||||||
public ItemActionIconStyle ItemIconStyle;
|
public ItemActionIconStyle ItemIconStyle;
|
||||||
@@ -169,6 +176,7 @@ public abstract class BaseActionComponentState : ComponentState
|
|||||||
Container = entManager.GetNetEntity(component.Container);
|
Container = entManager.GetNetEntity(component.Container);
|
||||||
EntityIcon = entManager.GetNetEntity(component.EntIcon);
|
EntityIcon = entManager.GetNetEntity(component.EntIcon);
|
||||||
AttachedEntity = entManager.GetNetEntity(component.AttachedEntity);
|
AttachedEntity = entManager.GetNetEntity(component.AttachedEntity);
|
||||||
|
RaiseOnUser = component.RaiseOnUser;
|
||||||
Icon = component.Icon;
|
Icon = component.Icon;
|
||||||
IconOn = component.IconOn;
|
IconOn = component.IconOn;
|
||||||
IconColor = component.IconColor;
|
IconColor = component.IconColor;
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ using Content.Shared.Database;
|
|||||||
using Content.Shared.Hands;
|
using Content.Shared.Hands;
|
||||||
using Content.Shared.Interaction;
|
using Content.Shared.Interaction;
|
||||||
using Content.Shared.Inventory.Events;
|
using Content.Shared.Inventory.Events;
|
||||||
|
using Content.Shared.Mind;
|
||||||
using Robust.Shared.Containers;
|
using Robust.Shared.Containers;
|
||||||
using Robust.Shared.GameStates;
|
using Robust.Shared.GameStates;
|
||||||
using Robust.Shared.Map;
|
using Robust.Shared.Map;
|
||||||
@@ -221,7 +222,6 @@ public abstract class SharedActionsSystem : EntitySystem
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
DebugTools.Assert(action.AttachedEntity == user);
|
DebugTools.Assert(action.AttachedEntity == user);
|
||||||
|
|
||||||
if (!action.Enabled)
|
if (!action.Enabled)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -369,7 +369,7 @@ public abstract class SharedActionsSystem : EntitySystem
|
|||||||
|
|
||||||
var toggledBefore = action.Toggled;
|
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)
|
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)}");
|
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 abstract class SharedActionsSystem : EntitySystem
|
|||||||
{
|
{
|
||||||
// This here is required because of client-side prediction (RaisePredictiveEvent results in event re-use).
|
// This here is required because of client-side prediction (RaisePredictiveEvent results in event re-use).
|
||||||
actionEvent.Handled = false;
|
actionEvent.Handled = false;
|
||||||
RaiseLocalEvent(action.Container ?? performer, (object) actionEvent, broadcast: true);
|
var target = performer;
|
||||||
|
|
||||||
|
if (!action.RaiseOnUser && action.Container != null && !HasComp<MindComponent>(action.Container))
|
||||||
|
target = action.Container.Value;
|
||||||
|
|
||||||
|
RaiseLocalEvent(target, (object) actionEvent, broadcast: true);
|
||||||
handled = actionEvent.Handled;
|
handled = actionEvent.Handled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Content.Shared.GameTicking;
|
using Content.Shared.Actions;
|
||||||
|
using Content.Shared.GameTicking;
|
||||||
using Content.Shared.Mind.Components;
|
using Content.Shared.Mind.Components;
|
||||||
using Robust.Shared.GameStates;
|
using Robust.Shared.GameStates;
|
||||||
using Robust.Shared.Network;
|
using Robust.Shared.Network;
|
||||||
|
|||||||
Reference in New Issue
Block a user