优化空投仓配置,添加调试日志以处理派系解析和投掷中心边界验证

This commit is contained in:
2026-02-17 13:58:49 +08:00
parent cda002ea9e
commit 4c2bf41f19
3 changed files with 37 additions and 26 deletions

Binary file not shown.

Binary file not shown.

View File

@@ -231,12 +231,14 @@ namespace ArachnaeSwarm
{
Faction faction = Find.FactionManager.FirstFactionOfDef(Props.pawnFactionDef);
if (faction != null) return faction;
ArachnaeLog.Debug($"[WARN] FactionDef '{Props.pawnFactionDef.defName}' not found in current world, trying fallback");
}
// 使用 Comp 的派系
if (Props.faction != null) return Props.faction;
// 使用默认中立派系
// 使用默认中立派系(记录警告以便排查配置问题)
ArachnaeLog.Debug("[WARN] No valid faction resolved for pawn generation, falling back to Faction.OfAncients");
return Faction.OfAncients;
}
@@ -521,8 +523,11 @@ namespace ArachnaeSwarm
if (Props.dropAllInSamePod)
{
// 所有物品在一个空投仓中,但生成多个相同的空投仓
for (int i = 0; i < Props.dropCount; i++)
// 第一个空投仓使用原始物品(包含 Pawn
podGroups.Add(new List<Thing>(thingsToDrop));
// 后续空投仓仅复制非 Pawn 物品,避免 Pawn 重复生成
for (int i = 1; i < Props.dropCount; i++)
{
List<Thing> podItems = CreatePodItemsCopy(thingsToDrop);
podGroups.Add(podItems);
@@ -570,36 +575,30 @@ namespace ArachnaeSwarm
}
}
// 创建物品的深拷贝
// 创建非 Pawn 物品的深拷贝Pawn 是唯一实体,不可复制)
private List<Thing> CreatePodItemsCopy(List<Thing> originalItems)
{
List<Thing> copies = new List<Thing>();
foreach (Thing original in originalItems)
{
if (original is Pawn originalPawn)
// Pawn 是唯一实体不能复制Pawn 只在第一个空投仓中投掷
if (original is Pawn)
{
// 对于 Pawn重新生成
Pawn newPawn = GeneratePawn(originalPawn.kindDef);
if (newPawn != null)
{
copies.Add(newPawn);
}
continue;
}
else
// 对于物品,创建副本
Thing copy = ThingMaker.MakeThing(original.def, original.Stuff);
copy.stackCount = original.stackCount;
// 复制其他重要属性
if (original.def.useHitPoints)
{
// 对于物品,创建副本
Thing copy = ThingMaker.MakeThing(original.def, original.Stuff);
copy.stackCount = original.stackCount;
// 复制其他重要属性
if (original.def.useHitPoints)
{
copy.HitPoints = original.HitPoints;
}
copies.Add(copy);
copy.HitPoints = original.HitPoints;
}
copies.Add(copy);
}
return copies;
@@ -607,6 +606,12 @@ namespace ArachnaeSwarm
private IntVec3 GetDropCenter(FlyOver flyOver)
{
// 如果使用贸易空投点,直接使用原版方法(已包含位置验证)
if (Props.useTradeDropSpot)
{
return DropCellFinder.TradeDropSpot(flyOver.Map);
}
// 计算投掷中心位置(基于当前飞行位置 + 偏移)
Vector3 currentPos = Vector3.Lerp(
flyOver.startPosition.ToVector3(),
@@ -615,11 +620,17 @@ namespace ArachnaeSwarm
);
IntVec3 dropCenter = currentPos.ToIntVec3() + Props.dropOffset;
Map map = flyOver.Map;
// 如果使用贸易空投点,找到贸易空投点
if (Props.useTradeDropSpot)
// 边界验证:确保投掷中心在地图范围内
if (!dropCenter.InBounds(map))
{
dropCenter = DropCellFinder.TradeDropSpot(flyOver.Map);
dropCenter = new IntVec3(
Mathf.Clamp(dropCenter.x, 0, map.Size.x - 1),
0,
Mathf.Clamp(dropCenter.z, 0, map.Size.z - 1)
);
ArachnaeLog.Debug($"Drop center out of bounds, clamped to {dropCenter}");
}
return dropCenter;