Allow actions to specify if they want to rotate the user when targeting (#37958)

This commit is contained in:
DrSmugleaf
2025-05-30 05:56:16 -07:00
committed by GitHub
parent 1e3212ab32
commit b86c1ea01d
3 changed files with 22 additions and 7 deletions

View File

@@ -1,5 +1,4 @@
using Content.Shared.Actions; using Content.Shared.Whitelist;
using Content.Shared.Whitelist;
using Robust.Shared.GameStates; using Robust.Shared.GameStates;
using Robust.Shared.Prototypes; using Robust.Shared.Prototypes;
@@ -45,4 +44,10 @@ public sealed partial class EntityTargetActionComponent : Component
/// </summary> /// </summary>
[DataField, AutoNetworkedField] [DataField, AutoNetworkedField]
public bool CanTargetSelf = true; public bool CanTargetSelf = true;
/// <summary>
/// Whether to make the user face towards the direction where they targeted this action.
/// </summary>
[DataField, AutoNetworkedField]
public bool RotateOnUse = true;
} }

View File

@@ -1,5 +1,4 @@
using Content.Shared.Actions; using Robust.Shared.GameStates;
using Robust.Shared.GameStates;
using Robust.Shared.Prototypes; using Robust.Shared.Prototypes;
namespace Content.Shared.Actions.Components; namespace Content.Shared.Actions.Components;
@@ -13,6 +12,7 @@ namespace Content.Shared.Actions.Components;
/// </remarks> /// </remarks>
[RegisterComponent, NetworkedComponent, Access(typeof(SharedActionsSystem))] [RegisterComponent, NetworkedComponent, Access(typeof(SharedActionsSystem))]
[EntityCategory("Actions")] [EntityCategory("Actions")]
[AutoGenerateComponentState]
public sealed partial class WorldTargetActionComponent : Component public sealed partial class WorldTargetActionComponent : Component
{ {
/// <summary> /// <summary>
@@ -20,4 +20,10 @@ public sealed partial class WorldTargetActionComponent : Component
/// </summary> /// </summary>
[DataField(required: true), NonSerialized] [DataField(required: true), NonSerialized]
public WorldTargetActionEvent? Event; public WorldTargetActionEvent? Event;
/// <summary>
/// Whether to make the user face towards the direction where they targeted this action.
/// </summary>
[DataField, AutoNetworkedField]
public bool RotateOnUse = true;
} }

View File

@@ -348,7 +348,9 @@ public abstract class SharedActionsSystem : EntitySystem
var target = GetEntity(netTarget); var target = GetEntity(netTarget);
var targetWorldPos = _transform.GetWorldPosition(target); var targetWorldPos = _transform.GetWorldPosition(target);
_rotateToFace.TryFaceCoordinates(user, targetWorldPos);
if (ent.Comp.RotateOnUse)
_rotateToFace.TryFaceCoordinates(user, targetWorldPos);
if (!ValidateEntityTarget(user, target, ent)) if (!ValidateEntityTarget(user, target, ent))
return; return;
@@ -369,7 +371,9 @@ public abstract class SharedActionsSystem : EntitySystem
var user = args.User; var user = args.User;
var target = GetCoordinates(netTarget); var target = GetCoordinates(netTarget);
_rotateToFace.TryFaceCoordinates(user, target.ToMapPos(EntityManager, _transform));
if (ent.Comp.RotateOnUse)
_rotateToFace.TryFaceCoordinates(user, _transform.ToMapCoordinates(target).Position);
if (!ValidateWorldTarget(user, target, ent)) if (!ValidateWorldTarget(user, target, ent))
return; return;
@@ -604,7 +608,7 @@ public abstract class SharedActionsSystem : EntitySystem
return AddAction(performer, ref actionId, out _, actionPrototypeId, container, component); return AddAction(performer, ref actionId, out _, actionPrototypeId, container, component);
} }
/// <inheritdoc cref="AddAction(Robust.Shared.GameObjects.EntityUid,ref System.Nullable{Robust.Shared.GameObjects.EntityUid},string?,Robust.Shared.GameObjects.EntityUid,Content.Shared.Actions.ActionsComponent?)"/> /// <inheritdoc cref="AddAction(Robust.Shared.GameObjects.EntityUid,ref System.Nullable{Robust.Shared.GameObjects.EntityUid},string?,Robust.Shared.GameObjects.EntityUid,ActionsComponent?)"/>
public bool AddAction(EntityUid performer, public bool AddAction(EntityUid performer,
[NotNullWhen(true)] ref EntityUid? actionId, [NotNullWhen(true)] ref EntityUid? actionId,
[NotNullWhen(true)] out ActionComponent? action, [NotNullWhen(true)] out ActionComponent? action,