Skip to content

Commit

Permalink
fix: Vehicle upgrades not working for the Seamoth (#492)
Browse files Browse the repository at this point in the history
* Fixed EquipmentType.VehicleUpgrade not getting called for seamoths

* Fixed upgrade module docs having incorrect code

* Better comparison for floats

Equality checks are very hard to meet for floats due to their precision points, therefore, approximation is always the better approach for comparing two floats.
  • Loading branch information
Metious committed Oct 25, 2023
1 parent e992abe commit 6bd3362
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
14 changes: 8 additions & 6 deletions Nautilus/Documentation/tutorials/vehicle-module.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ And finally, let's make the part that interest us: Adding the Upgrade Module Gad

```csharp
// This first function defines the equipment type and the quick slot type.
prefab.SetUpgradeModule(EquipmentType.SeamothModule, QuickSlotType.Passive)
prefab.SetVehicleUpgradeModule(EquipmentType.SeamothModule, QuickSlotType.Passive)
.WithDepthUpgrade(1700f, true) // 1700 is the depth in meters. The boolean after defines if we want the value to be absolute or "relative", added to the default depth.
// If it is on false, it will set the new crush depth to 1900 meters because the default depth of the Seamoth is 200 meters.
// Otherwise, it will set the new crush depth on 1700 meters.
Expand All @@ -92,11 +92,13 @@ prefab.SetUpgradeModule(EquipmentType.SeamothModule, QuickSlotType.Passive)
Admitting we've already done the prefab info and the custom prefab, let's directly work only with the upgrade module gadget.

```csharp
var maxcharge = 50f;
var maxCharge = 50f;
var cooldown = 10f;
prefab.SetUpgradeModule(EquipmentType.VehicleModule, QuickSlotType.SelectableChargeable)
.WithMaxCharge(maxcharge)
var energyCost = 6.9f;
prefab.SetVehicleUpgradeModule(EquipmentType.VehicleModule, QuickSlotType.SelectableChargeable)
.WithMaxCharge(maxCharge)
.WithCooldown(cooldown)
.WithEnergyCost(energyCost)
.WithOnModuleAdded((Vehicle inst, int slotId) =>
{
Subtitles.Add("Self-destruct module installed. The module needs to be charged fully to detonate.");
Expand All @@ -107,7 +109,7 @@ prefab.SetUpgradeModule(EquipmentType.VehicleModule, QuickSlotType.SelectableCha
})
.WithOnModuleUsed((Vehicle inst, int slotID, float charge, float chargeScalar) =>
{
if(charge != maxCharge)
if (charge < maxCharge)
{
Subtitles.Add("Self-destruction sequence disengaged.")
return;
Expand Down Expand Up @@ -136,7 +138,7 @@ static IEnumerator EngageSelfDestruct(Vehicle instance, float countdown)
Yet another example...

```csharp
prefab.SetUpgradeModule(EquipmentType.VehicleModule, QuickSlotType.Selectable)
prefab.SetVehicleUpgradeModule(EquipmentType.VehicleModule, QuickSlotType.Selectable)
.WithOnModuleUsed((Vehicle inst, int slotID, float _charge, float _chargeScalar) => // charge and chargeScalar are always 0f here.
{
Subtitles.Add("Hello world!");
Expand Down
2 changes: 1 addition & 1 deletion Nautilus/Patchers/VehicleUpgradesPatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ private static void SeamothOnUpgradeModuleHull(SeaMoth __instance, int slotID, T
//
public static void SeamothDelegateUse(SeaMoth __instance, ref float cooldown, int slotID, TechType techType)
{
if (!SeamothUpgradeModules.TryGetValue(techType, out ICustomPrefab prefab))
if (!SeamothUpgradeModules.TryGetValue(techType, out ICustomPrefab prefab) && !VehicleUpgradeModules.TryGetValue(techType, out prefab))
return;

if (!prefab.TryGetGadget(out UpgradeModuleGadget moduleGadget))
Expand Down

0 comments on commit 6bd3362

Please sign in to comment.