Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
7 changes: 5 additions & 2 deletions InscryptionAPI/Encounters/OpponentManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@
CodeInstruction codeInstruction = codes[i];
if (codeInstruction.opcode == OpCodes.Stfld)
{
if (codeInstruction.operand == bossTypeField)

Check warning on line 226 in InscryptionAPI/Encounters/OpponentManager.cs

View workflow job for this annotation

GitHub Actions / build

Possible unintended reference comparison; to get a value comparison, cast the left hand side to type 'FieldInfo'
{
codes.Insert(++i, new CodeInstruction(OpCodes.Ldloc_0));
codes.Insert(++i, new CodeInstruction(OpCodes.Call, ProcessMethodInfo));
Expand Down Expand Up @@ -255,11 +255,14 @@
[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<ViewManager>.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
{
Expand Down Expand Up @@ -329,7 +332,7 @@

for (int i = 0; i < codes.Count; i++)
{
if (codes[i].opcode == OpCodes.Ldstr && codes[i].operand == "knives_table_exit")

Check warning on line 335 in InscryptionAPI/Encounters/OpponentManager.cs

View workflow job for this annotation

GitHub Actions / build

Possible unintended reference comparison; to get a value comparison, cast the left hand side to type 'string'
{

// ldstr "knives_table_exit"
Expand Down
2 changes: 1 addition & 1 deletion InscryptionAPI/InscryptionAPI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<DebugType>full</DebugType>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<Version>2.23.2</Version>
<Version>2.23.3</Version>
</PropertyGroup>

<PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion InscryptionAPI/InscryptionAPIPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "";

Expand Down
2 changes: 2 additions & 0 deletions InscryptionAPI/Regions/Part1RegionData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -34,6 +35,7 @@ public Part1RegionData(RegionData region, int tier)
AllowTerrainOnPlayerSide = true;
RemoveDefaultReachTerrain = false;
DoNotForceReachTerrain = false;
CanAppearRandomly = true;
this.region = region;
this.tier = tier;
}
Expand Down
23 changes: 23 additions & 0 deletions InscryptionAPI/Regions/RegionExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using APIPlugin;
using DiskCardGame;
using InscryptionAPI.Card;
using InscryptionAPI.Encounters;
Expand All @@ -8,6 +9,23 @@ namespace InscryptionAPI.Regions;

public static class RegionExtensions
{
/// <summary>
/// If the created region will be added to the pool of regions that can appear in a run.
/// </summary>
/// <param name="data">The RegionData for the region we are modifying.</param>
/// <param name="canAppear">If the created region will be added to the pool of regions that can appear in a run.</param>
/// <returns>The same RegionData so a chain can continue.</returns>
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<RegionData> regions, string name) => regions.FirstOrDefault(x => x.name == name);

public static RegionData SetName(this RegionData region, string name)
Expand Down Expand Up @@ -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;
Expand Down
34 changes: 14 additions & 20 deletions InscryptionAPI/Regions/RegionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ private static List<RegionData> ReorderBaseRegions()

return orderedRegions;
}

private static List<Part1RegionData> GenerateBasePart1RegionData() {
List<RegionData> data = ReorderBaseRegions();
return data.Select(x => new Part1RegionData(x, 0)).ToList();
}

public static readonly ObservableCollection<Part1RegionData> NewRegions = new();

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

if (addToPool)
Add(retval, tier);
Add(retval, tier);
if (!addToPool) {
retval.SetCanAppearRandomly(false);
}


return retval;
}
Expand Down Expand Up @@ -355,38 +364,23 @@ private static bool MapDataReader_SpawnAndPlaceElement(ref MapDataReader __insta
return false;
}

private static List<RegionData> GetAllRegionsForMapGeneration()
{
private static List<RegionData> GetAllRegionsForMapGeneration() {
List<RegionData> 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;
}

[HarmonyPrefix]
[HarmonyPatch(typeof(AscensionSaveData), "RollCurrentRunRegionOrder")]
private static bool RollCurrentRunRegionOrder(AscensionSaveData __instance)
{
// Get all regions to choose from
List<RegionData> allRegions = GetAllRegionsForMapGeneration();
allRegions = allRegions.Randomize().ToList();

List<RegionData> selectedRegions = new();
List<Opponent.Type> 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)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using DiskCardGame;
using HarmonyLib;
using InscryptionAPI.Card;
using System.Collections;
using UnityEngine;

Expand All @@ -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<BoardManager>.Instance.PlayerSlotsCopy.FindAll(
x => x.Card != null && x.Card.Info.HasTrait(Trait.Gem)).Count;
Singleton<ViewManager>.Instance.SwitchToView(SaveManager.SaveFile.IsMagnificus ? View.WizardBattleSlots : View.Default);
yield return new WaitForSeconds(0.1f);

int numGems = Singleton<BoardManager>.Instance.PlayerSlotsCopy.Count(x => x.Card != null && x.Card.HasTrait(Trait.Gem));

if (numGems == 0)
{
Expand All @@ -29,18 +32,16 @@ private static IEnumerator BetterGemsDraw(GemsDraw __instance)
yield return new WaitForSeconds(0.45f);
yield break;
}

Singleton<ViewManager>.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<CardDrawPiles>.Instance.DrawCardFromDeck();
else
{
if (Singleton<CardDrawPiles3D>.Instance != null && Singleton<CardDrawPiles3D>.Instance.Pile != null) {
Singleton<CardDrawPiles3D>.Instance.Pile.Draw();
yield return Singleton<CardDrawPiles3D>.Instance.DrawCardFromDeck();
}
else
yield return Singleton<CardDrawPiles>.Instance.DrawCardFromDeck();

}
yield return __instance.LearnAbility(0.5f);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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))
Expand All @@ -62,17 +62,17 @@ 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))
yield return AddRandomSigil(__instance);
}

[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++)
{
Expand Down
Loading