-
Notifications
You must be signed in to change notification settings - Fork 7
Selectable Chargeable Upgrades
Michael Neises edited this page Oct 24, 2024
·
4 revisions
SelectableChargeable upgrades can be activated by the player after a charging period. The Seamoth Perimeter Defense System is an example.
To implement a SelectableChargeable upgrade, implement the abstract class
VehicleFramework.UpgradeTypes.SelectableChargeableUpgradeThat class implements ModVehicleUpgrade, with one important override:
public override QuickSlotType QuickSlotType => QuickSlotType.SelectableChargeable;Don't change this!
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());
}-
MaxChargedescribes how high the charge for this upgrade can go. Bigger numbers mean bigger possible effects! -
EnergyCostdescribes how much energy the vehicle will spend when the upgrade is activated. -
OnSelectedis 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:
-
chargeis a magnitude up to and including theMaxChargevalue. -
slotChargeis a percentage of the total charge. So this is essentiallychargedivided byMaxCharge.
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);
}