Files
ArachnaeSwarm/Source/ArachnaeSwarm/ARA_TrainingWork/TrainingSystem_Patcher.cs
2025-09-03 13:35:30 +08:00

48 lines
1.6 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 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; // 正常执行原版衰减
}
}
}