2020-11-03 21:42:14 +00:00
|
|
|
|
using QSB.EventsCore;
|
2020-08-13 19:46:16 +00:00
|
|
|
|
using QSB.Messaging;
|
2020-11-03 21:33:48 +00:00
|
|
|
|
using QSB.Player;
|
2020-08-09 07:17:00 +00:00
|
|
|
|
|
2020-11-03 17:56:48 +00:00
|
|
|
|
namespace QSB.Tools.Events
|
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-22 17:08:25 +00:00
|
|
|
|
public override EventType Type => EventType.SignalscopeActiveChange;
|
2020-08-08 11:23:23 +00:00
|
|
|
|
|
|
|
|
|
public override void SetupListener()
|
|
|
|
|
{
|
2020-08-15 19:52:43 +00:00
|
|
|
|
GlobalMessenger<Signalscope>.AddListener(EventNames.EquipSignalscope, HandleEquip);
|
|
|
|
|
GlobalMessenger.AddListener(EventNames.UnequipSignalscope, HandleUnequip);
|
2020-08-08 11:23:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-08-15 19:32:58 +00:00
|
|
|
|
public override void CloseListener()
|
|
|
|
|
{
|
2020-08-15 19:52:43 +00:00
|
|
|
|
GlobalMessenger<Signalscope>.RemoveListener(EventNames.EquipSignalscope, HandleEquip);
|
|
|
|
|
GlobalMessenger.RemoveListener(EventNames.UnequipSignalscope, HandleUnequip);
|
2020-08-15 19:32:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-08-15 19:52:43 +00:00
|
|
|
|
private void HandleEquip(Signalscope var) => SendEvent(CreateMessage(true));
|
|
|
|
|
private void HandleUnequip() => SendEvent(CreateMessage(false));
|
|
|
|
|
|
2020-08-10 16:17:54 +00:00
|
|
|
|
private ToggleMessage CreateMessage(bool value) => new ToggleMessage
|
|
|
|
|
{
|
2020-08-17 15:51:56 +00:00
|
|
|
|
AboutId = LocalPlayerId,
|
2020-08-10 16:17:54 +00:00
|
|
|
|
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-11-03 21:18:40 +00:00
|
|
|
|
var player = QSBPlayerManager.GetPlayer(message.AboutId);
|
2020-08-17 16:58:45 +00:00
|
|
|
|
player.UpdateState(State.Signalscope, message.ToggleValue);
|
|
|
|
|
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-11-03 21:18:40 +00:00
|
|
|
|
QSBPlayerManager.LocalPlayer.UpdateState(State.Signalscope, message.ToggleValue);
|
2020-08-08 11:23:23 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|