diff --git a/Content.Client/Buckle/BuckleComponent.cs b/Content.Client/Buckle/BuckleComponent.cs index 52743e3695..a840927388 100644 --- a/Content.Client/Buckle/BuckleComponent.cs +++ b/Content.Client/Buckle/BuckleComponent.cs @@ -1,3 +1,4 @@ +using Content.Shared.ActionBlocker; using Content.Shared.Buckle.Components; using Robust.Client.GameObjects; using Robust.Shared.GameObjects; @@ -9,6 +10,9 @@ namespace Content.Client.Buckle [ComponentReference(typeof(SharedBuckleComponent))] public sealed class BuckleComponent : SharedBuckleComponent { + [Dependency] private readonly IEntityManager _entMan = default!; + [Dependency] private readonly IEntitySystemManager _sysMan = default!; + private bool _buckled; private int? _originalDrawDepth; @@ -30,7 +34,10 @@ namespace Content.Client.Buckle _buckled = buckle.Buckled; LastEntityBuckledTo = buckle.LastEntityBuckledTo; DontCollide = buckle.DontCollide; - if (!IoCManager.Resolve().TryGetComponent(Owner, out SpriteComponent? ownerSprite)) + + _sysMan.GetEntitySystem().UpdateCanMove(Owner); + + if (!_entMan.TryGetComponent(Owner, out SpriteComponent? ownerSprite)) { return; } diff --git a/Content.Client/Cuffs/Components/CuffableComponent.cs b/Content.Client/Cuffs/Components/CuffableComponent.cs index 86012e33c4..b923491377 100644 --- a/Content.Client/Cuffs/Components/CuffableComponent.cs +++ b/Content.Client/Cuffs/Components/CuffableComponent.cs @@ -1,4 +1,5 @@ -using Content.Shared.CharacterAppearance; +using Content.Shared.ActionBlocker; +using Content.Shared.CharacterAppearance; using Content.Shared.Cuffs.Components; using Robust.Client.GameObjects; using Robust.Client.Graphics; @@ -17,6 +18,7 @@ namespace Content.Client.Cuffs.Components private string? _currentRSI; [Dependency] private readonly IEntityManager _entityManager = default!; + [Dependency] private readonly IEntitySystemManager _sysMan = default!; public override void HandleComponentState(ComponentState? curState, ComponentState? nextState) { @@ -26,6 +28,7 @@ namespace Content.Client.Cuffs.Components } CanStillInteract = cuffState.CanStillInteract; + _sysMan.GetEntitySystem().UpdateCanMove(Owner); if (_entityManager.TryGetComponent(Owner, out var spriteComponent)) { diff --git a/Content.Server/AI/Components/AiControllerComponent.cs b/Content.Server/AI/Components/AiControllerComponent.cs index 64602e2014..6b9210b0c3 100644 --- a/Content.Server/AI/Components/AiControllerComponent.cs +++ b/Content.Server/AI/Components/AiControllerComponent.cs @@ -1,14 +1,10 @@ -using Content.Server.AI.EntitySystems; +using Content.Server.AI.EntitySystems; using Content.Server.GameTicking; +using Content.Shared.ActionBlocker; using Content.Shared.Movement.Components; using Content.Shared.Roles; -using Robust.Shared.GameObjects; -using Robust.Shared.IoC; using Robust.Shared.Map; -using Robust.Shared.Maths; using Robust.Shared.Prototypes; -using Robust.Shared.Serialization.Manager.Attributes; -using Robust.Shared.ViewVariables; namespace Content.Server.AI.Components { @@ -19,6 +15,8 @@ namespace Content.Server.AI.Components { [DataField("logic")] private float _visionRadius = 8.0f; + public bool CanMove { get; set; } = true; + // TODO: Need to ECS a lot more of the AI first before we can ECS this /// /// Whether the AI is actively iterated. diff --git a/Content.Server/AI/Steering/AiSteeringSystem.cs b/Content.Server/AI/Steering/AiSteeringSystem.cs index eb368006fb..9d7bd23905 100644 --- a/Content.Server/AI/Steering/AiSteeringSystem.cs +++ b/Content.Server/AI/Steering/AiSteeringSystem.cs @@ -1,5 +1,3 @@ -using System; -using System.Collections.Generic; using System.Runtime.ExceptionServices; using System.Threading; using System.Threading.Tasks; @@ -8,17 +6,10 @@ using Content.Server.AI.Pathfinding; using Content.Server.AI.Pathfinding.Pathfinders; using Content.Server.CPUJob.JobQueues; using Content.Shared.Access.Systems; -using Content.Shared.ActionBlocker; using Content.Shared.Interaction; -using Content.Shared.Interaction.Helpers; -using Robust.Shared.GameObjects; -using Robust.Shared.IoC; using Robust.Shared.Map; -using Robust.Shared.Maths; using Robust.Shared.Physics; -using Robust.Shared.Timing; using Robust.Shared.Utility; -using Robust.Shared.ViewVariables; namespace Content.Server.AI.Steering { @@ -249,7 +240,7 @@ namespace Content.Server.AI.Steering // Main optimisation to be done below is the redundant calls and adding more variables if (Deleted(entity) || !EntityManager.TryGetComponent(entity, out AiControllerComponent? controller) || - !EntitySystem.Get().CanMove(entity) || + !controller.CanMove || !EntityManager.GetComponent(entity).GridID.IsValid()) { return SteeringStatus.NoPath; diff --git a/Content.Server/Buckle/Components/BuckleComponent.cs b/Content.Server/Buckle/Components/BuckleComponent.cs index 499acb2f19..a250d227c0 100644 --- a/Content.Server/Buckle/Components/BuckleComponent.cs +++ b/Content.Server/Buckle/Components/BuckleComponent.cs @@ -26,6 +26,7 @@ namespace Content.Server.Buckle.Components public sealed class BuckleComponent : SharedBuckleComponent { [Dependency] private readonly IEntityManager _entMan = default!; + [Dependency] private readonly IEntitySystemManager _sysMan = default!; [Dependency] private readonly IGameTiming _gameTiming = default!; [DataField("size")] @@ -63,7 +64,8 @@ namespace Content.Server.Buckle.Components { _buckledTo = value; _buckleTime = _gameTiming.CurTime; - Dirty(); + _sysMan.GetEntitySystem().UpdateCanMove(Owner); + Dirty(_entMan); } } diff --git a/Content.Server/Cuffs/Components/CuffableComponent.cs b/Content.Server/Cuffs/Components/CuffableComponent.cs index 1f815706a1..f567ee9b0f 100644 --- a/Content.Server/Cuffs/Components/CuffableComponent.cs +++ b/Content.Server/Cuffs/Components/CuffableComponent.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using Content.Server.DoAfter; using Content.Server.Hands.Components; +using Content.Shared.ActionBlocker; using Content.Shared.Alert; using Content.Shared.Cuffs.Components; using Content.Shared.Hands.EntitySystems; @@ -112,6 +113,7 @@ namespace Content.Server.Cuffs.Components Container.Insert(handcuff); CanStillInteract = _entMan.TryGetComponent(Owner, out HandsComponent? ownerHands) && ownerHands.Hands.Count() > CuffedHandCount; + _sysMan.GetEntitySystem().UpdateCanMove(Owner); OnCuffedStateChanged?.Invoke(); UpdateAlert(); @@ -267,6 +269,7 @@ namespace Content.Server.Cuffs.Components } CanStillInteract = _entMan.TryGetComponent(Owner, out HandsComponent? handsComponent) && handsComponent.SortedHands.Count() > CuffedHandCount; + _sysMan.GetEntitySystem().UpdateCanMove(Owner); OnCuffedStateChanged?.Invoke(); UpdateAlert(); Dirty(); diff --git a/Content.Server/Cuffs/CuffableSystem.cs b/Content.Server/Cuffs/CuffableSystem.cs index cb36ecfde8..213f07d1c9 100644 --- a/Content.Server/Cuffs/CuffableSystem.cs +++ b/Content.Server/Cuffs/CuffableSystem.cs @@ -7,9 +7,6 @@ using Content.Shared.MobState.Components; using Content.Shared.Popups; using Content.Shared.Verbs; using JetBrains.Annotations; -using Robust.Shared.GameObjects; -using Robust.Shared.IoC; -using Robust.Shared.Localization; using Robust.Shared.Player; namespace Content.Server.Cuffs @@ -121,6 +118,7 @@ namespace Content.Server.Cuffs if (dirty) { cuffable.CanStillInteract = handCount > cuffable.CuffedHandCount; + _actionBlockerSystem.UpdateCanMove(cuffable.Owner); cuffable.CuffedStateChanged(); Dirty(cuffable); } diff --git a/Content.Server/PAI/PAISystem.cs b/Content.Server/PAI/PAISystem.cs index 6796a24055..cda725d2f7 100644 --- a/Content.Server/PAI/PAISystem.cs +++ b/Content.Server/PAI/PAISystem.cs @@ -1,16 +1,11 @@ using Content.Shared.Examine; using Content.Shared.PAI; using Content.Shared.Verbs; -using Content.Shared.Instruments; using Content.Server.Popups; using Content.Server.Instruments; using Content.Server.Ghost.Roles.Components; using Content.Server.Mind.Components; using Robust.Server.GameObjects; -using Robust.Shared.IoC; -using Robust.Shared.Log; -using Robust.Shared.GameObjects; -using Robust.Shared.Localization; using Robust.Shared.Player; using Content.Shared.Actions; using Content.Shared.Interaction.Events; @@ -21,7 +16,6 @@ namespace Content.Server.PAI { [Dependency] private readonly PopupSystem _popupSystem = default!; [Dependency] private readonly InstrumentSystem _instrumentSystem = default!; - [Dependency] private readonly SharedActionsSystem _actionsSystem = default!; public override void Initialize() { @@ -32,21 +26,6 @@ namespace Content.Server.PAI SubscribeLocalEvent(OnMindAdded); SubscribeLocalEvent(OnMindRemoved); SubscribeLocalEvent>(AddWipeVerb); - - SubscribeLocalEvent(OnStartup); - SubscribeLocalEvent(OnShutdown); - } - - private void OnStartup(EntityUid uid, PAIComponent component, ComponentStartup args) - { - if (component.MidiAction != null) - _actionsSystem.AddAction(uid, component.MidiAction, null); - } - - private void OnShutdown(EntityUid uid, PAIComponent component, ComponentShutdown args) - { - if (component.MidiAction != null) - _actionsSystem.RemoveAction(uid, component.MidiAction); } private void OnExamined(EntityUid uid, PAIComponent component, ExaminedEvent args) diff --git a/Content.Server/Shuttles/EntitySystems/ShuttleConsoleSystem.cs b/Content.Server/Shuttles/EntitySystems/ShuttleConsoleSystem.cs index 53992d56be..2c69a9c373 100644 --- a/Content.Server/Shuttles/EntitySystems/ShuttleConsoleSystem.cs +++ b/Content.Server/Shuttles/EntitySystems/ShuttleConsoleSystem.cs @@ -10,9 +10,6 @@ using Content.Shared.Shuttles; using Content.Shared.Shuttles.Components; using Content.Shared.Tag; using Content.Shared.Verbs; -using Robust.Shared.GameObjects; -using Robust.Shared.IoC; -using Robust.Shared.Localization; using Robust.Shared.Map; using Robust.Shared.Player; using Robust.Shared.Utility; @@ -36,7 +33,6 @@ namespace Content.Server.Shuttles.EntitySystems SubscribeLocalEvent(HandlePowerChange); SubscribeLocalEvent>(OnConsoleInteract); - SubscribeLocalEvent(HandlePilotShutdown); SubscribeLocalEvent(HandlePilotMove); } @@ -177,8 +173,9 @@ namespace Content.Server.Shuttles.EntitySystems AddPilot(args.User, component); } - private void HandlePilotShutdown(EntityUid uid, PilotComponent component, ComponentShutdown args) + protected override void HandlePilotShutdown(EntityUid uid, PilotComponent component, ComponentShutdown args) { + base.HandlePilotShutdown(uid, component, args); RemovePilot(component); } @@ -206,6 +203,7 @@ namespace Content.Server.Shuttles.EntitySystems entity.PopupMessage(Loc.GetString("shuttle-pilot-start")); pilotComponent.Console = component; + ActionBlockerSystem.UpdateCanMove(entity); pilotComponent.Position = EntityManager.GetComponent(entity).Coordinates; pilotComponent.Dirty(); } diff --git a/Content.Shared/ActionBlocker/ActionBlockerSystem.cs b/Content.Shared/ActionBlocker/ActionBlockerSystem.cs index 7df72f4946..2e9389a3f6 100644 --- a/Content.Shared/ActionBlocker/ActionBlockerSystem.cs +++ b/Content.Shared/ActionBlocker/ActionBlockerSystem.cs @@ -1,15 +1,14 @@ -using Content.Shared.Body.Events; +using Content.Shared.Body.Events; using Content.Shared.DragDrop; using Content.Shared.Emoting; using Content.Shared.Interaction; using Content.Shared.Interaction.Events; -using Content.Shared.Inventory.Events; using Content.Shared.Item; using Content.Shared.Movement; +using Content.Shared.Movement.Components; using Content.Shared.Speech; using Content.Shared.Throwing; using JetBrains.Annotations; -using Robust.Shared.GameObjects; namespace Content.Shared.ActionBlocker { @@ -19,11 +18,34 @@ namespace Content.Shared.ActionBlocker [UsedImplicitly] public sealed class ActionBlockerSystem : EntitySystem { - public bool CanMove(EntityUid uid) + public override void Initialize() { - var ev = new MovementAttemptEvent(uid); + base.Initialize(); + SubscribeLocalEvent(OnMoverStartup); + } + + private void OnMoverStartup(EntityUid uid, IMoverComponent component, ComponentStartup args) + { + UpdateCanMove(uid, component); + } + + public bool CanMove(EntityUid uid, IMoverComponent? component = null) + { + return Resolve(uid, ref component, false) && component.CanMove; + } + + public bool UpdateCanMove(EntityUid uid, IMoverComponent? component = null) + { + if (!Resolve(uid, ref component, false)) + return false; + + var ev = new UpdateCanMoveEvent(uid); RaiseLocalEvent(uid, ev); + if (component.CanMove == ev.Cancelled && component is Component comp) + Dirty(comp); + + component.CanMove = !ev.Cancelled; return !ev.Cancelled; } diff --git a/Content.Shared/Administration/AdminFrozenSystem.cs b/Content.Shared/Administration/AdminFrozenSystem.cs index 3eb4629713..1b487c808c 100644 --- a/Content.Shared/Administration/AdminFrozenSystem.cs +++ b/Content.Shared/Administration/AdminFrozenSystem.cs @@ -1,3 +1,4 @@ +using Content.Shared.ActionBlocker; using Content.Shared.Interaction.Events; using Content.Shared.Item; using Content.Shared.Movement; @@ -7,6 +8,8 @@ namespace Content.Shared.Administration; public sealed class AdminFrozenSystem : EntitySystem { + [Dependency] private readonly ActionBlockerSystem _blocker = default!; + public override void Initialize() { base.Initialize(); @@ -14,7 +17,22 @@ public sealed class AdminFrozenSystem : EntitySystem SubscribeLocalEvent((_, _, args) => args.Cancel()); SubscribeLocalEvent((_, _, args) => args.Cancel()); SubscribeLocalEvent((_, _, args) => args.Cancel()); - SubscribeLocalEvent((_, _, args) => args.Cancel()); SubscribeLocalEvent((_, _, args) => args.Cancel()); + SubscribeLocalEvent(UpdateCanMove); + SubscribeLocalEvent(UpdateCanMove); + SubscribeLocalEvent(OnUpdateCanMove); + } + + private void OnUpdateCanMove(EntityUid uid, AdminFrozenComponent component, UpdateCanMoveEvent args) + { + if (component.LifeStage > ComponentLifeStage.Running) + return; + + args.Cancel(); + } + + private void UpdateCanMove(EntityUid uid, AdminFrozenComponent component, EntityEventArgs args) + { + _blocker.UpdateCanMove(uid); } } diff --git a/Content.Shared/Buckle/SharedBuckleSystem.cs b/Content.Shared/Buckle/SharedBuckleSystem.cs index 7e76ee96b4..6bd95d61f5 100644 --- a/Content.Shared/Buckle/SharedBuckleSystem.cs +++ b/Content.Shared/Buckle/SharedBuckleSystem.cs @@ -17,7 +17,7 @@ namespace Content.Shared.Buckle SubscribeLocalEvent(HandleDown); SubscribeLocalEvent(HandleStand); SubscribeLocalEvent(HandleThrowPushback); - SubscribeLocalEvent(HandleMove); + SubscribeLocalEvent(HandleMove); SubscribeLocalEvent(OnBuckleChangeDirectionAttempt); } @@ -27,8 +27,11 @@ namespace Content.Shared.Buckle args.Cancel(); } - private void HandleMove(EntityUid uid, SharedBuckleComponent component, MovementAttemptEvent args) + private void HandleMove(EntityUid uid, SharedBuckleComponent component, UpdateCanMoveEvent args) { + if (component.LifeStage > ComponentLifeStage.Running) + return; + if (component.Buckled) args.Cancel(); } diff --git a/Content.Shared/Climbing/SharedClimbSystem.cs b/Content.Shared/Climbing/SharedClimbSystem.cs index 15663b2b9a..0af9e05d90 100644 --- a/Content.Shared/Climbing/SharedClimbSystem.cs +++ b/Content.Shared/Climbing/SharedClimbSystem.cs @@ -8,11 +8,14 @@ namespace Content.Shared.Climbing public override void Initialize() { base.Initialize(); - SubscribeLocalEvent(HandleMoveAttempt); + SubscribeLocalEvent(HandleMoveAttempt); } - private void HandleMoveAttempt(EntityUid uid, SharedClimbingComponent component, MovementAttemptEvent args) + private void HandleMoveAttempt(EntityUid uid, SharedClimbingComponent component, UpdateCanMoveEvent args) { + if (component.LifeStage > ComponentLifeStage.Running) + return; + if (component.OwnerIsTransitioning) args.Cancel(); } diff --git a/Content.Shared/Climbing/SharedClimbingComponent.cs b/Content.Shared/Climbing/SharedClimbingComponent.cs index 5a48ad08e8..07eb2d6f3a 100644 --- a/Content.Shared/Climbing/SharedClimbingComponent.cs +++ b/Content.Shared/Climbing/SharedClimbingComponent.cs @@ -1,12 +1,8 @@ -using System; using Content.Shared.ActionBlocker; using Content.Shared.Physics; -using Robust.Shared.GameObjects; using Robust.Shared.GameStates; -using Robust.Shared.IoC; using Robust.Shared.Physics; using Robust.Shared.Serialization; -using Robust.Shared.ViewVariables; namespace Content.Shared.Climbing { @@ -14,6 +10,7 @@ namespace Content.Shared.Climbing public abstract class SharedClimbingComponent : Component { [Dependency] private readonly IEntityManager _entMan = default!; + [Dependency] private readonly IEntitySystemManager _sysMan = default!; protected bool IsOnClimbableThisFrame { @@ -47,6 +44,8 @@ namespace Content.Shared.Climbing { physicsComponent.BodyType = BodyType.KinematicController; } + + _sysMan.GetEntitySystem().UpdateCanMove(Owner); } } diff --git a/Content.Shared/Cuffs/SharedCuffableSystem.cs b/Content.Shared/Cuffs/SharedCuffableSystem.cs index 79a288d76f..69671fd1a1 100644 --- a/Content.Shared/Cuffs/SharedCuffableSystem.cs +++ b/Content.Shared/Cuffs/SharedCuffableSystem.cs @@ -1,9 +1,11 @@ +using Content.Shared.ActionBlocker; using Content.Shared.Cuffs.Components; using Content.Shared.DragDrop; using Content.Shared.Interaction.Events; using Content.Shared.Inventory.Events; using Content.Shared.Item; using Content.Shared.Movement; +using Content.Shared.Physics.Pull; using Content.Shared.Pulling.Components; using Robust.Shared.GameObjects; @@ -11,20 +13,29 @@ namespace Content.Shared.Cuffs { public abstract class SharedCuffableSystem : EntitySystem { + [Dependency] private readonly ActionBlockerSystem _blocker = default!; + public override void Initialize() { base.Initialize(); SubscribeLocalEvent(HandleStopPull); - SubscribeLocalEvent(HandleMoveAttempt); + SubscribeLocalEvent(HandleMoveAttempt); SubscribeLocalEvent(OnUseAttempt); SubscribeLocalEvent(OnInteractAttempt); SubscribeLocalEvent(OnEquipAttempt); SubscribeLocalEvent(OnUnequipAttempt); SubscribeLocalEvent(OnDropAttempt); SubscribeLocalEvent(OnPickupAttempt); + SubscribeLocalEvent(OnPull); } - private void HandleMoveAttempt(EntityUid uid, SharedCuffableComponent component, MovementAttemptEvent args) + private void OnPull(EntityUid uid, SharedCuffableComponent component, PullMessage args) + { + if (!component.CanStillInteract) + _blocker.UpdateCanMove(uid); + } + + private void HandleMoveAttempt(EntityUid uid, SharedCuffableComponent component, UpdateCanMoveEvent args) { if (component.CanStillInteract || !EntityManager.TryGetComponent(uid, out SharedPullableComponent? pullable) || !pullable.BeingPulled) return; diff --git a/Content.Shared/MobState/EntitySystems/MobStateSystem.cs b/Content.Shared/MobState/EntitySystems/MobStateSystem.cs index 229c70aa29..faedfc33ee 100644 --- a/Content.Shared/MobState/EntitySystems/MobStateSystem.cs +++ b/Content.Shared/MobState/EntitySystems/MobStateSystem.cs @@ -1,3 +1,4 @@ +using Content.Shared.ActionBlocker; using Content.Shared.Damage; using Content.Shared.DragDrop; using Content.Shared.Emoting; @@ -17,6 +18,8 @@ namespace Content.Shared.MobState.EntitySystems { public sealed class MobStateSystem : EntitySystem { + [Dependency] private readonly ActionBlockerSystem _blocker = default!; + public override void Initialize() { base.Initialize(); @@ -33,12 +36,17 @@ namespace Content.Shared.MobState.EntitySystems SubscribeLocalEvent(OnPickupAttempt); SubscribeLocalEvent(OnStartPullAttempt); SubscribeLocalEvent(UpdateState); - SubscribeLocalEvent(OnMoveAttempt); + SubscribeLocalEvent(OnMoveAttempt); SubscribeLocalEvent(OnStandAttempt); + SubscribeLocalEvent(OnStateChanged); // Note that there's no check for Down attempts because if a mob's in crit or dead, they can be downed... } #region ActionBlocker + private void OnStateChanged(MobStateChangedEvent ev) + { + _blocker.UpdateCanMove(ev.Entity); + } private void CheckAct(EntityUid uid, MobStateComponent component, CancellableEntityEventArgs args) { @@ -118,7 +126,7 @@ namespace Content.Shared.MobState.EntitySystems component.UpdateState(args.Damageable.TotalDamage); } - private void OnMoveAttempt(EntityUid uid, MobStateComponent component, MovementAttemptEvent args) + private void OnMoveAttempt(EntityUid uid, MobStateComponent component, UpdateCanMoveEvent args) { switch (component.CurrentState) { diff --git a/Content.Shared/Movement/Components/IMoverComponent.cs b/Content.Shared/Movement/Components/IMoverComponent.cs index 607d6e8e15..3b5ea08025 100644 --- a/Content.Shared/Movement/Components/IMoverComponent.cs +++ b/Content.Shared/Movement/Components/IMoverComponent.cs @@ -1,4 +1,4 @@ -using Robust.Shared.GameObjects; +using Robust.Shared.GameObjects; using Robust.Shared.Maths; namespace Content.Shared.Movement.Components @@ -22,6 +22,12 @@ namespace Content.Shared.Movement.Components /// bool Sprinting { get; } + /// + /// Can the entity currently move. Avoids having to raise move-attempt events every time a player moves. + /// Note that this value will be overridden by the action blocker system, and shouldn't just be set directly. + /// + bool CanMove { get; set; } + Angle LastGridAngle { get; set; } /// diff --git a/Content.Shared/Movement/Components/SharedDummyInputMoverComponent.cs b/Content.Shared/Movement/Components/SharedDummyInputMoverComponent.cs index 47a7705c64..857d4dc9f1 100644 --- a/Content.Shared/Movement/Components/SharedDummyInputMoverComponent.cs +++ b/Content.Shared/Movement/Components/SharedDummyInputMoverComponent.cs @@ -10,6 +10,7 @@ namespace Content.Shared.Movement.Components public bool IgnorePaused => false; public float CurrentWalkSpeed => 0f; public float CurrentSprintSpeed => 0f; + public bool CanMove { get; set; } = true; public Angle LastGridAngle { get => Angle.Zero; set {} } diff --git a/Content.Shared/Movement/Components/SharedPlayerInputMoverComponent.cs b/Content.Shared/Movement/Components/SharedPlayerInputMoverComponent.cs index d24bc816d2..cc8958dca5 100644 --- a/Content.Shared/Movement/Components/SharedPlayerInputMoverComponent.cs +++ b/Content.Shared/Movement/Components/SharedPlayerInputMoverComponent.cs @@ -1,14 +1,10 @@ using System; +using Content.Shared.ActionBlocker; using Content.Shared.CCVar; using Robust.Shared.Configuration; -using Robust.Shared.GameObjects; using Robust.Shared.GameStates; -using Robust.Shared.IoC; -using Robust.Shared.Maths; -using Robust.Shared.Players; using Robust.Shared.Serialization; using Robust.Shared.Timing; -using Robust.Shared.ViewVariables; namespace Content.Shared.Movement.Components { @@ -63,6 +59,9 @@ namespace Content.Shared.Movement.Components public bool Sprinting => !HasFlag(_heldMoveButtons, MoveButtons.Walk); + [ViewVariables(VVAccess.ReadWrite)] + public bool CanMove { get; set; } = true; + /// /// Calculated linear velocity direction of the entity. /// @@ -124,7 +123,7 @@ namespace Content.Shared.Movement.Components { base.Initialize(); Owner.EnsureComponentWarn(); - LastGridAngle = IoCManager.Resolve().GetComponent(Owner).Parent?.WorldRotation ?? new Angle(0); + LastGridAngle = _entityManager.GetComponent(Owner).Parent?.WorldRotation ?? new Angle(0); } /// @@ -200,12 +199,13 @@ namespace Content.Shared.Movement.Components _heldMoveButtons = state.Buttons; _lastInputTick = GameTick.Zero; _lastInputSubTick = 0; + CanMove = state.CanMove; } } public override ComponentState GetComponentState() { - return new MoverComponentState(_heldMoveButtons); + return new MoverComponentState(_heldMoveButtons, CanMove); } /// @@ -244,10 +244,12 @@ namespace Content.Shared.Movement.Components private sealed class MoverComponentState : ComponentState { public MoveButtons Buttons { get; } + public readonly bool CanMove; - public MoverComponentState(MoveButtons buttons) + public MoverComponentState(MoveButtons buttons, bool canMove) { Buttons = buttons; + CanMove = canMove; } } diff --git a/Content.Shared/Movement/MovementAttemptEvent.cs b/Content.Shared/Movement/MovementAttemptEvent.cs deleted file mode 100644 index 7a398793fa..0000000000 --- a/Content.Shared/Movement/MovementAttemptEvent.cs +++ /dev/null @@ -1,14 +0,0 @@ -using Robust.Shared.GameObjects; - -namespace Content.Shared.Movement -{ - public sealed class MovementAttemptEvent : CancellableEntityEventArgs - { - public MovementAttemptEvent(EntityUid uid) - { - Uid = uid; - } - - public EntityUid Uid { get; } - } -} diff --git a/Content.Shared/Movement/SharedMoverController.cs b/Content.Shared/Movement/SharedMoverController.cs index b02637b21a..af2a214e33 100644 --- a/Content.Shared/Movement/SharedMoverController.cs +++ b/Content.Shared/Movement/SharedMoverController.cs @@ -1,5 +1,4 @@ using System.Diagnostics.CodeAnalysis; -using Content.Shared.ActionBlocker; using Content.Shared.Audio; using Content.Shared.CCVar; using Content.Shared.Friction; @@ -27,7 +26,6 @@ namespace Content.Shared.Movement { [Dependency] private readonly IMapManager _mapManager = default!; [Dependency] private readonly ITileDefinitionManager _tileDefinitionManager = default!; - [Dependency] private readonly ActionBlockerSystem _blocker = default!; [Dependency] private readonly InventorySystem _inventory = default!; [Dependency] private readonly SharedPhysicsSystem _physics = default!; [Dependency] private readonly TagSystem _tags = default!; @@ -114,7 +112,7 @@ namespace Content.Shared.Movement { DebugTools.Assert(!UsedMobMovement.ContainsKey(mover.Owner)); - if (!UseMobMovement(physicsComponent)) + if (!UseMobMovement(mover, physicsComponent)) { UsedMobMovement[mover.Owner] = false; return; @@ -184,13 +182,13 @@ namespace Content.Shared.Movement return UsedMobMovement.TryGetValue(uid, out var used) && used; } - protected bool UseMobMovement(PhysicsComponent body) + protected bool UseMobMovement(IMoverComponent mover, PhysicsComponent body) { - return body.BodyStatus == BodyStatus.OnGround && - EntityManager.HasComponent(body.Owner) && + return mover.CanMove && + body.BodyStatus == BodyStatus.OnGround && + HasComp(body.Owner) && // If we're being pulled then don't mess with our velocity. - (!EntityManager.TryGetComponent(body.Owner, out SharedPullableComponent? pullable) || !pullable.BeingPulled) && - _blocker.CanMove((body).Owner); + (!TryComp(body.Owner, out SharedPullableComponent? pullable) || !pullable.BeingPulled); } /// diff --git a/Content.Shared/Movement/UpdateCanMoveEvent.cs b/Content.Shared/Movement/UpdateCanMoveEvent.cs new file mode 100644 index 0000000000..a7509f1d78 --- /dev/null +++ b/Content.Shared/Movement/UpdateCanMoveEvent.cs @@ -0,0 +1,17 @@ +using Content.Shared.Movement.Components; + +namespace Content.Shared.Movement; + +/// +/// Raised whenever needs to be updated. Cancel this event to prevent a +/// mover from moving. +/// +public sealed class UpdateCanMoveEvent : CancellableEntityEventArgs +{ + public UpdateCanMoveEvent(EntityUid uid) + { + Uid = uid; + } + + public EntityUid Uid { get; } +} diff --git a/Content.Shared/PAI/SharedPAISystem.cs b/Content.Shared/PAI/SharedPAISystem.cs index 241296942a..8884b195d9 100644 --- a/Content.Shared/PAI/SharedPAISystem.cs +++ b/Content.Shared/PAI/SharedPAISystem.cs @@ -1,9 +1,9 @@ -using System; +using Content.Shared.ActionBlocker; +using Content.Shared.Actions; using Content.Shared.DragDrop; using Content.Shared.Interaction.Events; using Content.Shared.Item; using Content.Shared.Movement; -using Robust.Shared.GameObjects; using Robust.Shared.Serialization; namespace Content.Shared.PAI @@ -19,6 +19,9 @@ namespace Content.Shared.PAI /// public abstract class SharedPAISystem : EntitySystem { + [Dependency] private readonly ActionBlockerSystem _blocker = default!; + [Dependency] private readonly SharedActionsSystem _actionsSystem = default!; + public override void Initialize() { base.Initialize(); @@ -26,12 +29,32 @@ namespace Content.Shared.PAI SubscribeLocalEvent(OnInteractAttempt); SubscribeLocalEvent(OnDropAttempt); SubscribeLocalEvent(OnPickupAttempt); - SubscribeLocalEvent(OnMoveAttempt); + SubscribeLocalEvent(OnMoveAttempt); SubscribeLocalEvent(OnChangeDirectionAttempt); + + SubscribeLocalEvent(OnStartup); + SubscribeLocalEvent(OnShutdown); } - private void OnMoveAttempt(EntityUid uid, PAIComponent component, MovementAttemptEvent args) + private void OnStartup(EntityUid uid, PAIComponent component, ComponentStartup args) { + _blocker.UpdateCanMove(uid); + if (component.MidiAction != null) + _actionsSystem.AddAction(uid, component.MidiAction, null); + } + + private void OnShutdown(EntityUid uid, PAIComponent component, ComponentShutdown args) + { + _blocker.UpdateCanMove(uid); + if (component.MidiAction != null) + _actionsSystem.RemoveAction(uid, component.MidiAction); + } + + private void OnMoveAttempt(EntityUid uid, PAIComponent component, UpdateCanMoveEvent args) + { + if (component.LifeStage > ComponentLifeStage.Running) + return; + args.Cancel(); // no more scurrying around on lil robot legs. } diff --git a/Content.Shared/Shuttles/Components/PilotComponent.cs b/Content.Shared/Shuttles/Components/PilotComponent.cs index 4b8f835fbf..66640ad705 100644 --- a/Content.Shared/Shuttles/Components/PilotComponent.cs +++ b/Content.Shared/Shuttles/Components/PilotComponent.cs @@ -1,4 +1,5 @@ using System; +using Content.Shared.ActionBlocker; using Robust.Shared.GameObjects; using Robust.Shared.GameStates; using Robust.Shared.IoC; @@ -16,6 +17,9 @@ namespace Content.Shared.Shuttles.Components [NetworkedComponent] public sealed class PilotComponent : Component { + [Dependency] private readonly IEntitySystemManager _sysMan = default!; + [Dependency] private readonly IEntityManager _entMan = default!; + [ViewVariables] public SharedShuttleConsoleComponent? Console { get; set; } /// @@ -37,15 +41,14 @@ namespace Content.Shared.Shuttles.Components return; } - var entityManager = IoCManager.Resolve(); - - if (!entityManager.TryGetComponent(console, out SharedShuttleConsoleComponent? shuttleConsoleComponent)) + if (!_entMan.TryGetComponent(console, out SharedShuttleConsoleComponent? shuttleConsoleComponent)) { Logger.Warning($"Unable to set Helmsman console to {console}"); return; } Console = shuttleConsoleComponent; + _sysMan.GetEntitySystem().UpdateCanMove(Owner); } public override ComponentState GetComponentState() diff --git a/Content.Shared/Shuttles/SharedShuttleConsoleSystem.cs b/Content.Shared/Shuttles/SharedShuttleConsoleSystem.cs index f3bb313daa..212de73fcc 100644 --- a/Content.Shared/Shuttles/SharedShuttleConsoleSystem.cs +++ b/Content.Shared/Shuttles/SharedShuttleConsoleSystem.cs @@ -1,19 +1,36 @@ +using Content.Shared.ActionBlocker; using Content.Shared.Movement; using Content.Shared.Shuttles.Components; -using Robust.Shared.GameObjects; namespace Content.Shared.Shuttles { public abstract class SharedShuttleConsoleSystem : EntitySystem { + [Dependency] protected readonly ActionBlockerSystem ActionBlockerSystem = default!; + public override void Initialize() { base.Initialize(); - SubscribeLocalEvent(HandleMovementBlock); + SubscribeLocalEvent(HandleMovementBlock); + SubscribeLocalEvent(OnStartup); + SubscribeLocalEvent(HandlePilotShutdown); } - private void HandleMovementBlock(EntityUid uid, PilotComponent component, MovementAttemptEvent args) + protected virtual void HandlePilotShutdown(EntityUid uid, PilotComponent component, ComponentShutdown args) { + ActionBlockerSystem.UpdateCanMove(uid); + } + + private void OnStartup(EntityUid uid, PilotComponent component, ComponentStartup args) + { + ActionBlockerSystem.UpdateCanMove(uid); + } + + private void HandleMovementBlock(EntityUid uid, PilotComponent component, UpdateCanMoveEvent args) + { + if (component.LifeStage > ComponentLifeStage.Running) + return; + if (component.Console == null) return; args.Cancel(); } diff --git a/Content.Shared/Stunnable/SharedStunSystem.cs b/Content.Shared/Stunnable/SharedStunSystem.cs index 157ceeb7f5..d9a8cd1823 100644 --- a/Content.Shared/Stunnable/SharedStunSystem.cs +++ b/Content.Shared/Stunnable/SharedStunSystem.cs @@ -1,4 +1,5 @@ using System; +using Content.Shared.ActionBlocker; using Content.Shared.Audio; using Content.Shared.DragDrop; using Content.Shared.Interaction; @@ -25,6 +26,7 @@ namespace Content.Shared.Stunnable [UsedImplicitly] public abstract class SharedStunSystem : EntitySystem { + [Dependency] private readonly ActionBlockerSystem _blocker = default!; [Dependency] private readonly StandingStateSystem _standingStateSystem = default!; [Dependency] private readonly StatusEffectsSystem _statusEffectSystem = default!; [Dependency] private readonly MovementSpeedModifierSystem _movementSpeedModifierSystem = default!; @@ -37,6 +39,9 @@ namespace Content.Shared.Stunnable SubscribeLocalEvent(OnSlowInit); SubscribeLocalEvent(OnSlowRemove); + SubscribeLocalEvent(UpdateCanMove); + SubscribeLocalEvent(UpdateCanMove); + SubscribeLocalEvent(OnSlowGetState); SubscribeLocalEvent(OnSlowHandleState); @@ -48,7 +53,7 @@ namespace Content.Shared.Stunnable SubscribeLocalEvent(OnRefreshMovespeed); // Attempt event subscriptions. - SubscribeLocalEvent(OnMoveAttempt); + SubscribeLocalEvent(OnMoveAttempt); SubscribeLocalEvent(OnInteractAttempt); SubscribeLocalEvent(OnUseAttempt); SubscribeLocalEvent(OnThrowAttempt); @@ -58,6 +63,11 @@ namespace Content.Shared.Stunnable SubscribeLocalEvent(OnUnequipAttempt); } + private void UpdateCanMove(EntityUid uid, StunnedComponent component, EntityEventArgs args) + { + _blocker.UpdateCanMove(uid); + } + private void OnSlowGetState(EntityUid uid, SlowedDownComponent component, ref ComponentGetState args) { args.State = new SlowedDownComponentState(component.SprintSpeedModifier, component.WalkSpeedModifier); @@ -205,8 +215,11 @@ namespace Content.Shared.Stunnable #region Attempt Event Handling - private void OnMoveAttempt(EntityUid uid, StunnedComponent stunned, MovementAttemptEvent args) + private void OnMoveAttempt(EntityUid uid, StunnedComponent stunned, UpdateCanMoveEvent args) { + if (stunned.LifeStage > ComponentLifeStage.Running) + return; + args.Cancel(); }