48 lines
1.6 KiB
C#
48 lines
1.6 KiB
C#
using HarmonyLib;
|
||
using RimWorld;
|
||
using Verse;
|
||
|
||
namespace ArachnaeSwarm
|
||
{
|
||
// Patcher 1: 阻止训练退化
|
||
[HarmonyPatch(typeof(Pawn_TrainingTracker), "TrainingTrackerTickRare")]
|
||
public static class Patch_TrainingTracker_TickRare
|
||
{
|
||
public static bool Prefix(Pawn_TrainingTracker __instance)
|
||
{
|
||
Pawn pawn = Traverse.Create(__instance).Field("pawn").GetValue<Pawn>();
|
||
if (pawn == null) return true;
|
||
|
||
var comp = pawn.GetComp<CompAdvancedTraining>();
|
||
if (comp != null && comp.Props.disableAllSkillDecay)
|
||
{
|
||
return false; // 阻止原版方法运行
|
||
}
|
||
return true;
|
||
}
|
||
}
|
||
|
||
// Patcher 2: 阻止特定技能的衰减
|
||
[HarmonyPatch(typeof(SkillRecord), "Interval")]
|
||
public static class Patch_SkillRecord_Interval
|
||
{
|
||
// 使用 __instance 来获取 SkillRecord 对象, __pawn 为 SkillRecord 内部的私有字段
|
||
public static bool Prefix(SkillRecord __instance, Pawn ___pawn)
|
||
{
|
||
if (___pawn == null) return true;
|
||
|
||
var comp = ___pawn.GetComp<CompAdvancedTraining>();
|
||
if (comp == null || comp.Props.skillLevels.NullOrEmpty())
|
||
{
|
||
return true; // 没有组件或配置,正常执行原版衰减
|
||
}
|
||
|
||
// 检查全局开关:如果设置了 disableAllSkillDecay 为 true,则阻止衰减
|
||
if (comp.Props.disableAllSkillDecay)
|
||
{
|
||
return false; // 阻止原版 Interval 方法的执行
|
||
}
|
||
return true; // 正常执行原版衰减
|
||
}
|
||
}
|
||
} |