Skip to content

Commit 564620f

Browse files
add support for custom exhaust deck sequences during custom opponent fights
1 parent 8502d90 commit 564620f

2 files changed

Lines changed: 73 additions & 50 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using DiskCardGame;
2+
using System.Collections;
3+
4+
namespace InscryptionAPI.Encounters;
5+
6+
/// <summary>
7+
/// An Opponent interface that implements custom logic when the player has exhausted both of their draw piles.
8+
/// </summary>
9+
public interface ICustomExhaustSequence
10+
{
11+
public bool RespondsToCustomExhaustSequence(CardDrawPiles drawPiles);
12+
/// <summary>
13+
/// Executes the sequence that plays when the player exhausts their draw piles.
14+
/// </summary>
15+
/// <param name="drawPiles">The CardDrawPiles instance for this scene.</param>
16+
/// <returns>An enumeration of Unity events.</returns>
17+
public IEnumerator DoCustomExhaustSequence(CardDrawPiles drawPiles);
18+
}

InscryptionAPI/Encounters/OpponentManager.cs

Lines changed: 55 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using InscryptionAPI.Guid;
44
using InscryptionAPI.Masks;
55
using InscryptionAPI.Saves;
6+
using System.Collections;
67
using System.Collections.ObjectModel;
78
using System.Reflection;
89
using System.Reflection.Emit;
@@ -89,10 +90,49 @@ public static FullOpponent Add(string guid, string opponentName, string sequence
8990
NewOpponents.Add(opp);
9091
return opp;
9192
}
93+
public static List<Opponent.Type> RunStateOpponents
94+
{
95+
get
96+
{
97+
List<Opponent.Type> previousBosses = new List<Opponent.Type>();
98+
99+
string value = ModdedSaveManager.RunState.GetValue(InscryptionAPIPlugin.ModGUID, "PreviousBosses"); // 2,0,1
100+
if (value == null)
101+
{
102+
// Do nothing
103+
}
104+
else if (!value.Contains(','))
105+
{
106+
// Single boss encounter
107+
previousBosses.Add((Opponent.Type)int.Parse(value));
108+
}
109+
else
110+
{
111+
// Multiple boss encounters
112+
IEnumerable<Opponent.Type> ids = value.Split(',').Select(static (a) => (Opponent.Type)int.Parse(a));
113+
previousBosses.AddRange(ids);
114+
}
115+
116+
return previousBosses;
117+
}
118+
set
119+
{
120+
string result = ""; // 2,0,1
121+
for (int i = 0; i < value.Count; i++)
122+
{
123+
if (i > 0)
124+
{
125+
result += ",";
126+
}
127+
result += (int)value[i];
128+
129+
}
130+
ModdedSaveManager.RunState.SetValue(InscryptionAPIPlugin.ModGUID, "PreviousBosses", result);
131+
}
132+
}
92133

