Selectable Upgrades - NeisesMike/VehicleFramework GitHub Wiki

Selectable upgrades can be activated by the player. Torpedo upgrades are an example.

Overview

To implement a Selectable upgrade, implement the abstract class

VehicleFramework.UpgradeTypes.SelectableUpgrade

That class implements ModVehicleUpgrade, with one important override:

public override QuickSlotType QuickSlotType => QuickSlotType.Selectable;

Don't change this!

Virtual Fields

The Selectable upgrade has only a few new fields over ModVehicleUpgrade:

public virtual float Cooldown => 0;
public virtual float EnergyCost => 0;
public virtual void OnSelected(SelectableActionParams param)
{
    Logger.Log("Selecting " + ClassId + " on ModVehicle: " + param.vehicle.subName.name + " in slotID: " + param.slotID.ToString());
}
  • Cooldown is a length of time in seconds. Once the upgrade is activated, it cannot again be activated for Cooldown seconds.
  • EnergyCost is how much energy the vehicle will spend when the upgrade is activated.
  • OnSelected is invoked when the player invokes the upgrade.

Here is the definition of the SelectableActionParams struct:

public struct SelectableActionParams
{
    public Vehicle vehicle;
    public int slotID;
    public TechType techType;
}

It's a lot like AddActionParams, so look at the ModVehicleUpgrade guide to understand more.

Here is an example from the Ion Defense Capacitor Module:

public override void OnSelected(SelectableActionParams param)
{
    FMODUWE.PlayOneShot("event:/tools/gravcannon/repulse", param.vehicle.transform.position, 1f);
    IEnumerator manageInvincibility(Vehicle thisVehicle)
    {
        thisVehicle.GetComponent<LiveMixin>().invincible = true;
        yield return new WaitForSeconds(invincibilityDuration);
        thisVehicle.GetComponent<LiveMixin>().invincible = false;
    }
    Player.main.StartCoroutine(manageInvincibility(param.vehicle));
}
⚠️ **GitHub.com Fallback** ⚠️