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