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

36 lines
1.2 KiB
C#
Raw Normal View History

2020-11-03 21:33:48 +00:00
using QSB.Events;
using QSB.Messaging;
2020-08-10 14:40:06 +01:00
using QSB.TransformSync;
2020-08-22 20:21:13 +01:00
using QSB.Utility;
2020-08-15 14:22:56 +01:00
using System.Linq;
2020-08-10 14:40:06 +01:00
2020-11-03 21:33:48 +00:00
namespace QSB.Player.Events
2020-08-10 14:40:06 +01:00
{
2020-08-10 18:17:54 +02:00
public class PlayerStatesRequestEvent : QSBEvent<PlayerMessage>
2020-08-10 14:40:06 +01:00
{
2020-08-22 18:08:25 +01:00
public override EventType Type => EventType.FullStateRequest;
2020-08-10 14:40:06 +01:00
2020-10-22 16:46:01 +01:00
public override void SetupListener() => GlobalMessenger.AddListener(EventNames.QSBPlayerStatesRequest, Handler);
2020-08-15 21:55:25 +02:00
2020-10-22 16:46:01 +01:00
public override void CloseListener() => GlobalMessenger.RemoveListener(EventNames.QSBPlayerStatesRequest, Handler);
2020-08-15 20:32:58 +01:00
2020-08-15 21:52:43 +02:00
private void Handler() => SendEvent(CreateMessage());
2020-08-10 18:17:54 +02:00
private PlayerMessage CreateMessage() => new PlayerMessage
{
AboutId = LocalPlayerId
2020-08-10 18:17:54 +02:00
};
2020-08-10 14:40:06 +01:00
public override void OnServerReceive(PlayerMessage message)
{
2020-08-24 15:51:12 +01:00
DebugLog.DebugWrite($"[S] Get state request from {message.FromId}");
2020-11-03 21:33:48 +00:00
PlayerStateEvent.LocalInstance.Send();
2020-11-03 21:18:40 +00:00
foreach (var item in QSBPlayerManager.GetSyncObjects<TransformSync.TransformSync>()
.Where(x => x != null && x.IsReady && x.ReferenceSector != null))
2020-08-14 19:31:33 +01:00
{
2020-09-04 20:09:25 +01:00
GlobalMessenger<uint, QSBSector>.FireEvent(EventNames.QSBSectorChange, item.netId.Value, item.ReferenceSector);
2020-08-14 19:31:33 +01:00
}
2020-08-10 14:40:06 +01:00
}
}
}