From d4ded874486e886656c2ac6dc7355e9f036d1b8a Mon Sep 17 00:00:00 2001 From: Vera Aguilera Puerto Date: Tue, 9 Nov 2021 13:40:27 +0100 Subject: [PATCH] ActionBlocker CanAttack uses EntityUid exclusively --- Content.Server/Actions/Actions/DisarmAction.cs | 2 +- Content.Server/Interaction/InteractionSystem.cs | 2 +- .../ActionBlocker/ActionBlockerSystem.cs | 16 +++++----------- .../Interaction/Events/AttackAttemptEvent.cs | 6 +++--- 4 files changed, 10 insertions(+), 16 deletions(-) diff --git a/Content.Server/Actions/Actions/DisarmAction.cs b/Content.Server/Actions/Actions/DisarmAction.cs index 45c16412d6..b88de1de28 100644 --- a/Content.Server/Actions/Actions/DisarmAction.cs +++ b/Content.Server/Actions/Actions/DisarmAction.cs @@ -65,7 +65,7 @@ namespace Content.Server.Actions.Actions } if (!args.Performer.TryGetComponent(out var actions)) return; - if (args.Target == args.Performer || !EntitySystem.Get().CanAttack(args.Performer)) return; + if (args.Target == args.Performer || !EntitySystem.Get().CanAttack(args.Performer.Uid)) return; var random = IoCManager.Resolve(); var system = EntitySystem.Get(); diff --git a/Content.Server/Interaction/InteractionSystem.cs b/Content.Server/Interaction/InteractionSystem.cs index e355d062ad..54425b880e 100644 --- a/Content.Server/Interaction/InteractionSystem.cs +++ b/Content.Server/Interaction/InteractionSystem.cs @@ -430,7 +430,7 @@ namespace Content.Server.Interaction if (!ValidateInteractAndFace(user, coordinates)) return; - if (!_actionBlockerSystem.CanAttack(user)) + if (!_actionBlockerSystem.CanAttack(user.Uid)) return; IEntity? targetEnt = null; diff --git a/Content.Shared/ActionBlocker/ActionBlockerSystem.cs b/Content.Shared/ActionBlocker/ActionBlockerSystem.cs index 5f53f44235..7e5ebd459c 100644 --- a/Content.Shared/ActionBlocker/ActionBlockerSystem.cs +++ b/Content.Shared/ActionBlocker/ActionBlockerSystem.cs @@ -66,7 +66,7 @@ namespace Content.Shared.ActionBlocker return !ev.Cancelled; } - + public bool CanDrop(EntityUid uid) { var ev = new DropAttemptEvent(uid); @@ -103,18 +103,12 @@ namespace Content.Shared.ActionBlocker return CanEmote(EntityManager.GetEntity(uid)); } - public bool CanAttack(IEntity entity) - { - var ev = new AttackAttemptEvent(entity); - - RaiseLocalEvent(entity.Uid, ev); - - return !ev.Cancelled; - } - public bool CanAttack(EntityUid uid) { - return CanAttack(EntityManager.GetEntity(uid)); + var ev = new AttackAttemptEvent(uid); + RaiseLocalEvent(uid, ev); + + return !ev.Cancelled; } public bool CanEquip(IEntity entity) diff --git a/Content.Shared/Interaction/Events/AttackAttemptEvent.cs b/Content.Shared/Interaction/Events/AttackAttemptEvent.cs index 0e1ed1a04e..0ac23db7ca 100644 --- a/Content.Shared/Interaction/Events/AttackAttemptEvent.cs +++ b/Content.Shared/Interaction/Events/AttackAttemptEvent.cs @@ -4,11 +4,11 @@ namespace Content.Shared.Interaction.Events { public class AttackAttemptEvent : CancellableEntityEventArgs { - public AttackAttemptEvent(IEntity entity) + public AttackAttemptEvent(EntityUid uid) { - Entity = entity; + Uid = uid; } - public IEntity Entity { get; } + public EntityUid Uid { get; } } }