quantum-space-buddies/QSB/ConversationSync/Messages/PersistentConditionMessage.cs

50 lines
1.0 KiB
C#
Raw Normal View History

2022-01-14 22:30:54 +00:00
using Mirror;
using QSB.Messaging;
2022-01-08 11:41:55 +00:00
using QSB.WorldSync;
namespace QSB.ConversationSync.Messages
2022-01-08 11:41:55 +00:00
{
2022-02-28 21:20:51 +00:00
internal class PersistentConditionMessage : QSBMessage<string, bool>
2022-01-08 11:41:55 +00:00
{
public PersistentConditionMessage(string condition, bool state)
2022-01-08 11:41:55 +00:00
{
2022-02-28 21:20:51 +00:00
Value1 = condition;
Value2 = state;
2022-01-08 11:41:55 +00:00
}
public override void OnReceiveRemote()
2022-01-08 11:41:55 +00:00
{
if (QSBCore.IsHost)
{
2022-02-28 21:20:51 +00:00
QSBWorldSync.SetPersistentCondition(Value1, Value2);
}
var gameSave = PlayerData._currentGameSave;
2022-02-28 21:20:51 +00:00
if (gameSave.dictConditions.ContainsKey(Value1))
{
2022-02-28 21:20:51 +00:00
gameSave.dictConditions[Value1] = Value2;
}
else
{
2022-02-28 21:20:51 +00:00
gameSave.dictConditions.Add(Value1, Value2);
}
2022-02-28 21:20:51 +00:00
if (Value1
is not "LAUNCH_CODES_GIVEN"
and not "PLAYER_ENTERED_TIMELOOPCORE"
and not "PROBE_ENTERED_TIMELOOPCORE"
and not "PLAYER_ENTERED_TIMELOOPCORE_MULTIPLE")
{
PlayerData.SaveCurrentGame();
}
2022-01-08 11:41:55 +00:00
}
public override void OnReceiveLocal()
2022-01-08 11:41:55 +00:00
{
if (QSBCore.IsHost)
{
2022-02-28 21:20:51 +00:00
QSBWorldSync.SetPersistentCondition(Value1, Value2);
}
2022-01-08 11:41:55 +00:00
}
}
}