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

51 lines
1.6 KiB
C#
Raw Normal View History

2020-12-14 16:24:52 +00:00
using QSB.Events;
2020-12-14 16:28:03 +00:00
using QSB.Messaging;
2020-11-03 22:29:23 +00:00
using QSB.SectorSync;
2020-08-22 20:21:13 +01:00
using QSB.Utility;
2020-12-11 22:42:21 +00:00
using QSB.WorldSync;
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-12-02 21:23:01 +00:00
public class PlayerStatesRequestEvent : QSBEvent<PlayerMessage>
{
public override EventType Type => EventType.PlayerStatesRequest;
2020-08-10 14:40:06 +01:00
2020-12-02 21:23:01 +00:00
public override void SetupListener() => GlobalMessenger.AddListener(EventNames.QSBPlayerStatesRequest, Handler);
public override void CloseListener() => GlobalMessenger.RemoveListener(EventNames.QSBPlayerStatesRequest, Handler);
2020-08-15 20:32:58 +01:00
2020-12-02 21:23:01 +00:00
private void Handler() => SendEvent(CreateMessage());
2020-08-15 21:52:43 +02:00
2020-12-02 21:23:01 +00:00
private PlayerMessage CreateMessage() => new PlayerMessage
{
2020-12-14 16:12:44 +00:00
AboutId = LocalPlayerId,
OnlySendToServer = true
2020-12-02 21:23:01 +00:00
};
2020-08-10 18:17:54 +02:00
2020-12-11 22:42:21 +00:00
public override void OnReceiveRemote(bool server, PlayerMessage message)
2020-12-02 21:23:01 +00:00
{
2020-12-19 10:56:25 +00:00
DebugLog.DebugWrite($"Get state request from {message.FromId} - isServer?{server}");
2020-12-02 21:23:01 +00:00
GlobalMessenger.FireEvent(EventNames.QSBServerSendPlayerStates);
foreach (var item in QSBPlayerManager.GetSyncObjects<TransformSync.TransformSync>()
.Where(x => x != null && x.IsReady && x.ReferenceSector != null))
{
GlobalMessenger<uint, QSBSector>.FireEvent(EventNames.QSBSectorChange, item.NetId.Value, item.ReferenceSector);
}
2020-12-11 22:42:21 +00:00
2020-12-19 10:56:25 +00:00
if (!server)
{
return;
}
2020-12-11 22:42:21 +00:00
foreach (var condition in QSBWorldSync.DialogueConditions)
{
GlobalMessenger<string, bool>.FireEvent(EventNames.DialogueCondition, condition.Key, condition.Value);
}
2020-12-19 10:56:25 +00:00
foreach (var fact in QSBWorldSync.ShipLogFacts)
{
GlobalMessenger<string, bool, bool>.FireEvent(EventNames.QSBRevealFact, fact.Id, fact.SaveGame, false);
}
2020-12-02 21:23:01 +00:00
}
}
2020-12-03 08:28:05 +00:00
}