60 lines
1.4 KiB
C#
Raw Normal View History

2021-12-23 22:40:37 -08:00
using QSB.AuthoritySync;
using QSB.Messaging;
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;
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);
var shipCockpitController = GameObject.Find("ShipCockpitController").GetComponent<ShipCockpitController>();
if (Data)
{
shipCockpitController._interactVolume.DisableInteraction();
}
else
2021-12-23 22:40:37 -08:00
{
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
{
2022-03-02 19:46:33 -08:00
ShipTransformSync.LocalInstance.netIdentity.SetAuthority(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
}
}
}