mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-01-10 06:51:36 +00:00
40 lines
1.2 KiB
C#
40 lines
1.2 KiB
C#
using QSB.Events;
|
|
using QSB.Messaging;
|
|
using QSB.Utility;
|
|
|
|
namespace QSB.Tools
|
|
{
|
|
public class PlayerSignalscopeEvent : QSBEvent<ToggleMessage>
|
|
{
|
|
public override MessageType Type => MessageType.SignalscopeActiveChange;
|
|
|
|
public override void SetupListener()
|
|
{
|
|
GlobalMessenger<Signalscope>.AddListener(EventNames.EquipSignalscope, var => SendEvent(CreateMessage(true)));
|
|
GlobalMessenger.AddListener(EventNames.UnequipSignalscope, () => SendEvent(CreateMessage(false)));
|
|
}
|
|
|
|
private ToggleMessage CreateMessage(bool value) => new ToggleMessage
|
|
{
|
|
SenderId = LocalPlayerId,
|
|
ToggleValue = value
|
|
};
|
|
|
|
public override void OnReceiveRemote(ToggleMessage message)
|
|
{
|
|
var player = PlayerRegistry.GetPlayer(message.SenderId);
|
|
player.UpdateState(State.Signalscope, message.ToggleValue);
|
|
if (!IsInUniverse)
|
|
{
|
|
return;
|
|
}
|
|
player.Signalscope?.ChangeEquipState(message.ToggleValue);
|
|
}
|
|
|
|
public override void OnReceiveLocal(ToggleMessage message)
|
|
{
|
|
PlayerRegistry.LocalPlayer.UpdateState(State.Signalscope, message.ToggleValue);
|
|
}
|
|
}
|
|
}
|