mirror of
https://github.com/WWhiteDreamProject/wwdpublic.git
synced 2026-04-17 13:37:47 +03:00
## Mirror of PR #24936: [Pulling rework v2](https://github.com/space-wizards/space-station-14/pull/24936) from <img src="https://avatars.githubusercontent.com/u/10567778?v=4" alt="space-wizards" width="22"/> [space-wizards](https://github.com/space-wizards)/[space-station-14](https://github.com/space-wizards/space-station-14) ###### `c584f6444a85cc53edb060230f7e7b2b76cc87bf` PR opened by <img src="https://avatars.githubusercontent.com/u/31366439?v=4" width="16"/><a href="https://github.com/metalgearsloth"> metalgearsloth</a> at 2024-02-04 01:43:17 UTC --- PR changed 53 files with 796 additions and 1356 deletions. The PR had the following labels: - Status: Needs Review --- <details open="true"><summary><h1>Original Body</h1></summary> > Health v2 moment > > Fixes https://github.com/space-wizards/space-station-14/issues/24900 > > - Fixes container changes. > - Fixes keybind. > - Fixes multi-pull. > - Fixes alerts cleanup for non-predicted pull stops. > > I'm awake now for any issues. </details> --------- Co-authored-by: SimpleStation14 <Unknown> Co-authored-by: Danger Revolution! <142105406+DangerRevolution@users.noreply.github.com> Co-authored-by: VMSolidus <evilexecutive@gmail.com>
140 lines
5.5 KiB
C#
140 lines
5.5 KiB
C#
using Content.Shared.Movement.Components;
|
|
using Content.Shared.Movement.Pulling.Components;
|
|
using Content.Shared.Movement.Systems;
|
|
using Robust.Client.GameObjects;
|
|
using Robust.Client.Physics;
|
|
using Robust.Client.Player;
|
|
using Robust.Shared.Physics.Components;
|
|
using Robust.Shared.Player;
|
|
using Robust.Shared.Timing;
|
|
|
|
namespace Content.Client.Physics.Controllers
|
|
{
|
|
public sealed class MoverController : SharedMoverController
|
|
{
|
|
[Dependency] private readonly IGameTiming _timing = default!;
|
|
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
SubscribeLocalEvent<RelayInputMoverComponent, LocalPlayerAttachedEvent>(OnRelayPlayerAttached);
|
|
SubscribeLocalEvent<RelayInputMoverComponent, LocalPlayerDetachedEvent>(OnRelayPlayerDetached);
|
|
SubscribeLocalEvent<InputMoverComponent, LocalPlayerAttachedEvent>(OnPlayerAttached);
|
|
SubscribeLocalEvent<InputMoverComponent, LocalPlayerDetachedEvent>(OnPlayerDetached);
|
|
|
|
SubscribeLocalEvent<InputMoverComponent, UpdateIsPredictedEvent>(OnUpdatePredicted);
|
|
SubscribeLocalEvent<MovementRelayTargetComponent, UpdateIsPredictedEvent>(OnUpdateRelayTargetPredicted);
|
|
SubscribeLocalEvent<PullableComponent, UpdateIsPredictedEvent>(OnUpdatePullablePredicted);
|
|
}
|
|
|
|
private void OnUpdatePredicted(EntityUid uid, InputMoverComponent component, ref UpdateIsPredictedEvent args)
|
|
{
|
|
// Enable prediction if an entity is controlled by the player
|
|
if (uid == _playerManager.LocalEntity)
|
|
args.IsPredicted = true;
|
|
}
|
|
|
|
private void OnUpdateRelayTargetPredicted(EntityUid uid, MovementRelayTargetComponent component, ref UpdateIsPredictedEvent args)
|
|
{
|
|
if (component.Source == _playerManager.LocalEntity)
|
|
args.IsPredicted = true;
|
|
}
|
|
|
|
private void OnUpdatePullablePredicted(EntityUid uid, PullableComponent component, ref UpdateIsPredictedEvent args)
|
|
{
|
|
// Enable prediction if an entity is being pulled by the player.
|
|
// Disable prediction if an entity is being pulled by some non-player entity.
|
|
|
|
if (component.Puller == _playerManager.LocalEntity)
|
|
args.IsPredicted = true;
|
|
else if (component.Puller != null)
|
|
args.BlockPrediction = true;
|
|
|
|
// TODO recursive pulling checks?
|
|
// What if the entity is being pulled by a vehicle controlled by the player?
|
|
}
|
|
|
|
private void OnRelayPlayerAttached(EntityUid uid, RelayInputMoverComponent component, LocalPlayerAttachedEvent args)
|
|
{
|
|
Physics.UpdateIsPredicted(uid);
|
|
Physics.UpdateIsPredicted(component.RelayEntity);
|
|
if (MoverQuery.TryGetComponent(component.RelayEntity, out var inputMover))
|
|
SetMoveInput(inputMover, MoveButtons.None);
|
|
}
|
|
|
|
private void OnRelayPlayerDetached(EntityUid uid, RelayInputMoverComponent component, LocalPlayerDetachedEvent args)
|
|
{
|
|
Physics.UpdateIsPredicted(uid);
|
|
Physics.UpdateIsPredicted(component.RelayEntity);
|
|
if (MoverQuery.TryGetComponent(component.RelayEntity, out var inputMover))
|
|
SetMoveInput(inputMover, MoveButtons.None);
|
|
}
|
|
|
|
private void OnPlayerAttached(EntityUid uid, InputMoverComponent component, LocalPlayerAttachedEvent args)
|
|
{
|
|
SetMoveInput(component, MoveButtons.None);
|
|
}
|
|
|
|
private void OnPlayerDetached(EntityUid uid, InputMoverComponent component, LocalPlayerDetachedEvent args)
|
|
{
|
|
SetMoveInput(component, MoveButtons.None);
|
|
}
|
|
|
|
public override void UpdateBeforeSolve(bool prediction, float frameTime)
|
|
{
|
|
base.UpdateBeforeSolve(prediction, frameTime);
|
|
|
|
if (_playerManager.LocalEntity is not {Valid: true} player)
|
|
return;
|
|
|
|
if (RelayQuery.TryGetComponent(player, out var relayMover))
|
|
HandleClientsideMovement(relayMover.RelayEntity, frameTime);
|
|
|
|
HandleClientsideMovement(player, frameTime);
|
|
}
|
|
|
|
private void HandleClientsideMovement(EntityUid player, float frameTime)
|
|
{
|
|
if (!MoverQuery.TryGetComponent(player, out var mover) ||
|
|
!XformQuery.TryGetComponent(player, out var xform))
|
|
{
|
|
return;
|
|
}
|
|
|
|
var physicsUid = player;
|
|
PhysicsComponent? body;
|
|
var xformMover = xform;
|
|
|
|
if (mover.ToParent && RelayQuery.HasComponent(xform.ParentUid))
|
|
{
|
|
if (!PhysicsQuery.TryGetComponent(xform.ParentUid, out body) ||
|
|
!XformQuery.TryGetComponent(xform.ParentUid, out xformMover))
|
|
{
|
|
return;
|
|
}
|
|
|
|
physicsUid = xform.ParentUid;
|
|
}
|
|
else if (!PhysicsQuery.TryGetComponent(player, out body))
|
|
{
|
|
return;
|
|
}
|
|
|
|
// Server-side should just be handled on its own so we'll just do this shizznit
|
|
HandleMobMovement(
|
|
player,
|
|
mover,
|
|
physicsUid,
|
|
body,
|
|
xformMover,
|
|
frameTime);
|
|
}
|
|
|
|
protected override bool CanSound()
|
|
{
|
|
return _timing is { IsFirstTimePredicted: true, InSimulation: true };
|
|
}
|
|
}
|
|
}
|