Skip to content

Commit

Permalink
Add Upgrade++ confirmation, OnUpgraded overrides
Browse files Browse the repository at this point in the history
  • Loading branch information
doombubbles committed Oct 22, 2023
1 parent f75218b commit 358f3c3
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 19 deletions.
6 changes: 5 additions & 1 deletion LATEST.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
- Fix custom upgrade containers not appearing for tier 5+ upgrades on towers with paragons
- When Paths++ and Paragon upgrades overlap for a tower, you can right click on the upgrade to swap which one is showing
- The "Paragon Overlap Default" setting controls which is the one it starts off as showing, with Paths++ being the default
- The "Paragon Overlap Default" setting controls which is the one it starts off as showing, with Paths++ being the default
- `PathPlusPlus.ValidTiers` can now override Ultimate Crosspathing when Balanced Mode is on, if the modder so desires
- Added `NeedsConfirmation`, `ConfirmationTitle` and `ConfirmationBody` overrides for `UpgradePlusPlus`s that work like they do for `ModUpgrades`s
- Added `PathPlusPlus.OnUpgraded` and `UpgradePlusPlus.OnUpgraded` overrides to perform effects when upgrades are bought
- The `BloonsTD6Mod.OnTowerUpgraded` hook will also be called for your mod's own Paths++ upgrades
4 changes: 1 addition & 3 deletions Patches/GamePatches.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
using System;
using System.Linq;
using BTD_Mod_Helper.Extensions;
using HarmonyLib;
using Il2CppAssets.Scripts;
using Il2CppAssets.Scripts.Models;
using Il2CppAssets.Scripts.Models.Towers;
using Il2CppAssets.Scripts.Models.Towers.Behaviors;
using Il2CppAssets.Scripts.Models.Towers.Upgrades;
using Il2CppAssets.Scripts.Simulation.Towers.Behaviors;
using Il2CppAssets.Scripts.Unity.Bridge;
using Il2CppAssets.Scripts.Unity.UI_New.InGame;
using Il2CppAssets.Scripts.Unity.UI_New.InGame.TowerSelectionMenu;
Expand Down Expand Up @@ -60,7 +58,7 @@ private static bool Prefix(UnityToSimulation __instance, ObjectId id, int pathIn
InGame.instance.SetCash(cash - cost);

// Apply the upgrade
tower.SetTier(pathIndex, current.tier + 1);
tower.SetTier(pathIndex, current.tier + 1, true);

if (action != null)
{
Expand Down
22 changes: 20 additions & 2 deletions PathPlusPlus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using Il2CppAssets.Scripts.Models.Towers;
using Il2CppAssets.Scripts.Models.Towers.Behaviors;
using Il2CppAssets.Scripts.Simulation.Towers;
using Il2CppAssets.Scripts.Simulation.Towers.Behaviors;

namespace PathsPlusPlus;

Expand Down Expand Up @@ -117,6 +116,15 @@ public override void Register()
}
}

/// <summary>
/// Runs in game when one of the Upgrades of this path is first applied to a tower
/// </summary>
/// <param name="tower">The tower receiving the upgrade</param>
/// <param name="tier">The tier of the upgrade</param>
public virtual void OnUpgraded(Tower tower, int tier)
{
}

/// <summary>
/// The Priority given to the PathPlusPlus mutator on the tower
/// </summary>
Expand Down Expand Up @@ -167,10 +175,20 @@ public int GetTier(Tower tower)
/// </summary>
/// <param name="tower">The tower</param>
/// <param name="tier">The new desired tier</param>
public void SetTier(Tower tower, int tier)
/// <param name="onUpgrade">Whether to perform OnUpgrade effects</param>
public void SetTier(Tower tower, int tier, bool onUpgrade = false)
{
tower.RemoveMutatorsById(Id);
tower.AddMutator(new RateSupportModel.RateSupportMutator(true, Id, tier, Priority, null));
if (onUpgrade && Upgrades[tier - 1] is UpgradePlusPlus upgrade)
{
OnUpgraded(tower, tier);
upgrade.OnUpgraded(tower);
if (mod is BloonsTD6Mod btd6Mod)
{
btd6Mod.OnTowerUpgraded(tower, upgrade.Name, tower.rootModel.Cast<TowerModel>());
}
}
}

/// <summary>
Expand Down
13 changes: 6 additions & 7 deletions PathPlusPlusExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Linq;
using BTD_Mod_Helper;
using Il2CppAssets.Scripts.Models.Towers;
using Il2CppAssets.Scripts.Models.Towers.Behaviors;
using Il2CppAssets.Scripts.Simulation.Towers;

namespace PathsPlusPlus;
Expand Down Expand Up @@ -59,34 +58,34 @@ public static List<int> GetAllTiers(this Tower tower) =>

