mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2024-12-28 18:25:18 +00:00
38 lines
948 B
C#
38 lines
948 B
C#
using OWML.Utils;
|
|
using QSB.Events;
|
|
using QSB.Messaging;
|
|
|
|
namespace QSB.ShipSync.Messages
|
|
{
|
|
internal class HatchEvent : QSBEvent<BoolMessage>
|
|
{
|
|
public override bool RequireWorldObjectsReady => true;
|
|
|
|
public override void SetupListener()
|
|
=> GlobalMessenger<bool>.AddListener(EventNames.QSBHatchState, Handler);
|
|
|
|
public override void CloseListener()
|
|
=> GlobalMessenger<bool>.RemoveListener(EventNames.QSBHatchState, Handler);
|
|
|
|
private void Handler(bool open) => SendEvent(CreateMessage(open));
|
|
|
|
private BoolMessage CreateMessage(bool open) => new()
|
|
{
|
|
AboutId = LocalPlayerId,
|
|
Value = open
|
|
};
|
|
|
|
public override void OnReceiveRemote(bool server, BoolMessage message)
|
|
{
|
|
if (message.Value)
|
|
{
|
|
ShipManager.Instance.HatchController.Invoke("OpenHatch");
|
|
}
|
|
else
|
|
{
|
|
ShipManager.Instance.ShipTractorBeam.DeactivateTractorBeam();
|
|
ShipManager.Instance.HatchController.Invoke("CloseHatch");
|
|
}
|
|
}
|
|
}
|
|
} |