quantum-space-buddies/QSB/Events/PlayerFlashlightEvent.cs
2020-08-09 22:10:47 +01:00

37 lines
1.3 KiB
C#

using QSB.Messaging;
namespace QSB.Events
{
class PlayerFlashlightEvent : QSBEvent<ToggleMessage>
{
public override MessageType Type => MessageType.FlashlightActiveChange;
public override void SetupListener()
{
GlobalMessenger.AddListener("TurnOnFlashlight", () => SendEvent(
new ToggleMessage {
SenderId = PlayerRegistry.LocalPlayer.NetId,
ToggleValue = true
}));
GlobalMessenger.AddListener("TurnOffFlashlight", () => SendEvent(
new ToggleMessage {
SenderId = PlayerRegistry.LocalPlayer.NetId,
ToggleValue = false
}));
}
public override void OnReceive(ToggleMessage message)
{
var player = PlayerRegistry.GetPlayer(message.SenderId);
player.UpdateState(State.Flashlight, message.ToggleValue);
player.FlashLight.UpdateState(message.ToggleValue);
}
public override void OnReceiveLocal(ToggleMessage message)
{
PlayerRegistry.LocalPlayer.UpdateState(State.Flashlight, message.ToggleValue);
PlayerRegistry.LocalPlayer.FlashLight.UpdateState(message.ToggleValue);
}
}
}