2021-06-09 22:19:39 +02:00
|
|
|
using Content.Shared.Movement.Components;
|
2022-06-24 17:44:30 +10:00
|
|
|
using Content.Shared.Movement.Systems;
|
2021-09-02 12:35:16 +10:00
|
|
|
using Content.Shared.Pulling.Components;
|
2022-10-22 12:50:14 +13:00
|
|
|
using Robust.Client.GameObjects;
|
2021-03-08 04:09:59 +11:00
|
|
|
using Robust.Client.Player;
|
2021-10-04 15:35:03 +11:00
|
|
|
using Robust.Shared.Physics;
|
2022-09-14 17:26:26 +10:00
|
|
|
using Robust.Shared.Physics.Components;
|
2022-03-14 02:42:39 +11:00
|
|
|
using Robust.Shared.Timing;
|
2023-01-16 21:20:22 +13:00
|
|
|
using Robust.Shared.Utility;
|
2021-03-08 04:09:59 +11:00
|
|
|
|
|
|
|
|
namespace Content.Client.Physics.Controllers
|
|
|
|
|
{
|
|
|
|
|
public sealed class MoverController : SharedMoverController
|
|
|
|
|
{
|
2022-03-14 02:42:39 +11:00
|
|
|
[Dependency] private readonly IGameTiming _timing = default!;
|
2021-03-08 04:09:59 +11:00
|
|
|
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
|
|
|
|
|
2022-10-22 12:50:14 +13:00
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-08 04:09:59 +11:00
|
|
|
public override void UpdateBeforeSolve(bool prediction, float frameTime)
|
|
|
|
|
{
|
|
|
|
|
base.UpdateBeforeSolve(prediction, frameTime);
|
|
|
|
|
|
2022-07-16 13:51:52 +10:00
|
|
|
if (_playerManager.LocalPlayer?.ControlledEntity is not {Valid: true} player)
|
|
|
|
|
return;
|
|
|
|
|
|
2023-01-16 21:20:22 +13:00
|
|
|
if (TryComp<RelayInputMoverComponent>(player, out var relayMover)
|
|
|
|
|
&& TryComp(relayMover.RelayEntity, out MovementRelayTargetComponent? targetComp))
|
2022-07-16 13:51:52 +10:00
|
|
|
{
|
2023-01-16 21:20:22 +13:00
|
|
|
DebugTools.Assert(targetComp.Entities.Count <= 1, "Multiple relayed movers are not supported at the moment");
|
|
|
|
|
HandleClientsideMovement(relayMover.RelayEntity.Value, frameTime);
|
2022-07-16 13:51:52 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HandleClientsideMovement(player, frameTime);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void HandleClientsideMovement(EntityUid player, float frameTime)
|
|
|
|
|
{
|
2022-08-29 15:05:53 +10:00
|
|
|
var xformQuery = GetEntityQuery<TransformComponent>();
|
2023-01-16 21:20:22 +13:00
|
|
|
var moverQuery = GetEntityQuery<InputMoverComponent>();
|
|
|
|
|
var relayTargetQuery = GetEntityQuery<MovementRelayTargetComponent>();
|
2022-08-29 15:05:53 +10:00
|
|
|
|
2022-07-16 13:51:52 +10:00
|
|
|
if (!TryComp(player, out InputMoverComponent? mover) ||
|
2022-08-29 15:05:53 +10:00
|
|
|
!xformQuery.TryGetComponent(player, out var xform))
|
2022-07-25 14:16:24 +10:00
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-07-16 13:51:52 +10:00
|
|
|
|
2023-01-16 21:20:22 +13:00
|
|
|
PhysicsComponent? body;
|
2022-07-25 14:16:24 +10:00
|
|
|
TransformComponent? xformMover = xform;
|
2022-07-16 13:51:52 +10:00
|
|
|
|
|
|
|
|
if (mover.ToParent && HasComp<RelayInputMoverComponent>(xform.ParentUid))
|
|
|
|
|
{
|
2022-07-25 14:16:24 +10:00
|
|
|
if (!TryComp(xform.ParentUid, out body) ||
|
|
|
|
|
!TryComp(xform.ParentUid, out xformMover))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-07-16 13:51:52 +10:00
|
|
|
}
|
|
|
|
|
else if (!TryComp(player, out body))
|
2021-12-05 18:09:01 +01:00
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2021-03-08 04:09:59 +11:00
|
|
|
|
2021-08-04 01:16:42 +10:00
|
|
|
// Essentially we only want to set our mob to predicted so every other entity we just interpolate
|
|
|
|
|
// (i.e. only see what the server has sent us).
|
|
|
|
|
// The exception to this is joints.
|
|
|
|
|
body.Predict = true;
|
2021-03-08 04:09:59 +11:00
|
|
|
|
2021-08-04 01:16:42 +10:00
|
|
|
// We set joints to predicted given these can affect how our mob moves.
|
|
|
|
|
// I would only recommend disabling this if you make pulling not use joints anymore (someday maybe?)
|
2021-10-04 15:35:03 +11:00
|
|
|
|
2022-02-02 17:34:25 +11:00
|
|
|
if (TryComp(player, out JointComponent? jointComponent))
|
2021-08-04 01:02:43 +10:00
|
|
|
{
|
2022-07-29 14:13:43 +12:00
|
|
|
foreach (var joint in jointComponent.GetJoints.Values)
|
2021-10-04 15:35:03 +11:00
|
|
|
{
|
2022-07-29 14:13:43 +12:00
|
|
|
if (TryComp(joint.BodyAUid, out PhysicsComponent? physics))
|
|
|
|
|
physics.Predict = true;
|
|
|
|
|
|
|
|
|
|
if (TryComp(joint.BodyBUid, out physics))
|
|
|
|
|
physics.Predict = true;
|
2021-10-04 15:35:03 +11:00
|
|
|
}
|
2021-08-04 01:02:43 +10:00
|
|
|
}
|
|
|
|
|
|
2021-09-02 12:35:16 +10:00
|
|
|
// If we're being pulled then we won't predict anything and will receive server lerps so it looks way smoother.
|
2022-02-02 17:34:25 +11:00
|
|
|
if (TryComp(player, out SharedPullableComponent? pullableComp))
|
2021-09-02 12:35:16 +10:00
|
|
|
{
|
2022-02-02 17:34:25 +11:00
|
|
|
if (pullableComp.Puller is {Valid: true} puller && TryComp<PhysicsComponent?>(puller, out var pullerBody))
|
2021-09-02 12:35:16 +10:00
|
|
|
{
|
|
|
|
|
pullerBody.Predict = false;
|
|
|
|
|
body.Predict = false;
|
2022-04-25 17:24:40 +10:00
|
|
|
|
|
|
|
|
if (TryComp<SharedPullerComponent>(player, out var playerPuller) && playerPuller.Pulling != null &&
|
|
|
|
|
TryComp<PhysicsComponent>(playerPuller.Pulling, out var pulledBody))
|
|
|
|
|
{
|
|
|
|
|
pulledBody.Predict = false;
|
|
|
|
|
}
|
2021-09-02 12:35:16 +10:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-08 04:09:59 +11:00
|
|
|
// Server-side should just be handled on its own so we'll just do this shizznit
|
2023-01-16 21:20:22 +13:00
|
|
|
HandleMobMovement(player, mover, body, xformMover, frameTime, xformQuery, moverQuery, relayTargetQuery);
|
2021-03-08 04:09:59 +11:00
|
|
|
}
|
2022-03-14 02:42:39 +11:00
|
|
|
|
|
|
|
|
protected override bool CanSound()
|
|
|
|
|
{
|
2022-12-12 00:18:25 +11:00
|
|
|
return _timing is { IsFirstTimePredicted: true, InSimulation: true };
|
2022-03-14 02:42:39 +11:00
|
|
|
}
|
2021-03-08 04:09:59 +11:00
|
|
|
}
|
|
|
|
|
}
|