quantum-space-buddies/QSB/Tools/SignalscopeTool/Messages/PlayerSignalscopeMessage.cs

35 lines
922 B
C#
Raw Normal View History

using QSB.Messaging;
2021-12-24 02:55:22 +00:00
using QSB.Player;
using QSB.Player.TransformSync;
namespace QSB.Tools.SignalscopeTool.Messages
{
public class PlayerSignalscopeMessage : QSBBoolMessage
{
static PlayerSignalscopeMessage()
{
GlobalMessenger<Signalscope>.AddListener(OWEvents.EquipSignalscope, _ => Handle(true));
GlobalMessenger.AddListener(OWEvents.UnequipSignalscope, () => Handle(false));
2021-12-24 02:55:22 +00:00
}
private static void Handle(bool equipped)
{
2021-12-24 06:40:37 +00:00
if (PlayerTransformSync.LocalInstance)
2021-12-24 02:55:22 +00:00
{
new PlayerSignalscopeMessage(equipped).Send();
}
}
private PlayerSignalscopeMessage(bool equipped) => Value = equipped;
public override void OnReceiveRemote()
{
var player = QSBPlayerManager.GetPlayer(From);
player.SignalscopeEquipped = Value;
player.Signalscope?.ChangeEquipState(Value);
}
public override void OnReceiveLocal() =>
QSBPlayerManager.LocalPlayer.SignalscopeEquipped = Value;
}
}