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

68 lines
1.5 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
{
internal class PersistentConditionMessage : QSBMessage
{
private string _conditionName;
private bool _conditionState;
public PersistentConditionMessage(string condition, bool state)
{
_conditionName = condition;
_conditionState = state;
}
2022-01-14 22:30:54 +00:00
public override void Serialize(NetworkWriter writer)
2022-01-08 11:41:55 +00:00
{
base.Serialize(writer);
writer.Write(_conditionName);
writer.Write(_conditionState);
}
2022-01-14 22:30:54 +00:00
public override void Deserialize(NetworkReader reader)
2022-01-08 11:41:55 +00:00
{
base.Deserialize(reader);
_conditionName = reader.ReadString();
2022-01-14 22:30:54 +00:00
_conditionState = reader.ReadBool();
2022-01-08 11:41:55 +00:00
}
public override void OnReceiveRemote()
{
if (QSBCore.IsHost)
{
QSBWorldSync.SetPersistentCondition(_conditionName, _conditionState);
}
var gameSave = PlayerData._currentGameSave;
if (gameSave.dictConditions.ContainsKey(_conditionName))
{
gameSave.dictConditions[_conditionName] = _conditionState;
}
else
{
gameSave.dictConditions.Add(_conditionName, _conditionState);
}
if (_conditionName
is not "LAUNCH_CODES_GIVEN"
and not "PLAYER_ENTERED_TIMELOOPCORE"
and not "PROBE_ENTERED_TIMELOOPCORE"
and not "PLAYER_ENTERED_TIMELOOPCORE_MULTIPLE")
{
PlayerData.SaveCurrentGame();
}
}
public override void OnReceiveLocal()
{
if (QSBCore.IsHost)
{
QSBWorldSync.SetPersistentCondition(_conditionName, _conditionState);
}
}
}
}