From 5f9cfaac4338ff0c775d1a61099cee554c690770 Mon Sep 17 00:00:00 2001 From: Vera Aguilera Puerto Date: Tue, 9 Nov 2021 13:15:55 +0100 Subject: [PATCH] ActionBlocker CanMove uses EntityUid exclusively --- Content.IntegrationTests/Tests/Buckle/BuckleTest.cs | 8 ++++---- Content.Server/AI/Steering/AiSteeringSystem.cs | 2 +- .../Considerations/ActionBlocker/CanMoveCon.cs | 2 +- Content.Server/Climbing/ClimbSystem.cs | 2 +- .../Unit/EntitySystems/DisposalUnitSystem.cs | 2 +- Content.Server/Medical/MedicalScannerSystem.cs | 2 +- Content.Shared/ActionBlocker/ActionBlockerSystem.cs | 13 ++++--------- Content.Shared/Movement/MovementAttemptEvent.cs | 6 +++--- Content.Shared/Movement/SharedMoverController.cs | 2 +- .../Pulling/Systems/SharedPullableSystem.cs | 4 ++-- 10 files changed, 19 insertions(+), 24 deletions(-) diff --git a/Content.IntegrationTests/Tests/Buckle/BuckleTest.cs b/Content.IntegrationTests/Tests/Buckle/BuckleTest.cs index 3a101ac2eb..4b8e1e3eb8 100644 --- a/Content.IntegrationTests/Tests/Buckle/BuckleTest.cs +++ b/Content.IntegrationTests/Tests/Buckle/BuckleTest.cs @@ -82,7 +82,7 @@ namespace Content.IntegrationTests.Tests.Buckle Assert.NotNull(buckle); Assert.Null(buckle.BuckledTo); Assert.False(buckle.Buckled); - Assert.True(actionBlocker.CanMove(human)); + Assert.True(actionBlocker.CanMove(human.Uid)); Assert.True(actionBlocker.CanChangeDirection(human)); Assert.True(standingState.Down(human.Uid)); Assert.True(standingState.Stand(human.Uid)); @@ -100,7 +100,7 @@ namespace Content.IntegrationTests.Tests.Buckle var player = IoCManager.Resolve().GetAllPlayers().Single(); Assert.True(((BuckleComponentState) buckle.GetComponentState(player)).Buckled); - Assert.False(actionBlocker.CanMove(human)); + Assert.False(actionBlocker.CanMove(human.Uid)); Assert.False(actionBlocker.CanChangeDirection(human)); Assert.False(standingState.Down(human.Uid)); Assert.That((human.Transform.WorldPosition - chair.Transform.WorldPosition).Length, Is.LessThanOrEqualTo(buckle.BuckleOffset.Length)); @@ -134,7 +134,7 @@ namespace Content.IntegrationTests.Tests.Buckle Assert.True(buckle.TryUnbuckle(human)); Assert.Null(buckle.BuckledTo); Assert.False(buckle.Buckled); - Assert.True(actionBlocker.CanMove(human)); + Assert.True(actionBlocker.CanMove(human.Uid)); Assert.True(actionBlocker.CanChangeDirection(human)); Assert.True(standingState.Down(human.Uid)); @@ -192,7 +192,7 @@ namespace Content.IntegrationTests.Tests.Buckle // Force unbuckle Assert.True(buckle.TryUnbuckle(human, true)); Assert.False(buckle.Buckled); - Assert.True(actionBlocker.CanMove(human)); + Assert.True(actionBlocker.CanMove(human.Uid)); Assert.True(actionBlocker.CanChangeDirection(human)); Assert.True(standingState.Down(human.Uid)); diff --git a/Content.Server/AI/Steering/AiSteeringSystem.cs b/Content.Server/AI/Steering/AiSteeringSystem.cs index ae2b190106..389b5fcb28 100644 --- a/Content.Server/AI/Steering/AiSteeringSystem.cs +++ b/Content.Server/AI/Steering/AiSteeringSystem.cs @@ -250,7 +250,7 @@ namespace Content.Server.AI.Steering // Main optimisation to be done below is the redundant calls and adding more variables if (entity.Deleted || !entity.TryGetComponent(out AiControllerComponent? controller) || - !EntitySystem.Get().CanMove(entity) || + !EntitySystem.Get().CanMove(entity.Uid) || !entity.Transform.GridID.IsValid()) { return SteeringStatus.NoPath; diff --git a/Content.Server/AI/Utility/Considerations/ActionBlocker/CanMoveCon.cs b/Content.Server/AI/Utility/Considerations/ActionBlocker/CanMoveCon.cs index 18ffa4ac79..83a7db8947 100644 --- a/Content.Server/AI/Utility/Considerations/ActionBlocker/CanMoveCon.cs +++ b/Content.Server/AI/Utility/Considerations/ActionBlocker/CanMoveCon.cs @@ -12,7 +12,7 @@ namespace Content.Server.AI.Utility.Considerations.ActionBlocker { var self = context.GetState().GetValue(); - if (self == null || !EntitySystem.Get().CanMove(self)) + if (self == null || !EntitySystem.Get().CanMove(self.Uid)) { return 0.0f; } diff --git a/Content.Server/Climbing/ClimbSystem.cs b/Content.Server/Climbing/ClimbSystem.cs index e36de443c3..27f4291afe 100644 --- a/Content.Server/Climbing/ClimbSystem.cs +++ b/Content.Server/Climbing/ClimbSystem.cs @@ -29,7 +29,7 @@ namespace Content.Server.Climbing private void AddClimbVerb(EntityUid uid, ClimbableComponent component, GetAlternativeVerbsEvent args) { - if (!args.CanAccess || !args.CanInteract || !_actionBlockerSystem.CanMove(args.User)) + if (!args.CanAccess || !args.CanInteract || !_actionBlockerSystem.CanMove(args.User.Uid)) return; // Check that the user climb. diff --git a/Content.Server/Disposal/Unit/EntitySystems/DisposalUnitSystem.cs b/Content.Server/Disposal/Unit/EntitySystems/DisposalUnitSystem.cs index 7e6b5cc54c..fb08bfa801 100644 --- a/Content.Server/Disposal/Unit/EntitySystems/DisposalUnitSystem.cs +++ b/Content.Server/Disposal/Unit/EntitySystems/DisposalUnitSystem.cs @@ -98,7 +98,7 @@ namespace Content.Server.Disposal.Unit.EntitySystems if (!args.CanAccess || !args.CanInteract || component.ContainedEntities.Contains(args.User) || - !_actionBlockerSystem.CanMove(args.User)) + !_actionBlockerSystem.CanMove(args.User.Uid)) return; // Add verb to climb inside of the unit, diff --git a/Content.Server/Medical/MedicalScannerSystem.cs b/Content.Server/Medical/MedicalScannerSystem.cs index e01f4beb8a..f749464338 100644 --- a/Content.Server/Medical/MedicalScannerSystem.cs +++ b/Content.Server/Medical/MedicalScannerSystem.cs @@ -60,7 +60,7 @@ namespace Content.Server.Medical // Self-insert verb if (!component.IsOccupied && component.CanInsert(args.User) && - _actionBlockerSystem.CanMove(args.User)) + _actionBlockerSystem.CanMove(args.User.Uid)) { Verb verb = new(); verb.Act = () => component.InsertBody(args.User); diff --git a/Content.Shared/ActionBlocker/ActionBlockerSystem.cs b/Content.Shared/ActionBlocker/ActionBlockerSystem.cs index bc6f8e14f5..be6ceafbca 100644 --- a/Content.Shared/ActionBlocker/ActionBlockerSystem.cs +++ b/Content.Shared/ActionBlocker/ActionBlockerSystem.cs @@ -21,17 +21,12 @@ namespace Content.Shared.ActionBlocker // TODO: Make the EntityUid the main overload for all these methods. // TODO: Move each of these to their relevant EntitySystems? - public bool CanMove(IEntity entity) - { - var ev = new MovementAttemptEvent(entity); - - RaiseLocalEvent(entity.Uid, ev); - return !ev.Cancelled; - } - public bool CanMove(EntityUid uid) { - return CanMove(EntityManager.GetEntity(uid)); + var ev = new MovementAttemptEvent(uid); + RaiseLocalEvent(uid, ev); + + return !ev.Cancelled; } public bool CanInteract(IEntity entity) diff --git a/Content.Shared/Movement/MovementAttemptEvent.cs b/Content.Shared/Movement/MovementAttemptEvent.cs index 058e3e4000..0d8bd98afd 100644 --- a/Content.Shared/Movement/MovementAttemptEvent.cs +++ b/Content.Shared/Movement/MovementAttemptEvent.cs @@ -4,11 +4,11 @@ namespace Content.Shared.Movement { public class MovementAttemptEvent : CancellableEntityEventArgs { - public MovementAttemptEvent(IEntity entity) + public MovementAttemptEvent(EntityUid uid) { - Entity = entity; + Uid = uid; } - public IEntity Entity { get; } + public EntityUid Uid { get; } } } diff --git a/Content.Shared/Movement/SharedMoverController.cs b/Content.Shared/Movement/SharedMoverController.cs index dd5007fdc5..e49a9089ba 100644 --- a/Content.Shared/Movement/SharedMoverController.cs +++ b/Content.Shared/Movement/SharedMoverController.cs @@ -163,7 +163,7 @@ namespace Content.Shared.Movement body.Owner.HasComponent() && // If we're being pulled then don't mess with our velocity. (!body.Owner.TryGetComponent(out SharedPullableComponent? pullable) || !pullable.BeingPulled) && - _blocker.CanMove(body.Owner); + _blocker.CanMove(body.OwnerUid); } /// diff --git a/Content.Shared/Pulling/Systems/SharedPullableSystem.cs b/Content.Shared/Pulling/Systems/SharedPullableSystem.cs index 6404b63f8d..03b8c48d57 100644 --- a/Content.Shared/Pulling/Systems/SharedPullableSystem.cs +++ b/Content.Shared/Pulling/Systems/SharedPullableSystem.cs @@ -19,8 +19,8 @@ namespace Content.Shared.Pulling.Systems private void OnRelayMoveInput(EntityUid uid, SharedPullableComponent component, RelayMoveInputEvent args) { - var entity = args.Session.AttachedEntity; - if (entity == null || !_blocker.CanMove(entity)) return; + var entity = args.Session.AttachedEntityUid; + if (entity == null || !_blocker.CanMove(entity.Value)) return; _pullSystem.TryStopPull(component); } }