quantum-space-buddies/QSB/Events/PlayerStatesRequestEvent.cs

39 lines
1.2 KiB
C#
Raw Normal View History

2020-08-10 13:40:06 +00:00
using QSB.Messaging;
using QSB.TransformSync;
2020-08-15 13:22:56 +00:00
using System.Linq;
2020-08-10 13:40:06 +00:00
namespace QSB.Events
{
2020-08-10 16:17:54 +00:00
public class PlayerStatesRequestEvent : QSBEvent<PlayerMessage>
2020-08-10 13:40:06 +00:00
{
2020-08-22 17:08:25 +00:00
public override EventType Type => EventType.FullStateRequest;
2020-08-10 13:40:06 +00:00
public override void SetupListener()
{
2020-08-15 19:52:43 +00:00
GlobalMessenger.AddListener(EventNames.QSBPlayerStatesRequest, Handler);
2020-08-10 13:40:06 +00:00
}
2020-08-15 19:55:25 +00:00
2020-08-15 19:32:58 +00:00
public override void CloseListener()
{
2020-08-15 19:52:43 +00:00
GlobalMessenger.RemoveListener(EventNames.QSBPlayerStatesRequest, Handler);
2020-08-15 19:32:58 +00:00
}
2020-08-15 19:52:43 +00:00
private void Handler() => SendEvent(CreateMessage());
2020-08-10 16:17:54 +00:00
private PlayerMessage CreateMessage() => new PlayerMessage
{
AboutId = LocalPlayerId
2020-08-10 16:17:54 +00:00
};
2020-08-10 13:40:06 +00:00
public override void OnServerReceive(PlayerMessage message)
{
PlayerState.LocalInstance.Send();
foreach (var item in PlayerRegistry.GetSyncObjects<TransformSync.TransformSync>()
.Where(x => x != null && x.IsReady && x.ReferenceSector != null))
2020-08-14 18:31:33 +00:00
{
GlobalMessenger<uint, QSBSector>.FireEvent(EventNames.QSBSectorChange, item.netId.Value, item.ReferenceSector);
2020-08-14 18:31:33 +00:00
}
2020-08-10 13:40:06 +00:00
}
}
}