有一点自私的护盾

This commit is contained in:
2025-07-23 18:50:51 +08:00
parent 6414a2a033
commit db4d08e4bd
7 changed files with 581 additions and 54 deletions

View File

@@ -0,0 +1,42 @@
using HarmonyLib;
using RimWorld;
using System.Linq;
using System.Reflection;
using UnityEngine;
using Verse;
namespace WulaFallenEmpire.HarmonyPatches
{
[HarmonyPatch(typeof(Projectile), "CheckForFreeInterceptBetween")]
public static class Projectile_CheckForFreeInterceptBetween_Patch
{
private static readonly MethodInfo ImpactMethod = AccessTools.Method(typeof(Projectile), "Impact");
public static bool Prefix(Projectile __instance, Vector3 lastExactPos, Vector3 newExactPos)
{
if (__instance.Map == null || __instance.Destroyed) return true;
foreach (Pawn pawn in __instance.Map.mapPawns.AllPawnsSpawned)
{
if (pawn.apparel != null)
{
foreach (Apparel apparel in pawn.apparel.WornApparel)
{
if (apparel.TryGetComp<CompApparelInterceptor>(out var interceptor))
{
if (interceptor.TryIntercept(__instance, lastExactPos, newExactPos))
{
ImpactMethod.Invoke(__instance, new object[] { null, true });
return false;
}
}
}
}
}
return true;
}
}
}