quantum-space-buddies/QSB/WorldSync/RequestInitialStatesMessage.cs
JohnCorby 1441dc4a32 Revert "Revert "QSBNetworkBehaviour: SendInitialState""
This reverts commit 6eb8b144b3b0bfe906b3b69a4475823842d9b7db.
2022-02-04 14:17:23 -08:00

42 lines
1.1 KiB
C#

using QSB.ConversationSync.Messages;
using QSB.LogSync.Messages;
using QSB.Messaging;
using QSB.Utility;
namespace QSB.WorldSync
{
/// <summary>
/// sent by non-host clients to get object states
/// </summary>
public class RequestInitialStatesMessage : QSBMessage
{
public override void OnReceiveRemote() =>
Delay.RunWhen(() => QSBWorldSync.AllObjectsReady,
() => SendInitialStates(From));
private static void SendInitialStates(uint to)
{
DebugLog.DebugWrite($"sending initial states to {to}");
if (QSBCore.IsHost)
{
QSBWorldSync.DialogueConditions.ForEach(condition
=> new DialogueConditionMessage(condition.Key, condition.Value) { To = to }.Send());
QSBWorldSync.ShipLogFacts.ForEach(fact
=> new RevealFactMessage(fact.Id, fact.SaveGame, false) { To = to }.Send());
}
foreach (var worldObject in QSBWorldSync.GetWorldObjects())
{
worldObject.SendInitialState(to);
}
foreach (var qsbNetworkBehaviour in QSBWorldSync.GetUnityObjects<QSBNetworkBehaviour>())
{
qsbNetworkBehaviour.SendInitialState(to);
}
}
}
}