From b2322864e9b4423451c1d921a887953926d09bfc Mon Sep 17 00:00:00 2001 From: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Date: Tue, 10 Aug 2021 10:34:01 +1000 Subject: [PATCH] Remove IActionBlocker.CanMove (#4449) * Remove IActionBlocker.CanMove Ported the remainders over to using MovementAttemptEvent which should also help make mob movement a bit faster. * Make that check faster --- Content.Client/Climbing/ClimbingSystem.cs | 9 +++++++++ Content.Server/Climbing/ClimbSystem.cs | 3 ++- .../Climbing/Components/ClimbingComponent.cs | 2 +- .../ActionBlocker/ActionBlockerSystem.cs | 10 ---------- .../ActionBlocker/IActionBlocker.cs | 3 --- .../Components/SharedBuckleComponent.cs | 5 ----- Content.Shared/Buckle/SharedBuckleSystem.cs | 8 ++++++++ Content.Shared/Climbing/SharedClimbSystem.cs | 20 +++++++++++++++++++ .../Climbing/SharedClimbingComponent.cs | 4 +--- .../Components/SharedCuffableComponent.cs | 4 ---- Content.Shared/Cuffs/SharedCuffableSystem.cs | 10 ++++++++++ .../Components/SharedMobStateComponent.cs | 5 ----- .../EntitySystems/SharedMobStateSystem.cs | 16 +++++++++++++++ Content.Shared/MobState/State/BaseMobState.cs | 5 ----- .../MobState/State/SharedCriticalMobState.cs | 5 ----- .../MobState/State/SharedDeadMobState.cs | 5 ----- .../MobState/State/SharedNormalMobState.cs | 5 ----- .../Stunnable/SharedStunnableComponent.cs | 2 -- Content.Shared/Stunnable/StunSystem.cs | 13 ++++++++++++ 19 files changed, 80 insertions(+), 54 deletions(-) create mode 100644 Content.Client/Climbing/ClimbingSystem.cs create mode 100644 Content.Shared/Climbing/SharedClimbSystem.cs diff --git a/Content.Client/Climbing/ClimbingSystem.cs b/Content.Client/Climbing/ClimbingSystem.cs new file mode 100644 index 0000000000..99f7a4b4f6 --- /dev/null +++ b/Content.Client/Climbing/ClimbingSystem.cs @@ -0,0 +1,9 @@ +using Content.Shared.Climbing; + +namespace Content.Client.Climbing +{ + public sealed class ClimbingSystem : SharedClimbSystem + { + + } +} diff --git a/Content.Server/Climbing/ClimbSystem.cs b/Content.Server/Climbing/ClimbSystem.cs index 3a4a0517bb..f10268b15c 100644 --- a/Content.Server/Climbing/ClimbSystem.cs +++ b/Content.Server/Climbing/ClimbSystem.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.Linq; using Content.Server.Climbing.Components; +using Content.Shared.Climbing; using Content.Shared.GameTicking; using JetBrains.Annotations; using Robust.Shared.GameObjects; @@ -8,7 +9,7 @@ using Robust.Shared.GameObjects; namespace Content.Server.Climbing { [UsedImplicitly] - internal sealed class ClimbSystem : EntitySystem + internal sealed class ClimbSystem : SharedClimbSystem { private readonly HashSet _activeClimbers = new(); diff --git a/Content.Server/Climbing/Components/ClimbingComponent.cs b/Content.Server/Climbing/Components/ClimbingComponent.cs index 8d06859605..3b5f6b3c68 100644 --- a/Content.Server/Climbing/Components/ClimbingComponent.cs +++ b/Content.Server/Climbing/Components/ClimbingComponent.cs @@ -41,7 +41,7 @@ namespace Content.Server.Climbing.Components } } - protected override bool OwnerIsTransitioning + public override bool OwnerIsTransitioning { get => base.OwnerIsTransitioning; set diff --git a/Content.Shared/ActionBlocker/ActionBlockerSystem.cs b/Content.Shared/ActionBlocker/ActionBlockerSystem.cs index 253475235b..0223ba54b8 100644 --- a/Content.Shared/ActionBlocker/ActionBlockerSystem.cs +++ b/Content.Shared/ActionBlocker/ActionBlockerSystem.cs @@ -25,16 +25,6 @@ namespace Content.Shared.ActionBlocker var ev = new MovementAttemptEvent(entity); RaiseLocalEvent(entity.Uid, ev); - - foreach (var blocker in entity.GetAllComponents()) - { - if (!blocker.CanMove()) - { - ev.Cancel(); - break; - } - } - return !ev.Cancelled; } diff --git a/Content.Shared/ActionBlocker/IActionBlocker.cs b/Content.Shared/ActionBlocker/IActionBlocker.cs index 2646a8ae4b..cdcae76223 100644 --- a/Content.Shared/ActionBlocker/IActionBlocker.cs +++ b/Content.Shared/ActionBlocker/IActionBlocker.cs @@ -10,9 +10,6 @@ namespace Content.Shared.ActionBlocker [Obsolete("Use events instead")] public interface IActionBlocker { - [Obsolete("Use MoveAttemptEvent instead")] - bool CanMove() => true; - [Obsolete("Use InteractAttemptEvent instead")] bool CanInteract() => true; diff --git a/Content.Shared/Buckle/Components/SharedBuckleComponent.cs b/Content.Shared/Buckle/Components/SharedBuckleComponent.cs index 73e5026e3e..db60285697 100644 --- a/Content.Shared/Buckle/Components/SharedBuckleComponent.cs +++ b/Content.Shared/Buckle/Components/SharedBuckleComponent.cs @@ -36,11 +36,6 @@ namespace Content.Shared.Buckle.Components public abstract bool TryBuckle(IEntity? user, IEntity to); - bool IActionBlocker.CanMove() - { - return !Buckled; - } - bool IActionBlocker.CanChangeDirection() { return !Buckled; diff --git a/Content.Shared/Buckle/SharedBuckleSystem.cs b/Content.Shared/Buckle/SharedBuckleSystem.cs index 2363b2b196..700deb5540 100644 --- a/Content.Shared/Buckle/SharedBuckleSystem.cs +++ b/Content.Shared/Buckle/SharedBuckleSystem.cs @@ -1,4 +1,5 @@ using Content.Shared.Buckle.Components; +using Content.Shared.Movement; using Content.Shared.Standing; using Content.Shared.Throwing; using Robust.Shared.GameObjects; @@ -15,6 +16,13 @@ namespace Content.Shared.Buckle SubscribeLocalEvent(HandleDown); SubscribeLocalEvent(HandleStand); SubscribeLocalEvent(HandleThrowPushback); + SubscribeLocalEvent(HandleMove); + } + + private void HandleMove(EntityUid uid, SharedBuckleComponent component, MovementAttemptEvent args) + { + if (component.Buckled) + args.Cancel(); } private void HandleStand(EntityUid uid, SharedBuckleComponent component, StandAttemptEvent args) diff --git a/Content.Shared/Climbing/SharedClimbSystem.cs b/Content.Shared/Climbing/SharedClimbSystem.cs new file mode 100644 index 0000000000..15663b2b9a --- /dev/null +++ b/Content.Shared/Climbing/SharedClimbSystem.cs @@ -0,0 +1,20 @@ +using Content.Shared.Movement; +using Robust.Shared.GameObjects; + +namespace Content.Shared.Climbing +{ + public abstract class SharedClimbSystem : EntitySystem + { + public override void Initialize() + { + base.Initialize(); + SubscribeLocalEvent(HandleMoveAttempt); + } + + private void HandleMoveAttempt(EntityUid uid, SharedClimbingComponent component, MovementAttemptEvent args) + { + if (component.OwnerIsTransitioning) + args.Cancel(); + } + } +} diff --git a/Content.Shared/Climbing/SharedClimbingComponent.cs b/Content.Shared/Climbing/SharedClimbingComponent.cs index 3f8c99c64f..b139b0e3f1 100644 --- a/Content.Shared/Climbing/SharedClimbingComponent.cs +++ b/Content.Shared/Climbing/SharedClimbingComponent.cs @@ -29,10 +29,8 @@ namespace Content.Shared.Climbing } } - bool IActionBlocker.CanMove() => !OwnerIsTransitioning; - [ViewVariables] - protected virtual bool OwnerIsTransitioning + public virtual bool OwnerIsTransitioning { get => _ownerIsTransitioning; set diff --git a/Content.Shared/Cuffs/Components/SharedCuffableComponent.cs b/Content.Shared/Cuffs/Components/SharedCuffableComponent.cs index f3b6a7a59f..72c61a6cb3 100644 --- a/Content.Shared/Cuffs/Components/SharedCuffableComponent.cs +++ b/Content.Shared/Cuffs/Components/SharedCuffableComponent.cs @@ -14,8 +14,6 @@ namespace Content.Shared.Cuffs.Components { public override string Name => "Cuffable"; - [ComponentDependency] private readonly SharedPullableComponent? _pullable = default!; - [ViewVariables] public bool CanStillInteract { get; set; } = true; @@ -28,8 +26,6 @@ namespace Content.Shared.Cuffs.Components bool IActionBlocker.CanAttack() => CanStillInteract; bool IActionBlocker.CanEquip() => CanStillInteract; bool IActionBlocker.CanUnequip() => CanStillInteract; - bool IActionBlocker.CanMove() => _pullable == null || !_pullable.BeingPulled || CanStillInteract; - #endregion [Serializable, NetSerializable] diff --git a/Content.Shared/Cuffs/SharedCuffableSystem.cs b/Content.Shared/Cuffs/SharedCuffableSystem.cs index 9877c4659c..2891da884c 100644 --- a/Content.Shared/Cuffs/SharedCuffableSystem.cs +++ b/Content.Shared/Cuffs/SharedCuffableSystem.cs @@ -1,4 +1,5 @@ using Content.Shared.Cuffs.Components; +using Content.Shared.Movement; using Content.Shared.Pulling.Components; using Robust.Shared.GameObjects; @@ -10,6 +11,15 @@ namespace Content.Shared.Cuffs { base.Initialize(); SubscribeLocalEvent(HandleStopPull); + SubscribeLocalEvent(HandleMoveAttempt); + } + + private void HandleMoveAttempt(EntityUid uid, SharedCuffableComponent component, MovementAttemptEvent args) + { + if (component.CanStillInteract || !ComponentManager.TryGetComponent(uid, out SharedPullableComponent? pullable) || !pullable.BeingPulled) + return; + + args.Cancel(); } private void HandleStopPull(EntityUid uid, SharedCuffableComponent component, StopPullingEvent args) diff --git a/Content.Shared/MobState/Components/SharedMobStateComponent.cs b/Content.Shared/MobState/Components/SharedMobStateComponent.cs index 79dc0977d8..5ded3365f1 100644 --- a/Content.Shared/MobState/Components/SharedMobStateComponent.cs +++ b/Content.Shared/MobState/Components/SharedMobStateComponent.cs @@ -338,11 +338,6 @@ namespace Content.Shared.MobState.Components return CurrentState?.CanInteract() ?? true; } - bool IActionBlocker.CanMove() - { - return CurrentState?.CanMove() ?? true; - } - bool IActionBlocker.CanUse() { return CurrentState?.CanUse() ?? true; diff --git a/Content.Shared/MobState/EntitySystems/SharedMobStateSystem.cs b/Content.Shared/MobState/EntitySystems/SharedMobStateSystem.cs index 6db4899389..bc7a0e9f6f 100644 --- a/Content.Shared/MobState/EntitySystems/SharedMobStateSystem.cs +++ b/Content.Shared/MobState/EntitySystems/SharedMobStateSystem.cs @@ -1,4 +1,6 @@ using Content.Shared.MobState.Components; +using Content.Shared.MobState.State; +using Content.Shared.Movement; using Content.Shared.Pulling.Events; using Robust.Shared.GameObjects; @@ -11,6 +13,7 @@ namespace Content.Shared.MobState.EntitySystems base.Initialize(); SubscribeLocalEvent(OnStartPullAttempt); + SubscribeLocalEvent(OnMoveAttempt); } private void OnStartPullAttempt(EntityUid uid, SharedMobStateComponent component, StartPullAttemptEvent args) @@ -18,5 +21,18 @@ namespace Content.Shared.MobState.EntitySystems if(component.IsIncapacitated()) args.Cancel(); } + + private void OnMoveAttempt(EntityUid uid, SharedMobStateComponent component, MovementAttemptEvent args) + { + switch (component.CurrentState) + { + case SharedCriticalMobState: + case SharedDeadMobState: + args.Cancel(); + return; + default: + return; + } + } } } diff --git a/Content.Shared/MobState/State/BaseMobState.cs b/Content.Shared/MobState/State/BaseMobState.cs index 760c33e3eb..d82771b00f 100644 --- a/Content.Shared/MobState/State/BaseMobState.cs +++ b/Content.Shared/MobState/State/BaseMobState.cs @@ -39,11 +39,6 @@ namespace Content.Shared.MobState.State return true; } - public virtual bool CanMove() - { - return true; - } - public virtual bool CanUse() { return true; diff --git a/Content.Shared/MobState/State/SharedCriticalMobState.cs b/Content.Shared/MobState/State/SharedCriticalMobState.cs index 038b14e77b..35683f2bb2 100644 --- a/Content.Shared/MobState/State/SharedCriticalMobState.cs +++ b/Content.Shared/MobState/State/SharedCriticalMobState.cs @@ -41,11 +41,6 @@ namespace Content.Shared.MobState.State return false; } - public override bool CanMove() - { - return false; - } - public override bool CanUse() { return false; diff --git a/Content.Shared/MobState/State/SharedDeadMobState.cs b/Content.Shared/MobState/State/SharedDeadMobState.cs index a511b3463a..09804138ba 100644 --- a/Content.Shared/MobState/State/SharedDeadMobState.cs +++ b/Content.Shared/MobState/State/SharedDeadMobState.cs @@ -49,11 +49,6 @@ namespace Content.Shared.MobState.State return false; } - public override bool CanMove() - { - return false; - } - public override bool CanUse() { return false; diff --git a/Content.Shared/MobState/State/SharedNormalMobState.cs b/Content.Shared/MobState/State/SharedNormalMobState.cs index f6ec05ae90..0dddbbcf3c 100644 --- a/Content.Shared/MobState/State/SharedNormalMobState.cs +++ b/Content.Shared/MobState/State/SharedNormalMobState.cs @@ -27,11 +27,6 @@ namespace Content.Shared.MobState.State return true; } - public override bool CanMove() - { - return true; - } - public override bool CanUse() { return true; diff --git a/Content.Shared/Stunnable/SharedStunnableComponent.cs b/Content.Shared/Stunnable/SharedStunnableComponent.cs index 2ac8f3c1f5..0ca20b8b77 100644 --- a/Content.Shared/Stunnable/SharedStunnableComponent.cs +++ b/Content.Shared/Stunnable/SharedStunnableComponent.cs @@ -323,8 +323,6 @@ namespace Content.Shared.Stunnable } #region ActionBlockers - public bool CanMove() => (!Stunned); - public bool CanInteract() => (!Stunned); public bool CanUse() => (!Stunned); diff --git a/Content.Shared/Stunnable/StunSystem.cs b/Content.Shared/Stunnable/StunSystem.cs index 7f83eca61f..bd44708f96 100644 --- a/Content.Shared/Stunnable/StunSystem.cs +++ b/Content.Shared/Stunnable/StunSystem.cs @@ -1,3 +1,4 @@ +using Content.Shared.Movement; using JetBrains.Annotations; using Robust.Shared.GameObjects; @@ -6,6 +7,18 @@ namespace Content.Shared.Stunnable [UsedImplicitly] internal sealed class StunSystem : EntitySystem { + public override void Initialize() + { + base.Initialize(); + SubscribeLocalEvent(HandleMoveAttempt); + } + + private void HandleMoveAttempt(EntityUid uid, SharedStunnableComponent component, MovementAttemptEvent args) + { + if (component.Stunned) + args.Cancel(); + } + public override void Update(float frameTime) { base.Update(frameTime);