diff --git a/Content.Client/UserInterface/Systems/Actions/ActionUIController.cs b/Content.Client/UserInterface/Systems/Actions/ActionUIController.cs index 09663ba82c..c79f0f80f9 100644 --- a/Content.Client/UserInterface/Systems/Actions/ActionUIController.cs +++ b/Content.Client/UserInterface/Systems/Actions/ActionUIController.cs @@ -200,7 +200,7 @@ public sealed class ActionUIController : UIController, IOnStateChanged(component.ActionEntities, args.CanReach); for (var i = entOptions.Count - 1; i >= 0; i--) { - var action = entOptions[i].Comp; + var action = entOptions[i]; if (!_actions.ValidateEntityTarget(args.User, args.Target.Value, action)) entOptions.RemoveAt(i); } @@ -88,7 +88,7 @@ public sealed class ActionOnInteractSystem : EntitySystem var options = GetValidActions(component.ActionEntities, args.CanReach); for (var i = options.Count - 1; i >= 0; i--) { - var action = options[i].Comp; + var action = options[i]; if (!_actions.ValidateWorldTarget(args.User, args.ClickLocation, action)) options.RemoveAt(i); } diff --git a/Content.Shared/Actions/Events/ValidateActionEntityTargetEvent.cs b/Content.Shared/Actions/Events/ValidateActionEntityTargetEvent.cs new file mode 100644 index 0000000000..9f22e7973a --- /dev/null +++ b/Content.Shared/Actions/Events/ValidateActionEntityTargetEvent.cs @@ -0,0 +1,4 @@ +namespace Content.Shared.Actions.Events; + +[ByRefEvent] +public record struct ValidateActionEntityTargetEvent(EntityUid User, EntityUid Target, bool Cancelled = false); diff --git a/Content.Shared/Actions/Events/ValidateActionWorldTargetEvent.cs b/Content.Shared/Actions/Events/ValidateActionWorldTargetEvent.cs new file mode 100644 index 0000000000..43e398aad4 --- /dev/null +++ b/Content.Shared/Actions/Events/ValidateActionWorldTargetEvent.cs @@ -0,0 +1,6 @@ +using Robust.Shared.Map; + +namespace Content.Shared.Actions.Events; + +[ByRefEvent] +public record struct ValidateActionWorldTargetEvent(EntityUid User, EntityCoordinates Target, bool Cancelled = false); diff --git a/Content.Shared/Actions/SharedActionsSystem.cs b/Content.Shared/Actions/SharedActionsSystem.cs index 9f3fb96410..e1b76f517e 100644 --- a/Content.Shared/Actions/SharedActionsSystem.cs +++ b/Content.Shared/Actions/SharedActionsSystem.cs @@ -8,14 +8,13 @@ using Content.Shared.Hands; using Content.Shared.Interaction; using Content.Shared.Inventory.Events; using Content.Shared.Mind; -using Content.Shared.Mobs.Components; +using Content.Shared.Rejuvenate; using Robust.Shared.Audio.Systems; using Robust.Shared.Containers; using Robust.Shared.GameStates; using Robust.Shared.Map; using Robust.Shared.Timing; using Robust.Shared.Utility; -using Content.Shared.Rejuvenate; namespace Content.Shared.Actions; @@ -389,7 +388,7 @@ public abstract class SharedActionsSystem : EntitySystem var targetWorldPos = _transformSystem.GetWorldPosition(entityTarget); _rotateToFaceSystem.TryFaceCoordinates(user, targetWorldPos); - if (!ValidateEntityTarget(user, entityTarget, entityAction)) + if (!ValidateEntityTarget(user, entityTarget, (actionEnt, entityAction))) return; _adminLogger.Add(LogType.Action, @@ -413,7 +412,7 @@ public abstract class SharedActionsSystem : EntitySystem var entityCoordinatesTarget = GetCoordinates(netCoordinatesTarget); _rotateToFaceSystem.TryFaceCoordinates(user, entityCoordinatesTarget.ToMapPos(EntityManager, _transformSystem)); - if (!ValidateWorldTarget(user, entityCoordinatesTarget, worldAction)) + if (!ValidateWorldTarget(user, entityCoordinatesTarget, (actionEnt, worldAction))) return; _adminLogger.Add(LogType.Action, @@ -445,7 +444,17 @@ public abstract class SharedActionsSystem : EntitySystem PerformAction(user, component, actionEnt, action, performEvent, curTime); } - public bool ValidateEntityTarget(EntityUid user, EntityUid target, EntityTargetActionComponent action) + public bool ValidateEntityTarget(EntityUid user, EntityUid target, Entity actionEnt) + { + if (!ValidateEntityTargetBase(user, target, actionEnt)) + return false; + + var ev = new ValidateActionEntityTargetEvent(user, target); + RaiseLocalEvent(actionEnt, ref ev); + return !ev.Cancelled; + } + + private bool ValidateEntityTargetBase(EntityUid user, EntityUid target, EntityTargetActionComponent action) { if (!target.IsValid() || Deleted(target)) return false; @@ -484,7 +493,17 @@ public abstract class SharedActionsSystem : EntitySystem return _interactionSystem.CanAccessViaStorage(user, target); } - public bool ValidateWorldTarget(EntityUid user, EntityCoordinates coords, WorldTargetActionComponent action) + public bool ValidateWorldTarget(EntityUid user, EntityCoordinates coords, Entity action) + { + if (!ValidateWorldTargetBase(user, coords, action)) + return false; + + var ev = new ValidateActionWorldTargetEvent(user, coords); + RaiseLocalEvent(action, ref ev); + return !ev.Cancelled; + } + + private bool ValidateWorldTargetBase(EntityUid user, EntityCoordinates coords, WorldTargetActionComponent action) { if (action.CheckCanInteract && !_actionBlockerSystem.CanInteract(user, null)) return false;