暂存修收获

This commit is contained in:
2025-09-03 12:45:40 +08:00
parent aca5fa287d
commit 2d4d171eb9
2 changed files with 35 additions and 22 deletions

Binary file not shown.

View File

@@ -25,12 +25,11 @@ namespace ArachnaeSwarm
} }
} }
// 1. 优先收获 // 1. 优先收获 - 使用基于 Cell 的新方法
Thing bestHarvestable = FindClosestThing(pawn, _workGiverHarvest); IntVec3 bestHarvestCell = FindClosestHarvestableCell(pawn);
if (bestHarvestable != null) if (bestHarvestCell.IsValid)
{ {
// 调用 JobOnCell 以利用 WorkGiver_GrowerHarvest 的多目标打包逻辑 return _workGiverHarvest.JobOnCell(pawn, bestHarvestCell);
return _workGiverHarvest.JobOnCell(pawn, bestHarvestable.Position);
} }
// 2. 其次播种 // 2. 其次播种
@@ -44,17 +43,32 @@ namespace ArachnaeSwarm
return null; return null;
} }
private Thing FindClosestThing(Pawn pawn, WorkGiver_Scanner scanner) private IntVec3 FindClosestHarvestableCell(Pawn pawn)
{ {
return GenClosest.ClosestThingReachable( IntVec3 bestCell = IntVec3.Invalid;
pawn.Position, float bestDistSq = float.MaxValue;
pawn.Map,
scanner.PotentialWorkThingRequest, foreach (Zone zone in pawn.Map.zoneManager.AllZones)
PathEndMode.Touch, {
TraverseParms.For(pawn), if (zone is Zone_Growing growingZone)
9999f, {
t => scanner.HasJobOnThing(pawn, t) // 遍历区域中的所有单元格
); foreach (IntVec3 cell in growingZone.Cells)
{
float distSq = pawn.Position.DistanceToSquared(cell);
if (distSq < bestDistSq && pawn.CanReach(cell, PathEndMode.ClosestTouch, Danger.Deadly))
{
// 使用 HasJobOnCell 来判断是否可以收获
if (_workGiverHarvest.HasJobOnCell(pawn, cell))
{
bestDistSq = distSq;
bestCell = cell;
}
}
}
}
}
return bestCell;
} }
private (IntVec3, ThingDef) FindClosestSowableCellAndPlant(Pawn pawn, WorkGiver_ArachnaeSow scanner) // 修改为我们的新 WorkGiver 类型 private (IntVec3, ThingDef) FindClosestSowableCellAndPlant(Pawn pawn, WorkGiver_ArachnaeSow scanner) // 修改为我们的新 WorkGiver 类型
@@ -97,7 +111,6 @@ namespace ArachnaeSwarm
public static class WorkGiverDefOf public static class WorkGiverDefOf
{ {
public static WorkGiverDef GrowerHarvest; public static WorkGiverDef GrowerHarvest;
public static WorkGiverDef GrowerSow;
static WorkGiverDefOf() static WorkGiverDefOf()
{ {