Skip to content

Commit

Permalink
EliteAPI change (#308)
Browse files Browse the repository at this point in the history
* - adding to the custom elite tier array now by default insert based on the cost multiplier of the elite tier.
- expose the elite tiers array before any changes are made to it for modder that want to change the vanilla elite tiers.

* remove outdated comment and remove breakline

Co-authored-by: Tristan McPherson <shredder8910@gmail.com>
  • Loading branch information
xiaoxiao921 and tristanmcpherson authored Oct 25, 2021
1 parent dc947ef commit 5722b23
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions R2API/EliteAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@ public static bool Add(CustomElite? elite) {

#region Combat Director Modifications

private static CombatDirector.EliteTierDef[] RetrieveVanillaEliteTiers() {
LazyInitVanillaEliteTiers();

return CombatDirector.eliteTiers;
}

private static CombatDirector.EliteTierDef RetrieveFirstVanillaTierDef() {
LazyInitVanillaEliteTiers();

Expand All @@ -159,6 +165,7 @@ private static CombatDirector.EliteTierDef RetrieveVanillaEliteOnlyFirstTierDef(
return CombatDirector.eliteTiers[2];
}

public static CombatDirector.EliteTierDef[] VanillaEliteTiers { get; private set; } = RetrieveVanillaEliteTiers();
public static CombatDirector.EliteTierDef VanillaFirstTierDef { get; private set; } = RetrieveFirstVanillaTierDef();
public static CombatDirector.EliteTierDef VanillaEliteOnlyFirstTierDef { get; private set; } = RetrieveVanillaEliteOnlyFirstTierDef();

Expand Down Expand Up @@ -187,22 +194,34 @@ public static void OverrideCombatDirectorEliteTiers(CombatDirector.EliteTierDef?
/// When adding a new elite tier,
/// do not fill the eliteTypes field with your custom elites defs if your goal is to add your custom elite in it right after.
/// Because when doing EliteAPI.Add, the API will add your elite to the specified tiers <see cref="CustomElite.EliteTierDefs"/>.
/// Note that if your eliteTierDef has a cheaper cost than let's say the highest vanilla tier,
/// you'll have to use the indexToInsertAt parameter to put it before the tier in array
/// </summary>
/// <param name="eliteTierDef">The new elite tier to add.</param>
public static int AddCustomEliteTier(CombatDirector.EliteTierDef? eliteTierDef) {
public static int AppendCustomEliteTier(CombatDirector.EliteTierDef? eliteTierDef) {
return AddCustomEliteTier(eliteTierDef, -1);
}

/// <summary>
/// Allows for adding a new elite tier def to the combat director.
/// Automatically insert the eliteTierDef at the correct position in the array based on its <see cref="CombatDirector.EliteTierDef.costMultiplier"/>
/// When adding a new elite tier, do not fill the eliteTypes field with your custom elites defs if your goal is to add your custom elite in it right after.
/// Because when doing EliteAPI.Add, the API will add your elite to the specified tiers <see cref="CustomElite.EliteTierDefs"/>.
/// </summary>
/// <param name="eliteTierDef">The new elite tier to add.</param>
public static int AddCustomEliteTier(CombatDirector.EliteTierDef? eliteTierDef) {
var indexToInsertAt = Array.FindIndex(CombatDirector.eliteTiers, x => x.costMultiplier >= eliteTierDef.costMultiplier);
if (indexToInsertAt >= 0) {
return AddCustomEliteTier(eliteTierDef, indexToInsertAt);
}
else {
return AppendCustomEliteTier(eliteTierDef);
}
}

// todo : maybe sort the CombatDirector.eliteTiers array based on cost ? the game code isnt the cleanest about this
/// <summary>
/// Allows for adding a new elite tier def to the combat director.
/// When adding a new elite tier,
/// do not fill the eliteTypes field with your custom elites defs if your goal is to add your custom elite in it right after.
/// When adding a new elite tier, do not fill the eliteTypes field with your custom elites defs if your goal is to add your custom elite in it right after.
/// Because when doing EliteAPI.Add, the API will add your elite to the specified tiers <see cref="CustomElite.EliteTierDefs"/>.
/// Note that if your eliteTierDef has a cheaper cost than let's say the highest vanilla tier,
/// you'll have to use the indexToInsertAt parameter to put it before the tier in the final array
/// </summary>
/// <param name="eliteTierDef">The new elite tier to add.</param>
/// <param name="indexToInsertAt">Optional index to specify if you want to insert a cheaper elite tier</param>
Expand Down

0 comments on commit 5722b23

Please sign in to comment.