Add events for custom action target validation (#27230)
This commit is contained in:
@@ -200,7 +200,7 @@ public sealed class ActionUIController : UIController, IOnStateChanged<GameplayS
|
|||||||
|
|
||||||
var coords = args.Coordinates;
|
var coords = args.Coordinates;
|
||||||
|
|
||||||
if (!_actionsSystem.ValidateWorldTarget(user, coords, action))
|
if (!_actionsSystem.ValidateWorldTarget(user, coords, (actionId, action)))
|
||||||
{
|
{
|
||||||
// Invalid target.
|
// Invalid target.
|
||||||
if (action.DeselectOnMiss)
|
if (action.DeselectOnMiss)
|
||||||
@@ -235,7 +235,7 @@ public sealed class ActionUIController : UIController, IOnStateChanged<GameplayS
|
|||||||
|
|
||||||
var entity = args.EntityUid;
|
var entity = args.EntityUid;
|
||||||
|
|
||||||
if (!_actionsSystem.ValidateEntityTarget(user, entity, action))
|
if (!_actionsSystem.ValidateEntityTarget(user, entity, (actionId, action)))
|
||||||
{
|
{
|
||||||
if (action.DeselectOnMiss)
|
if (action.DeselectOnMiss)
|
||||||
StopTargeting();
|
StopTargeting();
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ public sealed class ActionOnInteractSystem : EntitySystem
|
|||||||
var entOptions = GetValidActions<EntityTargetActionComponent>(component.ActionEntities, args.CanReach);
|
var entOptions = GetValidActions<EntityTargetActionComponent>(component.ActionEntities, args.CanReach);
|
||||||
for (var i = entOptions.Count - 1; i >= 0; i--)
|
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))
|
if (!_actions.ValidateEntityTarget(args.User, args.Target.Value, action))
|
||||||
entOptions.RemoveAt(i);
|
entOptions.RemoveAt(i);
|
||||||
}
|
}
|
||||||
@@ -88,7 +88,7 @@ public sealed class ActionOnInteractSystem : EntitySystem
|
|||||||
var options = GetValidActions<WorldTargetActionComponent>(component.ActionEntities, args.CanReach);
|
var options = GetValidActions<WorldTargetActionComponent>(component.ActionEntities, args.CanReach);
|
||||||
for (var i = options.Count - 1; i >= 0; i--)
|
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))
|
if (!_actions.ValidateWorldTarget(args.User, args.ClickLocation, action))
|
||||||
options.RemoveAt(i);
|
options.RemoveAt(i);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
namespace Content.Shared.Actions.Events;
|
||||||
|
|
||||||
|
[ByRefEvent]
|
||||||
|
public record struct ValidateActionEntityTargetEvent(EntityUid User, EntityUid Target, bool Cancelled = false);
|
||||||
@@ -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);
|
||||||
@@ -8,14 +8,13 @@ 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 Content.Shared.Mind;
|
||||||
using Content.Shared.Mobs.Components;
|
using Content.Shared.Rejuvenate;
|
||||||
using Robust.Shared.Audio.Systems;
|
using Robust.Shared.Audio.Systems;
|
||||||
using Robust.Shared.Containers;
|
using Robust.Shared.Containers;
|
||||||
using Robust.Shared.GameStates;
|
using Robust.Shared.GameStates;
|
||||||
using Robust.Shared.Map;
|
using Robust.Shared.Map;
|
||||||
using Robust.Shared.Timing;
|
using Robust.Shared.Timing;
|
||||||
using Robust.Shared.Utility;
|
using Robust.Shared.Utility;
|
||||||
using Content.Shared.Rejuvenate;
|
|
||||||
|
|
||||||
namespace Content.Shared.Actions;
|
namespace Content.Shared.Actions;
|
||||||
|
|
||||||
@@ -389,7 +388,7 @@ public abstract class SharedActionsSystem : EntitySystem
|
|||||||
var targetWorldPos = _transformSystem.GetWorldPosition(entityTarget);
|
var targetWorldPos = _transformSystem.GetWorldPosition(entityTarget);
|
||||||
_rotateToFaceSystem.TryFaceCoordinates(user, targetWorldPos);
|
_rotateToFaceSystem.TryFaceCoordinates(user, targetWorldPos);
|
||||||
|
|
||||||
if (!ValidateEntityTarget(user, entityTarget, entityAction))
|
if (!ValidateEntityTarget(user, entityTarget, (actionEnt, entityAction)))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
_adminLogger.Add(LogType.Action,
|
_adminLogger.Add(LogType.Action,
|
||||||
@@ -413,7 +412,7 @@ public abstract class SharedActionsSystem : EntitySystem
|
|||||||
var entityCoordinatesTarget = GetCoordinates(netCoordinatesTarget);
|
var entityCoordinatesTarget = GetCoordinates(netCoordinatesTarget);
|
||||||
_rotateToFaceSystem.TryFaceCoordinates(user, entityCoordinatesTarget.ToMapPos(EntityManager, _transformSystem));
|
_rotateToFaceSystem.TryFaceCoordinates(user, entityCoordinatesTarget.ToMapPos(EntityManager, _transformSystem));
|
||||||
|
|
||||||
if (!ValidateWorldTarget(user, entityCoordinatesTarget, worldAction))
|
if (!ValidateWorldTarget(user, entityCoordinatesTarget, (actionEnt, worldAction)))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
_adminLogger.Add(LogType.Action,
|
_adminLogger.Add(LogType.Action,
|
||||||
@@ -445,7 +444,17 @@ public abstract class SharedActionsSystem : EntitySystem
|
|||||||
PerformAction(user, component, actionEnt, action, performEvent, curTime);
|
PerformAction(user, component, actionEnt, action, performEvent, curTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool ValidateEntityTarget(EntityUid user, EntityUid target, EntityTargetActionComponent action)
|
public bool ValidateEntityTarget(EntityUid user, EntityUid target, Entity<EntityTargetActionComponent> 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))
|
if (!target.IsValid() || Deleted(target))
|
||||||
return false;
|
return false;
|
||||||
@@ -484,7 +493,17 @@ public abstract class SharedActionsSystem : EntitySystem
|
|||||||
return _interactionSystem.CanAccessViaStorage(user, target);
|
return _interactionSystem.CanAccessViaStorage(user, target);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool ValidateWorldTarget(EntityUid user, EntityCoordinates coords, WorldTargetActionComponent action)
|
public bool ValidateWorldTarget(EntityUid user, EntityCoordinates coords, Entity<WorldTargetActionComponent> 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))
|
if (action.CheckCanInteract && !_actionBlockerSystem.CanInteract(user, null))
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
Reference in New Issue
Block a user