using QSB.ConversationSync.Messages; using QSB.LogSync.Messages; using QSB.Messaging; using QSB.Utility; namespace QSB.WorldSync; /// /// sent to the host to get initial object states. /// /// world objects will be ready on both sides at this point /// public class RequestInitialStatesMessage : QSBMessage { public RequestInitialStatesMessage() => To = 0; public override void OnReceiveRemote() => Delay.RunWhen(() => QSBWorldSync.AllObjectsReady, () => SendInitialStates(From)); private static void SendInitialStates(uint to) { 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()); var target = to.GetNetworkConnection(); foreach (var qsbNetworkBehaviour in QSBWorldSync.GetUnityObjects()) { qsbNetworkBehaviour.SendInitialState(target); } foreach (var worldObject in QSBWorldSync.GetWorldObjects()) { worldObject.Try("sending initial state", () => worldObject.SendInitialState(to)); } DebugLog.DebugWrite($"sent initial states to {to}"); } }