fix(feed-with-honey): avoid modified-collection crash in workgiver scan
- Snapshot `AllPawnsSpawned` with `ToList()` before iteration in `WorkGiver_FeedWithHoney` - Apply the same fix in both `ArachnaeSwarm` and `KalospacerRWLib` - Add `otherPawn.CurJob != null` guard to prevent potential NRE during target checks
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -1,5 +1,6 @@
|
|||||||
using RimWorld;
|
using RimWorld;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using Verse;
|
using Verse;
|
||||||
using Verse.AI;
|
using Verse.AI;
|
||||||
|
|
||||||
@@ -17,7 +18,7 @@ namespace ArachnaeSwarm
|
|||||||
// 扫描所有需要喂食的Pawn(没有蜜罐需求但需要食物的虫族成员)
|
// 扫描所有需要喂食的Pawn(没有蜜罐需求但需要食物的虫族成员)
|
||||||
public override IEnumerable<Thing> PotentialWorkThingsGlobal(Pawn pawn)
|
public override IEnumerable<Thing> PotentialWorkThingsGlobal(Pawn pawn)
|
||||||
{
|
{
|
||||||
IReadOnlyList<Pawn> allPawns = pawn.Map.mapPawns.AllPawnsSpawned;
|
List<Pawn> allPawns = pawn.Map.mapPawns.AllPawnsSpawned.ToList();
|
||||||
List<Thing> workThings = new List<Thing>();
|
List<Thing> workThings = new List<Thing>();
|
||||||
|
|
||||||
foreach (Pawn potentialPawn in allPawns)
|
foreach (Pawn potentialPawn in allPawns)
|
||||||
@@ -154,11 +155,12 @@ namespace ArachnaeSwarm
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
// 检查是否有其他虫族正在向这个Pawn移动以喂食
|
// 检查是否有其他虫族正在向这个Pawn移动以喂食
|
||||||
IReadOnlyList<Pawn> allPawns = pawn.Map.mapPawns.AllPawnsSpawned;
|
List<Pawn> allPawns = pawn.Map.mapPawns.AllPawnsSpawned.ToList();
|
||||||
foreach (Pawn otherPawn in allPawns)
|
foreach (Pawn otherPawn in allPawns)
|
||||||
{
|
{
|
||||||
if (otherPawn != pawn &&
|
if (otherPawn != pawn &&
|
||||||
otherPawn.CurJobDef == ARA_JobDefOf.ARA_FeedWithHoney &&
|
otherPawn.CurJobDef == ARA_JobDefOf.ARA_FeedWithHoney &&
|
||||||
|
otherPawn.CurJob != null &&
|
||||||
otherPawn.CurJob.targetA.Thing == pawn)
|
otherPawn.CurJob.targetA.Thing == pawn)
|
||||||
{
|
{
|
||||||
return false; // 已经有人正在喂食这个Pawn
|
return false; // 已经有人正在喂食这个Pawn
|
||||||
|
|||||||
Reference in New Issue
Block a user