From 358f3c391bf8b40951a44987e5865e9bb6909ae0 Mon Sep 17 00:00:00 2001 From: doombubbles Date: Sun, 22 Oct 2023 11:28:25 -0700 Subject: [PATCH] Add Upgrade++ confirmation, OnUpgraded overrides --- LATEST.md | 6 ++++- Patches/GamePatches.cs | 4 +-- PathPlusPlus.cs | 22 ++++++++++++++-- PathPlusPlusExtensions.cs | 13 +++++----- UpgradePlusPlus.cs | 53 ++++++++++++++++++++++++++++++++++----- 5 files changed, 79 insertions(+), 19 deletions(-) diff --git a/LATEST.md b/LATEST.md index f74d71a..ebe2164 100644 --- a/LATEST.md +++ b/LATEST.md @@ -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 \ No newline at end of file + - 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 \ No newline at end of file diff --git a/Patches/GamePatches.cs b/Patches/GamePatches.cs index f69073c..ee5c3c2 100644 --- a/Patches/GamePatches.cs +++ b/Patches/GamePatches.cs @@ -1,5 +1,4 @@ using System; -using System.Linq; using BTD_Mod_Helper.Extensions; using HarmonyLib; using Il2CppAssets.Scripts; @@ -7,7 +6,6 @@ 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; @@ -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) { diff --git a/PathPlusPlus.cs b/PathPlusPlus.cs index 9bc5c9d..c007eb1 100644 --- a/PathPlusPlus.cs +++ b/PathPlusPlus.cs @@ -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; @@ -117,6 +116,15 @@ public override void Register() } } + /// + /// Runs in game when one of the Upgrades of this path is first applied to a tower + /// + /// The tower receiving the upgrade + /// The tier of the upgrade + public virtual void OnUpgraded(Tower tower, int tier) + { + } + /// /// The Priority given to the PathPlusPlus mutator on the tower /// @@ -167,10 +175,20 @@ public int GetTier(Tower tower) /// /// The tower /// The new desired tier - public void SetTier(Tower tower, int tier) + /// Whether to perform OnUpgrade effects + 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()); + } + } } /// diff --git a/PathPlusPlusExtensions.cs b/PathPlusPlusExtensions.cs index f0e7e72..81755a0 100644 --- a/PathPlusPlusExtensions.cs +++ b/PathPlusPlusExtensions.cs @@ -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; @@ -59,12 +58,12 @@ public static List GetAllTiers(this Tower tower) => /// /// 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 /// /// The tower /// The PathPlusPlus id /// The new desired tier - public static void SetTier(this Tower tower, string pathId, int tier) + /// Whether onUpgrade effects are triggered + public static void SetTier(this Tower tower, string pathId, int tier, bool onUpgrade = false) { if (!PathsPlusPlusMod.PathsById.TryGetValue(pathId, out var path)) { @@ -72,21 +71,21 @@ public static void SetTier(this Tower tower, string pathId, int tier) return; } - path.SetTier(tower, tier); + path.SetTier(tower, tier, onUpgrade); } /// /// 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 /// /// The tower /// The PathPlusPlus number /// The new desired tier - public static void SetTier(this Tower tower, int path, int tier) + /// Whether onUpgrade effects are triggered + 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); } } diff --git a/UpgradePlusPlus.cs b/UpgradePlusPlus.cs index 9565fca..cb6d9fe 100644 --- a/UpgradePlusPlus.cs +++ b/UpgradePlusPlus.cs @@ -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; @@ -71,6 +70,21 @@ public abstract class UpgradePlusPlus : NamedModContent public virtual SpriteReference? ContainerReference => string.IsNullOrEmpty(Container) ? null : GetSpriteReferenceOrDefault(Container); + /// + /// Whether this upgrade requires a confirmation popup + /// + public virtual bool NeedsConfirmation => false; + + /// + /// The title for the confirmation popup, if needed + /// + public virtual string? ConfirmationTitle => null; + + /// + /// The body text for the confirmation popup, if needed + /// + public virtual string? ConfirmationBody => null; + private UpgradeModel? upgradeModel; /// @@ -82,7 +96,7 @@ public abstract class UpgradePlusPlus : NamedModContent /// A Diamond version of the Tier 5 Upgrade Container /// protected static string UpgradeContainerDiamond => GetTextureGUID("UpgradeContainerDiamond"); - + /// /// A Rainbow version of the Tier 5 Upgrade Container /// @@ -97,13 +111,31 @@ public override void Register() Game.instance.model.AddUpgrade(GetUpgradeModel()); } + /// + public override void RegisterText(Il2CppSystem.Collections.Generic.Dictionary textTable) + { + base.RegisterText(textTable); + if (NeedsConfirmation) + { + if (ConfirmationTitle != null) + { + textTable[Id + " Title"] = ConfirmationTitle; + } + + if (ConfirmationBody != null) + { + textTable[Id + " Body"] = ConfirmationBody; + } + } + } + /// /// Gets or constructs the UpgradeModel for this UpgradePlusPlus /// /// - 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 : "", ""); /// /// Returns whether this Upgrade is of a higher tier than any other base or PathsPlusPlus upgrade that the tower has @@ -133,6 +165,15 @@ public virtual void ApplyUpgrade(TowerModel towerModel) public virtual void ApplyUpgrade(TowerModel towerModel, int tier) { } + + /// + /// Runs in game when this upgrade is applied to a Tower for the first time + /// + /// The tower being upgraded + public virtual void OnUpgraded(Tower tower) + { + + } } ///