This commit is contained in:
2025-08-26 18:33:49 +08:00
parent c3161287d3
commit a897c2e44c
12 changed files with 11864 additions and 80 deletions

View File

@@ -0,0 +1,40 @@
using HarmonyLib;
using Verse;
using System.Reflection;
using UnityEngine; // Add UnityEngine for MoteMaker and Color
namespace WulaFallenEmpire.HarmonyPatches
{
[HarmonyPatch(typeof(Pawn_HealthTracker), "PreApplyDamage")]
public static class DamageShieldPatch
{
// 使用 Harmony 的 AccessTools.Field 来获取私有的 pawn 字段
private static readonly FieldInfo PawnField = AccessTools.Field(typeof(Pawn_HealthTracker), "pawn");
public static bool Prefix(Pawn_HealthTracker __instance, ref DamageInfo dinfo, out bool absorbed)
{
// 获取 Pawn 实例
Pawn pawn = (Pawn)PawnField.GetValue(__instance);
// 查找 Pawn 身上是否有 Hediff_DamageShield
Hediff_DamageShield damageShield = pawn.health.hediffSet.GetFirstHediff<Hediff_DamageShield>();
if (damageShield != null && damageShield.ShieldCharges > 0)
{
// 如果有护盾层数,则消耗一层并抵挡伤害
damageShield.ShieldCharges--;
// MoteMaker.ThrowText(pawn.DrawPos, pawn.Map, "伤害被护盾抵挡!", Color.cyan, 1.2f); // 视觉反馈,明确指定 Verse.MoteMaker此行将被删除
// 设置 absorbed 为 true表示伤害被完全吸收
absorbed = true;
// 返回 false阻止原始方法执行即伤害不会被应用
return false;
}
// 如果没有护盾 Hediff 或者层数用尽,则正常处理伤害
absorbed = false;
return true; // 继续执行原始方法
}
}
}