/// <summary>
/// Sets the tier for a given PathPlusPlus pathId to be a particular value.
/// Will handle the mutation of the tower but not any upgrade side effects
/// </summary>
/// <param name="tower">The tower</param>
/// <param name="pathId">The PathPlusPlus id</param>
/// <param name="tier">The new desired tier</param>
public static void SetTier(this Tower tower, string pathId, int tier)
/// <param name="onUpgrade">Whether onUpgrade effects are triggered</param>
public static void SetTier(this Tower tower, string pathId, int tier, bool onUpgrade = false)
{
if (!PathsPlusPlusMod.PathsById.TryGetValue(pathId, out var path))
{
ModHelper.Warning<PathsPlusPlusMod>($"No path found with id {pathId}");
return;
}

path.SetTier(tower, tier);
path.SetTier(tower, tier, onUpgrade);
}

/// <summary>
/// Sets the tier for a given PathPlusPlus number to be a particular value.
/// Will handle the mutation of the tower but not any upgrade side effects
/// </summary>
/// <param name="tower">The tower</param>
/// <param name="path">The PathPlusPlus number</param>
/// <param name="tier">The new desired tier</param>
public static void SetTier(this Tower tower, int path, int tier)
/// <param name="onUpgrade">Whether onUpgrade effects are triggered</param>
public static void SetTier(this Tower tower, int path, int tier, bool onUpgrade = false)
{
if (PathPlusPlus.TryGetPath(tower.towerModel.baseId, path, out var pathPlusPlus))
{
pathPlusPlus.SetTier(tower, tier);
pathPlusPlus.SetTier(tower, tier, onUpgrade);
}
}

Expand Down
53 changes: 47 additions & 6 deletions UpgradePlusPlus.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using System.Collections.Generic;
using System.Linq;
using System.Linq;
using BTD_Mod_Helper.Api;
using BTD_Mod_Helper.Api.Enums;
using BTD_Mod_Helper.Extensions;
using Il2CppAssets.Scripts.Models.Towers;
using Il2CppAssets.Scripts.Models.Towers.Upgrades;
using Il2CppAssets.Scripts.Simulation.Towers;
using Il2CppAssets.Scripts.Unity;
using Il2CppAssets.Scripts.Utils;

Expand Down Expand Up @@ -71,6 +70,21 @@ public abstract class UpgradePlusPlus : NamedModContent
public virtual SpriteReference? ContainerReference =>
string.IsNullOrEmpty(Container) ? null : GetSpriteReferenceOrDefault(Container);

/// <summary>
/// Whether this upgrade requires a confirmation popup
/// </summary>
public virtual bool NeedsConfirmation => false;

/// <summary>
/// The title for the confirmation popup, if needed
/// </summary>
public virtual string? ConfirmationTitle => null;

/// <summary>
/// The body text for the confirmation popup, if needed
/// </summary>
public virtual string? ConfirmationBody => null;

private UpgradeModel? upgradeModel;

/// <summary>
Expand All @@ -82,7 +96,7 @@ public abstract class UpgradePlusPlus : NamedModContent
/// A Diamond version of the Tier 5 Upgrade Container
/// </summary>
protected static string UpgradeContainerDiamond => GetTextureGUID<PathsPlusPlusMod>("UpgradeContainerDiamond");

/// <summary>
/// A Rainbow version of the Tier 5 Upgrade Container
/// </summary>
Expand All @@ -97,13 +111,31 @@ public override void Register()
Game.instance.model.AddUpgrade(GetUpgradeModel());
}

/// <inheritdoc />
public override void RegisterText(Il2CppSystem.Collections.Generic.Dictionary<string, string> textTable)
{
base.RegisterText(textTable);
if (NeedsConfirmation)
{
if (ConfirmationTitle != null)
{
textTable[Id + " Title"] = ConfirmationTitle;
}

if (ConfirmationBody != null)
{
textTable[Id + " Body"] = ConfirmationBody;
}
}
}


/// <summary>
/// Gets or constructs the UpgradeModel for this UpgradePlusPlus
/// </summary>
/// <returns></returns>
public UpgradeModel GetUpgradeModel() =>
upgradeModel ??= new UpgradeModel(Id, Cost, 0, IconReference, Path.Path, Tier - 1, 0, "", "");
public UpgradeModel GetUpgradeModel() => upgradeModel ??= new UpgradeModel(Id, Cost, 0, IconReference, Path.Path,
Tier - 1, 0, NeedsConfirmation ? Id : "", "");

/// <summary>
/// Returns whether this Upgrade is of a higher tier than any other base or PathsPlusPlus upgrade that the tower has
Expand Down Expand Up @@ -133,6 +165,15 @@ public virtual void ApplyUpgrade(TowerModel towerModel)
public virtual void ApplyUpgrade(TowerModel towerModel, int tier)
{
}

/// <summary>
/// Runs in game when this upgrade is applied to a Tower for the first time
/// </summary>
/// <param name="tower">The tower being upgraded</param>
public virtual void OnUpgraded(Tower tower)
{

}
}

/// <inheritdoc />
Expand Down

0 comments on commit 358f3c3

Please sign in to comment.