Add events for custom action target validation (#27230)
This commit is contained in:
@@ -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<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))
|
||||
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<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))
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user