怪了好使了

This commit is contained in:
2025-09-02 21:43:35 +08:00
parent 8a7a947669
commit 9b5a8a58d3
3 changed files with 20 additions and 26 deletions

Binary file not shown.

View File

@@ -16,36 +16,35 @@ namespace ArachnaeSwarm
}
}
[HarmonyPatch(typeof(Pawn_WorkSettings), nameof(Pawn_WorkSettings.EnableAndInitialize))]
[HarmonyPatch(typeof(Pawn_WorkSettings), "EnableAndInitialize")]
public static class Patch_Pawn_WorkSettings_EnableAndInitialize
{
// 缓存原始的 IsMechanoid 属性 Getter
private static PropertyInfo isMechanoidProperty =
typeof(RaceProperties).GetProperty("IsMechanoid", BindingFlags.Public | BindingFlags.Instance);
public static bool Prefix(Pawn_WorkSettings __instance, Pawn ___pawn)
public static void Postfix(Pawn_WorkSettings __instance, Pawn ___pawn)
{
// 检查是否是我们想要启用工作系统的动物
// 检查是否是我们想要启用工作系统的动物,并且它不是机械体
// 因为原版的 EnableAndInitialize 已经处理了机械体的工作设置
if (___pawn.Faction != null && ___pawn.Faction.IsPlayer &&
!___pawn.RaceProps.IsMechanoid && // 真实身份不是机械体
ShouldEnableWorkSystem(___pawn)) // 但我们需要为它启用工作系统
!___pawn.RaceProps.IsMechanoid &&
ShouldEnableWorkSystem(___pawn))
{
// 局部伪装成机械体来执行初始化逻辑
// 执行机械体工作优先级初始化逻辑(来自 Pawn_WorkSettings.EnableAndInitialize
if (ModsConfig.BiotechActive && !___pawn.RaceProps.mechWorkTypePriorities.NullOrEmpty())
// 获取 CompProperties_WorkForNonMechs
CompProperties_WorkForNonMechs compProps = null;
if (___pawn.def.comps != null)
{
for (int i = 0; i < ___pawn.RaceProps.mechWorkTypePriorities.Count; i++)
foreach (var comp in ___pawn.def.comps)
{
var priority = ___pawn.RaceProps.mechWorkTypePriorities[i];
__instance.SetPriority(priority.def, priority.priority);
if (comp is CompProperties_WorkForNonMechs props)
{
compProps = props;
break;
}
}
}
// 同时也可以初始化 mechEnabledWorkTypes 中的工作类型(如果你需要)
if (!___pawn.RaceProps.mechEnabledWorkTypes.NullOrEmpty())
if (compProps != null && compProps.workTypes != null)
{
foreach (var workType in ___pawn.RaceProps.mechEnabledWorkTypes)
// 设置 CompProperties_WorkForNonMechs 中定义的工作类型优先级
foreach (var workType in compProps.workTypes)
{
if (!__instance.WorkIsActive(workType) && !___pawn.WorkTypeIsDisabled(workType))
{
@@ -53,12 +52,7 @@ namespace ArachnaeSwarm
}
}
}
// 阻止原方法继续执行(因为我们已经手动处理了初始化)
return false;
}
return true; // 其他情况正常执行原逻辑
}
private static bool ShouldEnableWorkSystem(Pawn pawn)

View File

@@ -25,7 +25,7 @@ namespace ArachnaeSwarm
var pawn = parent as Pawn;
if (pawn == null || pawn.Faction == null || !pawn.Faction.IsPlayer) return;
// 启用工作设置
// 确保 workSettings 实例存在
if (pawn.workSettings == null)
{
pawn.workSettings = new Pawn_WorkSettings(pawn);