2020-08-13 21:46:16 +02:00
|
|
|
|
using QSB.Events;
|
|
|
|
|
using QSB.Messaging;
|
2020-08-09 09:17:00 +02:00
|
|
|
|
|
2020-08-13 21:46:16 +02:00
|
|
|
|
namespace QSB.Tools
|
2020-08-08 12:23:23 +01:00
|
|
|
|
{
|
2020-08-10 18:17:54 +02:00
|
|
|
|
public class PlayerSignalscopeEvent : QSBEvent<ToggleMessage>
|
2020-08-08 12:23:23 +01:00
|
|
|
|
{
|
2020-08-09 09:17:00 +02:00
|
|
|
|
public override MessageType Type => MessageType.SignalscopeActiveChange;
|
2020-08-08 12:23:23 +01:00
|
|
|
|
|
|
|
|
|
public override void SetupListener()
|
|
|
|
|
{
|
2020-08-15 21:52:43 +02:00
|
|
|
|
GlobalMessenger<Signalscope>.AddListener(EventNames.EquipSignalscope, HandleEquip);
|
|
|
|
|
GlobalMessenger.AddListener(EventNames.UnequipSignalscope, HandleUnequip);
|
2020-08-08 12:23:23 +01:00
|
|
|
|
}
|
|
|
|
|
|
2020-08-15 20:32:58 +01:00
|
|
|
|
public override void CloseListener()
|
|
|
|
|
{
|
2020-08-15 21:52:43 +02:00
|
|
|
|
GlobalMessenger<Signalscope>.RemoveListener(EventNames.EquipSignalscope, HandleEquip);
|
|
|
|
|
GlobalMessenger.RemoveListener(EventNames.UnequipSignalscope, HandleUnequip);
|
2020-08-15 20:32:58 +01:00
|
|
|
|
}
|
|
|
|
|
|
2020-08-15 21:52:43 +02:00
|
|
|
|
private void HandleEquip(Signalscope var) => SendEvent(CreateMessage(true));
|
|
|
|
|
private void HandleUnequip() => SendEvent(CreateMessage(false));
|
|
|
|
|
|
2020-08-10 18:17:54 +02:00
|
|
|
|
private ToggleMessage CreateMessage(bool value) => new ToggleMessage
|
|
|
|
|
{
|
|
|
|
|
SenderId = LocalPlayerId,
|
|
|
|
|
ToggleValue = value
|
|
|
|
|
};
|
|
|
|
|
|
2020-08-10 14:40:06 +01:00
|
|
|
|
public override void OnReceiveRemote(ToggleMessage message)
|
2020-08-08 12:23:23 +01:00
|
|
|
|
{
|
2020-08-09 12:19:51 +01:00
|
|
|
|
var player = PlayerRegistry.GetPlayer(message.SenderId);
|
2020-08-09 19:33:36 +01:00
|
|
|
|
player.UpdateState(State.Signalscope, message.ToggleValue);
|
2020-08-10 19:25:10 +01:00
|
|
|
|
if (!IsInUniverse)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-08-10 12:12:51 +01:00
|
|
|
|
player.Signalscope?.ChangeEquipState(message.ToggleValue);
|
2020-08-08 12:23:23 +01:00
|
|
|
|
}
|
|
|
|
|
|
2020-08-09 09:37:32 +02:00
|
|
|
|
public override void OnReceiveLocal(ToggleMessage message)
|
2020-08-08 12:23:23 +01:00
|
|
|
|
{
|
2020-08-09 22:10:47 +01:00
|
|
|
|
PlayerRegistry.LocalPlayer.UpdateState(State.Signalscope, message.ToggleValue);
|
2020-08-08 12:23:23 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|