93134
#region Patches
94-
[HarmonyPatch(typeof(Opponent), nameof(Opponent.SpawnOpponent))]
95-
[HarmonyPrefix]
135+
[HarmonyPrefix, HarmonyPatch(typeof(Opponent), nameof(Opponent.SpawnOpponent))]
96136
private static bool ReplaceSpawnOpponent(EncounterData encounterData, ref Opponent __result)
97137
{
98138
if (encounterData.opponentType == Opponent.Type.Default || !ProgressionData.LearnedMechanic(MechanicsConcept.OpponentQueue))
@@ -124,27 +164,19 @@ private static bool ReplaceSpawnOpponent(EncounterData encounterData, ref Oppone
124164
[MethodImpl(MethodImplOptions.NoInlining)]
125165
public static string OriginalGetSequencerIdForBoss(Opponent.Type bossType) { throw new NotImplementedException(); }
126166

127-
[HarmonyPatch(typeof(BossBattleSequencer), nameof(BossBattleSequencer.GetSequencerIdForBoss))]
128-
[HarmonyPrefix]
167+
[HarmonyPrefix, HarmonyPatch(typeof(BossBattleSequencer), nameof(BossBattleSequencer.GetSequencerIdForBoss))]
129168
private static bool ReplaceGetSequencerId(Opponent.Type bossType, ref string __result)
130169
{
131170
__result = AllOpponents.First(o => o.Id == bossType).SpecialSequencerId;
132171
return false;
133172
}
134173

135-
[HarmonyPatch(typeof(BossBattleNodeData), nameof(BossBattleNodeData.PrefabPath), MethodType.Getter)]
136-
[HarmonyPrefix]
174+
[HarmonyPrefix, HarmonyPatch(typeof(BossBattleNodeData), nameof(BossBattleNodeData.PrefabPath), MethodType.Getter)]
137175
private static bool ReplacePrefabPath(ref string __result, Opponent.Type ___bossType)
138176
{
139-
GameObject obj = ResourceBank.Get<GameObject>("Prefabs/Map/MapNodesPart1/MapNode_" + ___bossType);
140-
if (obj != null)
141-
{
142-
__result = "Prefabs/Map/MapNodesPart1/MapNode_" + ___bossType;
143-
}
144-
else
145-
{
146-
__result = "Prefabs/Map/MapNodesPart1/MapNode_ProspectorBoss";
147-
}
177+
string fullPath = "Prefabs/Map/MapNodesPart1/MapNode_" + ___bossType;
178+
GameObject obj = ResourceBank.Get<GameObject>(fullPath);
179+
__result = obj != null ? fullPath : "Prefabs/Map/MapNodesPart1/MapNode_ProspectorBoss";
148180
return false;
149181
}
150182

@@ -220,47 +252,20 @@ public static void ProcessBossType(NodeData nodeData)
220252
}
221253
}
222254

223-
public static List<Opponent.Type> RunStateOpponents
255+
[HarmonyPostfix, HarmonyPatch(typeof(CardDrawPiles), nameof(CardDrawPiles.ExhaustedSequence))]
256+
private static IEnumerator CustomBossExhaustionSequence(IEnumerator enumerator, CardDrawPiles __instance)
224257
{
225-
get
258+
if (TurnManager.Instance.Opponent is ICustomExhaustSequence exhaustSeq && exhaustSeq != null && exhaustSeq.RespondsToCustomExhaustSequence(__instance))
226259
{
227-
List<Opponent.Type> previousBosses = new List<Opponent.Type>();
228-
229-
string value = ModdedSaveManager.RunState.GetValue(InscryptionAPIPlugin.ModGUID, "PreviousBosses"); // 2,0,1
230-
if (value == null)
231-
{
232-
// Do nothing
233-
}
234-
else if (!value.Contains(','))
235-
{
236-
// Single boss encounter
237-
previousBosses.Add((Opponent.Type)int.Parse(value));
238-
}
239-
else
240-
{
241-
// Multiple boss encounters
242-
IEnumerable<Opponent.Type> ids = value.Split(',').Select(static (a) => (Opponent.Type)int.Parse(a));
243-
previousBosses.AddRange(ids);
244-
}
245-
246-
return previousBosses;
260+
Singleton<ViewManager>.Instance.SwitchToView(View.CardPiles, immediate: false, lockAfter: true);
261+
yield return new WaitForSeconds(1f);
262+
yield return exhaustSeq.DoCustomExhaustSequence(__instance);
247263
}
248-
set
264+
else
249265
{
250-
string result = ""; // 2,0,1
251-
for (int i = 0; i < value.Count; i++)
252-
{
253-
if (i > 0)
254-
{
255-
result += ",";
256-
}
257-
result += (int)value[i];
258-
259-
}
260-
ModdedSaveManager.RunState.SetValue(InscryptionAPIPlugin.ModGUID, "PreviousBosses", result);
266+
yield return enumerator;
261267
}
262268
}
263-
264269
#endregion
265270

266271
#region Optimization Patches

0 commit comments

Comments
 (0)