Skip to content

Commit 6c5d2e1

Browse files
authored
Merge pull request #34 from ScottWilson0903/regions
Added regions and encounters
2 parents f282677 + 65a8c38 commit 6c5d2e1

10 files changed

Lines changed: 725 additions & 0 deletions

InscryptionAPI/Card/CardExtensions.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ public static TailParams SetLostTailPortrait(this TailParams info, Texture2D por
115115
return info;
116116
}
117117

118+
/// <summary>
119+
/// Sets the card so it shows up for normal card choices in Act 1.
120+
/// </summary>
118121
public static CardInfo SetDefaultPart1Card(this CardInfo info)
119122
{
120123
if (!info.metaCategories.Contains(CardMetaCategory.Rare))
@@ -126,6 +129,9 @@ public static CardInfo SetDefaultPart1Card(this CardInfo info)
126129
return info;
127130
}
128131

132+
/// <summary>
133+
/// Sets the card so it shows up for normal card choices in Act 3.
134+
/// </summary>
129135
public static CardInfo SetDefaultPart3Card(this CardInfo info)
130136
{
131137
if (!info.metaCategories.Contains(CardMetaCategory.Rare))
@@ -137,6 +143,9 @@ public static CardInfo SetDefaultPart3Card(this CardInfo info)
137143
return info;
138144
}
139145

146+
/// <summary>
147+
/// Sets the card so it shows up for rare card choices and applies the rare background.
148+
/// </summary>
140149
public static CardInfo SetRare(this CardInfo info)
141150
{
142151
info.AddMetaCategories(CardMetaCategory.Rare);
@@ -151,6 +160,9 @@ public static CardInfo SetRare(this CardInfo info)
151160
return info;
152161
}
153162

