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
|
|
|
|
{
|
|
|
|
|
public override MessageType Type => MessageType.FullStateRequest;
|
|
|
|
|
|
|
|
|
|
public override void SetupListener()
|
|
|
|
|
{
|
2020-08-10 17:24:28 +00:00
|
|
|
|
GlobalMessenger.AddListener(EventNames.QSBPlayerStatesRequest, () => SendEvent(CreateMessage()));
|
2020-08-10 13:40:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-08-15 19:32:58 +00:00
|
|
|
|
public override void CloseListener()
|
|
|
|
|
{
|
|
|
|
|
GlobalMessenger.RemoveListener(EventNames.QSBPlayerStatesRequest, () => SendEvent(CreateMessage()));
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-10 16:17:54 +00:00
|
|
|
|
private PlayerMessage CreateMessage() => new PlayerMessage
|
|
|
|
|
{
|
|
|
|
|
SenderId = PlayerTransformSync.LocalInstance.netId.Value
|
|
|
|
|
};
|
|
|
|
|
|
2020-08-10 13:40:06 +00:00
|
|
|
|
public override void OnServerReceive(PlayerMessage message)
|
|
|
|
|
{
|
|
|
|
|
PlayerState.LocalInstance.Send();
|
2020-08-15 13:22:56 +00:00
|
|
|
|
foreach (var item in PlayerRegistry.TransformSyncs.Where(x => x.IsReady && x.ReferenceSector != null))
|
2020-08-14 18:31:33 +00:00
|
|
|
|
{
|
2020-08-14 19:04:29 +00:00
|
|
|
|
GlobalMessenger<uint, Sector.Name, string>.FireEvent(EventNames.QSBSectorChange, item.netId.Value, item.ReferenceSector.GetName(), item.ReferenceSector.name);
|
2020-08-14 18:31:33 +00:00
|
|
|
|
}
|
2020-08-10 13:40:06 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|