quantum-space-buddies/QSB/SaveSync/Messages/RequestGameStateMessage.cs

42 lines
1021 B
C#
Raw Normal View History

2022-01-08 15:04:52 +00:00
using QSB.ConversationSync.Messages;
using QSB.ConversationSync.Patches;
using QSB.Messaging;
using QSB.Player;
using QSB.Utility;
2022-01-08 15:04:52 +00:00
using System.Linq;
2021-12-22 22:44:31 -08:00
2022-03-02 19:46:33 -08:00
namespace QSB.SaveSync.Messages;
/// <summary>
/// always sent to host
/// </summary>
internal class RequestGameStateMessage : QSBMessage
2021-12-22 22:44:31 -08:00
{
2022-03-02 19:46:33 -08:00
public RequestGameStateMessage() => To = 0;
2022-03-02 19:46:33 -08:00
public override void OnReceiveRemote() => Delay.RunFramesLater(100, () =>
{
if (!QSBPlayerManager.PlayerExists(From))
2022-01-08 11:41:55 +00:00
{
2022-03-02 19:46:33 -08:00
// player was kicked
return;
}
2022-03-02 19:46:33 -08:00
new GameStateMessage(From).Send();
2022-01-08 11:41:55 +00:00
2022-03-02 19:46:33 -08:00
var gameSave = PlayerData._currentGameSave;
2022-01-08 11:41:55 +00:00
2022-03-02 19:46:33 -08:00
var factSaves = gameSave.shipLogFactSaves;
foreach (var item in factSaves)
{
new ShipLogFactSaveMessage(item.Value).Send();
}
2022-01-08 15:04:52 +00:00
2022-03-02 19:46:33 -08:00
var dictConditions = gameSave.dictConditions;
var dictConditionsToSend = dictConditions.Where(x => ConversationPatches.PersistentConditionsToSync.Contains(x.Key));
foreach (var item in dictConditionsToSend)
{
new PersistentConditionMessage(item.Key, item.Value).Send();
}
});
}