暂存
This commit is contained in:
@@ -88,6 +88,7 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="CompWorkForNonMechs.cs" />
|
||||
<Compile Include="AnimalWorkSystemPatcher.cs" />
|
||||
<Compile Include="Patch_WorkGivers_Growing.cs" />
|
||||
<Compile Include="Patch_QualityUtility.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
||||
96
Source/ArachnaeSwarm/Patch_WorkGivers_Growing.cs
Normal file
96
Source/ArachnaeSwarm/Patch_WorkGivers_Growing.cs
Normal file
@@ -0,0 +1,96 @@
|
||||
using HarmonyLib;
|
||||
using RimWorld;
|
||||
using Verse;
|
||||
using Verse.AI;
|
||||
using System.Reflection;
|
||||
|
||||
namespace ArachnaeSwarm
|
||||
{
|
||||
[StaticConstructorOnStartup]
|
||||
public static class Patch_WorkGivers_Growing
|
||||
{
|
||||
static Patch_WorkGivers_Growing()
|
||||
{
|
||||
var harmony = new Harmony("com.yourname.workgiversgrowingpatch");
|
||||
|
||||
// Patch WorkGiver_GrowerSow.JobOnCell
|
||||
harmony.Patch(
|
||||
original: AccessTools.Method(typeof(WorkGiver_GrowerSow), nameof(WorkGiver_GrowerSow.JobOnCell)),
|
||||
prefix: new HarmonyMethod(typeof(Patch_WorkGivers_Growing), nameof(JobOnCell_GrowerSow_Prefix))
|
||||
);
|
||||
|
||||
// Patch JobDriver_Deconstruct.TickActionInterval
|
||||
harmony.Patch(
|
||||
original: AccessTools.Method(typeof(JobDriver_Deconstruct), "TickActionInterval"),
|
||||
prefix: new HarmonyMethod(typeof(Patch_WorkGivers_Growing), nameof(TickActionInterval_Deconstruct_Prefix))
|
||||
);
|
||||
}
|
||||
|
||||
public static bool JobOnCell_GrowerSow_Prefix(Pawn pawn, IntVec3 c, ref Job __result, WorkGiver_GrowerSow __instance)
|
||||
{
|
||||
// 检查是否是我们的自定义动物,并且它不是真正的机械体 (因为真正的机械体原版会处理)
|
||||
if (ShouldEnableWorkSystem(pawn) && !pawn.RaceProps.IsMechanoid)
|
||||
{
|
||||
// 使用反射获取 WorkGiver_GrowerSow 实例的 wantedPlantDef 字段
|
||||
ThingDef wantedPlantDef = (ThingDef)AccessTools.Field(typeof(WorkGiver_Grower), "wantedPlantDef").GetValue(__instance);
|
||||
|
||||
if (wantedPlantDef == null)
|
||||
{
|
||||
__result = null;
|
||||
return false; // 跳过原版方法
|
||||
}
|
||||
|
||||
// 强制使用 mechFixedSkillLevel 作为相关技能等级
|
||||
int relevantSkillLevel = pawn.RaceProps.mechFixedSkillLevel;
|
||||
|
||||
// 然后进行原始的 sowMinSkill 检查
|
||||
if (wantedPlantDef.plant.sowMinSkill > relevantSkillLevel)
|
||||
{
|
||||
__result = null; // 技能不足,不生成 Job
|
||||
return false; // 跳过原版方法
|
||||
}
|
||||
|
||||
// 如果技能足够,让原版方法继续执行,处理其他复杂的检查
|
||||
// 注意:这里我们只处理了技能检查部分,其他逻辑仍然依赖原版方法。
|
||||
// 如果原版方法在其他地方再次访问 pawn.skills,仍然可能出错。
|
||||
// 但这是最直接的修复方法,避免了完全复制整个原始方法。
|
||||
}
|
||||
|
||||
return true; // 执行原版方法
|
||||
}
|
||||
|
||||
public static bool TickActionInterval_Deconstruct_Prefix(JobDriver_Deconstruct __instance, Pawn ___pawn, int delta)
|
||||
{
|
||||
// 检查是否是我们的自定义动物,并且它不是真正的机械体
|
||||
if (ShouldEnableWorkSystem(___pawn) && !___pawn.RaceProps.IsMechanoid)
|
||||
{
|
||||
// 模拟技能学习,避免访问 pawn.skills 导致 NullReferenceException
|
||||
// 这里我们不实际增加经验值,只是模拟原版方法的行为
|
||||
// 避免了对 pawn.skills 的访问
|
||||
if (__instance.Building.def.CostListAdjusted(__instance.Building.Stuff).Count > 0)
|
||||
{
|
||||
// 可以选择在这里添加一些日志,以便调试
|
||||
// Log.Message($"Animal {___pawn.LabelShort} is deconstructing, simulating skill gain.");
|
||||
}
|
||||
return false; // 跳过原版方法
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
// <autogenerated />
|
||||
using System;
|
||||
using System.Reflection;
|
||||
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
|
||||
Binary file not shown.
@@ -0,0 +1 @@
|
||||
70a1ccfa141c7c82eb05a9fac71c32df86f6b34332995c92bb7aac69bc46394b
|
||||
@@ -0,0 +1,2 @@
|
||||
C:\Steam\steamapps\common\RimWorld\Mods\ArachnaeSwarm\Source\ArachnaeSwarm\obj\Debug\ArachnaeSwarm.csproj.AssemblyReference.cache
|
||||
C:\Steam\steamapps\common\RimWorld\Mods\ArachnaeSwarm\Source\ArachnaeSwarm\obj\Debug\ArachnaeSwarm.csproj.CoreCompileInputs.cache
|
||||
Reference in New Issue
Block a user