Skip to content

Commit

Permalink
Change spike pierce patches
Browse files Browse the repository at this point in the history
  • Loading branch information
doombubbles committed Dec 14, 2024
1 parent 8cf1ba9 commit 8537567
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 83 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:

- name: Download Specific MelonLoader
if: env.MELONLOADER_BRANCH != ''
uses: dawidd6/action-download-artifact@v2
uses: dawidd6/action-download-artifact@v6
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
workflow: build.yml
Expand Down Expand Up @@ -76,7 +76,7 @@ jobs:


- name: Download Specific Mod Helper
uses: dawidd6/action-download-artifact@v2
uses: dawidd6/action-download-artifact@v6
if: env.MOD_HELPER_BRANCH != ''
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
Expand Down
2 changes: 1 addition & 1 deletion LATEST.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
- Fixed for BTD6 v45.0
- Reworked the Spike Factory Mega Knowledge to just be "Spike Factories choose the spot where their spikes land." because of side effects that the pierce changes were having
4 changes: 1 addition & 3 deletions MegaKnowledges/Support/SpikeEmpowerment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ public class SpikeEmpowerment : MegaKnowledge
{
public override string TowerId => TowerType.SpikeFactory;

public override string Description =>
"Spike Factories choose the spot where their spikes land, and spikes damage Bloons while traveling.";
public override string Description => "Spike Factories choose the spot where their spikes land.";

public override int Offset => 400;

Expand All @@ -35,6 +34,5 @@ public override void Apply(TowerModel model)
}

model.UpdateTargetProviders();
model.GetDescendant<ArriveAtTargetModel>().filterCollisionWhileMoving = false;
}
}
78 changes: 1 addition & 77 deletions MiscPatches.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.Collections.Generic;
using Il2CppAssets.Scripts.Simulation.Towers.Behaviors.Attack.Behaviors;
using Il2CppAssets.Scripts.Simulation.Towers.Projectiles;
using Il2CppAssets.Scripts.Simulation.Towers.Behaviors.Attack.Behaviors;
using Il2CppAssets.Scripts.Simulation.Towers.Projectiles.Behaviors;
using Il2CppAssets.Scripts.Simulation.Towers.Weapons.Behaviors;
using BTD_Mod_Helper.Api;
Expand All @@ -12,7 +10,6 @@
using Il2CppAssets.Scripts.Simulation.Input;
using Il2CppAssets.Scripts.Simulation.SMath;
using MegaKnowledge.MegaKnowledges.Support;
using Math = System.Math;

namespace MegaKnowledge;

Expand Down Expand Up @@ -72,79 +69,6 @@ internal static bool Prefix(TrackTargetWithinTime __instance)
}
}

private static readonly Dictionary<int, (ArriveAtTarget, float)> SpikeInfo = new();

[HarmonyPatch(typeof(Projectile), nameof(Projectile.CollideBloon))]
internal class Projectile_CollideBloon
{
[HarmonyPrefix]
internal static void Prefix(Projectile __instance, ref float __state)
{
if (__instance.emittedBy?.towerModel.baseId == TowerType.SpikeFactory)
{
__state = __instance.pierce;
}
else
{
__state = 0;
}
}


[HarmonyPostfix]
internal static void Postfix(Projectile __instance, ref float __state)
{
if (__state > 0 && ModContent.GetInstance<SpikeEmpowerment>().Enabled)
{
if (!SpikeInfo.ContainsKey(__instance.Id.Id))
{
var projectileBehavior =
__instance.projectileBehaviors.list.FirstOrDefault(b =>
b.TryCast<ArriveAtTarget>() != null);
if (projectileBehavior != null)
{
SpikeInfo[__instance.Id.Id] = (projectileBehavior.Cast<ArriveAtTarget>(), 0);
}
else
{
return;
}
}

var (arriveAtTarget, pierce) = SpikeInfo[__instance.Id.Id];
var arriveAtTargetModel = arriveAtTarget.arriveModel;
if (!arriveAtTargetModel.filterCollisionWhileMoving && arriveAtTarget.GetPercThruMovement() < .99)
{
pierce += __state - __instance.pierce;
__instance.pierce = __state;

if (Math.Abs(pierce - __state) < .00001)
{
arriveAtTargetModel = arriveAtTargetModel.Duplicate();
arriveAtTargetModel.filterCollisionWhileMoving = true;
arriveAtTarget.UpdatedModel(arriveAtTargetModel);
}
}

SpikeInfo[__instance.Id.Id] = (arriveAtTarget, pierce);
}
}
}

[HarmonyPatch(typeof(Projectile), nameof(Projectile.OnDestroy))]
[HarmonyPatch]
internal class Projectile_Destroy
{
[HarmonyPostfix]
internal static void Postfix(Projectile __instance)
{
if (SpikeInfo.ContainsKey(__instance.Id.Id))
{
SpikeInfo.Remove(__instance.Id.Id);
}
}
}

[HarmonyPatch(typeof(InputManager), nameof(InputManager.GetRangeMeshes))]
internal static class InputManager_GetRangeMeshes
{
Expand Down

0 comments on commit 8537567

Please sign in to comment.