Add projectile explode on stick configuration option

This commit is contained in:
2025-02-24 22:06:00 +01:00
parent b10eb8752b
commit 9e3e4fa367
5 changed files with 32 additions and 3 deletions

View File

@@ -21,6 +21,7 @@ namespace TerraTech {
public static ConfigEntry<float> seekingProjectileVisionConeAngleMultiplier; public static ConfigEntry<float> seekingProjectileVisionConeAngleMultiplier;
public static ConfigEntry<float> seekingProjectileVisionRangeMultiplier; public static ConfigEntry<float> seekingProjectileVisionRangeMultiplier;
public static ConfigEntry<float> seekingProjectileTurningSpeedMultiplier; public static ConfigEntry<float> seekingProjectileTurningSpeedMultiplier;
public static ConfigEntry<bool> projectileExplodeOnStick;
public void Awake() { public void Awake() {
debug = Config.Bind("General", "Debug", false); debug = Config.Bind("General", "Debug", false);
@@ -65,6 +66,9 @@ namespace TerraTech {
Config.Bind("Weapons", "Seeking Projectile Turn Speed Multiplier", 1f, Config.Bind("Weapons", "Seeking Projectile Turn Speed Multiplier", 1f,
new ConfigDescription("Seeking Projectile Turn Speed Multiplier", new ConfigDescription("Seeking Projectile Turn Speed Multiplier",
new AcceptableValueRange<float>(min, max))); new AcceptableValueRange<float>(min, max)));
projectileExplodeOnStick = Config.Bind(
"Weapons", "Projectile Explode On Stick", false,
new ConfigDescription("Projectile Explode On Stick", new AcceptableValueRange<bool>(false, true)));
Logger.LogInfo("Cyka mod loaded"); Logger.LogInfo("Cyka mod loaded");
HarmonyFileLog.Enabled = true; HarmonyFileLog.Enabled = true;

View File

@@ -0,0 +1,22 @@
using System;
using HarmonyLib;
namespace TerraTech {
[HarmonyPatch]
public class ProjectilePatch {
[HarmonyPrefix]
[HarmonyPatch(typeof(Projectile), "StickToObjectWithVisuals")]
static void Prefix(Projectile __instance) {
if (Main.debug.Value)
Console.WriteLine("Projectile created");
var trav = Traverse.Create(__instance);
var explodeOnStick = trav.Field("m_ExplodeOnStick");
if (!explodeOnStick.GetValue<bool>()) {
if (Main.debug.Value)
Console.WriteLine("Exploding on stick");
explodeOnStick.SetValue(Main.projectileExplodeOnStick.Value);
}
}
}
}

View File

@@ -6,7 +6,9 @@ namespace TerraTech {
[HarmonyPatch(typeof(SeekingProjectile), "OnSpawn")] [HarmonyPatch(typeof(SeekingProjectile), "OnSpawn")]
class Patch { class Patch {
static void Postfix(SeekingProjectile __instance) { static void Postfix(SeekingProjectile __instance) {
Console.WriteLine("SeekingProjectile created"); if (Main.debug.Value)
Console.WriteLine("SeekingProjectile created");
SetField( SetField(
__instance, "m_VisionConeAngle", __instance, "m_VisionConeAngle",
Main.seekingProjectileVisionConeAngleMultiplier.Value * GetField(__instance, "m_VisionConeAngle")); Main.seekingProjectileVisionConeAngleMultiplier.Value * GetField(__instance, "m_VisionConeAngle"));

View File

@@ -58,6 +58,7 @@
<Compile Include="CykUtil.cs" /> <Compile Include="CykUtil.cs" />
<Compile Include="ModuleHeartManager.cs" /> <Compile Include="ModuleHeartManager.cs" />
<Compile Include="ModuleFuelTankManager.cs" /> <Compile Include="ModuleFuelTankManager.cs" />
<Compile Include="ProjectilePatch.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Reference Include="0Harmony"> <Reference Include="0Harmony">

View File

@@ -1 +1 @@
wgo -dir TerraTech -debounce 1s echo "Formatters" :: clang-format -i TerraTech/*.cs clang-format -i TerraTech/*.cs