Reset movement on player (de)attach (#12073)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using Content.Shared.Movement.Components;
|
||||
using Content.Shared.Movement.Systems;
|
||||
using Content.Shared.Pulling.Components;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.Player;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Physics.Components;
|
||||
@@ -13,6 +14,37 @@ namespace Content.Client.Physics.Controllers
|
||||
[Dependency] private readonly IGameTiming _timing = default!;
|
||||
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<RelayInputMoverComponent, PlayerAttachedEvent>(OnRelayPlayerAttached);
|
||||
SubscribeLocalEvent<RelayInputMoverComponent, PlayerDetachedEvent>(OnRelayPlayerDetached);
|
||||
SubscribeLocalEvent<InputMoverComponent, PlayerAttachedEvent>(OnPlayerAttached);
|
||||
SubscribeLocalEvent<InputMoverComponent, PlayerDetachedEvent>(OnPlayerDetached);
|
||||
}
|
||||
|
||||
private void OnRelayPlayerAttached(EntityUid uid, RelayInputMoverComponent component, PlayerAttachedEvent args)
|
||||
{
|
||||
if (TryComp<InputMoverComponent>(component.RelayEntity, out var inputMover))
|
||||
SetMoveInput(inputMover, MoveButtons.None);
|
||||
}
|
||||
|
||||
private void OnRelayPlayerDetached(EntityUid uid, RelayInputMoverComponent component, PlayerDetachedEvent args)
|
||||
{
|
||||
if (TryComp<InputMoverComponent>(component.RelayEntity, out var inputMover))
|
||||
SetMoveInput(inputMover, MoveButtons.None);
|
||||
}
|
||||
|
||||
private void OnPlayerAttached(EntityUid uid, InputMoverComponent component, PlayerAttachedEvent args)
|
||||
{
|
||||
SetMoveInput(component, MoveButtons.None);
|
||||
}
|
||||
|
||||
private void OnPlayerDetached(EntityUid uid, InputMoverComponent component, PlayerDetachedEvent args)
|
||||
{
|
||||
SetMoveInput(component, MoveButtons.None);
|
||||
}
|
||||
|
||||
public override void UpdateBeforeSolve(bool prediction, float frameTime)
|
||||
{
|
||||
base.UpdateBeforeSolve(prediction, frameTime);
|
||||
|
||||
@@ -5,6 +5,7 @@ using Content.Shared.Movement.Components;
|
||||
using Content.Shared.Movement.Systems;
|
||||
using Content.Shared.Shuttles.Components;
|
||||
using Content.Shared.Shuttles.Systems;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Physics.Components;
|
||||
using Robust.Shared.Player;
|
||||
@@ -18,6 +19,37 @@ namespace Content.Server.Physics.Controllers
|
||||
|
||||
private Dictionary<ShuttleComponent, List<(PilotComponent, InputMoverComponent, TransformComponent)>> _shuttlePilots = new();
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<RelayInputMoverComponent, PlayerAttachedEvent>(OnRelayPlayerAttached);
|
||||
SubscribeLocalEvent<RelayInputMoverComponent, PlayerDetachedEvent>(OnRelayPlayerDetached);
|
||||
SubscribeLocalEvent<InputMoverComponent, PlayerAttachedEvent>(OnPlayerAttached);
|
||||
SubscribeLocalEvent<InputMoverComponent, PlayerDetachedEvent>(OnPlayerDetached);
|
||||
}
|
||||
|
||||
private void OnRelayPlayerAttached(EntityUid uid, RelayInputMoverComponent component, PlayerAttachedEvent args)
|
||||
{
|
||||
if (TryComp<InputMoverComponent>(component.RelayEntity, out var inputMover))
|
||||
SetMoveInput(inputMover, MoveButtons.None);
|
||||
}
|
||||
|
||||
private void OnRelayPlayerDetached(EntityUid uid, RelayInputMoverComponent component, PlayerDetachedEvent args)
|
||||
{
|
||||
if (TryComp<InputMoverComponent>(component.RelayEntity, out var inputMover))
|
||||
SetMoveInput(inputMover, MoveButtons.None);
|
||||
}
|
||||
|
||||
private void OnPlayerAttached(EntityUid uid, InputMoverComponent component, PlayerAttachedEvent args)
|
||||
{
|
||||
SetMoveInput(component, MoveButtons.None);
|
||||
}
|
||||
|
||||
private void OnPlayerDetached(EntityUid uid, InputMoverComponent component, PlayerDetachedEvent args)
|
||||
{
|
||||
SetMoveInput(component, MoveButtons.None);
|
||||
}
|
||||
|
||||
protected override bool CanSound()
|
||||
{
|
||||
return true;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using Content.Shared.Movement.Systems;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
|
||||
@@ -59,7 +59,7 @@ namespace Content.Shared.Movement.Systems
|
||||
CameraRotationLocked = obj;
|
||||
}
|
||||
|
||||
private void SetMoveInput(InputMoverComponent component, MoveButtons buttons)
|
||||
protected void SetMoveInput(InputMoverComponent component, MoveButtons buttons)
|
||||
{
|
||||
if (component.HeldMoveButtons == buttons) return;
|
||||
component.HeldMoveButtons = buttons;
|
||||
@@ -517,7 +517,6 @@ namespace Content.Shared.Movement.Systems
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Flags]
|
||||
public enum MoveButtons : byte
|
||||
@@ -542,3 +541,5 @@ public enum ShuttleButtons : byte
|
||||
RotateRight = 1 << 5,
|
||||
Brake = 1 << 6,
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using Content.Shared.Movement.Systems;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
Reference in New Issue
Block a user