quantum-space-buddies/QSB/Tools/PlayerSignalscopeEvent.cs
AmazingAlek f434ed027b
sector overhaul (#176)
* wrapper for sector
* using world registry for sectors
* using order id as unique sector key
* sector manager
* not checking closest sector every frame
2020-08-16 17:15:36 +02:00

39 lines
1.2 KiB
C#

using QSB.Events;
using QSB.Messaging;
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);
}
}
}