diff --git a/CHANGELOG.md b/CHANGELOG.md index 69156fae..0c72b7a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +# 2.23.3 +- Fixed custom deck exhaust sequence not performing the requisite checks +- Added 'CanAppearRandomly' bool and associated extension method for custom regions +- All custom regions added through the API are now included in AllRegionsCopy and NewRegions (if addToPool was false then it won't be encounterable in-game like normal) + # 2.23.2 - Fixed error when trying to create cards that evolve/transform in 4 or more turns - Fixed Fledgling and Transformer sigil appearing as black boxes when a card evolves/transform in 4 or more turns diff --git a/InscryptionAPI/Encounters/OpponentManager.cs b/InscryptionAPI/Encounters/OpponentManager.cs index 4ae483c6..1585d454 100644 --- a/InscryptionAPI/Encounters/OpponentManager.cs +++ b/InscryptionAPI/Encounters/OpponentManager.cs @@ -255,11 +255,14 @@ public static void ProcessBossType(NodeData nodeData) [HarmonyPostfix, HarmonyPatch(typeof(CardDrawPiles), nameof(CardDrawPiles.ExhaustedSequence))] private static IEnumerator CustomBossExhaustionSequence(IEnumerator enumerator, CardDrawPiles __instance) { - if (TurnManager.Instance.Opponent is ICustomExhaustSequence exhaustSeq && exhaustSeq != null) + if (TurnManager.Instance.Opponent is ICustomExhaustSequence exhaustSeq && exhaustSeq.RespondsToCustomExhaustSequence(__instance)) { - Singleton.Instance.SwitchToView(View.CardPiles, immediate: false, lockAfter: true); + ViewManager.Instance.SwitchToView(View.CardPiles, immediate: false, lockAfter: true); yield return new WaitForSeconds(1f); yield return exhaustSeq.DoCustomExhaustSequence(__instance); + ViewManager.Instance.SwitchToView(View.Default); + ViewManager.Instance.Controller.LockState = ViewLockState.Unlocked; + __instance.turnsSinceExhausted++; } else { diff --git a/InscryptionAPI/InscryptionAPI.csproj b/InscryptionAPI/InscryptionAPI.csproj index a3a6cf3c..bea651c4 100644 --- a/InscryptionAPI/InscryptionAPI.csproj +++ b/InscryptionAPI/InscryptionAPI.csproj @@ -10,7 +10,7 @@ full false true - 2.23.2 + 2.23.3 diff --git a/InscryptionAPI/InscryptionAPIPlugin.cs b/InscryptionAPI/InscryptionAPIPlugin.cs index 7fb8fdc8..4002ce6c 100644 --- a/InscryptionAPI/InscryptionAPIPlugin.cs +++ b/InscryptionAPI/InscryptionAPIPlugin.cs @@ -31,7 +31,7 @@ public class InscryptionAPIPlugin : BaseUnityPlugin { public const string ModGUID = "cyantist.inscryption.api"; public const string ModName = "InscryptionAPI"; - public const string ModVer = "2.23.2"; + public const string ModVer = "2.23.3"; public static string Directory = ""; diff --git a/InscryptionAPI/Regions/Part1RegionData.cs b/InscryptionAPI/Regions/Part1RegionData.cs index 0b977823..4cd5c8e2 100644 --- a/InscryptionAPI/Regions/Part1RegionData.cs +++ b/InscryptionAPI/Regions/Part1RegionData.cs @@ -17,6 +17,7 @@ public class Part1RegionData public bool DoNotForceReachTerrain { get; set; } public bool AllowLockedTerrainCards { get; set; } public bool AllowSacrificableTerrainCards { get; set; } + public bool CanAppearRandomly { get; set; } private int tier; private RegionData region; @@ -34,6 +35,7 @@ public Part1RegionData(RegionData region, int tier) AllowTerrainOnPlayerSide = true; RemoveDefaultReachTerrain = false; DoNotForceReachTerrain = false; + CanAppearRandomly = true; this.region = region; this.tier = tier; } diff --git a/InscryptionAPI/Regions/RegionExtensions.cs b/InscryptionAPI/Regions/RegionExtensions.cs index 54fd5cf2..db19960e 100644 --- a/InscryptionAPI/Regions/RegionExtensions.cs +++ b/InscryptionAPI/Regions/RegionExtensions.cs @@ -1,3 +1,4 @@ +using APIPlugin; using DiskCardGame; using InscryptionAPI.Card; using InscryptionAPI.Encounters; @@ -8,6 +9,23 @@ namespace InscryptionAPI.Regions; public static class RegionExtensions { + /// + /// If the created region will be added to the pool of regions that can appear in a run. + /// + /// The RegionData for the region we are modifying. + /// If the created region will be added to the pool of regions that can appear in a run. + /// The same RegionData so a chain can continue. + public static RegionData SetCanAppearRandomly(this RegionData data, bool canAppear) { + Part1RegionData region = RegionManager.NewRegions.FirstOrDefault(x => x.Region == data); + if (region != null) { + region.CanAppearRandomly = canAppear; + } + else { + InscryptionAPIPlugin.Logger.LogWarning($"Could not find custom region for RegionData [{data.name}]!"); + } + return data; + } + public static RegionData RegionByName(this IEnumerable regions, string name) => regions.FirstOrDefault(x => x.name == name); public static RegionData SetName(this RegionData region, string name) @@ -199,6 +217,11 @@ public static RegionData SetFogAlpha(this RegionData region, float alpha) return region; } + public static RegionData SetMapEmission(this RegionData region, Texture texture) { + region.mapEmission = texture; + return region; + } + public static RegionData SetMapEmission(this RegionData region, Texture2D texture) { region.mapEmission = texture; diff --git a/InscryptionAPI/Regions/RegionManager.cs b/InscryptionAPI/Regions/RegionManager.cs index e1d7ffad..e7fde7bb 100644 --- a/InscryptionAPI/Regions/RegionManager.cs +++ b/InscryptionAPI/Regions/RegionManager.cs @@ -36,6 +36,12 @@ private static List ReorderBaseRegions() return orderedRegions; } + + private static List GenerateBasePart1RegionData() { + List data = ReorderBaseRegions(); + return data.Select(x => new Part1RegionData(x, 0)).ToList(); + } + public static readonly ObservableCollection NewRegions = new(); public static event Func, List> ModifyRegionsList; @@ -109,8 +115,11 @@ public static RegionData New(string name, int tier, bool addToPool = true) RegionData retval = ScriptableObject.CreateInstance(); retval.name = name; - if (addToPool) - Add(retval, tier); + Add(retval, tier); + if (!addToPool) { + retval.SetCanAppearRandomly(false); + } + return retval; } @@ -355,11 +364,11 @@ private static bool MapDataReader_SpawnAndPlaceElement(ref MapDataReader __insta return false; } - private static List GetAllRegionsForMapGeneration() - { + private static List GetAllRegionsForMapGeneration() { List allRegions = new(RegionProgression.Instance.regions); allRegions.RemoveAt(allRegions.Count - 1); // Remove midnight region - allRegions.AddRange(NewRegions.Select(a => a.Region)); // New Regions + allRegions.AddRange(NewRegions.Where(x => x.CanAppearRandomly).Select(a => a.Region)); // New Regions + allRegions.ForEach(x => InscryptionAPIPlugin.Logger.LogInfo(x.name)); return allRegions; } @@ -367,26 +376,11 @@ private static List GetAllRegionsForMapGeneration() [HarmonyPatch(typeof(AscensionSaveData), "RollCurrentRunRegionOrder")] private static bool RollCurrentRunRegionOrder(AscensionSaveData __instance) { - // Get all regions to choose from List allRegions = GetAllRegionsForMapGeneration(); allRegions = allRegions.Randomize().ToList(); List selectedRegions = new(); List selectedOpponents = new(); - for (int i = 0; i < allRegions.Count; i++) - { - RegionData regionData = allRegions[i]; - Opponent.Type opponentType = GetRandomAvailableOpponent(regionData, selectedOpponents); - if (opponentType != Opponent.Type.Default) - { - // Add a region that doesn't conflict with the already selected ones - selectedRegions.Add(regionData); - selectedOpponents.Add(opponentType); - } - - if (selectedRegions.Count == 3) - break; - } // Safety check: Make sure we have 3 regions! while (selectedRegions.Count < 3) diff --git a/InscryptionCommunityPatch/Card/Vanilla Ability Patches/GemsDrawFix.cs b/InscryptionCommunityPatch/Card/Vanilla Ability Patches/GemsDrawFix.cs index dc81c926..50ae655d 100644 --- a/InscryptionCommunityPatch/Card/Vanilla Ability Patches/GemsDrawFix.cs +++ b/InscryptionCommunityPatch/Card/Vanilla Ability Patches/GemsDrawFix.cs @@ -1,5 +1,6 @@ using DiskCardGame; using HarmonyLib; +using InscryptionAPI.Card; using System.Collections; using UnityEngine; @@ -16,11 +17,13 @@ private static bool FixGemsDraw(GemsDraw __instance, ref IEnumerator __result) return false; } - private static IEnumerator BetterGemsDraw(GemsDraw __instance) + public static IEnumerator BetterGemsDraw(GemsDraw __instance) { yield return __instance.PreSuccessfulTriggerSequence(); - int numGems = Singleton.Instance.PlayerSlotsCopy.FindAll( - x => x.Card != null && x.Card.Info.HasTrait(Trait.Gem)).Count; + Singleton.Instance.SwitchToView(SaveManager.SaveFile.IsMagnificus ? View.WizardBattleSlots : View.Default); + yield return new WaitForSeconds(0.1f); + + int numGems = Singleton.Instance.PlayerSlotsCopy.Count(x => x.Card != null && x.Card.HasTrait(Trait.Gem)); if (numGems == 0) { @@ -29,18 +32,16 @@ private static IEnumerator BetterGemsDraw(GemsDraw __instance) yield return new WaitForSeconds(0.45f); yield break; } - - Singleton.Instance.SwitchToView(SaveManager.SaveFile.IsPart2 ? View.WizardBattleSlots : View.Hand); - yield return new WaitForSeconds(0.1f); + for (int i = 0; i < numGems; i++) { - if (SaveManager.SaveFile.IsPart2) - yield return Singleton.Instance.DrawCardFromDeck(); - else - { + if (Singleton.Instance != null && Singleton.Instance.Pile != null) { Singleton.Instance.Pile.Draw(); yield return Singleton.Instance.DrawCardFromDeck(); } + else + yield return Singleton.Instance.DrawCardFromDeck(); + } yield return __instance.LearnAbility(0.5f); } diff --git a/InscryptionCommunityPatch/Card/Vanilla Ability Patches/RandomAbilityPatches.cs b/InscryptionCommunityPatch/Card/Vanilla Ability Patches/RandomAbilityPatches.cs index 96a69641..287e0127 100644 --- a/InscryptionCommunityPatch/Card/Vanilla Ability Patches/RandomAbilityPatches.cs +++ b/InscryptionCommunityPatch/Card/Vanilla Ability Patches/RandomAbilityPatches.cs @@ -35,7 +35,7 @@ private static IEnumerator ActivateRandomOnQueue(IEnumerator enumerator, Opponen yield return enumerator; PlayableCard card = __instance.Queue.Find(x => x.QueuedSlot == slot); - if (!card) + if (card == null) yield break; if (card.HasAbility(Ability.RandomAbility) && !card.Status.hiddenAbilities.Contains(Ability.RandomAbility)) @@ -48,7 +48,7 @@ private static IEnumerator ActivateRandomOnResolve(IEnumerator enumerator, Playa { yield return enumerator; - if (!card || card.Dead) + if (card == null || card.Dead) yield break; if (card.HasAbility(Ability.RandomAbility) && !card.Status.hiddenAbilities.Contains(Ability.RandomAbility)) @@ -62,7 +62,7 @@ private static IEnumerator ActivateRandomOnResolve(IEnumerator enumerator, Playa private static IEnumerator ActivateOnEvolve(IEnumerator enumerator, PlayableCard __instance, CardInfo evolvedInfo) { yield return enumerator; - if (!__instance) + if (__instance == null || evolvedInfo == null) yield break; if (evolvedInfo.HasAbility(Ability.RandomAbility) && !__instance.Status.hiddenAbilities.Contains(Ability.RandomAbility)) @@ -70,9 +70,9 @@ private static IEnumerator ActivateOnEvolve(IEnumerator enumerator, PlayableCard } [HarmonyPrefix, HarmonyPatch(typeof(PlayableCard), nameof(PlayableCard.AddTemporaryMod))] - private static void ActivateOnAddTempMod(PlayableCard __instance, ref CardModificationInfo mod) + private static void ActivateOnAddTempMod(PlayableCard __instance, CardModificationInfo mod) { - if (mod.HasAbility(Ability.RandomAbility)) + if (mod != null && mod.HasAbility(Ability.RandomAbility)) { for (int i = 0; i < mod.abilities.Count; i++) {