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

36 lines
1.3 KiB
C#
Raw Normal View History

2020-11-03 21:42:14 +00:00
using QSB.EventsCore;
2020-11-03 21:33:48 +00:00
using QSB.Messaging;
2020-11-03 22:29:23 +00:00
using QSB.SectorSync;
2020-08-22 19:21:13 +00:00
using QSB.Utility;
2020-08-15 13:22:56 +00:00
using System.Linq;
2020-08-10 13:40:06 +00:00
2020-11-03 21:33:48 +00:00
namespace QSB.Player.Events
2020-08-10 13:40:06 +00:00
{
2020-08-10 16:17:54 +00:00
public class PlayerStatesRequestEvent : QSBEvent<PlayerMessage>
2020-08-10 13:40:06 +00:00
{
2020-11-04 09:34:01 +00:00
public override EventType Type => EventType.PlayerStatesRequest;
2020-08-10 13:40:06 +00:00
2020-10-22 15:46:01 +00:00
public override void SetupListener() => GlobalMessenger.AddListener(EventNames.QSBPlayerStatesRequest, Handler);
2020-08-15 19:55:25 +00:00
2020-10-22 15:46:01 +00:00
public override void CloseListener() => 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)
{
2020-08-24 14:51:12 +00:00
DebugLog.DebugWrite($"[S] Get state request from {message.FromId}");
GlobalMessenger.FireEvent(EventNames.QSBServerSendPlayerStates);
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 18:31:33 +00:00
{
2020-12-02 09:51:53 +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
}
}
}