Skip to content

Commit

Permalink
Allow ValidTiers to override Ultimate Crosspathing
Browse files Browse the repository at this point in the history
  • Loading branch information
doombubbles committed Oct 16, 2023
1 parent 3b967c8 commit f75218b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 deletions.
12 changes: 7 additions & 5 deletions Patches/PreventPatches.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using BTD_Mod_Helper.Extensions;
using HarmonyLib;
using HarmonyLib;
using Il2CppAssets.Scripts.Models.Towers.Upgrades;
using Il2CppAssets.Scripts.Simulation.Input;
using Il2CppAssets.Scripts.Simulation.Objects;
Expand All @@ -25,18 +24,22 @@ private static bool Prefix(TowerSelectionMenu __instance, int path, ref bool __r

var tower = __instance.selectedTower.tower;
var tiers = tower.GetAllTiers();
var towerId = tower.towerModel.baseId;

if (PathPlusPlus.TryGetPath(tower.towerModel.baseId, path, out var pathPlusPlus))
{
tiers[path]++;
__result = !pathPlusPlus.ValidTiers(tiers.ToArray());
return false;
}
else

if (PathsPlusPlusMod.PathsByTower.ContainsKey(towerId))
{
__result = !PathPlusPlus.DefaultValidTiers(tiers.ToArray());
return false;
}

return false;
return true;
}
}

Expand Down Expand Up @@ -188,6 +191,5 @@ internal static class UpgradeDetails_OnPointerExit
[HarmonyPostfix]
private static void Postfix(UpgradeDetails __instance)
{

}
}
31 changes: 15 additions & 16 deletions Patches/UiPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -247,22 +247,25 @@ private static bool Prefix(Tower __instance, int path, ref UpgradeModel? __resul
internal class UpgradeObject_CheckBlockedPath
{
[HarmonyPrefix]
private static bool Prefix(UpgradeObject __instance) => __instance.isActiveAndEnabled;

[HarmonyPostfix]
internal static void Postfix(UpgradeObject __instance, ref int __result)
private static bool Prefix(UpgradeObject __instance, ref int __result)
{
if (!__instance.isActiveAndEnabled) return;
if (!__instance.isActiveAndEnabled) return false;

var tower = __instance.towerSelectionMenu.selectedTower.tower;
var path = __instance.path;
var pathPlusPlus = PathPlusPlus.GetPath(tower.towerModel.baseId, path);
var max = pathPlusPlus?.UpgradeCount ?? 5;

if (!PathsPlusPlusMod.BalancedMode && pathPlusPlus != null)
{
__result = max;
return false;
}

if (!PathsPlusPlusMod.BalancedMode || path < 3 && ModHelper.HasMod("UltimateCrosspathing"))
if (pathPlusPlus == null &&
(!PathsPlusPlusMod.BalancedMode || path < 3 && ModHelper.HasMod("UltimateCrosspathing")))
{
if (pathPlusPlus != null) __result = max;
return;
return true;
}

var tiers = tower.GetAllTiers();
Expand All @@ -274,19 +277,15 @@ internal static void Postfix(UpgradeObject __instance, ref int __result)
tiers[path] = i + 1;
if (pathPlusPlus != null)
{
if (!pathPlusPlus.ValidTiers(tiers.ToArray()))
{
return;
}
if (!pathPlusPlus.ValidTiers(tiers.ToArray())) break;
}
else
{
if (!PathPlusPlus.DefaultValidTiers(tiers.ToArray()))
{
return;
}
if (!PathPlusPlus.DefaultValidTiers(tiers.ToArray())) break;
}
}

return false;
}
}

Expand Down

0 comments on commit f75218b

Please sign in to comment.