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