quantum-space-buddies/QSB/WorldSync/RequestInitialStatesMessage.cs

44 lines
1.2 KiB
C#
Raw Normal View History

using QSB.ConversationSync.Messages;
using QSB.LogSync.Messages;
using QSB.Messaging;
using QSB.Utility;
2022-03-03 03:46:33 +00:00
namespace QSB.WorldSync;
/// <summary>
/// sent to the host to get initial object states.
/// <para/>
/// world objects will be ready on both sides at this point
/// </summary>
public class RequestInitialStatesMessage : QSBMessage
{
2022-03-03 03:46:33 +00:00
public RequestInitialStatesMessage() => To = 0;
2022-03-03 03:46:33 +00:00
public override void OnReceiveRemote() =>
Delay.RunWhen(() => QSBWorldSync.AllObjectsReady,
() => SendInitialStates(From));
2022-03-03 03:46:33 +00:00
private static void SendInitialStates(uint to)
{
DebugLog.DebugWrite($"sending initial states to {to}");
2022-03-03 03:46:33 +00:00
QSBWorldSync.DialogueConditions.ForEach(condition
=> new DialogueConditionMessage(condition.Key, condition.Value) { To = to }.Send());
2022-03-03 03:46:33 +00:00
QSBWorldSync.ShipLogFacts.ForEach(fact
=> new RevealFactMessage(fact.Id, fact.SaveGame, false) { To = to }.Send());
2022-03-03 03:46:33 +00:00
var target = to.GetNetworkConnection();
foreach (var qsbNetworkBehaviour in QSBWorldSync.GetUnityObjects<QSBNetworkBehaviour>())
{
qsbNetworkBehaviour.SendInitialState(target);
}
2022-03-03 03:46:33 +00:00
foreach (var worldObject in QSBWorldSync.GetWorldObjects())
{
worldObject.Try("sending initial state", () =>
worldObject.SendInitialState(to));
}
}
}