quantum-space-buddies/QSB/Tools/Events/PlayerSignalscopeEvent.cs

45 lines
1.3 KiB
C#
Raw Normal View History

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-12-02 21:23:01 +00:00
public class PlayerSignalscopeEvent : QSBEvent<ToggleMessage>
{
public override EventType Type => EventType.SignalscopeActiveChange;
2020-08-08 11:23:23 +00:00
2020-12-02 21:23:01 +00:00
public override void SetupListener()
{
GlobalMessenger<Signalscope>.AddListener(EventNames.EquipSignalscope, HandleEquip);
GlobalMessenger.AddListener(EventNames.UnequipSignalscope, HandleUnequip);
}
2020-08-08 11:23:23 +00:00
2020-12-02 21:23:01 +00:00
public override void CloseListener()
{
GlobalMessenger<Signalscope>.RemoveListener(EventNames.EquipSignalscope, HandleEquip);
GlobalMessenger.RemoveListener(EventNames.UnequipSignalscope, HandleUnequip);
}
2020-08-15 19:32:58 +00:00
2020-12-02 21:23:01 +00:00
private void HandleEquip(Signalscope var) => SendEvent(CreateMessage(true));
2020-12-03 08:28:05 +00:00
2020-12-02 21:23:01 +00:00
private void HandleUnequip() => SendEvent(CreateMessage(false));
2020-08-15 19:52:43 +00:00
2020-12-02 21:23:01 +00:00
private ToggleMessage CreateMessage(bool value) => new ToggleMessage
{
AboutId = LocalPlayerId,
ToggleValue = value
};
2020-08-10 16:17:54 +00:00
2020-12-02 21:23:01 +00:00
public override void OnReceiveRemote(ToggleMessage message)
{
var player = QSBPlayerManager.GetPlayer(message.AboutId);
player.UpdateState(State.Signalscope, message.ToggleValue);
player.Signalscope?.ChangeEquipState(message.ToggleValue);
}
2020-08-08 11:23:23 +00:00
2020-12-02 21:23:01 +00:00
public override void OnReceiveLocal(ToggleMessage message)
{
QSBPlayerManager.LocalPlayer.UpdateState(State.Signalscope, message.ToggleValue);
}
}
2020-12-03 08:28:05 +00:00
}