ActionBlocker CanUse uses EntityUid exclusively

This commit is contained in:
Vera Aguilera Puerto
2021-11-09 13:19:56 +01:00
parent 5f9cfaac43
commit c051b1e056
16 changed files with 23 additions and 29 deletions

View File

@@ -174,7 +174,7 @@ namespace Content.Server.AME.Components
var actionBlocker = EntitySystem.Get<ActionBlockerSystem>();
//Check if player can interact in their current state
if (!actionBlocker.CanInteract(playerEntity) || !actionBlocker.CanUse(playerEntity))
if (!actionBlocker.CanInteract(playerEntity) || !actionBlocker.CanUse(playerEntity.Uid))
return false;
//Check if device is powered
if (needsPower && !Powered)

View File

@@ -218,7 +218,7 @@ namespace Content.Server.Atmos.Components
{
var user = GetInternalsComponent()?.Owner;
if (user == null || !EntitySystem.Get<ActionBlockerSystem>().CanUse(user))
if (user == null || !EntitySystem.Get<ActionBlockerSystem>().CanUse(user.Uid))
return;
if (IsConnected)

View File

@@ -165,7 +165,7 @@ namespace Content.Server.Chemistry.Components
var actionBlocker = EntitySystem.Get<ActionBlockerSystem>();
//Check if player can interact in their current state
if (!actionBlocker.CanInteract(playerEntity) || !actionBlocker.CanUse(playerEntity))
if (!actionBlocker.CanInteract(playerEntity) || !actionBlocker.CanUse(playerEntity.Uid))
return false;
//Check if device is powered
if (needsPower && !Powered)

View File

@@ -218,7 +218,7 @@ namespace Content.Server.Chemistry.Components
var actionBlocker = EntitySystem.Get<ActionBlockerSystem>();
//Check if player can interact in their current state
if (!actionBlocker.CanInteract(playerEntity) || !actionBlocker.CanUse(playerEntity))
if (!actionBlocker.CanInteract(playerEntity) || !actionBlocker.CanUse(playerEntity.Uid))
return false;
//Check if device is powered
if (needsPower && !Powered)

View File

@@ -147,7 +147,7 @@ namespace Content.Server.Cuffs.Components
{
if (_cuffing) return true;
if (eventArgs.Target == null || !EntitySystem.Get<ActionBlockerSystem>().CanUse(eventArgs.User) || !eventArgs.Target.TryGetComponent<CuffableComponent>(out var cuffed))
if (eventArgs.Target == null || !EntitySystem.Get<ActionBlockerSystem>().CanUse(eventArgs.User.Uid) || !eventArgs.Target.TryGetComponent<CuffableComponent>(out var cuffed))
{
return false;
}

View File

@@ -112,7 +112,7 @@ namespace Content.Server.Disposal.Tube.Components
var actionBlocker = EntitySystem.Get<ActionBlockerSystem>();
var groupController = IoCManager.Resolve<IConGroupController>();
//Check if player can interact in their current state
if (!groupController.CanAdminMenu(session) && (!actionBlocker.CanInteract(session.AttachedEntity) || !actionBlocker.CanUse(session.AttachedEntity)))
if (!groupController.CanAdminMenu(session) && (!actionBlocker.CanInteract(session.AttachedEntity) || !actionBlocker.CanUse(session.AttachedEntityUid!.Value)))
return false;
return true;

View File

@@ -94,7 +94,7 @@ namespace Content.Server.Disposal.Tube.Components
var actionBlocker = EntitySystem.Get<ActionBlockerSystem>();
var groupController = IoCManager.Resolve<IConGroupController>();
//Check if player can interact in their current state
if (!groupController.CanAdminMenu(session) && (!actionBlocker.CanInteract(session.AttachedEntity) || !actionBlocker.CanUse(session.AttachedEntity)))
if (!groupController.CanAdminMenu(session) && (!actionBlocker.CanInteract(session.AttachedEntity) || !actionBlocker.CanUse(session.AttachedEntityUid!.Value)))
return false;
return true;

View File

@@ -97,7 +97,7 @@ namespace Content.Server.Disposal.Unit.Components
var actionBlocker = EntitySystem.Get<ActionBlockerSystem>();
if (!actionBlocker.CanInteract(player) ||
!actionBlocker.CanUse(player))
!actionBlocker.CanUse(player.Uid))
{
return false;
}

View File

@@ -82,7 +82,7 @@ namespace Content.Server.HandLabeler
{
if (session.AttachedEntity is not { } entity
|| !Get<ActionBlockerSystem>().CanInteract(entity)
|| !Get<ActionBlockerSystem>().CanUse(entity))
|| !Get<ActionBlockerSystem>().CanUse(entity.Uid))
return false;
return true;

View File

@@ -105,7 +105,7 @@ namespace Content.Server.Light.Components
/// <returns>True if the light's status was toggled, false otherwise.</returns>
public bool ToggleStatus(IEntity user)
{
if (!EntitySystem.Get<ActionBlockerSystem>().CanUse(user)) return false;
if (!EntitySystem.Get<ActionBlockerSystem>().CanUse(user.Uid)) return false;
return Activated ? TurnOff() : TurnOn(user);
}

View File

@@ -44,7 +44,7 @@ namespace Content.Server.Light.EntitySystems
return;
// standard interaction checks
if (!_blocker.CanUse(eventArgs.User)) return;
if (!_blocker.CanUse(eventArgs.User.Uid)) return;
if (!eventArgs.CanReach) return;
// behaviour will depends on target type

View File

@@ -73,7 +73,7 @@ namespace Content.Server.Stunnable
private void OnUseInHand(EntityUid uid, StunbatonComponent comp, UseInHandEvent args)
{
if (!Get<ActionBlockerSystem>().CanUse(args.User))
if (!Get<ActionBlockerSystem>().CanUse(args.User.Uid))
return;
if (comp.Activated)

View File

@@ -43,18 +43,12 @@ namespace Content.Shared.ActionBlocker
return CanInteract(EntityManager.GetEntity(uid));
}
public bool CanUse(IEntity entity)
{
var ev = new UseAttemptEvent(entity);
RaiseLocalEvent(entity.Uid, ev);
return !ev.Cancelled;
}
public bool CanUse(EntityUid uid)
{
return CanUse(EntityManager.GetEntity(uid));
var ev = new UseAttemptEvent(uid);
RaiseLocalEvent(uid, ev);
return !ev.Cancelled;
}
public bool CanThrow(IEntity entity)

View File

@@ -4,11 +4,11 @@ namespace Content.Shared.Interaction.Events
{
public class UseAttemptEvent : CancellableEntityEventArgs
{
public UseAttemptEvent(IEntity entity)
public UseAttemptEvent(EntityUid uid)
{
Entity = entity;
Uid = uid;
}
public IEntity Entity { get; }
public EntityUid Uid { get; }
}
}

View File

@@ -444,7 +444,7 @@ namespace Content.Shared.Interaction
delayComponent.BeginDelay();
}
if (!_actionBlockerSystem.CanInteract(user) || !_actionBlockerSystem.CanUse(user))
if (!_actionBlockerSystem.CanInteract(user) || !_actionBlockerSystem.CanUse(user.Uid))
return;
// all activates should only fire when in range / unobstructed
@@ -474,7 +474,7 @@ namespace Content.Shared.Interaction
/// <param name="used"></param>
public void TryUseInteraction(IEntity user, IEntity used, bool altInteract = false)
{
if (user != null && used != null && _actionBlockerSystem.CanUse(user))
if (user != null && used != null && _actionBlockerSystem.CanUse(user.Uid))
{
if (altInteract)
AltInteract(user, used);

View File

@@ -166,7 +166,7 @@ namespace Content.Shared.Verbs
/// The entity currently being held by the active hand.
/// </summary>
/// <remarks>
/// This is only ever not null when <see cref="ActionBlockerSystem.CanUse(IEntity)"/> is true and the user
/// This is only ever not null when <see cref="ActionBlockerSystem.CanUse(EntityUid)"/> is true and the user
/// has hands.
/// </remarks>
public IEntity? Using;
@@ -185,7 +185,7 @@ namespace Content.Shared.Verbs
CanInteract = force || actionBlockerSystem.CanInteract(user);
if (!user.TryGetComponent(out Hands) ||
!actionBlockerSystem.CanUse(user))
!actionBlockerSystem.CanUse(user.Uid))
return;
Hands.TryGetActiveHeldEntity(out Using);