41 lines
1.5 KiB
C#
41 lines
1.5 KiB
C#
using HarmonyLib;
|
|
using RimWorld;
|
|
using Verse;
|
|
using UnityEngine;
|
|
|
|
namespace ArachnaeSwarm
|
|
{
|
|
[HarmonyPatch(typeof(Projectile), "CheckForFreeInterceptBetween")]
|
|
public static class Projectile_CheckForFreeInterceptBetween_Patch
|
|
{
|
|
// This patch will find our custom ThingComp on pawns and call its intercept method.
|
|
public static bool Prefix(Projectile __instance, Vector3 lastExactPos, Vector3 newExactPos)
|
|
{
|
|
if (__instance.Map == null || __instance.Destroyed)
|
|
{
|
|
return true; // Let original method run if something is wrong
|
|
}
|
|
|
|
// Iterate through all pawns on the map
|
|
foreach (Pawn pawn in __instance.Map.mapPawns.AllPawnsSpawned)
|
|
{
|
|
// Our comp is directly on the pawn, not on apparel
|
|
if (pawn.TryGetComp<ThingComp_GuardianPsyField>(out var interceptor))
|
|
{
|
|
// Call our custom intercept method
|
|
if (interceptor.TryIntercept(__instance))
|
|
{
|
|
// If interception is successful, destroy the projectile
|
|
__instance.Destroy(DestroyMode.Vanish);
|
|
|
|
// Prevent the original game method from running, as we've handled it
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
|
|
// If no interception happened, let the original method run
|
|
return true;
|
|
}
|
|
}
|
|
} |