quantum-space-buddies/QSB/GeyserSync/GeyserEvent.cs
Mister_Nebula 298ebc531e cleanup
2020-08-13 17:45:33 +01:00

43 lines
1.3 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 static SyncObjects ObjectType => SyncObjects.Geysers;
public override void SetupListener()
{
GlobalMessenger<GeyserController, bool>.AddListener(EventNames.QSBGeyserState, (controller, state) => SendEvent(CreateMessage(controller, state)));
}
private GeyserMessage CreateMessage(GeyserController controller, bool state) => new GeyserMessage
{
SenderId = PlayerRegistry.LocalPlayer.NetId,
ObjectID = WorldRegistry.GetObjectID(ObjectType, controller),
ObjectType = ObjectType,
State = state
};
public override void OnReceiveRemote(GeyserMessage message)
{
if (!IsInUniverse)
{
return;
}
if (message.State)
{
WorldRegistry.GeyserControllers[message.ObjectID].ActivateGeyser();
}
else
{
WorldRegistry.GeyserControllers[message.ObjectID].DeactivateGeyser();
}
}
}
}