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.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
|
|
|
public override void Initialize()
|
2022-04-23 21:05:02 -04:00
|
|
|
{
|
2022-05-04 14:21:39 -04:00
|
|
|
base.Initialize();
|
2022-10-04 15:49:46 +13:00
|
|
|
SubscribeLocalEvent<RiderComponent, ComponentStartup>(OnRiderStartup);
|
2022-07-16 13:51:52 +10:00
|
|
|
SubscribeLocalEvent<RiderComponent, ComponentShutdown>(OnRiderShutdown);
|
|
|
|
|
SubscribeLocalEvent<RiderComponent, ComponentHandleState>(OnRiderHandleState);
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-04 15:49:46 +13:00
|
|
|
private void OnRiderStartup(EntityUid uid, RiderComponent component, ComponentStartup args)
|
2022-07-16 13:51:52 +10:00
|
|
|
{
|
2022-10-04 15:49:46 +13:00
|
|
|
// Center the player's eye on the vehicle
|
|
|
|
|
if (TryComp(uid, out EyeComponent? eyeComp))
|
|
|
|
|
eyeComp.Target ??= component.Vehicle;
|
2022-05-04 14:21:39 -04:00
|
|
|
}
|
|
|
|
|
|
2022-10-04 15:49:46 +13:00
|
|
|
private void OnRiderShutdown(EntityUid uid, RiderComponent component, ComponentShutdown args)
|
2022-07-16 13:51:52 +10:00
|
|
|
{
|
2022-10-04 15:49:46 +13:00
|
|
|
// reset the riders eye centering.
|
|
|
|
|
if (TryComp(uid, out EyeComponent? eyeComp) && eyeComp.Target == component.Vehicle)
|
|
|
|
|
eyeComp.Target = null;
|
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)
|
|
|
|
|
{
|
2022-10-04 15:49:46 +13:00
|
|
|
if (args.Current is not RiderComponentState state)
|
2022-09-26 17:50:32 +13:00
|
|
|
return;
|
|
|
|
|
|
2022-10-04 15:49:46 +13:00
|
|
|
if (TryComp(uid, out EyeComponent? eyeComp) && eyeComp.Target == component.Vehicle)
|
|
|
|
|
eyeComp.Target = state.Entity;
|
2022-07-16 13:51:52 +10:00
|
|
|
|
2022-10-04 15:49:46 +13:00
|
|
|
component.Vehicle = state.Entity;
|
2022-07-16 13:51:52 +10:00
|
|
|
}
|
2022-04-23 21:05:02 -04:00
|
|
|
}
|
|
|
|
|
}
|