mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-01-18 13:23:05 +00:00
37 lines
1.3 KiB
C#
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);
|
|
}
|
|
}
|
|
}
|