暂存修收获

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. 优先收获
Thing bestHarvestable = FindClosestThing(pawn, _workGiverHarvest);
if (bestHarvestable != null)
// 1. 优先收获 - 使用基于 Cell 的新方法
IntVec3 bestHarvestCell = FindClosestHarvestableCell(pawn);
if (bestHarvestCell.IsValid)
{
// 调用 JobOnCell 以利用 WorkGiver_GrowerHarvest 的多目标打包逻辑
return _workGiverHarvest.JobOnCell(pawn, bestHarvestable.Position);
return _workGiverHarvest.JobOnCell(pawn, bestHarvestCell);
}
// 2. 其次播种
@@ -44,17 +43,32 @@ namespace ArachnaeSwarm
return null;
}
private Thing FindClosestThing(Pawn pawn, WorkGiver_Scanner scanner)
private IntVec3 FindClosestHarvestableCell(Pawn pawn)
{
return GenClosest.ClosestThingReachable(
pawn.Position,
pawn.Map,
scanner.PotentialWorkThingRequest,
PathEndMode.Touch,
TraverseParms.For(pawn),
9999f,
t => scanner.HasJobOnThing(pawn, t)
);
IntVec3 bestCell = IntVec3.Invalid;
float bestDistSq = float.MaxValue;
foreach (Zone zone in pawn.Map.zoneManager.AllZones)
{
if (zone is Zone_Growing growingZone)
{
// 遍历区域中的所有单元格
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 类型
@@ -97,7 +111,6 @@ namespace ArachnaeSwarm
public static class WorkGiverDefOf
{
public static WorkGiverDef GrowerHarvest;
public static WorkGiverDef GrowerSow;
static WorkGiverDefOf()
{