Skip to content

Commit b71c80a

Browse files
authored
Merge pull request #324 from HumabHatterZed/main
Fix custom deck exhaust sequence not calling RespondsToCustomExhaustSequence
2 parents dfaecca + 8a37618 commit b71c80a

File tree

9 files changed

+67
-39
lines changed

9 files changed

+67
-39
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# 2.23.3
2+
- Fixed custom deck exhaust sequence not performing the requisite checks
3+
- Added 'CanAppearRandomly' bool and associated extension method for custom regions
4+
- 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)
5+
16
# 2.23.2
27
- Fixed error when trying to create cards that evolve/transform in 4 or more turns
38
- Fixed Fledgling and Transformer sigil appearing as black boxes when a card evolves/transform in 4 or more turns

InscryptionAPI/Encounters/OpponentManager.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,11 +255,14 @@ public static void ProcessBossType(NodeData nodeData)
255255
[HarmonyPostfix, HarmonyPatch(typeof(CardDrawPiles), nameof(CardDrawPiles.ExhaustedSequence))]
256256
private static IEnumerator CustomBossExhaustionSequence(IEnumerator enumerator, CardDrawPiles __instance)
257257
{
258-
if (TurnManager.Instance.Opponent is ICustomExhaustSequence exhaustSeq && exhaustSeq != null)
258+
if (TurnManager.Instance.Opponent is ICustomExhaustSequence exhaustSeq && exhaustSeq.RespondsToCustomExhaustSequence(__instance))
259259
{
260-
Singleton<ViewManager>.Instance.SwitchToView(View.CardPiles, immediate: false, lockAfter: true);
260+
ViewManager.Instance.SwitchToView(View.CardPiles, immediate: false, lockAfter: true);
261261
yield return new WaitForSeconds(1f);
262262
yield return exhaustSeq.DoCustomExhaustSequence(__instance);
263+
ViewManager.Instance.SwitchToView(View.Default);
264+
ViewManager.Instance.Controller.LockState = ViewLockState.Unlocked;
265+
__instance.turnsSinceExhausted++;
263266
}
264267
else
265268
{

InscryptionAPI/InscryptionAPI.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<DebugType>full</DebugType>
1111
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
1212
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
13-
<Version>2.23.2</Version>
13+
<Version>2.23.3</Version>
1414
</PropertyGroup>
1515

1616
<PropertyGroup>

InscryptionAPI/InscryptionAPIPlugin.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public class InscryptionAPIPlugin : BaseUnityPlugin
3131
{
3232
public const string ModGUID = "cyantist.inscryption.api";
3333
public const string ModName = "InscryptionAPI";
34-
public const string ModVer = "2.23.2";
34+
public const string ModVer = "2.23.3";
3535

3636
public static string Directory = "";
3737

InscryptionAPI/Regions/Part1RegionData.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public class Part1RegionData
1717
public bool DoNotForceReachTerrain { get; set; }
1818
public bool AllowLockedTerrainCards { get; set; }
1919
public bool AllowSacrificableTerrainCards { get; set; }
20+
public bool CanAppearRandomly { get; set; }
2021

2122
private int tier;
2223
private RegionData region;
@@ -34,6 +35,7 @@ public Part1RegionData(RegionData region, int tier)
3435
AllowTerrainOnPlayerSide = true;
3536
RemoveDefaultReachTerrain = false;
3637
DoNotForceReachTerrain = false;
38+
CanAppearRandomly = true;
3739
this.region = region;
3840
this.tier = tier;
3941
}

InscryptionAPI/Regions/RegionExtensions.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using APIPlugin;
12
using DiskCardGame;
23
using InscryptionAPI.Card;
34
using InscryptionAPI.Encounters;
@@ -8,6 +9,23 @@ namespace InscryptionAPI.Regions;
89

910
public static class RegionExtensions
1011
{
12+
/// <summary>
13+
/// If the created region will be added to the pool of regions that can appear in a run.
14+
/// </summary>
15+
/// <param name="data">The RegionData for the region we are modifying.</param>
16+
/// <param name="canAppear">If the created region will be added to the pool of regions that can appear in a run.</param>
17+
/// <returns>The same RegionData so a chain can continue.</returns>
18+
public static RegionData SetCanAppearRandomly(this RegionData data, bool canAppear) {
19+
Part1RegionData region = RegionManager.NewRegions.FirstOrDefault(x => x.Region == data);
20+
if (region != null) {
21+
region.CanAppearRandomly = canAppear;
22+
}
23+
else {
24+
InscryptionAPIPlugin.Logger.LogWarning($"Could not find custom region for RegionData [{data.name}]!");
25+
}
26+
return data;
27+
}
28+
1129
public static RegionData RegionByName(this IEnumerable<RegionData> regions, string name) => regions.FirstOrDefault(x => x.name == name);
1230

1331
public static RegionData SetName(this RegionData region, string name)
@@ -199,6 +217,11 @@ public static RegionData SetFogAlpha(this RegionData region, float alpha)
199217
return region;
200218
}
201219

220+
public static RegionData SetMapEmission(this RegionData region, Texture texture) {
221+
region.mapEmission = texture;
222+
return region;
223+
}
224+
202225
public static RegionData SetMapEmission(this RegionData region, Texture2D texture)
203226
{
204227
region.mapEmission = texture;

InscryptionAPI/Regions/RegionManager.cs

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ private static List<RegionData> ReorderBaseRegions()
3636

3737
return orderedRegions;
3838
}
39+
40+
private static List<Part1RegionData> GenerateBasePart1RegionData() {
41+
List<RegionData> data = ReorderBaseRegions();
42+
return data.Select(x => new Part1RegionData(x, 0)).ToList();
43+
}
44+
3945
public static readonly ObservableCollection<Part1RegionData> NewRegions = new();
4046

4147
public static event Func<List<RegionData>, List<RegionData>> ModifyRegionsList;
@@ -109,8 +115,11 @@ public static RegionData New(string name, int tier, bool addToPool = true)
109115
RegionData retval = ScriptableObject.CreateInstance<RegionData>();
110116
retval.name = name;
111117

112-
if (addToPool)
113-
Add(retval, tier);
118+
Add(retval, tier);
119+
if (!addToPool) {
120+
retval.SetCanAppearRandomly(false);
121+
}
122+
114123

115124
return retval;
116125
}
@@ -355,38 +364,23 @@ private static bool MapDataReader_SpawnAndPlaceElement(ref MapDataReader __insta
355364
return false;
356365
}
357366

358-
private static List<RegionData> GetAllRegionsForMapGeneration()
359-
{
367+
private static List<RegionData> GetAllRegionsForMapGeneration() {
360368
List<RegionData> allRegions = new(RegionProgression.Instance.regions);
361369
allRegions.RemoveAt(allRegions.Count - 1); // Remove midnight region
362-
allRegions.AddRange(NewRegions.Select(a => a.Region)); // New Regions
370+
allRegions.AddRange(NewRegions.Where(x => x.CanAppearRandomly).Select(a => a.Region)); // New Regions
371+
allRegions.ForEach(x => InscryptionAPIPlugin.Logger.LogInfo(x.name));
363372
return allRegions;
364373
}
365374

366375
[HarmonyPrefix]
367376
[HarmonyPatch(typeof(AscensionSaveData), "RollCurrentRunRegionOrder")]
368377
private static bool RollCurrentRunRegionOrder(AscensionSaveData __instance)
369378
{
370-
// Get all regions to choose from
371379
List<RegionData> allRegions = GetAllRegionsForMapGeneration();
372380
allRegions = allRegions.Randomize().ToList();
373381

374382
List<RegionData> selectedRegions = new();
375383
List<Opponent.Type> selectedOpponents = new();
376-
for (int i = 0; i < allRegions.Count; i++)
377-
{
378-
RegionData regionData = allRegions[i];
379-
Opponent.Type opponentType = GetRandomAvailableOpponent(regionData, selectedOpponents);
380-
if (opponentType != Opponent.Type.Default)
381-
{
382-
// Add a region that doesn't conflict with the already selected ones
383-
selectedRegions.Add(regionData);
384-
selectedOpponents.Add(opponentType);
385-
}
386-
387-
if (selectedRegions.Count == 3)
388-
break;
389-
}
390384

391385
// Safety check: Make sure we have 3 regions!
392386
while (selectedRegions.Count < 3)

InscryptionCommunityPatch/Card/Vanilla Ability Patches/GemsDrawFix.cs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using DiskCardGame;
22
using HarmonyLib;
3+
using InscryptionAPI.Card;
34
using System.Collections;
45
using UnityEngine;
56

@@ -16,11 +17,13 @@ private static bool FixGemsDraw(GemsDraw __instance, ref IEnumerator __result)
1617
return false;
1718
}
1819

19-
private static IEnumerator BetterGemsDraw(GemsDraw __instance)
20+
public static IEnumerator BetterGemsDraw(GemsDraw __instance)
2021
{
2122
yield return __instance.PreSuccessfulTriggerSequence();
22-
int numGems = Singleton<BoardManager>.Instance.PlayerSlotsCopy.FindAll(
23-
x => x.Card != null && x.Card.Info.HasTrait(Trait.Gem)).Count;
23+
Singleton<ViewManager>.Instance.SwitchToView(SaveManager.SaveFile.IsMagnificus ? View.WizardBattleSlots : View.Default);
24+
yield return new WaitForSeconds(0.1f);
25+
26+
int numGems = Singleton<BoardManager>.Instance.PlayerSlotsCopy.Count(x => x.Card != null && x.Card.HasTrait(Trait.Gem));
2427

2528
if (numGems == 0)
2629
{
@@ -29,18 +32,16 @@ private static IEnumerator BetterGemsDraw(GemsDraw __instance)
2932
yield return new WaitForSeconds(0.45f);
3033
yield break;
3134
}
32-
33-
Singleton<ViewManager>.Instance.SwitchToView(SaveManager.SaveFile.IsPart2 ? View.WizardBattleSlots : View.Hand);
34-
yield return new WaitForSeconds(0.1f);
35+
3536
for (int i = 0; i < numGems; i++)
3637
{
37-
if (SaveManager.SaveFile.IsPart2)
38-
yield return Singleton<CardDrawPiles>.Instance.DrawCardFromDeck();
39-
else
40-
{
38+
if (Singleton<CardDrawPiles3D>.Instance != null && Singleton<CardDrawPiles3D>.Instance.Pile != null) {
4139
Singleton<CardDrawPiles3D>.Instance.Pile.Draw();
4240
yield return Singleton<CardDrawPiles3D>.Instance.DrawCardFromDeck();
4341
}
42+
else
43+
yield return Singleton<CardDrawPiles>.Instance.DrawCardFromDeck();
44+
4445
}
4546
yield return __instance.LearnAbility(0.5f);
4647
}

InscryptionCommunityPatch/Card/Vanilla Ability Patches/RandomAbilityPatches.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ private static IEnumerator ActivateRandomOnQueue(IEnumerator enumerator, Opponen
3535
yield return enumerator;
3636

3737
PlayableCard card = __instance.Queue.Find(x => x.QueuedSlot == slot);
38-
if (!card)
38+
if (card == null)
3939
yield break;
4040

4141
if (card.HasAbility(Ability.RandomAbility) && !card.Status.hiddenAbilities.Contains(Ability.RandomAbility))
@@ -48,7 +48,7 @@ private static IEnumerator ActivateRandomOnResolve(IEnumerator enumerator, Playa
4848
{
4949
yield return enumerator;
5050

51-
if (!card || card.Dead)
51+
if (card == null || card.Dead)
5252
yield break;
5353

5454
if (card.HasAbility(Ability.RandomAbility) && !card.Status.hiddenAbilities.Contains(Ability.RandomAbility))
@@ -62,17 +62,17 @@ private static IEnumerator ActivateRandomOnResolve(IEnumerator enumerator, Playa
6262
private static IEnumerator ActivateOnEvolve(IEnumerator enumerator, PlayableCard __instance, CardInfo evolvedInfo)
6363
{
6464
yield return enumerator;
65-
if (!__instance)
65+
if (__instance == null || evolvedInfo == null)
6666
yield break;
6767

6868
if (evolvedInfo.HasAbility(Ability.RandomAbility) && !__instance.Status.hiddenAbilities.Contains(Ability.RandomAbility))
6969
yield return AddRandomSigil(__instance);
7070
}
7171

7272
[HarmonyPrefix, HarmonyPatch(typeof(PlayableCard), nameof(PlayableCard.AddTemporaryMod))]
73-
private static void ActivateOnAddTempMod(PlayableCard __instance, ref CardModificationInfo mod)
73+
private static void ActivateOnAddTempMod(PlayableCard __instance, CardModificationInfo mod)
7474
{
75-
if (mod.HasAbility(Ability.RandomAbility))
75+
if (mod != null && mod.HasAbility(Ability.RandomAbility))
7676
{
7777
for (int i = 0; i < mod.abilities.Count; i++)
7878
{

0 commit comments

Comments
 (0)