mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-01-30 12:32:55 +00:00
9e5e7bb6a1
- 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
42 lines
1.1 KiB
C#
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);
|
|
}
|
|
}
|
|
}
|
|
}
|