Mister_Nebula 4fc6d55537 test
2020-08-15 20:32:58 +01:00

39 lines
1.1 KiB
C#

using QSB.Events;
using QSB.Messaging;
using QSB.WorldSync;
namespace QSB.GeyserSync
{
public class GeyserEvent : QSBEvent<GeyserMessage>
{
public override MessageType Type => MessageType.Geyser;
public override void SetupListener()
{
GlobalMessenger<int, bool>.AddListener(EventNames.QSBGeyserState, (id, state) => SendEvent(CreateMessage(id, state)));
}
public override void CloseListener()
{
GlobalMessenger<int, bool>.RemoveListener(EventNames.QSBGeyserState, (id, state) => SendEvent(CreateMessage(id, state)));
}
private GeyserMessage CreateMessage(int id, bool state) => new GeyserMessage
{
SenderId = PlayerRegistry.LocalPlayer.NetId,
ObjectId = id,
State = state
};
public override void OnReceiveRemote(GeyserMessage message)
{
if (!IsInUniverse)
{
return;
}
var geyser = WorldRegistry.GetObject<QSBGeyser>(message.ObjectId);
geyser.SetState(message.State);
}
}
}