quantum-space-buddies/QSB/WorldSync/RequestInitialStatesMessage.cs
JohnCorby 9e5e7bb6a1 initial state:
- always send from the host
- QSBNetworkBehaviour will store last known data in an array and send that, since real data will be wrong if no authority
2022-02-16 19:22:21 -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 to the host to get initial object states
/// </summary>
public class RequestInitialStatesMessage : QSBMessage
{
public RequestInitialStatesMessage() => To = 0;
public override void OnReceiveRemote() =>
Delay.RunWhen(() => QSBWorldSync.AllObjectsReady,
() => SendInitialStates(From));
private static void SendInitialStates(uint to)
{
DebugLog.DebugWrite($"sending initial states to {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>())
{
qsbNetworkBehaviour.SendInitialState(target);
}
foreach (var worldObject in QSBWorldSync.GetWorldObjects())
{
worldObject.SendInitialState(to);
}
}
}
}