mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-01-09 03:40:46 +00:00
39 lines
1.2 KiB
C#
39 lines
1.2 KiB
C#
using QSB.Messaging;
|
|
using QSB.TransformSync;
|
|
using System.Linq;
|
|
|
|
namespace QSB.Events
|
|
{
|
|
public class PlayerStatesRequestEvent : QSBEvent<PlayerMessage>
|
|
{
|
|
public override EventType Type => EventType.FullStateRequest;
|
|
|
|
public override void SetupListener()
|
|
{
|
|
GlobalMessenger.AddListener(EventNames.QSBPlayerStatesRequest, Handler);
|
|
}
|
|
|
|
public override void CloseListener()
|
|
{
|
|
GlobalMessenger.RemoveListener(EventNames.QSBPlayerStatesRequest, Handler);
|
|
}
|
|
|
|
private void Handler() => SendEvent(CreateMessage());
|
|
|
|
private PlayerMessage CreateMessage() => new PlayerMessage
|
|
{
|
|
AboutId = LocalPlayerId
|
|
};
|
|
|
|
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))
|
|
{
|
|
GlobalMessenger<uint, QSBSector>.FireEvent(EventNames.QSBSectorChange, item.netId.Value, item.ReferenceSector);
|
|
}
|
|
}
|
|
}
|
|
}
|