diff --git a/1.6/1.6/Assemblies/ArachnaeSwarm.dll b/1.6/1.6/Assemblies/ArachnaeSwarm.dll index c1336e9..e4ab335 100644 Binary files a/1.6/1.6/Assemblies/ArachnaeSwarm.dll and b/1.6/1.6/Assemblies/ArachnaeSwarm.dll differ diff --git a/1.6/1.6/Assemblies/ArachnaeSwarm.pdb b/1.6/1.6/Assemblies/ArachnaeSwarm.pdb index ad94408..e8974e3 100644 Binary files a/1.6/1.6/Assemblies/ArachnaeSwarm.pdb and b/1.6/1.6/Assemblies/ArachnaeSwarm.pdb differ diff --git a/1.6/1.6/Defs/Thing_Misc/Apparels/ARA_Apparel.xml b/1.6/1.6/Defs/Thing_Misc/Apparels/ARA_Apparel.xml index d74e626..b1cb50e 100644 --- a/1.6/1.6/Defs/Thing_Misc/Apparels/ARA_Apparel.xml +++ b/1.6/1.6/Defs/Thing_Misc/Apparels/ARA_Apparel.xml @@ -59,6 +59,7 @@
  • ARA_Equipment_Ootheca
  • +
  • ARA_BioforgeIncubator_Thing
  • @@ -87,6 +88,7 @@
  • ARA_Equipment_Ootheca
  • +
  • ARA_BioforgeIncubator_Thing
  • @@ -115,6 +117,7 @@
  • ARA_Equipment_Ootheca
  • +
  • ARA_BioforgeIncubator_Thing
  • @@ -143,6 +146,7 @@
  • ARA_Equipment_Ootheca
  • +
  • ARA_BioforgeIncubator_Thing
  • @@ -171,6 +175,7 @@
  • ARA_Equipment_Ootheca
  • +
  • ARA_BioforgeIncubator_Thing
  • @@ -298,6 +303,7 @@
  • ARA_Equipment_Ootheca
  • +
  • ARA_BioforgeIncubator_Thing
  • @@ -344,6 +350,7 @@
  • ARA_Equipment_Ootheca
  • +
  • ARA_BioforgeIncubator_Thing
  • @@ -390,6 +397,7 @@
  • ARA_Equipment_Ootheca
  • +
  • ARA_BioforgeIncubator_Thing
  • @@ -437,6 +445,7 @@
  • ARA_Equipment_Ootheca
  • +
  • ARA_BioforgeIncubator_Thing
  • @@ -486,6 +495,7 @@
  • ARA_Equipment_Ootheca
  • +
  • ARA_BioforgeIncubator_Thing
  • @@ -535,6 +545,7 @@
  • ARA_Equipment_Ootheca
  • +
  • ARA_BioforgeIncubator_Thing
  • @@ -582,6 +593,7 @@
  • ARA_Equipment_Ootheca
  • +
  • ARA_BioforgeIncubator_Thing
  • @@ -659,6 +671,7 @@
  • ARA_Equipment_Ootheca
  • +
  • ARA_BioforgeIncubator_Thing
  • @@ -708,6 +721,7 @@
  • ARA_Equipment_Ootheca
  • +
  • ARA_BioforgeIncubator_Thing
  • diff --git a/1.6/1.6/Defs/Thing_Misc/Weapons/ARA_Weapon.xml b/1.6/1.6/Defs/Thing_Misc/Weapons/ARA_Weapon.xml index 66d1218..46c8317 100644 --- a/1.6/1.6/Defs/Thing_Misc/Weapons/ARA_Weapon.xml +++ b/1.6/1.6/Defs/Thing_Misc/Weapons/ARA_Weapon.xml @@ -71,6 +71,7 @@
  • ARA_Equipment_Ootheca
  • +
  • ARA_BioforgeIncubator_Thing
  • @@ -137,6 +138,7 @@
  • ARA_Equipment_Ootheca
  • +
  • ARA_BioforgeIncubator_Thing
  • @@ -212,6 +214,7 @@
  • ARA_Equipment_Ootheca
  • +
  • ARA_BioforgeIncubator_Thing
  • @@ -321,6 +324,7 @@
  • ARA_Equipment_Ootheca
  • +
  • ARA_BioforgeIncubator_Thing
  • @@ -414,6 +418,7 @@
  • ARA_Equipment_Ootheca
  • +
  • ARA_BioforgeIncubator_Thing
  • @@ -507,6 +512,7 @@
  • ARA_Equipment_Ootheca
  • +
  • ARA_BioforgeIncubator_Thing
  • @@ -627,6 +633,7 @@
  • ARA_Equipment_Ootheca
  • +
  • ARA_BioforgeIncubator_Thing
  • @@ -741,6 +748,7 @@
  • ARA_Equipment_Ootheca
  • +
  • ARA_BioforgeIncubator_Thing
  • @@ -839,6 +847,7 @@
  • ARA_Equipment_Ootheca
  • +
  • ARA_BioforgeIncubator_Thing
  • @@ -950,6 +959,7 @@
  • ARA_Equipment_Ootheca
  • +
  • ARA_BioforgeIncubator_Thing
  • @@ -1095,6 +1105,7 @@
  • ARA_Equipment_Ootheca
  • +
  • ARA_BioforgeIncubator_Thing
  • @@ -1209,6 +1220,7 @@
  • ARA_Equipment_Ootheca
  • +
  • ARA_BioforgeIncubator_Thing
  • @@ -1338,6 +1350,7 @@
  • ARA_Equipment_Ootheca
  • +
  • ARA_BioforgeIncubator_Thing
  • @@ -1469,6 +1482,7 @@
  • ARA_Equipment_Ootheca
  • +
  • ARA_BioforgeIncubator_Thing
  • @@ -1622,6 +1636,7 @@
  • ARA_Equipment_Ootheca
  • +
  • ARA_BioforgeIncubator_Thing
  • diff --git a/Source/ArachnaeSwarm/Building_Comps/ARA_CompInteractiveProducer/CompQueuedInteractiveProducerWithFlux.cs b/Source/ArachnaeSwarm/Building_Comps/ARA_CompInteractiveProducer/CompQueuedInteractiveProducerWithFlux.cs index 2c828e9..432c956 100644 --- a/Source/ArachnaeSwarm/Building_Comps/ARA_CompInteractiveProducer/CompQueuedInteractiveProducerWithFlux.cs +++ b/Source/ArachnaeSwarm/Building_Comps/ARA_CompInteractiveProducer/CompQueuedInteractiveProducerWithFlux.cs @@ -179,52 +179,70 @@ namespace ArachnaeSwarm } // === 幼虫激活逻辑 === + // 每次只呼叫一只幼虫,避免预留冲突 private void CallLarvae() { - int neededLarvae = WaitingForLarvaCount - assignedLarvae.Count; - if (neededLarvae <= 0) + if (assignedLarvae.Count > 0) + { + Messages.Message("已有幼虫正在工作中,请等待完成", MessageTypeDefOf.RejectInput); + return; + } + + if (WaitingForLarvaCount <= 0) { Messages.Message("没有需要激活的订单", MessageTypeDefOf.RejectInput); return; } - int called = 0; - var availableLarvae = FindAvailableLarvae(neededLarvae); - foreach (var larva in availableLarvae) - { - var job = JobMaker.MakeJob(DefDatabase.GetNamed("ARA_OperateIncubator"), parent); - if (larva.jobs.TryTakeOrderedJob(job, JobTag.Misc)) - { - assignedLarvae.Add(larva); - called++; - } - } - - if (called > 0) - Messages.Message($"已呼叫 {called} 只幼虫", MessageTypeDefOf.PositiveEvent); - else - Messages.Message("未找到可用的幼虫!", MessageTypeDefOf.RejectInput); + CallOneLarva(true); } - private List FindAvailableLarvae(int maxCount) + private bool CallOneLarva(bool showMessage) { - var result = new List(); - float searchRadius = 50f; - if (parent.Map == null) return result; + var larva = FindOneLarva(); + if (larva == null) + { + if (showMessage) + Messages.Message("未找到可用的幼虫!", MessageTypeDefOf.RejectInput); + return false; + } + + var job = JobMaker.MakeJob(DefDatabase.GetNamed("ARA_OperateIncubator"), parent); + if (larva.jobs.TryTakeOrderedJob(job, JobTag.Misc)) + { + assignedLarvae.Add(larva); + if (showMessage) + Messages.Message("已呼叫幼虫", MessageTypeDefOf.PositiveEvent); + return true; + } + else + { + if (showMessage) + Messages.Message("幼虫无法接受任务", MessageTypeDefOf.RejectInput); + return false; + } + } + + private Pawn FindOneLarva() + { + if (parent.Map == null) return null; foreach (var pawn in parent.Map.mapPawns.AllPawnsSpawned) { - if (result.Count >= maxCount) break; - if (pawn.def.defName == "ArachnaeBase_Race_Larva" && - !pawn.Downed && !pawn.Dead && - pawn.Faction == parent.Faction && - !assignedLarvae.Contains(pawn) && - parent.Position.DistanceTo(pawn.Position) <= searchRadius) - { - result.Add(pawn); - } + if (pawn.def.defName != "ArachnaeBase_Race_Larva") continue; + if (pawn.Downed || pawn.Dead) continue; + if (pawn.Faction != parent.Faction) continue; + if (assignedLarvae.Contains(pawn)) continue; + + bool isBusy = pawn.CurJobDef != null && + pawn.CurJobDef != JobDefOf.Wait_Wander && + pawn.CurJobDef != JobDefOf.GotoWander && + pawn.CurJobDef.defName != "Wait"; + if (isBusy) continue; + + return pawn; } - return result; + return null; } public void NotifyLarvaArrived(Pawn larva) { } @@ -240,6 +258,12 @@ namespace ArachnaeSwarm waitingOrder.qualityProgress = 0f; } assignedLarvae.Remove(larva); + + // 自动呼叫下一只幼虫 + if (WaitingForLarvaCount > 0 && assignedLarvae.Count == 0) + { + CallOneLarva(false); + } } // === Tick 逻辑 === @@ -247,7 +271,12 @@ namespace ArachnaeSwarm { base.CompTick(); - assignedLarvae.RemoveAll(l => l == null || l.Dead || l.Destroyed); + // 清理无效的幼虫 + assignedLarvae.RemoveAll(l => + l == null || l.Dead || l.Destroyed || + l.CurJobDef == null || + l.CurJobDef.defName != "ARA_OperateIncubator" || + l.CurJob?.targetA.Thing != parent); bool hasFuel = (FuelComp?.Fuel ?? 10f) > 0.01f; @@ -388,17 +417,27 @@ namespace ArachnaeSwarm }; } - int needed = WaitingForLarvaCount - assignedLarvae.Count; - if (needed > 0) + // 呼叫幼虫按钮 + if (WaitingForLarvaCount > 0 && assignedLarvae.Count == 0) { yield return new Command_Action { - defaultLabel = $"呼叫幼虫 ({needed})", - defaultDesc = $"呼叫 {needed} 只幼虫来激活等待中的订单", + defaultLabel = "呼叫幼虫", + defaultDesc = $"呼叫一只幼虫来激活下一个订单(还有{WaitingForLarvaCount}个等待中)", icon = ContentFinder.Get("ArachnaeSwarm/UI/Commands/ARA_CallLarva", false), action = CallLarvae }; } + else if (WaitingForLarvaCount > 0 && assignedLarvae.Count > 0) + { + yield return new Command_Action + { + defaultLabel = "幼虫工作中", + defaultDesc = $"一只幼虫正在操作孵化器(还有{WaitingForLarvaCount}个订单等待)", + icon = ContentFinder.Get("ArachnaeSwarm/UI/Commands/ARA_CallLarva", false), + Disabled = true + }; + } } public void ShowOrderMenuPublic() => ShowOrderMenu(); diff --git a/Source/ArachnaeSwarm/Building_Comps/ARA_SpawnPawnFromList/CompQueuedPawnSpawnerWithFlux.cs b/Source/ArachnaeSwarm/Building_Comps/ARA_SpawnPawnFromList/CompQueuedPawnSpawnerWithFlux.cs index 92415ec..19c26f9 100644 --- a/Source/ArachnaeSwarm/Building_Comps/ARA_SpawnPawnFromList/CompQueuedPawnSpawnerWithFlux.cs +++ b/Source/ArachnaeSwarm/Building_Comps/ARA_SpawnPawnFromList/CompQueuedPawnSpawnerWithFlux.cs @@ -183,47 +183,59 @@ namespace ArachnaeSwarm } // === 幼虫激活逻辑 === + // 每次只呼叫一只幼虫,避免预留冲突 private void CallLarvae() { - int neededLarvae = WaitingForLarvaCount - assignedLarvae.Count; - if (neededLarvae <= 0) + // 检查是否已有幼虫在工作/路上 + if (assignedLarvae.Count > 0) + { + Messages.Message("已有幼虫正在工作中,请等待完成", MessageTypeDefOf.RejectInput); + return; + } + + if (WaitingForLarvaCount <= 0) { Messages.Message("没有需要激活的订单", MessageTypeDefOf.RejectInput); return; } - int called = 0; - int found = 0; - var availableLarvae = FindAvailableLarvae(neededLarvae * 2); - found = availableLarvae.Count; - - foreach (var larva in availableLarvae) - { - if (called >= neededLarvae) break; - - var job = JobMaker.MakeJob(DefDatabase.GetNamed("ARA_OperateIncubator"), parent); - if (larva.jobs.TryTakeOrderedJob(job, JobTag.Misc)) - { - assignedLarvae.Add(larva); - called++; - } - } - - if (called > 0) - Messages.Message($"已呼叫 {called} 只幼虫 (找到{found}只)", MessageTypeDefOf.PositiveEvent); - else - Messages.Message($"未找到可用的幼虫! (需要{neededLarvae}只,找到{found}只)", MessageTypeDefOf.RejectInput); + // 只呼叫一只幼虫 + CallOneLarva(true); } - private List FindAvailableLarvae(int maxCount) + // 呼叫单只幼虫 + private bool CallOneLarva(bool showMessage) { - var result = new List(); - if (parent.Map == null) return result; + var larva = FindOneLarva(); + if (larva == null) + { + if (showMessage) + Messages.Message("未找到可用的幼虫!", MessageTypeDefOf.RejectInput); + return false; + } + + var job = JobMaker.MakeJob(DefDatabase.GetNamed("ARA_OperateIncubator"), parent); + if (larva.jobs.TryTakeOrderedJob(job, JobTag.Misc)) + { + assignedLarvae.Add(larva); + if (showMessage) + Messages.Message("已呼叫幼虫", MessageTypeDefOf.PositiveEvent); + return true; + } + else + { + if (showMessage) + Messages.Message("幼虫无法接受任务", MessageTypeDefOf.RejectInput); + return false; + } + } + + private Pawn FindOneLarva() + { + if (parent.Map == null) return null; foreach (var pawn in parent.Map.mapPawns.AllPawnsSpawned) { - if (result.Count >= maxCount) break; - if (pawn.def.defName != "ArachnaeBase_Race_Larva") continue; if (pawn.Downed || pawn.Dead) continue; if (pawn.Faction != parent.Faction) continue; @@ -235,9 +247,9 @@ namespace ArachnaeSwarm pawn.CurJobDef.defName != "Wait"; if (isBusy) continue; - result.Add(pawn); + return pawn; } - return result; + return null; } public void NotifyLarvaArrived(Pawn larva) { } @@ -254,6 +266,12 @@ namespace ArachnaeSwarm waitingOrder.qualityProgress = 0f; } assignedLarvae.Remove(larva); + + // 自动呼叫下一只幼虫(如果还有等待订单) + if (WaitingForLarvaCount > 0 && assignedLarvae.Count == 0) + { + CallOneLarva(false); + } } // === Tick 逻辑 === @@ -261,7 +279,12 @@ namespace ArachnaeSwarm { base.CompTick(); - assignedLarvae.RemoveAll(l => l == null || l.Dead || l.Destroyed); + // 清理无效的幼虫:死亡、销毁、或不再执行来孵化器的任务 + assignedLarvae.RemoveAll(l => + l == null || l.Dead || l.Destroyed || + l.CurJobDef == null || + l.CurJobDef.defName != "ARA_OperateIncubator" || + l.CurJob?.targetA.Thing != parent); bool hasFuel = (FuelComp?.Fuel ?? 10f) > 0.01f; @@ -393,17 +416,28 @@ namespace ArachnaeSwarm }; } - int needed = WaitingForLarvaCount - assignedLarvae.Count; - if (needed > 0) + // 呼叫幼虫按钮:只有没有幼虫在工作且有等待订单时显示 + if (WaitingForLarvaCount > 0 && assignedLarvae.Count == 0) { yield return new Command_Action { - defaultLabel = $"呼叫幼虫 ({needed})", - defaultDesc = $"呼叫 {needed} 只幼虫来激活等待中的订单", + defaultLabel = $"呼叫幼虫", + defaultDesc = $"呼叫一只幼虫来激活下一个订单(还有{WaitingForLarvaCount}个等待中)", icon = ContentFinder.Get("ArachnaeSwarm/UI/Commands/ARA_CallLarva", false), action = CallLarvae }; } + else if (WaitingForLarvaCount > 0 && assignedLarvae.Count > 0) + { + // 显示幼虫正在工作的状态 + yield return new Command_Action + { + defaultLabel = "幼虫工作中", + defaultDesc = $"一只幼虫正在操作孵化器(还有{WaitingForLarvaCount}个订单等待)", + icon = ContentFinder.Get("ArachnaeSwarm/UI/Commands/ARA_CallLarva", false), + Disabled = true + }; + } } public void ShowOrderMenuPublic() => ShowOrderMenu();