diff --git a/Core/Models/GraveControllerExt.cs b/Core/Models/GraveControllerExt.cs index 626cc01d..54ad683d 100644 --- a/Core/Models/GraveControllerExt.cs +++ b/Core/Models/GraveControllerExt.cs @@ -37,7 +37,10 @@ private void Start() public static void SetupNewController(GravestoneCardAnimationController graveController) { + Log.LogInfo($"[GraveControllerExt] SetupNewController [{graveController}]"); + Log.LogInfo($"[GraveControllerExt] SetupNewController [{graveController.gameObject}]"); GraveControllerExt ext = graveController.gameObject.AddComponent(); + Log.LogInfo($"[GraveControllerExt] ext [{ext}]"); ext.cardRenderer = graveController.cardRenderer; ext.intendedRendererYPos = ext.cardRenderer.transform.localPosition.y; ext.armAnim = graveController.armAnim; @@ -50,6 +53,7 @@ public static void SetupNewController(GravestoneCardAnimationController graveCon ext.statsLater = graveController.statsLater; ext._graveAnim = graveController.Anim; + Log.LogInfo($"[GraveControllerExt] graveController.PlayableCard [{graveController.PlayableCard}]"); if (graveController.PlayableCard) { ext._playableCard = graveController.PlayableCard; diff --git a/Core/Utils/GrimoraSaveUtil.cs b/Core/Utils/GrimoraSaveUtil.cs index feeb562d..4ccf3a24 100644 --- a/Core/Utils/GrimoraSaveUtil.cs +++ b/Core/Utils/GrimoraSaveUtil.cs @@ -10,9 +10,9 @@ public static void ClearDeck() DeckInfo.cardIds.Clear(); } - public static bool IsGrimora => SaveManager.SaveFile.IsGrimora || SaveDataRelatedPatches.IsGrimoraRun; + public static bool IsGrimora => SaveDataRelatedPatches.IsGrimoraRun; - public static bool IsNotGrimora => !SaveManager.SaveFile.IsGrimora || SaveDataRelatedPatches.IsNotGrimoraRun; + public static bool IsNotGrimora => SaveDataRelatedPatches.IsNotGrimoraRun; public static DeckInfo DeckInfo => GrimoraSaveData.Data.deck; diff --git a/Patches/AscensionRelatedPatches.cs b/Patches/AscensionRelatedPatches.cs index f0336922..8f3ef9ac 100644 --- a/Patches/AscensionRelatedPatches.cs +++ b/Patches/AscensionRelatedPatches.cs @@ -1,5 +1,6 @@ using DiskCardGame; using GBC; +using GrimoraMod.Saving; using HarmonyLib; using InscryptionAPI.Ascension; using Sirenix.Utilities; @@ -133,12 +134,13 @@ public class AscensionRelatedPatches [HarmonyBefore(ConfigHelper.PackManagerGuid, ConfigHelper.P03ModGuid)] public static bool InitializeGrimoraSaveData(ref AscensionMenuScreens __instance, bool newRun = true) { + GrimoraAscensionSaveData ascensionSaveData = (GrimoraAscensionSaveData)AscensionSaveData.Data; Log.LogInfo($"[AscensionMenuScreens.TransitionToGame] " + - $"IsGrimoraRun [{SaveDataRelatedPatches.IsGrimoraRun}] " + - $"newRun [{newRun}] " + - $"screen state [{ScreenManagement.ScreenState}] " + - $"currentStarterDeck [{AscensionSaveData.Data.currentStarterDeck}]" + - $"currentRun [{AscensionSaveData.Data.currentRun}]" + $"IsGrimoraRun [{SaveDataRelatedPatches.IsGrimoraRun}] " + + $"newRun [{newRun}] " + + $"screen state [{ScreenManagement.ScreenState}] " + + $"currentStarterDeck [{ascensionSaveData.currentStarterDeck}]" + + $"currentRun [{ascensionSaveData.currentRun}]" ); if (newRun) @@ -159,18 +161,18 @@ public static bool InitializeGrimoraSaveData(ref AscensionMenuScreens __instance { Log.LogInfo($"[AscensionMenuScreens.TransitionToGame] Setting ScreenState to Undead"); ScreenManagement.ScreenState = CardTemple.Undead; - if (AscensionSaveData.Data.currentStarterDeck.Equals("Vanilla", StringComparison.InvariantCultureIgnoreCase)) + if (ascensionSaveData.currentStarterDeck.Equals("Vanilla", StringComparison.InvariantCultureIgnoreCase)) { Log.LogInfo($"[AscensionMenuScreens.TransitionToGame] --> Changing current starter deck to default"); - AscensionSaveData.Data.currentStarterDeck = StarterDecks.DefaultStarterDeck; + ascensionSaveData.currentStarterDeck = StarterDecks.DefaultStarterDeck; } - Log.LogInfo($"[AscensionMenuScreens.TransitionToGame] Creating new ascension run from starter deck [{StarterDecks.DefaultStarterDeck}]"); - StarterDeckInfo deckInfo = StarterDecksUtil.GetInfo(StarterDecks.DefaultStarterDeck); + Log.LogInfo($"[AscensionMenuScreens.TransitionToGame] Creating new ascension run from starter deck [{ascensionSaveData.currentStarterDeck}]"); + StarterDeckInfo deckInfo = StarterDecksUtil.GetInfo(ascensionSaveData.currentStarterDeck); if (deckInfo) { Log.LogInfo($"[AscensionMenuScreens.TransitionToGame] --> DeckInfo not null [{deckInfo.cards.Join(c => c.name)}]"); - AscensionSaveData.Data.NewRun(deckInfo.cards); + ascensionSaveData.NewRun(deckInfo.cards); SaveManager.SaveToFile(false); } else @@ -191,34 +193,6 @@ public static bool InitializeGrimoraSaveData(ref AscensionMenuScreens __instance return true; } - private static void ClearGrimoraData() - { - if (!AscensionMenuScreens.ReturningFromFailedRun && !AscensionMenuScreens.ReturningFromSuccessfulRun) - { - ScreenManagement.ScreenState = CardTemple.Undead; - } - } - - [HarmonyPrefix, HarmonyPatch(nameof(AscensionMenuScreens.SwitchToScreen))] - public static void ClearGrimoraSaveOnNewRun(AscensionMenuScreens __instance, AscensionMenuScreens.Screen screen) - { - if (screen == AscensionMenuScreens.Screen.Start) // At the main screen, you can't be in any style of run. Not yet. - { - ClearGrimoraData(); - } - } - - [HarmonyPrefix, HarmonyPatch(nameof(AscensionMenuScreens.Start))] - public static void ClearScreenStatePrefix(AscensionMenuScreens __instance) - { - ClearGrimoraData(); - } - - - - - - internal static AscensionMenuInteractable CreateAscensionButton(AscensionMenuInteractable newRunButton) { Log.LogDebug($"[AscensionMenuScreens.Start] Creating new Grimora ascension run button"); @@ -229,6 +203,7 @@ internal static AscensionMenuInteractable CreateAscensionButton(AscensionMenuInt SaveDataRelatedPatches.IsGrimoraRun = true; ScreenManagement.ScreenState = CardTemple.Undead; ChallengeManager.SyncChallengeList(); + GrimoraSaveManager.CurrentSaveFile.NewAscensionRun(); Log.LogDebug($"[AscensionMenuScreens.Start] Set screen state to undead, invoking CursorSelectStart"); newRunButton.CursorSelectStart(); }; diff --git a/Patches/Cards/BaseCardPatches.cs b/Patches/Cards/BaseCardPatches.cs index 35e749e3..22c2b747 100644 --- a/Patches/Cards/BaseCardPatches.cs +++ b/Patches/Cards/BaseCardPatches.cs @@ -41,7 +41,11 @@ public static void AddNewController(Card __instance, CardInfo info) if (__instance.GetComponentInParent().SafeIsUnityNull() && __instance.GetComponent().SafeIsUnityNull()) { var oldController = __instance.GetComponent(); - GraveControllerExt.SetupNewController(oldController); + if (oldController != null) + { + GrimoraPlugin.Log.LogInfo($"[AddNewController] oldController [{oldController}][{info.name}]"); + GraveControllerExt.SetupNewController(oldController); + } } } } diff --git a/Patches/SaveDataRelatedPatches.cs b/Patches/SaveDataRelatedPatches.cs index 16e21315..3d6ba9e0 100644 --- a/Patches/SaveDataRelatedPatches.cs +++ b/Patches/SaveDataRelatedPatches.cs @@ -31,15 +31,7 @@ public static string SaveKey public static bool IsGrimoraRun { - get - { - string activeSceneName = SceneLoader.ActiveSceneName.ToLowerInvariant(); - // Log.LogDebug($"[IsGrimoraRun] Active scene name is [{activeSceneName}] Screen State [{ScreenManagement.ScreenState}]"); - if (activeSceneName.Contains("grimora") || ScreenManagement.ScreenState == CardTemple.Undead) - return true; - - return AscensionSaveData.Data is { currentRun.playerLives: > 0 } && ModdedSaveManager.SaveData.GetValueAsBoolean(GUID, IsGrimoraRunKey); - } + get => ModdedSaveManager.SaveData.GetValueAsBoolean(GUID, IsGrimoraRunKey); set => ModdedSaveManager.SaveData.SetValue(GUID, IsGrimoraRunKey, value); } } diff --git a/Saving/GrimoraAscensionSaveData.cs b/Saving/GrimoraAscensionSaveData.cs index 3060ed2a..4e2c514f 100644 --- a/Saving/GrimoraAscensionSaveData.cs +++ b/Saving/GrimoraAscensionSaveData.cs @@ -26,51 +26,26 @@ public class GrimoraAscensionSaveData : AscensionSaveData public new void NewRun(List starterDeck) { + GrimoraPlugin.Log.LogInfo("[GrimoraAscensionSaveData] NewRun"); this.currentRunSeed = Environment.TickCount; this.currentOuroborosDeaths = 0; GrimoraRunState grimoraRunState = new GrimoraRunState(); this.currentRun = grimoraRunState; grimoraRunState.Initialize(); + this.RollCurrentRunRegionOrder(); this.oilPaintingState.TryAdvanceRewardIndex(); this.oilPaintingState.puzzleSolution = OilPaintingPuzzle.GenerateSolution(true); - this.currentRun.playerDeck = new DeckInfo(); + + this.currentRun.consumables.Clear(); + this.currentRun.consumables.Add("Pliers"); + foreach (CardInfo cardInfo in starterDeck) { this.currentRun.playerDeck.AddCard(CardLoader.GetCardByName(cardInfo.name)); + GrimoraPlugin.Log.LogInfo("[GrimoraAscensionSaveData] card " + cardInfo.name); } - if (this.numRunsSinceReachedFirstBoss == 0) - { - this.currentRun.playerDeck.AddCard(CardLoader.GetCardByName("PeltHare")); - this.currentRun.playerDeck.AddCard(CardLoader.GetCardByName("PeltHare")); - } - else if (this.numRunsSinceReachedFirstBoss == 1) - { - this.currentRun.playerDeck.AddCard(CardLoader.GetCardByName("Opossum")); - this.currentRun.playerDeck.AddCard(CardLoader.GetCardByName("PeltHare")); - } - else if (this.numRunsSinceReachedFirstBoss > 1) - { - this.currentRun.playerDeck.AddCard(CardLoader.GetCardByName("Opossum")); - this.currentRun.playerDeck.AddCard(CardLoader.GetCardByName("RingWorm")); - } - this.currentRun.consumables.Add("SquirrelBottle"); - if (this.GetNumChallengesOfTypeActive(AscensionChallenge.LessConsumables) < 2) - { - this.currentRun.consumables.Add("Pliers"); - } - if (!this.ChallengeIsActive(AscensionChallenge.NoHook)) - { - if (this.currentRun.consumables.Count == this.currentRun.MaxConsumables) - { - this.currentRun.consumables.RemoveAt(this.currentRun.consumables.Count - 1); - } - this.currentRun.consumables.Add("FishHook"); - } - if (this.ChallengeIsActive(AscensionChallenge.LessLives)) - { - this.currentRun.maxPlayerLives = (this.currentRun.playerLives = 1); - } + GrimoraPlugin.Log.LogInfo("[GrimoraAscensionSaveData] " + this.currentRun.playerDeck.Cards.Count); } } diff --git a/Saving/GrimoraSaveFile.cs b/Saving/GrimoraSaveFile.cs index 89fb171b..81393676 100644 --- a/Saving/GrimoraSaveFile.cs +++ b/Saving/GrimoraSaveFile.cs @@ -16,9 +16,8 @@ public void Initialize() public void NewAscensionRun() { - GrimoraRunState currentRun = (GrimoraRunState)AscensionSaveData.currentRun; - currentRun.Initialize(); - currentRun.NewStandardGame(); + AscensionSaveData.Initialize(); + AscensionSaveData.NewRun(new List()); } public void NewStandardRun() diff --git a/Saving/GrimoraSaveManager.cs b/Saving/GrimoraSaveManager.cs index 0a96e04e..43b60b5e 100644 --- a/Saving/GrimoraSaveManager.cs +++ b/Saving/GrimoraSaveManager.cs @@ -24,6 +24,11 @@ public static void ResetStandardRun() CurrentSaveFile.NewStandardRun(); } + public static void NewAscensionRun() + { + CurrentSaveFile.NewAscensionRun(); + } + #region Patches public static string SaveFilePath => SaveManager.SaveFolderPath + "GrimoraSaveFile.gwsave"; @@ -41,6 +46,7 @@ public static bool SaveManager_LoadFromFile() { if (File.Exists(SaveFilePath)) { + GrimoraPlugin.Log.LogInfo("Loaded from file"); string json = File.ReadAllText(SaveFilePath); CurrentSaveFile = SaveManager.FromJSON(json); } @@ -80,7 +86,14 @@ public static bool SaveFile_CurrentDeck(ref DeckInfo __result) { if (GrimoraSaveUtil.IsGrimora) { - __result = CurrentSaveFile.CurrentRun.playerDeck; + if (SaveFile.IsAscension) + { + __result = CurrentSaveFile.AscensionSaveData.currentRun.playerDeck; + } + else + { + __result = CurrentSaveFile.CurrentRun.playerDeck; + } return false; } @@ -91,10 +104,12 @@ public static bool SaveFile_CurrentDeck(ref DeckInfo __result) [HarmonyPrefix] public static bool AscensionSaveData_Data(ref AscensionSaveData __result) { + //GrimoraPlugin.Log.LogInfo(Environment.StackTrace); + //GrimoraPlugin.Log.LogInfo("Done"); if (GrimoraSaveUtil.IsGrimora) { __result = CurrentSaveFile.AscensionSaveData; - return false; + return false; // ***************************** } return true;