sync all persistent conditions

This commit is contained in:
JohnCorby 2022-03-27 00:24:07 -07:00
parent 179a7ddfc3
commit 4d339df9db
3 changed files with 6 additions and 43 deletions

View File

@ -7,7 +7,6 @@ using QSB.Patches;
using QSB.Player;
using QSB.Utility;
using QSB.WorldSync;
using System.Linq;
namespace QSB.ConversationSync.Patches;
@ -16,22 +15,10 @@ public class ConversationPatches : QSBPatch
{
public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect;
public static readonly string[] PersistentConditionsToSync =
{
"MET_SOLANUM",
"MET_PRISONER",
"TALKED_TO_GABBRO",
"GABBRO_MERGE_TRIGGERED",
"KNOWS_MEDITATION"
};
[HarmonyPrefix]
[HarmonyPatch(typeof(DialogueConditionManager), nameof(DialogueConditionManager.SetConditionState))]
public static bool SetConditionState(string conditionName, bool conditionState)
{
public static void SetConditionState(string conditionName, bool conditionState) =>
new DialogueConditionMessage(conditionName, conditionState).Send();
return true;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(CharacterDialogueTree), nameof(CharacterDialogueTree.StartConversation))]
@ -159,19 +146,11 @@ public class ConversationPatches : QSBPatch
[HarmonyPostfix]
[HarmonyPatch(typeof(GameSave), nameof(GameSave.SetPersistentCondition))]
public static void SetPersistentCondition(string condition, bool state)
{
if (PersistentConditionsToSync.Contains(condition))
{
new PersistentConditionMessage(condition, state).Send();
}
}
public static void SetPersistentCondition(string condition, bool state) =>
new PersistentConditionMessage(condition, state).Send();
[HarmonyPrefix]
[HarmonyPatch(typeof(DialogueConditionManager), nameof(DialogueConditionManager.AddCondition))]
public static bool AddCondition(string conditionName, bool conditionState)
{
public static void AddCondition(string conditionName, bool conditionState) =>
new DialogueConditionMessage(conditionName, conditionState).Send();
return true;
}
}

View File

@ -1,9 +1,7 @@
using QSB.ConversationSync.Messages;
using QSB.ConversationSync.Patches;
using QSB.Messaging;
using QSB.Player;
using QSB.Utility;
using System.Linq;
namespace QSB.SaveSync.Messages;
@ -33,8 +31,7 @@ internal class RequestGameStateMessage : QSBMessage
}
var dictConditions = gameSave.dictConditions;
var dictConditionsToSend = dictConditions.Where(x => ConversationPatches.PersistentConditionsToSync.Contains(x.Key));
foreach (var item in dictConditionsToSend)
foreach (var item in dictConditions)
{
new PersistentConditionMessage(item.Key, item.Value).Send();
}

View File

@ -1,7 +1,6 @@
using Cysharp.Threading.Tasks;
using MonoMod.Utils;
using OWML.Common;
using QSB.ConversationSync.Patches;
using QSB.LogSync;
using QSB.Messaging;
using QSB.Player.TransformSync;
@ -174,23 +173,11 @@ public static class QSBWorldSync
return;
}
DebugLog.DebugWrite($"DIALOGUE CONDITIONS :");
DialogueConditions.Clear();
DialogueConditions.AddRange(DialogueConditionManager.SharedInstance._dictConditions);
foreach (var item in DialogueConditions)
{
DebugLog.DebugWrite($"- {item.Key}, {item.Value}");
}
DebugLog.DebugWrite($"PERSISTENT CONDITIONS :");
var dictConditions = PlayerData._currentGameSave.dictConditions;
var syncedConditions = dictConditions.Where(x => ConversationPatches.PersistentConditionsToSync.Contains(x.Key));
PersistentConditions.Clear();
PersistentConditions.AddRange(syncedConditions.ToDictionary(x => x.Key, x => x.Value));
foreach (var item in PersistentConditions)
{
DebugLog.DebugWrite($"- {item.Key}, {item.Value}");
}
PersistentConditions.AddRange(PlayerData._currentGameSave.dictConditions);
}
private static void GameReset()