2023-05-08 11:30:59 -07:00
|
|
|
|
using QSB.Messaging;
|
|
|
|
|
using QSB.OwnershipSync;
|
2021-12-23 22:40:37 -08:00
|
|
|
|
using QSB.Player;
|
|
|
|
|
using QSB.Player.TransformSync;
|
|
|
|
|
using QSB.ShipSync.TransformSync;
|
|
|
|
|
using QSB.WorldSync;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
2022-03-02 19:46:33 -08:00
|
|
|
|
namespace QSB.ShipSync.Messages;
|
|
|
|
|
|
2022-08-15 15:25:50 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// TODO: initial state for the current flyer
|
|
|
|
|
/// </summary>
|
2022-03-02 19:46:33 -08:00
|
|
|
|
internal class FlyShipMessage : QSBMessage<bool>
|
2021-12-23 22:40:37 -08:00
|
|
|
|
{
|
2022-03-02 19:46:33 -08:00
|
|
|
|
static FlyShipMessage()
|
2021-12-23 22:40:37 -08:00
|
|
|
|
{
|
2022-03-02 19:46:33 -08:00
|
|
|
|
GlobalMessenger<OWRigidbody>.AddListener(OWEvents.EnterFlightConsole, _ => Handler(true));
|
|
|
|
|
GlobalMessenger.AddListener(OWEvents.ExitFlightConsole, () => Handler(false));
|
|
|
|
|
}
|
2021-12-23 22:40:37 -08:00
|
|
|
|
|
2022-03-02 19:46:33 -08:00
|
|
|
|
private static void Handler(bool flying)
|
|
|
|
|
{
|
|
|
|
|
if (PlayerTransformSync.LocalInstance)
|
2021-12-23 22:40:37 -08:00
|
|
|
|
{
|
2022-03-02 19:46:33 -08:00
|
|
|
|
new FlyShipMessage(flying).Send();
|
2021-12-23 22:40:37 -08:00
|
|
|
|
}
|
2022-03-02 19:46:33 -08:00
|
|
|
|
}
|
2021-12-23 22:40:37 -08:00
|
|
|
|
|
2022-05-05 15:42:07 +01:00
|
|
|
|
public FlyShipMessage(bool flying) : base(flying) { }
|
2021-12-23 22:40:37 -08:00
|
|
|
|
|
2022-03-02 19:46:33 -08:00
|
|
|
|
public override bool ShouldReceive => QSBWorldSync.AllObjectsReady;
|
2021-12-23 22:40:37 -08:00
|
|
|
|
|
2022-05-05 15:42:07 +01:00
|
|
|
|
public override void OnReceiveLocal() => OnReceiveRemote();
|
2021-12-23 22:40:37 -08:00
|
|
|
|
|
2022-03-02 19:46:33 -08:00
|
|
|
|
public override void OnReceiveRemote()
|
|
|
|
|
{
|
|
|
|
|
SetCurrentFlyer(From, Data);
|
2022-07-07 13:38:51 +01:00
|
|
|
|
var shipCockpitController = ShipManager.Instance.CockpitController;
|
2022-03-02 19:46:33 -08:00
|
|
|
|
if (Data)
|
|
|
|
|
{
|
2022-08-28 00:04:36 -04:00
|
|
|
|
QSBPlayerManager.GetPlayer(From)?.AudioController?.PlayOneShot(AudioType.ShipCockpitBuckleUp);
|
2022-03-02 19:46:33 -08:00
|
|
|
|
shipCockpitController._interactVolume.DisableInteraction();
|
|
|
|
|
}
|
|
|
|
|
else
|
2021-12-23 22:40:37 -08:00
|
|
|
|
{
|
2022-08-28 00:04:36 -04:00
|
|
|
|
QSBPlayerManager.GetPlayer(From)?.AudioController?.PlayOneShot(AudioType.ShipCockpitUnbuckle);
|
2022-03-02 19:46:33 -08:00
|
|
|
|
shipCockpitController._interactVolume.EnableInteraction();
|
2021-12-23 22:40:37 -08:00
|
|
|
|
}
|
2022-03-02 19:46:33 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void SetCurrentFlyer(uint id, bool isFlying)
|
|
|
|
|
{
|
|
|
|
|
ShipManager.Instance.CurrentFlyer = isFlying
|
|
|
|
|
? id
|
|
|
|
|
: uint.MaxValue;
|
2021-12-23 22:40:37 -08:00
|
|
|
|
|
2022-03-02 19:46:33 -08:00
|
|
|
|
if (QSBCore.IsHost)
|
2021-12-23 22:40:37 -08:00
|
|
|
|
{
|
2023-05-08 11:38:24 -07:00
|
|
|
|
ShipTransformSync.LocalInstance.netIdentity.SetOwner(isFlying
|
2021-12-23 22:40:37 -08:00
|
|
|
|
? id
|
2022-03-02 19:46:33 -08:00
|
|
|
|
: QSBPlayerManager.LocalPlayerId);
|
2021-12-23 22:40:37 -08:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-02-24 22:04:54 -08:00
|
|
|
|
}
|