2020-08-09 07:17:00 +00:00
|
|
|
|
using QSB.Messaging;
|
|
|
|
|
|
|
|
|
|
namespace QSB.Events
|
2020-08-07 23:08:44 +00:00
|
|
|
|
{
|
2020-08-09 07:37:32 +00:00
|
|
|
|
class PlayerFlashlightEvent : QSBEvent<ToggleMessage>
|
2020-08-07 23:08:44 +00:00
|
|
|
|
{
|
2020-08-09 07:17:00 +00:00
|
|
|
|
public override MessageType Type => MessageType.FlashlightActiveChange;
|
2020-08-07 23:08:44 +00:00
|
|
|
|
|
2020-08-08 11:23:23 +00:00
|
|
|
|
public override void SetupListener()
|
|
|
|
|
{
|
2020-08-09 12:48:55 +00:00
|
|
|
|
GlobalMessenger.AddListener("TurnOnFlashlight", () => SendEvent(
|
|
|
|
|
new ToggleMessage {
|
|
|
|
|
SenderId = PlayerRegistry.LocalPlayer.NetId,
|
2020-08-09 18:33:36 +00:00
|
|
|
|
ToggleValue = true
|
2020-08-09 12:48:55 +00:00
|
|
|
|
}));
|
|
|
|
|
GlobalMessenger.AddListener("TurnOffFlashlight", () => SendEvent(
|
|
|
|
|
new ToggleMessage {
|
|
|
|
|
SenderId = PlayerRegistry.LocalPlayer.NetId,
|
2020-08-09 18:33:36 +00:00
|
|
|
|
ToggleValue = false
|
2020-08-09 12:48:55 +00:00
|
|
|
|
}));
|
2020-08-08 11:23:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-08-09 11:19:51 +00:00
|
|
|
|
public override void OnReceive(ToggleMessage message)
|
2020-08-07 23:08:44 +00:00
|
|
|
|
{
|
2020-08-09 11:19:51 +00:00
|
|
|
|
var player = PlayerRegistry.GetPlayer(message.SenderId);
|
2020-08-09 18:33:36 +00:00
|
|
|
|
player.UpdateState(State.Flashlight, message.ToggleValue);
|
|
|
|
|
player.FlashLight.UpdateState(message.ToggleValue);
|
2020-08-07 23:08:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-08-09 07:37:32 +00:00
|
|
|
|
public override void OnReceiveLocal(ToggleMessage message)
|
2020-08-07 23:08:44 +00:00
|
|
|
|
{
|
2020-08-09 18:33:36 +00:00
|
|
|
|
PlayerRegistry.LocalPlayer.FlashLight.UpdateState(message.ToggleValue);
|
2020-08-07 23:08:44 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|