2021-04-12 11:43:22 +01:00
|
|
|
|
using OWML.Utils;
|
|
|
|
|
using QSB.Events;
|
|
|
|
|
using QSB.Messaging;
|
|
|
|
|
|
|
|
|
|
namespace QSB.ShipSync.Events
|
|
|
|
|
{
|
2021-05-15 21:31:29 +01:00
|
|
|
|
internal class HatchEvent : QSBEvent<BoolMessage>
|
2021-04-12 11:43:22 +01:00
|
|
|
|
{
|
2021-12-05 11:03:09 +00:00
|
|
|
|
public override bool RequireWorldObjectsReady => true;
|
2021-12-04 16:39:37 +00:00
|
|
|
|
|
2021-06-19 11:26:05 +01:00
|
|
|
|
public override void SetupListener()
|
2021-04-12 11:43:22 +01:00
|
|
|
|
=> GlobalMessenger<bool>.AddListener(EventNames.QSBHatchState, Handler);
|
|
|
|
|
|
2021-06-19 11:26:05 +01:00
|
|
|
|
public override void CloseListener()
|
2021-04-12 11:43:22 +01:00
|
|
|
|
=> GlobalMessenger<bool>.RemoveListener(EventNames.QSBHatchState, Handler);
|
|
|
|
|
|
|
|
|
|
private void Handler(bool open) => SendEvent(CreateMessage(open));
|
|
|
|
|
|
2021-11-20 19:49:50 +00:00
|
|
|
|
private BoolMessage CreateMessage(bool open) => new()
|
2021-04-12 11:43:22 +01:00
|
|
|
|
{
|
|
|
|
|
AboutId = LocalPlayerId,
|
|
|
|
|
Value = open
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
public override void OnReceiveRemote(bool server, BoolMessage message)
|
|
|
|
|
{
|
|
|
|
|
if (message.Value)
|
|
|
|
|
{
|
2021-04-13 18:50:15 +01:00
|
|
|
|
ShipManager.Instance.HatchController.Invoke("OpenHatch");
|
2021-04-12 11:43:22 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-04-13 18:50:15 +01:00
|
|
|
|
ShipManager.Instance.ShipTractorBeam.DeactivateTractorBeam();
|
|
|
|
|
ShipManager.Instance.HatchController.Invoke("CloseHatch");
|
2021-04-12 11:43:22 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|