This commit is contained in:
2025-09-03 12:07:45 +08:00
parent 254a621c55
commit ed9ac9d389
4 changed files with 41 additions and 77 deletions

Binary file not shown.

View File

@@ -14,36 +14,7 @@
<Wildness>0.3</Wildness>
</statBases>
<uiIconScale>1.1</uiIconScale>
<comps>
<li Class="ArachnaeSwarm.CompProperties_InstantTrain">
<trainables>
<li>ARA_Sowing</li>
<li>ARA_PlantCutting</li>
</trainables>
</li>
<li Class="ArachnaeSwarm.CompProperties_AnimalWorkSettings">
<!-- 定义技能等级 -->
<skillLevels>
<li>
<skill>Plants</skill>
<level>10</level>
<disableDecay>true</disableDecay>
</li>
</skillLevels>
<!-- 定义训练项与工作类型的映射 -->
<workTypeMap>
<li>
<trainable>ARA_Sowing</trainable>
<workType>Growing</workType>
</li>
<li>
<trainable>ARA_PlantCutting</trainable>
<workType>PlantCutting</workType>
</li>
</workTypeMap>
</li>
<li Class="ArachnaeSwarm.CompProperties_NoTrainingDecay" />
</comps>
<tools>
<li>
<label>head claw</label>
@@ -104,19 +75,19 @@
</deathAction>
</race>
<comps>
<li Class="ArachnaeSwarm.CompProperties_AdvancedTraining">
<skillLevels>
<li>
<skill>Plants</skill>
<level>10</level> <!-- 动物生成时种植技能固定为8级 -->
</li>
</skillLevels>
<instantTrainables>
<li>ARA_Sowing</li> <!-- 动物生成时,立即完成播种训练 -->
</instantTrainables>
<disableAllSkillDecay>true</disableAllSkillDecay> <!-- 阻止这个动物的所有技能衰减 -->
</li>
</comps>
<li Class="ArachnaeSwarm.CompProperties_AdvancedTraining">
<skillLevels>
<li>
<skill>Plants</skill>
<level>10</level> <!-- 动物生成时种植技能固定为8级 -->
</li>
</skillLevels>
<instantTrainables>
<li>ARA_Sowing</li> <!-- 动物生成时,立即完成播种训练 -->
</instantTrainables>
<disableAllSkillDecay>true</disableAllSkillDecay> <!-- 阻止这个动物的所有技能衰减 -->
</li>
</comps>
<tradeTags>
<li>AnimalInsect</li>
</tradeTags>

View File

@@ -5,39 +5,24 @@ using RimWorld;
namespace ArachnaeSwarm
{
// 确保 WorkGiverDefOf 被正确初始化
[DefOf]
public static class WorkGiverDefOf
{
public static WorkGiverDef Harvest;
public static WorkGiverDef GrowerSow;
static WorkGiverDefOf()
{
DefOfHelper.EnsureInitializedInCtor(typeof(WorkGiverDefOf));
}
}
public class JobGiver_Grower : ThinkNode_JobGiver
{
private static WorkGiver_GrowerHarvest _workGiverHarvest;
private static WorkGiver_GrowerSow _workGiverSow;
static JobGiver_Grower()
{
// 确保在访问 WorkGiverDefOf 之前,它已经被初始化
// 尽管 [DefOf] 会自动处理,但显式调用可以避免某些加载时序问题
DefOfHelper.EnsureInitializedInCtor(typeof(WorkGiverDefOf));
_workGiverHarvest = WorkGiverDefOf.Harvest.Worker as WorkGiver_GrowerHarvest;
_workGiverSow = WorkGiverDefOf.GrowerSow.Worker as WorkGiver_GrowerSow;
}
private WorkGiver_GrowerHarvest _workGiverHarvest;
private WorkGiver_GrowerSow _workGiverSow;
protected override Job TryGiveJob(Pawn pawn)
{
if (_workGiverHarvest == null || _workGiverSow == null)
// 懒加载 WorkGiver 实例,确保 DefOf 已被初始化
if (_workGiverHarvest == null)
{
Log.ErrorOnce("JobGiver_Grower could not find vanilla Grower WorkGivers.", 123457);
return null;
_workGiverHarvest = WorkGiverDefOf.GrowerHarvest.Worker as WorkGiver_GrowerHarvest;
_workGiverSow = WorkGiverDefOf.GrowerSow.Worker as WorkGiver_GrowerSow;
if (_workGiverHarvest == null || _workGiverSow == null)
{
Log.ErrorOnce("JobGiver_Grower: Failed to get WorkGiver_GrowerHarvest or WorkGiver_GrowerSow. DefOfs might not be initialized or DefNames are incorrect.", 123457);
return null;
}
}
// 1. 优先收获
@@ -96,4 +81,17 @@ namespace ArachnaeSwarm
return bestCell;
}
}
}
// 确保 WorkGiverDefOf 被正确初始化,放在命名空间顶层
[DefOf]
public static class WorkGiverDefOf
{
public static WorkGiverDef GrowerHarvest;
public static WorkGiverDef GrowerSow;
static WorkGiverDefOf()
{
DefOfHelper.EnsureInitializedInCtor(typeof(WorkGiverDefOf));
}
}

View File

@@ -9,7 +9,6 @@ namespace ArachnaeSwarm
public static class ARA_TrainableDefOf
{
public static TrainableDef ARA_Sowing;
public static TrainableDef ARA_PlantCutting;
static ARA_TrainableDefOf()
{
@@ -32,12 +31,8 @@ namespace ArachnaeSwarm
bool canSow = pawn.training.HasLearned(ARA_TrainableDefOf.ARA_Sowing) &&
pawn.training.GetWanted(ARA_TrainableDefOf.ARA_Sowing);
// 检查动物是否学会并被允许执行“植物切割”工作
bool canCut = pawn.training.HasLearned(ARA_TrainableDefOf.ARA_PlantCutting) &&
pawn.training.GetWanted(ARA_TrainableDefOf.ARA_PlantCutting);
// 只要满足其中任何一个条件,就返回 true
return canSow || canCut;
// 现在只需要检查播种技能,因为切割功能已合并
return canSow;
}
}
}