2021-12-26 18:55:54 -08:00

35 lines
868 B
C#

using QSB.Messaging;
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));
}
private static void Handle(bool on)
{
if (PlayerTransformSync.LocalInstance)
{
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;
}
}