62 lines
2.4 KiB
C#
62 lines
2.4 KiB
C#
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;
|
||
}
|
||
}
|
||
} |