Files
ArachnaeSwarm/Source/ArachnaeSwarm/Patch_QualityUtility.cs
2025-09-02 21:49:46 +08:00

62 lines
2.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;
using System.Reflection; // For MethodInfo
namespace ArachnaeSwarm
{
[StaticConstructorOnStartup]
public static class QualityUtilityPatch
{
static QualityUtilityPatch()
{
var harmony = new Harmony("com.yourname.qualityutilitypatch");
harmony.Patch(
original: AccessTools.Method(typeof(QualityUtility), nameof(QualityUtility.GenerateQualityCreatedByPawn), new[] { typeof(Pawn), typeof(SkillDef), typeof(bool) }),
prefix: new HarmonyMethod(typeof(QualityUtilityPatch), nameof(GenerateQualityCreatedByPawn_Prefix))
);
}
public static bool GenerateQualityCreatedByPawn_Prefix(Pawn pawn, SkillDef relevantSkill, bool consumeInspiration, ref QualityCategory __result)
{
// 检查当前 Pawn 是否是我们的自定义动物(通过检查其 ThingDef 是否拥有 CompProperties_WorkForNonMechs
if (pawn != null && pawn.def.comps != null && ShouldEnableWorkSystem(pawn))
{
// 如果是,强制使用 mechFixedSkillLevel
int relevantSkillLevel = pawn.RaceProps.mechFixedSkillLevel;
bool inspired = consumeInspiration && pawn.InspirationDef == InspirationDefOf.Inspired_Creativity;
// 调用 QualityUtility.GenerateQualityCreatedByPawn 的 int 重载
__result = QualityUtility.GenerateQualityCreatedByPawn(relevantSkillLevel, inspired);
// 消耗灵感(如果适用)
if (inspired)
{
pawn.mindState.inspirationHandler.EndInspiration(InspirationDefOf.Inspired_Creativity);
}
// 返回 false跳过原版方法执行
return false;
}
// 返回 true执行原版方法
return true;
}
private static bool ShouldEnableWorkSystem(Pawn pawn)
{
// 检查 ThingDef 中是否有 CompProperties_WorkForNonMechs 配置
if (pawn.def.comps != null)
{
foreach (var compProperties in pawn.def.comps)
{
if (compProperties is CompProperties_WorkForNonMechs)
{
return true;
}
}
}
return false;
}
}
}