From 51e785c0fd7b0b8cf424586e9d7aea8351aaf866 Mon Sep 17 00:00:00 2001 From: Vera Aguilera Puerto Date: Tue, 9 Nov 2021 13:23:50 +0100 Subject: [PATCH] ActionBlocker CanDrop uses EntityUid exclusively --- Content.Server/Access/IdCardConsoleSystem.cs | 8 ++++---- .../EntitySystems/ChemMasterSystem.cs | 2 +- .../EntitySystems/ReagentDispenserSystem.cs | 2 +- .../Power/EntitySystems/BaseChargerSystem.cs | 2 +- Content.Server/PowerCell/PowerCellSystem.cs | 2 +- .../Weapon/Ranged/Barrels/BarrelSystem.cs | 4 ++-- .../ActionBlocker/ActionBlockerSystem.cs | 18 +++++------------- .../ItemSlot/SharedItemSlotsSystem.cs | 2 +- Content.Shared/DragDrop/DropAttemptEvent.cs | 6 +++--- .../Hands/Components/SharedHandsComponent.cs | 2 +- .../Interaction/SharedInteractionSystem.cs | 2 +- 11 files changed, 21 insertions(+), 29 deletions(-) diff --git a/Content.Server/Access/IdCardConsoleSystem.cs b/Content.Server/Access/IdCardConsoleSystem.cs index 8dbc2d0972..597a6381f9 100644 --- a/Content.Server/Access/IdCardConsoleSystem.cs +++ b/Content.Server/Access/IdCardConsoleSystem.cs @@ -7,7 +7,7 @@ using Robust.Shared.Localization; namespace Content.Server.Access { - public class IdCardConsoleSystem : EntitySystem + public class IdCardConsoleSystem : EntitySystem { [Dependency] private readonly ActionBlockerSystem _actionBlockerSystem = default!; @@ -24,10 +24,10 @@ namespace Content.Server.Access !args.CanAccess || !args.CanInteract || !args.Using.HasComponent() || - !_actionBlockerSystem.CanDrop(args.User)) + !_actionBlockerSystem.CanDrop(args.User.Uid)) return; - // Can we insert a privileged ID? + // Can we insert a privileged ID? if (component.PrivilegedIDEmpty) { Verb verb = new(); @@ -56,7 +56,7 @@ namespace Content.Server.Access !_actionBlockerSystem.CanPickup(args.User)) return; - // Can we eject a privileged ID? + // Can we eject a privileged ID? if (!component.PrivilegedIDEmpty) { Verb verb = new(); diff --git a/Content.Server/Chemistry/EntitySystems/ChemMasterSystem.cs b/Content.Server/Chemistry/EntitySystems/ChemMasterSystem.cs index c04d0fd6ae..55b0a7337b 100644 --- a/Content.Server/Chemistry/EntitySystems/ChemMasterSystem.cs +++ b/Content.Server/Chemistry/EntitySystems/ChemMasterSystem.cs @@ -53,7 +53,7 @@ namespace Content.Server.Chemistry.EntitySystems !args.CanInteract || component.HasBeaker || !args.Using.HasComponent() || - !_actionBlockerSystem.CanDrop(args.User)) + !_actionBlockerSystem.CanDrop(args.User.Uid)) return; Verb verb = new(); diff --git a/Content.Server/Chemistry/EntitySystems/ReagentDispenserSystem.cs b/Content.Server/Chemistry/EntitySystems/ReagentDispenserSystem.cs index 6d445fdec1..525efe5a37 100644 --- a/Content.Server/Chemistry/EntitySystems/ReagentDispenserSystem.cs +++ b/Content.Server/Chemistry/EntitySystems/ReagentDispenserSystem.cs @@ -56,7 +56,7 @@ namespace Content.Server.Chemistry.EntitySystems !args.CanInteract || component.HasBeaker || !args.Using.HasComponent() || - !_actionBlockerSystem.CanDrop(args.User)) + !_actionBlockerSystem.CanDrop(args.User.Uid)) return; Verb verb = new(); diff --git a/Content.Server/Power/EntitySystems/BaseChargerSystem.cs b/Content.Server/Power/EntitySystems/BaseChargerSystem.cs index 7943c441ac..82f5866580 100644 --- a/Content.Server/Power/EntitySystems/BaseChargerSystem.cs +++ b/Content.Server/Power/EntitySystems/BaseChargerSystem.cs @@ -56,7 +56,7 @@ namespace Content.Server.Power.EntitySystems !args.CanInteract || component.HasCell || !component.IsEntityCompatible(args.Using) || - !_actionBlockerSystem.CanDrop(args.User)) + !_actionBlockerSystem.CanDrop(args.User.Uid)) return; Verb verb = new(); diff --git a/Content.Server/PowerCell/PowerCellSystem.cs b/Content.Server/PowerCell/PowerCellSystem.cs index b954b51874..ea41f72894 100644 --- a/Content.Server/PowerCell/PowerCellSystem.cs +++ b/Content.Server/PowerCell/PowerCellSystem.cs @@ -48,7 +48,7 @@ namespace Content.Server.PowerCell !args.CanInteract || component.HasCell || !args.Using.HasComponent() || - !_actionBlockerSystem.CanDrop(args.User)) + !_actionBlockerSystem.CanDrop(args.User.Uid)) return; Verb verb = new(); diff --git a/Content.Server/Weapon/Ranged/Barrels/BarrelSystem.cs b/Content.Server/Weapon/Ranged/Barrels/BarrelSystem.cs index 3f786fb2a1..726c2840a6 100644 --- a/Content.Server/Weapon/Ranged/Barrels/BarrelSystem.cs +++ b/Content.Server/Weapon/Ranged/Barrels/BarrelSystem.cs @@ -88,7 +88,7 @@ namespace Content.Server.Weapon.Ranged.Barrels !args.CanInteract || component.PowerCell != null || !args.Using.HasComponent() || - !_actionBlockerSystem.CanDrop(args.User)) + !_actionBlockerSystem.CanDrop(args.User.Uid)) return; Verb verb = new(); @@ -135,7 +135,7 @@ namespace Content.Server.Weapon.Ranged.Barrels // Are we holding a mag that we can insert? if (args.Using == null || !component.CanInsertMagazine(args.User, args.Using) || - !_actionBlockerSystem.CanDrop(args.User)) + !_actionBlockerSystem.CanDrop(args.User.Uid)) return; // Insert mag verb diff --git a/Content.Shared/ActionBlocker/ActionBlockerSystem.cs b/Content.Shared/ActionBlocker/ActionBlockerSystem.cs index 24b174f0a4..5f53f44235 100644 --- a/Content.Shared/ActionBlocker/ActionBlockerSystem.cs +++ b/Content.Shared/ActionBlocker/ActionBlockerSystem.cs @@ -54,7 +54,6 @@ namespace Content.Shared.ActionBlocker public bool CanThrow(EntityUid uid) { var ev = new ThrowAttemptEvent(uid); - RaiseLocalEvent(uid, ev); return !ev.Cancelled; @@ -63,24 +62,17 @@ namespace Content.Shared.ActionBlocker public bool CanSpeak(EntityUid uid) { var ev = new SpeakAttemptEvent(uid); - RaiseLocalEvent(uid, ev); return !ev.Cancelled; } - - public bool CanDrop(IEntity entity) - { - var ev = new DropAttemptEvent(entity); - - RaiseLocalEvent(entity.Uid, ev); - - return !ev.Cancelled; - } - + public bool CanDrop(EntityUid uid) { - return CanDrop(EntityManager.GetEntity(uid)); + var ev = new DropAttemptEvent(uid); + RaiseLocalEvent(uid, ev); + + return !ev.Cancelled; } public bool CanPickup(IEntity entity) diff --git a/Content.Shared/Containers/ItemSlot/SharedItemSlotsSystem.cs b/Content.Shared/Containers/ItemSlot/SharedItemSlotsSystem.cs index d427558bb0..0c2c195a27 100644 --- a/Content.Shared/Containers/ItemSlot/SharedItemSlotsSystem.cs +++ b/Content.Shared/Containers/ItemSlot/SharedItemSlotsSystem.cs @@ -89,7 +89,7 @@ namespace Content.Shared.Containers.ItemSlots if (args.Using == null || !args.CanAccess || !args.CanInteract || - !_actionBlockerSystem.CanDrop(args.User)) + !_actionBlockerSystem.CanDrop(args.User.Uid)) return; foreach (var (slotName, slot) in component.Slots) diff --git a/Content.Shared/DragDrop/DropAttemptEvent.cs b/Content.Shared/DragDrop/DropAttemptEvent.cs index 564093bafd..98bdeab9fb 100644 --- a/Content.Shared/DragDrop/DropAttemptEvent.cs +++ b/Content.Shared/DragDrop/DropAttemptEvent.cs @@ -4,11 +4,11 @@ namespace Content.Shared.DragDrop { public class DropAttemptEvent : CancellableEntityEventArgs { - public DropAttemptEvent(IEntity entity) + public DropAttemptEvent(EntityUid uid) { - Entity = entity; + Uid = uid; } - public IEntity Entity { get; } + public EntityUid Uid { get; } } } diff --git a/Content.Shared/Hands/Components/SharedHandsComponent.cs b/Content.Shared/Hands/Components/SharedHandsComponent.cs index 3b7b82b6fe..96bece3897 100644 --- a/Content.Shared/Hands/Components/SharedHandsComponent.cs +++ b/Content.Shared/Hands/Components/SharedHandsComponent.cs @@ -430,7 +430,7 @@ namespace Content.Shared.Hands.Components /// private bool PlayerCanDrop() { - if (!IoCManager.Resolve().GetEntitySystem().CanDrop(Owner)) + if (!IoCManager.Resolve().GetEntitySystem().CanDrop(OwnerUid)) return false; return true; diff --git a/Content.Shared/Interaction/SharedInteractionSystem.cs b/Content.Shared/Interaction/SharedInteractionSystem.cs index f4921dfd0b..179e0535cc 100644 --- a/Content.Shared/Interaction/SharedInteractionSystem.cs +++ b/Content.Shared/Interaction/SharedInteractionSystem.cs @@ -660,7 +660,7 @@ namespace Content.Shared.Interaction /// public bool TryDroppedInteraction(IEntity user, IEntity item, bool intentional) { - if (user == null || item == null || !_actionBlockerSystem.CanDrop(user)) return false; + if (user == null || item == null || !_actionBlockerSystem.CanDrop(user.Uid)) return false; DroppedInteraction(user, item, intentional); return true;