Grouped Upgrade Handlers - PrimeSonic/PrimeSonicSubnauticaMods GitHub Wiki

Originally introduced in the 3.0 update and later refined in the 4.0 overhaul, MoreCyclopsUpgrades can now be used as a public API, allowing other mods to integrate their own cyclops upgrade modules and have them be fully compatible with the Auxiliary Upgrade Console.


Grouped Upgrade Handlers

While the standard UpgradeHandler is flexible enough for most cases, sometimes you might want to do something more complex than a single upgrade modules doing one thing. While you can always extend the UpgradeHandler class yourself, there are a couple of UpgradeHandler extending classes that are already provided in MoreCyclopsUpgrades.API.Upgrades that should cover most of the features you might want.

// Make sure you include this in your using statements to gain access to the all these classes.
using MoreCyclopsUpgrades.API.Upgrades;

TieredGroupHandler - For a family of different upgrade modules where only the best one applies

When you should use TieredGroupHandler<T>:

  • You have multiple upgrade modules, each with its own TechType, that affect the same thing on the Cyclops
  • Only the best module applies, even when multiple versions are equipped at the same time
  • Each upgrade module in this family can be compared to others using simple comparable value such as int or float. MoreCyclopsUpgrades already has a TieredGroupHandler in use to handle the depth upgrades.
// The Cyclops Hull Modules provide bonus crush depth as a float value.
var chm = new TieredGroupHandler<float>(0f, cyclops);
chm.OnFinishedUpgrades = () =>
{
    // The HighestValue property of the TieredGroupHandler will return the best value among all installed upgrade modules
    cyclops.gameObject.GetComponent<CrushDamage>().SetExtraCrushDepth(chm.HighestValue);
};
// You'll notice that the TieredGroupHandler constructor doesn't ask for have a TechType
// Instead, the TechType values are provided on the CreateTier calls along with the value associated to that upgrade
TieredUpgradeHandler<float> tier1 = chm.CreateTier(TechType.CyclopsHullModule1, 400f);
TieredUpgradeHandler<float> tier2 = chm.CreateTier(TechType.CyclopsHullModule2, 800f);
TieredUpgradeHandler<float> tier3 = chm.CreateTier(TechType.CyclopsHullModule3, 1200f);
// If you want to apply further 

TieredGroupHandler<T> inherits from UpgradeHandler, so you can treat it almost entirely the same, with all the same upgrade events being available for you to define.

While TieredUpgradeHandler<T> also inherits from UpgradeHandler, these instances will not invoke any upgrade events themselves.
Instead, they will all refer back to their TieredGroupHandler<T>, and it will be this parent handler that will invoke the events.
The value of HighestValue is always updated before these events are invoked.


StackingGroupHandler - For a family of different upgrade modules where they all apply together

When you should use StackingGroupHandler:

  • You have multiple upgrade modules, each with its own TechType, that affect the same thing on the Cyclops
  • The effects of all modules apply, even when multiple versions are equipped at the same time
  • The number of instances of each type of upgrade module makes a difference
  • Each upgrade module in this family is only compared to the others by its TechType This is, admittedly, a bit of an outlier, and isn't normally present in MoreCyclopsUpgrades.
    However, this is example how the modded Cyclops Solar and Thermal Chargers work.

The StackingGroupHandler and its individual StackingUpgradeHandler instances behave very similarly to how the TieredGroupHandler works.
The StackingGroupHandler exposes the method int TierCount(TechType tier), allowing you to track how many copies of each upgrade module were found.


If your upgrade module can't be self-contained and instead you need an external component to check what your highest installed tier is: First, find your upgrade handler and then check the value of its HighestValue property.

This one is a bit odd, so reach out on Discord if you think you will need it and have questions.

⚠️ **GitHub.com Fallback** ⚠️