Files
WulaFallenEmpireRW/Source/WulaFallenEmpire/HarmonyPatches/Patch_Pawn_PreApplyDamage.cs
ProjectKoi-Kalo\Kalo 98a0400c78 WulaFallenEmpireSettings.cs - 添加了 public bool enableDebugLogs = false; 字段和保存配置
 WulaLog.cs - 修改了DebugEnabled属性,仅检查enableDebugLogs设置(不检查DevMode)
 WulaFallenEmpireMod.cs - 在DoSettingsWindowContents中添加了UI复选框,显示"Enable Debug Logs"选项
 替换了所有848个Log.Message/Error/Warning调用为WulaLog.Debug()
2025-12-15 13:05:50 +08:00

42 lines
1.4 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using HarmonyLib;
using RimWorld;
using Verse;
namespace WulaFallenEmpire
{
[HarmonyPatch(typeof(Pawn), "PreApplyDamage")]
public static class Patch_Pawn_PreApplyDamage
{
[HarmonyPrefix]
public static bool Prefix(Pawn __instance, ref DamageInfo dinfo)
{
// 检查Pawn是否有伤害拦截组件
var interceptorComp = __instance.TryGetComp<CompDamageInterceptor>();
if (interceptorComp != null)
{
WulaLog.Debug($"[DamageInterceptor] {__instance.LabelShort} 即将受到 {dinfo.Amount} 点伤害,拦截组件激活");
// 让拦截组件处理伤害
return interceptorComp.PreApplyDamage(ref dinfo);
}
return true; // 继续正常处理伤害
}
}
[HarmonyPatch(typeof(Pawn), "PostApplyDamage")]
public static class Patch_Pawn_PostApplyDamage
{
[HarmonyPostfix]
public static void Postfix(Pawn __instance, DamageInfo dinfo, float totalDamageDealt)
{
// 记录实际承受的伤害
var interceptorComp = __instance.TryGetComp<CompDamageInterceptor>();
if (interceptorComp != null && totalDamageDealt == 0f)
{
WulaLog.Debug($"[DamageInterceptor] {__instance.LabelShort} 成功拦截所有伤害实际承受0点伤害");
}
}
}
}