Files
OldThink/Content.Client/Vehicle/VehicleSystem.cs

44 lines
1.6 KiB
C#
Raw Normal View History

2022-04-23 21:05:02 -04:00
using Content.Shared.Vehicle;
using Content.Shared.Vehicle.Components;
using Robust.Client.GameObjects;
using Robust.Shared.GameStates;
2022-04-23 21:05:02 -04:00
namespace Content.Client.Vehicle
{
public sealed class VehicleSystem : SharedVehicleSystem
2022-04-23 21:05:02 -04:00
{
public override void Initialize()
2022-04-23 21:05:02 -04:00
{
base.Initialize();
2022-10-04 15:49:46 +13:00
SubscribeLocalEvent<RiderComponent, ComponentStartup>(OnRiderStartup);
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-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-10-04 15:49:46 +13:00
private void OnRiderShutdown(EntityUid uid, RiderComponent component, ComponentShutdown args)
{
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
}
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-10-04 15:49:46 +13:00
component.Vehicle = state.Entity;
}
2022-04-23 21:05:02 -04:00
}
}