163+
/// <summary>
164+
/// Adds the terrain trait and background to this card.
165+
/// </summary>
154166
public static CardInfo SetTerrain(this CardInfo info)
155167
{
156168
info.AddTraits(Trait.Terrain);
@@ -267,6 +279,9 @@ public static CardInfo AddSpecialAbilities(this CardInfo info, params SpecialTri
267279
return info;
268280
}
269281

282+
/// <summary>
283+
/// Adds this card to Act 2 packs and collection.
284+
/// </summary>
270285
public static CardInfo SetGBCPlayable(this CardInfo info, CardTemple temple)
271286
{
272287
info.AddMetaCategories(CardMetaCategory.GBCPack, CardMetaCategory.GBCPlayable);

InscryptionAPI/Encounters/BossManager.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,19 @@ public static bool ReplaceGetSequencerId(Opponent.Type bossType, ref string __re
107107
__result = AllOpponents.First(o => o.Id == bossType).SpecialSequencerId;
108108
return false;
109109
}
110+
111+
[HarmonyPatch(typeof(BossBattleNodeData), nameof(BossBattleNodeData.PrefabPath), MethodType.Getter)]
112+
[HarmonyPrefix]
113+
public static bool ReplacePrefabPath(ref string __result, Opponent.Type ___bossType)
114+
{
115+
GameObject obj = ResourceBank.Get<GameObject>("Prefabs/Map/MapNodesPart1/MapNode_" + ___bossType);
116+
if (obj != null)
117+
{
118+
__result = "Prefabs/Map/MapNodesPart1/MapNode_" + ___bossType;
119+
} else
120+
{
121+
__result = "Prefabs/Map/MapNodesPart1/MapNode_ProspectorBoss";
122+
}
123+
return false;
124+
}
110125
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using DiskCardGame;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Text;
5+
6+
namespace InscryptionAPI.Encounters
7+
{
8+
public class EncounterBuilderBlueprintData : EncounterBlueprintData
9+
{
10+
internal RegionData region;
11+
12+
public void SetBasic(string name, RegionData region)
13+
{
14+
this.region = region;
15+
this.name = name;
16+
region.encounters = region.encounters ?? new();
17+
region.encounters.Add(this);
18+
}
19+
}
20+
21+
public static class EncounterBuilder
22+
{
23+
public static RegionData Build(this EncounterBuilderBlueprintData blueprint)
24+
{
25+
return blueprint.region;
26+
}
27+
}
28+
}

InscryptionAPI/Encounters/EncounterExtensions.cs

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
using DiskCardGame;
2+
using InscryptionAPI.Card;
3+
using static DiskCardGame.EncounterBlueprintData;
24

35
namespace InscryptionAPI.Encounters;
46

@@ -27,4 +29,105 @@ public static OpponentManager.FullOpponent SetNewSequencer(this OpponentManager.
2729
opp.SpecialSequencerId = newSequencer.Id;
2830
return opp;
2931
}
32+
33+
/// <summary>
34+
/// Sets the difficulty range of this encounter.<br/>
35+
/// Difficulty is determined by the formula (6 * <c>tier</c>) + <c>battle#</c> + <c>modifier</c>.
36+
/// </summary>
37+
/// <param name="min">The minimum difficulty.</param>
38+
/// <param name="max">The maximum difficulty.</param>
39+
public static T SetDifficulty<T>(this T blueprint, int min, int max) where T : EncounterBlueprintData
40+
{
41+
blueprint.minDifficulty = min;
42+
blueprint.maxDifficulty = max;
43+
return blueprint;
44+
}
45+
46+
/// <summary>
47+
/// Adds dominant tribes to this region.<br/>
48+
/// The dominant tribes list determines the totems for this battle.
49+
/// </summary>
50+
/// <param name="tribes">The tribes to add.</param>
51+
public static T AddDominantTribes<T>(this T blueprint, params Tribe[] tribes) where T : EncounterBlueprintData
52+
{
53+
blueprint.dominantTribes = blueprint.dominantTribes ?? new();
54+
foreach (Tribe tribe in tribes)
55+
{
56+
blueprint.dominantTribes.Add(tribe);
57+
}
58+
return blueprint;
59+
}
60+
61+
[Obsolete("regionSpecific is unused.")]
62+
public static T SetRegionSpecific<T>(this T blueprint, bool enabled) where T : EncounterBlueprintData
63+
{
64+
blueprint.regionSpecific = enabled;
65+
return blueprint;
66+
}
67+
68+
/// <summary>
69+
/// Adds random replacement cards to this region.<br/>
70+
/// A card from this list is selected whenever a card is randomly replaced by <c>randomReplaceChance</c>.
71+
/// </summary>
72+
/// <param name="cards">The cards to add.</param>
73+
public static T AddRandomReplacementCards<T>(this T blueprint, params string[] cards) where T : EncounterBlueprintData
74+
{
75+
blueprint.randomReplacementCards = blueprint.randomReplacementCards ?? new();
76+
foreach (string card in cards)
77+
{
78+
CardInfo cardInfo = CardManager.AllCardsCopy.CardByName(card);
79+
if (!blueprint.randomReplacementCards.Contains(cardInfo))
80+
{
81+
blueprint.randomReplacementCards.Add(cardInfo);
82+
}
83+
}
84+
return blueprint;
85+
}
86+
87+
/// <summary>
88+
/// Adds redundant abilities to this region.<br/>
89+
/// Redundant abilities will not be used on totems for this encounter.
90+
/// </summary>
91+
/// <param name="abilities">The abilities to add.</param>
92+
public static T SetRedundantAbilities<T>(this T blueprint, params Ability[] abilities) where T : EncounterBlueprintData
93+
{
94+
blueprint.redundantAbilities = abilities.ToList();
95+
return blueprint;
96+
}
97+
98+
public static T SetUnlockedCardPrerequisites<T>(this T blueprint, params string[] cards) where T : EncounterBlueprintData
99+
{
100+
blueprint.unlockedCardPrerequisites = blueprint.unlockedCardPrerequisites ?? new();
101+
foreach (string card in cards)
102+
{
103+
CardInfo cardInfo = CardManager.AllCardsCopy.CardByName(card);
104+
if (!blueprint.unlockedCardPrerequisites.Contains(cardInfo))
105+
{
106+
blueprint.unlockedCardPrerequisites.Add(cardInfo);
107+
}
108+
}
109+
return blueprint;
110+
}
111+
112+
public static T AddTurnMods<T>(this T blueprint, params TurnModBlueprint[] turnMods) where T : EncounterBlueprintData
113+
{
114+
blueprint.turnMods = turnMods.ToList();
115+
return blueprint;
116+
}
117+
118+
public static T AddTurn<T>(this T blueprint, params CardBlueprint[] turn) where T : EncounterBlueprintData
119+
{
120+
blueprint.turns.Add(turn.ToList());
121+
return blueprint;
122+
}
123+
124+
/// <summary>
125+
/// Creates a new turn for this encounter and returns the builder.
126+
/// </summary>
127+
public static TurnBuilder<T> CreateTurn<T>(this T blueprint) where T : EncounterBlueprintData
128+
{
129+
TurnBuilder<T> turnBuilder = new();
130+
turnBuilder.SetBlueprint(blueprint);
131+
return turnBuilder;
132+
}
30133
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
using System.Collections.ObjectModel;
2+
using System.Diagnostics.CodeAnalysis;
3+
using DiskCardGame;
4+
using HarmonyLib;
5+
using UnityEngine;
6+
7+
namespace InscryptionAPI.Encounters;
8+
9+
[HarmonyPatch]
10+
public static class EncounterManager
11+
{
12+
public static readonly ReadOnlyCollection<EncounterBlueprintData> BaseGameEncounters = new(Resources.LoadAll<EncounterBlueprintData>("Data"));
13+
private static readonly ObservableCollection<EncounterBlueprintData> NewEncounters = new();
14+
15+
public static event Func<List<EncounterBlueprintData>, List<EncounterBlueprintData>> ModifyEncountersList;
16+
17+
internal static void SyncEncounterList()
18+
{
19+
var encounters = BaseGameEncounters.Concat(NewEncounters).Select(x => (EncounterBlueprintData)UnityEngine.Object.Internal_CloneSingle(x)).ToList();
20+
//var encounters = BaseGameEncounters.Concat(NewEncounters).ToList();
21+
AllEncountersCopy = ModifyEncountersList?.Invoke(encounters) ?? encounters;
22+
}
23+
24+
static EncounterManager()
25+
{
26+
InscryptionAPIPlugin.ScriptableObjectLoaderLoad += static type =>
27+
{
28+
if (type == typeof(EncounterBlueprintData))
29+
{
30+
ScriptableObjectLoader<EncounterBlueprintData>.allData = AllEncountersCopy;
31+
}
32+
};
33+
NewEncounters.CollectionChanged += static (_, _) =>
34+
{
35+
SyncEncounterList();
36+
};
37+
}
38+
39+
public static List<EncounterBlueprintData> AllEncountersCopy { get; private set; } = BaseGameEncounters.ToList();
40+
41+
public static void Add(EncounterBlueprintData newEncounter) { if (!NewEncounters.Contains(newEncounter)) NewEncounters.Add(newEncounter); }
42+
public static void Remove(EncounterBlueprintData encounter) => NewEncounters.Remove(encounter);
43+
44+
public static EncounterBlueprintData New(string name, bool addToPool = true)
45+
{
46+
EncounterBlueprintData retval = ScriptableObject.CreateInstance<EncounterBlueprintData>();
47+
retval.name = name;
48+
49+
if (addToPool)
50+
Add(retval);
51+
52+
return retval;
53+
}
54+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
using DiskCardGame;
2+
using InscryptionAPI.Card;
3+
using static DiskCardGame.EncounterBlueprintData;
4+
5+
namespace InscryptionAPI.Encounters
6+
{
7+
public class TurnBuilder<T> where T : EncounterBlueprintData
8+
{
9+
internal T blueprint;
10+
internal List<CardBlueprint> cards;
11+
12+
public TurnBuilder()
13+
{
14+
cards = new();
15+
}
16+
17+
public void SetBlueprint(T blueprint)
18+
{
19+
this.blueprint = blueprint;
20+
blueprint.turns = blueprint.turns ?? new();
21+
blueprint.turns.Add(cards);
22+
}
23+
24+
}
25+
26+
public static class TurnExtensions
27+
{
28+
/// <summary>
29+
/// Adds a card blueprint to this turn.
30+
/// </summary>
31+
/// <param name="card">The default card. Can be null for no card.</param>
32+
/// <param name="randomReplaceChance">The integer probability of this card getting replaced by a card from the encounter's <c>randomReplacementCards</c></param>
33+
/// <param name="minDifficulty">The minimum difficulty for this card to appear.</param>
34+
/// <param name="maxDifficulty">The maximum difficulty for this card to appear.</param>
35+
/// <param name="difficultyReplace">Whether to replace this card when a certain difficulty threshold is met.</param>
36+
/// <param name="difficultyReplaceReq">The difficulty threshold for the <c>replacement</c> card to be used instead.</param>
37+
/// <param name="replacement">The replacement card for the difficulty replacement.</param>
38+
public static TurnBuilder<T> AddCardBlueprint<T>(this TurnBuilder<T> turnBuilder, string card, int randomReplaceChance = 0,
39+
int minDifficulty = 1, int maxDifficulty = 20,
40+
bool difficultyReplace = false, int difficultyReplaceReq = 0, string replacement = null)
41+
where T : EncounterBlueprintData
42+
{
43+
turnBuilder.cards.Add(new CardBlueprint()
44+
{
45+
card = CardManager.AllCardsCopy.CardByName(card),
46+
randomReplaceChance = randomReplaceChance,
47+
minDifficulty = minDifficulty,
48+
maxDifficulty = maxDifficulty,
49+
difficultyReplace = difficultyReplace,
50+
difficultyReq = difficultyReplaceReq,
51+
replacement = CardManager.AllCardsCopy.CardByName(card)
52+
});
53+
return turnBuilder;
54+
}
55+
56+
public static T Build<T>(this TurnBuilder<T> turnBuilder) where T : EncounterBlueprintData
57+
{
58+
return turnBuilder.blueprint;
59+
}
60+
}
61+
}

InscryptionAPI/InscryptionAPI.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<IsPackable>false</IsPackable>
88
<LangVersion>latest</LangVersion>
99
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
10+
<DebugType>full</DebugType>
1011
</PropertyGroup>
1112

1213
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using DiskCardGame;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Text;
5+
6+
namespace InscryptionAPI.Regions
7+
{
8+
public class Part1RegionData
9+
{
10+
private int tier;
11+
private RegionData region;
12+
13+
public int Tier { get => tier; private set => tier = value; }
14+
public RegionData Region { get => region; private set => region = value; }
15+
16+
public Part1RegionData (RegionData region, int tier)
17+
{
18+
this.region = region;
19+
this.tier = tier;
20+
}
21+
}
22+
}

0 commit comments

Comments
 (0)