Skip to content

Commit

Permalink
feat: Add better support for Hoverbike modules (#429)
Browse files Browse the repository at this point in the history
* Added hoverbike quickslot component

Complement of PR #391.

* Should be working. Tests are needed.

* Hoverbike Modules Support is now fully functional. I didn't expect it was gonna work so well.

* Removed useless commands and useless usings and commented code.
Added a notice in VehicleUpgradesPatcher for modders who would like to edit.

* Fix compiler error

* Fixed visibility of the HoverbikeModulesSupport behaviour.

* Fixed one more visibility thing

* removed useless comments and fixed a techtype reference.

* Update VehicleUpgradeExample_BelowZero.cs

fixed the is statements.

---------

Co-authored-by: LeeTwentyThree <[email protected]>
  • Loading branch information
VELD-Dev and LeeTwentyThree committed Jul 4, 2023
1 parent 356b4d7 commit 7323b6b
Show file tree
Hide file tree
Showing 5 changed files with 827 additions and 80 deletions.
143 changes: 143 additions & 0 deletions Example mod/VehicleUpgradeExample_BelowZero.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
#if BELOWZERO
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using BepInEx;
using Nautilus.Assets;
using Nautilus.Assets.Gadgets;
using Nautilus.Assets.PrefabTemplates;
using Nautilus.Handlers;
using UnityEngine;
using UWE;

namespace Nautilus.Examples;

[BepInPlugin("com.snmodding.nautilus.vehicleupgrades", "Nautilus Vehicle Upgrades Example Mod", Nautilus.PluginInfo.PLUGIN_VERSION)]
public class VehicleUpgradeExample : BaseUnityPlugin
{
GameObject electricalDefensePrefab;
private void Awake()
{

var DefenseRecipe = new Crafting.RecipeData()
{
craftAmount = 1,
Ingredients = new List<Ingredient>()
{
new Ingredient(TechType.Polyaniline, 1),
new Ingredient(TechType.Quartz, 2),
new Ingredient(TechType.Battery, 2),
new Ingredient(TechType.AluminumOxide, 1)
}
};
Action<Hoverbike, int> onAdded = (Hoverbike instance, int slotID) =>
{
if (electricalDefensePrefab == null)
CoroutineHost.StartCoroutine(InitElectricalPrefab());
Subtitles.Add("Hoverbike perimeter defense upgrade module engaged.");
};

Action<Hoverbike, int> onRemoved = (Hoverbike instance, int slotID) =>
{
Subtitles.Add("Hoverbike perimeter defense upgrade module disengaged. Caution advised.");
};

Action<Hoverbike, int, float, float> onUsed = (Hoverbike instance, int slotID, float charge, float chargeScalar) =>
{
if (electricalDefensePrefab != null)
{
var electricalDefense = Utils.SpawnZeroedAt(electricalDefensePrefab, instance.transform, false).GetComponent<ElectricalDefense>();
electricalDefense.charge = charge;
electricalDefense.chargeScalar = chargeScalar;
}
else
{
CoroutineHost.StartCoroutine(InitElectricalPrefab());
Subtitles.Add("Hoverbike perimeter defense upgrade was not initialized. Initializing.");
}
};

/*
* Here we will make an Hoverbike module.
* This system is very easy to use but was complex enough to implement.
*/
var hoverbikePeriDefInfo = PrefabInfo.WithTechType(
"HoverbikePerimeterDefense",
"Hoverbike Perimeter Defense Module",
"A perimeter defense upgrade for the Hoverbike... No one knows if it will be useful.",
techTypeOwner: Assembly.GetExecutingAssembly())
.WithIcon(SpriteManager.Get(TechType.SeaTruckUpgradePerimeterDefense));

CustomPrefab hoverbikePeriDefPrefab = new CustomPrefab(hoverbikePeriDefInfo);
CloneTemplate seatruckPeriDefClone = new CloneTemplate(hoverbikePeriDefInfo, TechType.SeaTruckUpgradePerimeterDefense);

hoverbikePeriDefPrefab.SetGameObject(seatruckPeriDefClone);

hoverbikePeriDefPrefab.SetRecipe(DefenseRecipe)
.WithFabricatorType(CraftTree.Type.Fabricator)
.WithStepsToFabricatorTab("Machines")
.WithCraftingTime(2.5f);

hoverbikePeriDefPrefab.SetPdaGroupCategory(TechGroup.VehicleUpgrades, TechCategory.VehicleUpgrades);
hoverbikePeriDefPrefab.SetUnlock(TechType.Polyaniline);
hoverbikePeriDefPrefab.SetVehicleUpgradeModule(EquipmentType.HoverbikeModule, QuickSlotType.Chargeable)
.WithCooldown(5f)
.WithEnergyCost(5f)
.WithMaxCharge(10f)
.WithOnModuleAdded(onAdded)
.WithOnModuleRemoved(onRemoved)
.WithOnModuleUsed(onUsed);

hoverbikePeriDefPrefab.Register();


/*
* Now let's make one that can be selected and charged.
*/
var hoverbikeSelectDef = PrefabInfo.WithTechType("HoverbikeSelectDefense",
"Hoverbike Selectable Perimeter Defense Module",
"The same than the other module, but selectable.")
.WithIcon(SpriteManager.Get(TechType.SeaTruckUpgradePerimeterDefense));

var hoverbikeSelDefPrefab = new CustomPrefab(hoverbikeSelectDef);

hoverbikeSelDefPrefab.SetGameObject(seatruckPeriDefClone);
hoverbikeSelDefPrefab.SetPdaGroupCategory(TechGroup.VehicleUpgrades, TechCategory.VehicleUpgrades)
.WithCompoundTechsForUnlock(new()
{
TechType.Polyaniline
});
hoverbikeSelDefPrefab.SetRecipe(DefenseRecipe)
.WithFabricatorType(CraftTree.Type.Fabricator)
.WithStepsToFabricatorTab("Machines")
.WithCraftingTime(2.5f);
hoverbikeSelDefPrefab.SetVehicleUpgradeModule(EquipmentType.HoverbikeModule, QuickSlotType.SelectableChargeable)
.WithCooldown(5f)
.WithEnergyCost(5f)
.WithMaxCharge(10f)
.WithOnModuleAdded(onAdded)
.WithOnModuleRemoved(onRemoved)
.WithOnModuleUsed(onUsed);

hoverbikeSelDefPrefab.Register();
}

internal IEnumerator InitElectricalPrefab()
{
/*
* This function is getting the ElectricalDefense prefab from the SeaTruckUpgrades.
* You can see that this monobehaviour is not stored in the upgrade prefab.
*/
var task = CraftData.GetPrefabForTechTypeAsync(TechType.SeaTruck);
yield return task;
var result = task.GetResult();
var seatruckUpgrades = result.GetComponent<SeaTruckUpgrades>();
electricalDefensePrefab = seatruckUpgrades.electricalDefensePrefab;
Subtitles.Add("Hoverbike perimeter defense upgrade is initialized.");
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ private void Awake()
* Here, we're assigning the hull icon for our item.
* You may also use a custom image icon by calling the ImageUtils.LoadSpriteFromFile method or with AssetBundles, like mentioned higher.
*/
depthUpgradeInfo.WithIcon(SpriteManager.Get(TechType.HullReinforcementModule2));
depthUpgradeInfo.WithIcon(SpriteManager.Get(TechType.VehicleHullModule3));
Logger.LogDebug("Registerd depth upgrade icon");

/*
Expand Down Expand Up @@ -157,45 +157,6 @@ private void Awake()
defense.chargeScalar = chargeScalar;
});
selfDefMK2prefab.Register();

/*
* And finally, a CUSTOMIZABLE-after-restart depth module!
*/

// PLANNED FOR ANOTHER PR.
/*
PrefabInfo prefabInfo = PrefabInfo.WithTechType("SeamothCustomDepthModule", "Seamoth Variable Depth Upgrade", "Customize the depth of your upgrade from the game settings!")
.WithIcon(SpriteManager.Get(TechType.SeamothReinforcementModule))
.WithSizeInInventory(new Vector2int(1, 1));
CustomPrefab prefab = new(prefabInfo);
CloneTemplate clone = new(prefabInfo, TechType.SeamothReinforcementModule);
prefab.SetGameObject(clone);
prefab.SetPdaGroupCategory(TechGroup.VehicleUpgrades, TechCategory.VehicleUpgrades);
prefab.SetRecipe(new Crafting.RecipeData()
{
craftAmount = 1,
Ingredients = new List<CraftData.Ingredient>()
{
new CraftData.Ingredient(TechType.SeamothReinforcementModule),
new CraftData.Ingredient(TechType.Diamond, 2)
}
})
.WithFabricatorType(CraftTree.Type.SeamothUpgrades)
.WithCraftingTime(4f)
.WithStepsToFabricatorTab("SeamothModules");
prefab.SetVehicleUpgradeModule(EquipmentType.SeamothModule)
.WithDepthUpgrade(() => config.MaxDepth, true)
.WithOnModuleAdded((Vehicle vehicleInstance, int slotId) => {
Subtitles.Add($"New seamoth depth: {config.MaxDepth} meters.\nAdded in slot #{slotId + 1}.");
})
.WithOnModuleRemoved((Vehicle vehicleInstance, int slotId) =>
{
Subtitles.Add($"Seamoth depth module removed from slot #{slotId + 1}!");
});
prefab.Register();
*/
}
}

Expand Down
3 changes: 2 additions & 1 deletion Nautilus/Assets/Gadgets/UpgradeModuleGadget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Nautilus.Handlers;
using Nautilus.Utility;
using Nautilus.Patchers;
using Nautilus.MonoBehaviours;

namespace Nautilus.Assets.Gadgets;

Expand Down Expand Up @@ -410,7 +411,7 @@ protected internal override void Build()
VehicleUpgradesPatcher.SeatruckUpgradeModules.Add(prefab.Info.TechType, prefab);
break;
case EquipmentType.HoverbikeModule:
VehicleUpgradesPatcher.SnowbikeUpgradeModules.Add(prefab.Info.TechType, prefab);
HoverbikeModulesSupport.CustomModules.Add(prefab.Info.TechType, prefab);
break;
#elif SUBNAUTICA
case EquipmentType.SeamothModule:
Expand Down
Loading

0 comments on commit 7323b6b

Please sign in to comment.