35 lines
868 B
C#
Raw Normal View History

using QSB.Messaging;
2021-12-23 18:55:22 -08:00
using QSB.Player;
using QSB.Player.TransformSync;
namespace QSB.Tools.FlashlightTool.Messages
{
public class PlayerFlashlightMessage : QSBBoolMessage
{
static PlayerFlashlightMessage()
{
GlobalMessenger.AddListener(OWEvents.TurnOnFlashlight, () => Handle(true));
GlobalMessenger.AddListener(OWEvents.TurnOffFlashlight, () => Handle(false));
2021-12-23 18:55:22 -08:00
}
private static void Handle(bool on)
{
2021-12-23 22:40:37 -08:00
if (PlayerTransformSync.LocalInstance)
2021-12-23 18:55:22 -08:00
{
new PlayerFlashlightMessage(on).Send();
}
}
private PlayerFlashlightMessage(bool on) => Value = on;
public override void OnReceiveRemote()
{
var player = QSBPlayerManager.GetPlayer(From);
player.FlashlightActive = Value;
player.FlashLight?.UpdateState(Value);
}
public override void OnReceiveLocal() =>
QSBPlayerManager.LocalPlayer.FlashlightActive = Value;
}
}