Selectable Chargeable Upgrades - NeisesMike/VehicleFramework GitHub Wiki

SelectableChargeable upgrades can be activated by the player after a charging period. The Seamoth Perimeter Defense System is an example.

Overview

To implement a SelectableChargeable upgrade, implement the abstract class

VehicleFramework.UpgradeTypes.SelectableChargeableUpgrade

That class implements ModVehicleUpgrade, with one important override:

public override QuickSlotType QuickSlotType => QuickSlotType.SelectableChargeable;

Don't change this!

Virtual Fields

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

public virtual float MaxCharge => 0;
public virtual float EnergyCost => 0;
public virtual void OnSelected(SelectableChargeableActionParams param)
{
    Logger.Log("Selecting-Charging " + ClassId + " on ModVehicle: " + param.vehicle.subName.name + " in slotID: " + param.slotID.ToString());
}
  • MaxCharge describes how high the charge for this upgrade can go. Bigger numbers mean bigger possible effects!
  • EnergyCost describes how much energy the vehicle will spend when the upgrade is activated.
  • OnSelected is invoked when the player finishes charging the upgrade or releases activation before charging is finished.

Here is the definition of the SelectableActionParams struct:

public struct SelectableChargeableActionParams
{
    public Vehicle vehicle;
    public int slotID;
    public TechType techType;
    public float charge;
    public float slotCharge;
}

The charge and slotCharge names are weird, but they follow the Subnautica naming convention. They beg for explanation:

  • charge is a magnitude up to and including the MaxCharge value.
  • slotCharge is a percentage of the total charge. So this is essentially charge divided by MaxCharge.

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

Here is an example from the Impulse Speed Booster Module:

public override void OnSelected(SelectableChargeableActionParams param)
{
    FMODUWE.PlayOneShot("event:/sub/seamoth/pulse", param.vehicle.transform.position, param.slotCharge);
    param.vehicle.useRigidbody.AddForce(param.vehicle.transform.forward * param.charge * param.vehicle.useRigidbody.mass * 3, ForceMode.Impulse);
}