2022-07-16 13:51:52 +10:00
|
|
|
using Content.Client.Buckle.Strap;
|
2022-04-23 21:05:02 -04:00
|
|
|
using Content.Shared.Vehicle;
|
2022-07-16 13:51:52 +10:00
|
|
|
using Content.Shared.Vehicle.Components;
|
2022-05-04 14:21:39 -04:00
|
|
|
using Robust.Client.GameObjects;
|
2022-07-16 13:51:52 +10:00
|
|
|
using Robust.Client.Graphics;
|
|
|
|
|
using Robust.Client.Player;
|
|
|
|
|
using Robust.Shared.GameStates;
|
2022-04-23 21:05:02 -04:00
|
|
|
|
|
|
|
|
namespace Content.Client.Vehicle
|
|
|
|
|
{
|
2022-07-16 13:51:52 +10:00
|
|
|
public sealed class VehicleSystem : SharedVehicleSystem
|
2022-04-23 21:05:02 -04:00
|
|
|
{
|
2022-05-04 14:21:39 -04:00
|
|
|
[Dependency] private readonly IEyeManager _eyeManager = default!;
|
2022-07-16 13:51:52 +10:00
|
|
|
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
2022-05-04 14:21:39 -04:00
|
|
|
|
|
|
|
|
public override void Initialize()
|
2022-04-23 21:05:02 -04:00
|
|
|
{
|
2022-05-04 14:21:39 -04:00
|
|
|
base.Initialize();
|
2022-07-16 13:51:52 +10:00
|
|
|
SubscribeLocalEvent<RiderComponent, ComponentShutdown>(OnRiderShutdown);
|
|
|
|
|
SubscribeLocalEvent<RiderComponent, ComponentHandleState>(OnRiderHandleState);
|
|
|
|
|
SubscribeLocalEvent<RiderComponent, PlayerAttachedEvent>(OnRiderAttached);
|
|
|
|
|
SubscribeLocalEvent<RiderComponent, PlayerDetachedEvent>(OnRiderDetached);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnRiderShutdown(EntityUid uid, RiderComponent component, ComponentShutdown args)
|
|
|
|
|
{
|
|
|
|
|
component.Vehicle = null;
|
|
|
|
|
UpdateEye(component);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnRiderAttached(EntityUid uid, RiderComponent component, PlayerAttachedEvent args)
|
|
|
|
|
{
|
|
|
|
|
UpdateEye(component);
|
2022-05-04 14:21:39 -04:00
|
|
|
}
|
|
|
|
|
|
2022-07-16 13:51:52 +10:00
|
|
|
private void OnRiderDetached(EntityUid uid, RiderComponent component, PlayerDetachedEvent args)
|
2022-05-04 14:21:39 -04:00
|
|
|
{
|
2022-07-16 13:51:52 +10:00
|
|
|
UpdateEye(component);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateEye(RiderComponent component)
|
|
|
|
|
{
|
|
|
|
|
if (!TryComp(component.Vehicle, out EyeComponent? eyeComponent))
|
2022-04-23 21:05:02 -04:00
|
|
|
{
|
2022-07-16 13:51:52 +10:00
|
|
|
TryComp(_playerManager.LocalPlayer?.ControlledEntity, out eyeComponent);
|
2022-04-23 21:05:02 -04:00
|
|
|
}
|
2022-07-16 13:51:52 +10:00
|
|
|
|
|
|
|
|
if (eyeComponent?.Eye == null) return;
|
|
|
|
|
|
|
|
|
|
_eyeManager.CurrentEye = eyeComponent.Eye;
|
2022-04-23 21:05:02 -04:00
|
|
|
}
|
2022-05-04 14:21:39 -04:00
|
|
|
|
2022-07-16 13:51:52 +10:00
|
|
|
private void OnRiderHandleState(EntityUid uid, RiderComponent component, ref ComponentHandleState args)
|
|
|
|
|
{
|
|
|
|
|
// Server should only be sending states for our entity.
|
|
|
|
|
if (args.Current is not RiderComponentState state) return;
|
|
|
|
|
component.Vehicle = state.Entity;
|
|
|
|
|
|
|
|
|
|
UpdateEye(component);
|
|
|
|
|
}
|
2022-04-23 21:05:02 -04:00
|
|
|
}
|
|
|
|
|
}
|