Skip to content

Commit 41176fa

Browse files
adjustments to RegionManager
1 parent b095744 commit 41176fa

File tree

4 files changed

+41
-20
lines changed

4 files changed

+41
-20
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# 2.23.3
22
- 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)
35

46
# 2.23.2
57
- Fixed error when trying to create cards that evolve/transform in 4 or more turns

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)

0 commit comments

Comments
 (0)