2023-05-08 11:30:59 -07:00
|
|
|
|
using QSB.Messaging;
|
2022-05-28 20:39:42 +01:00
|
|
|
|
using QSB.ModelShip.TransformSync;
|
2023-05-08 11:30:59 -07:00
|
|
|
|
using QSB.OwnershipSync;
|
2022-05-28 20:39:42 +01:00
|
|
|
|
using QSB.Player;
|
|
|
|
|
using QSB.Player.TransformSync;
|
2022-06-07 20:07:24 -07:00
|
|
|
|
using QSB.Utility;
|
2022-05-28 20:39:42 +01:00
|
|
|
|
using QSB.WorldSync;
|
|
|
|
|
|
|
|
|
|
namespace QSB.ModelShip.Messages;
|
|
|
|
|
|
2023-07-28 19:30:57 +01:00
|
|
|
|
public class UseFlightConsoleMessage : QSBMessage<bool>
|
2022-05-28 20:39:42 +01:00
|
|
|
|
{
|
2022-06-07 22:07:39 -07:00
|
|
|
|
static UseFlightConsoleMessage()
|
2022-05-28 20:39:42 +01:00
|
|
|
|
{
|
|
|
|
|
GlobalMessenger<OWRigidbody>.AddListener(OWEvents.EnterRemoteFlightConsole, _ => Handler(true));
|
|
|
|
|
GlobalMessenger.AddListener(OWEvents.ExitRemoteFlightConsole, () => Handler(false));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void Handler(bool active)
|
|
|
|
|
{
|
|
|
|
|
if (PlayerTransformSync.LocalInstance != null)
|
|
|
|
|
{
|
2022-06-07 22:07:39 -07:00
|
|
|
|
new UseFlightConsoleMessage(active).Send();
|
2022-05-28 20:39:42 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-07 22:07:39 -07:00
|
|
|
|
private UseFlightConsoleMessage(bool active) : base(active) { }
|
2022-05-28 20:39:42 +01:00
|
|
|
|
|
2022-08-28 15:35:07 -04:00
|
|
|
|
public override void OnReceiveLocal() => SetCurrentFlyer(From, Data);
|
2022-05-28 20:39:42 +01:00
|
|
|
|
|
|
|
|
|
public override void OnReceiveRemote()
|
|
|
|
|
{
|
|
|
|
|
var console = QSBWorldSync.GetUnityObject<RemoteFlightConsole>();
|
|
|
|
|
|
2022-08-28 18:22:41 -04:00
|
|
|
|
SetCurrentFlyer(From, Data);
|
|
|
|
|
|
2022-05-28 20:39:42 +01:00
|
|
|
|
if (Data)
|
|
|
|
|
{
|
2022-06-07 19:59:22 -07:00
|
|
|
|
console._modelShipBody.Unsuspend();
|
2022-05-28 20:39:42 +01:00
|
|
|
|
console._interactVolume.ResetInteraction();
|
|
|
|
|
console._interactVolume.DisableInteraction();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
console._interactVolume.ResetInteraction();
|
|
|
|
|
|
|
|
|
|
if (console._modelShipBody == null)
|
|
|
|
|
{
|
|
|
|
|
console._interactVolume.DisableInteraction();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
console._modelShipBody.Suspend(console._suspensionBody);
|
|
|
|
|
console._interactVolume.EnableInteraction();
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-07 20:07:24 -07:00
|
|
|
|
QSBWorldSync.GetUnityObject<ModelShipController>()._detector.SetActive(Data);
|
|
|
|
|
QSBWorldSync.GetUnityObjects<ModelShipLandingSpot>().ForEach(x => x._owCollider.SetActivation(Data));
|
2022-08-28 15:35:07 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SetCurrentFlyer(uint flyer, bool isFlying)
|
|
|
|
|
{
|
|
|
|
|
ModelShipManager.Instance.CurrentFlyer = isFlying
|
|
|
|
|
? flyer
|
|
|
|
|
: uint.MaxValue;
|
|
|
|
|
|
2022-05-28 20:39:42 +01:00
|
|
|
|
if (QSBCore.IsHost)
|
|
|
|
|
{
|
2023-05-08 11:38:24 -07:00
|
|
|
|
ModelShipTransformSync.LocalInstance.netIdentity.SetOwner(isFlying
|
2022-08-28 15:35:07 -04:00
|
|
|
|
? flyer
|
2023-05-08 11:38:24 -07:00
|
|
|
|
: QSBPlayerManager.LocalPlayerId); // Host gets ownership when its not in use
|
2022-05-28 20:39:42 +01:00
|
|
|
|
}
|
2022-08-28 15:35:07 -04:00
|
|
|
|
|
|
|
|
|
// Client messes up its position when they start flying it
|
|
|
|
|
// We can just recall it immediately so its in the right place.
|
|
|
|
|
var console = QSBWorldSync.GetUnityObject<RemoteFlightConsole>();
|
2022-11-19 14:09:09 -08:00
|
|
|
|
if (console._modelShipBody) // for when model ship is destroyed
|
|
|
|
|
{
|
|
|
|
|
console.RespawnModelShip(false);
|
|
|
|
|
}
|
2022-05-28 20:39:42 +01:00
|
|
|
|
}
|
|
|
|
|
}
|