quantum-space-buddies/QSB/LogSync/Messages/RevealFactMessage.cs

60 lines
1.2 KiB
C#
Raw Normal View History

using Mirror;
using QSB.Messaging;
2021-12-24 21:28:41 -08:00
using QSB.WorldSync;
2020-12-19 10:56:25 +00:00
2022-03-02 19:46:33 -08:00
namespace QSB.LogSync.Messages;
public class RevealFactMessage : QSBMessage
2020-12-19 10:56:25 +00:00
{
2022-03-02 19:46:33 -08:00
private string FactId;
private bool SaveGame;
private bool ShowNotification;
public RevealFactMessage(string id, bool saveGame, bool showNotification)
{
2022-03-02 19:46:33 -08:00
FactId = id;
SaveGame = saveGame;
ShowNotification = showNotification;
}
2020-12-19 10:56:25 +00:00
2022-03-02 19:46:33 -08:00
public override void Serialize(NetworkWriter writer)
{
base.Serialize(writer);
writer.Write(FactId);
writer.Write(SaveGame);
writer.Write(ShowNotification);
}
2021-12-24 21:28:41 -08:00
2022-03-02 19:46:33 -08:00
public override void Deserialize(NetworkReader reader)
{
base.Deserialize(reader);
FactId = reader.ReadString();
SaveGame = reader.Read<bool>();
ShowNotification = reader.Read<bool>();
}
public override bool ShouldReceive => QSBWorldSync.AllObjectsReady;
2021-12-24 21:28:41 -08:00
2022-03-02 19:46:33 -08:00
public override void OnReceiveLocal()
{
if (QSBCore.IsHost)
2021-12-24 21:28:41 -08:00
{
2022-03-02 19:46:33 -08:00
QSBWorldSync.AddFactReveal(FactId, SaveGame);
2021-12-24 21:28:41 -08:00
}
2022-03-02 19:46:33 -08:00
}
2021-12-24 21:28:41 -08:00
2022-03-02 19:46:33 -08:00
public override void OnReceiveRemote()
{
if (QSBCore.IsHost)
2021-12-24 21:28:41 -08:00
{
2022-03-02 19:46:33 -08:00
QSBWorldSync.AddFactReveal(FactId, SaveGame);
2021-12-24 21:28:41 -08:00
}
2022-03-02 19:46:33 -08:00
if (!QSBWorldSync.AllObjectsReady)
{
2022-03-02 19:46:33 -08:00
return;
}
2022-03-02 19:46:33 -08:00
Locator.GetShipLogManager().RevealFact(FactId, SaveGame, ShowNotification);
2020-12-19 10:56:25 +00:00
}
2021-12-24 21:28:41 -08:00
}