优化空投仓配置,添加调试日志以处理派系解析和投掷中心边界验证
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -231,12 +231,14 @@ namespace ArachnaeSwarm
|
|||||||
{
|
{
|
||||||
Faction faction = Find.FactionManager.FirstFactionOfDef(Props.pawnFactionDef);
|
Faction faction = Find.FactionManager.FirstFactionOfDef(Props.pawnFactionDef);
|
||||||
if (faction != null) return faction;
|
if (faction != null) return faction;
|
||||||
|
ArachnaeLog.Debug($"[WARN] FactionDef '{Props.pawnFactionDef.defName}' not found in current world, trying fallback");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 使用 Comp 的派系
|
// 使用 Comp 的派系
|
||||||
if (Props.faction != null) return Props.faction;
|
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;
|
return Faction.OfAncients;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -521,8 +523,11 @@ namespace ArachnaeSwarm
|
|||||||
|
|
||||||
if (Props.dropAllInSamePod)
|
if (Props.dropAllInSamePod)
|
||||||
{
|
{
|
||||||
// 所有物品在一个空投仓中,但生成多个相同的空投仓
|
// 第一个空投仓使用原始物品(包含 Pawn)
|
||||||
for (int i = 0; i < Props.dropCount; i++)
|
podGroups.Add(new List<Thing>(thingsToDrop));
|
||||||
|
|
||||||
|
// 后续空投仓仅复制非 Pawn 物品,避免 Pawn 重复生成
|
||||||
|
for (int i = 1; i < Props.dropCount; i++)
|
||||||
{
|
{
|
||||||
List<Thing> podItems = CreatePodItemsCopy(thingsToDrop);
|
List<Thing> podItems = CreatePodItemsCopy(thingsToDrop);
|
||||||
podGroups.Add(podItems);
|
podGroups.Add(podItems);
|
||||||
@@ -570,36 +575,30 @@ namespace ArachnaeSwarm
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建物品的深拷贝
|
// 创建非 Pawn 物品的深拷贝(Pawn 是唯一实体,不可复制)
|
||||||
private List<Thing> CreatePodItemsCopy(List<Thing> originalItems)
|
private List<Thing> CreatePodItemsCopy(List<Thing> originalItems)
|
||||||
{
|
{
|
||||||
List<Thing> copies = new List<Thing>();
|
List<Thing> copies = new List<Thing>();
|
||||||
|
|
||||||
foreach (Thing original in originalItems)
|
foreach (Thing original in originalItems)
|
||||||
{
|
{
|
||||||
if (original is Pawn originalPawn)
|
// Pawn 是唯一实体,不能复制;Pawn 只在第一个空投仓中投掷
|
||||||
|
if (original is Pawn)
|
||||||
{
|
{
|
||||||
// 对于 Pawn,重新生成
|
continue;
|
||||||
Pawn newPawn = GeneratePawn(originalPawn.kindDef);
|
|
||||||
if (newPawn != null)
|
|
||||||
{
|
|
||||||
copies.Add(newPawn);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
// 对于物品,创建副本
|
||||||
|
Thing copy = ThingMaker.MakeThing(original.def, original.Stuff);
|
||||||
|
copy.stackCount = original.stackCount;
|
||||||
|
|
||||||
|
// 复制其他重要属性
|
||||||
|
if (original.def.useHitPoints)
|
||||||
{
|
{
|
||||||
// 对于物品,创建副本
|
copy.HitPoints = original.HitPoints;
|
||||||
Thing copy = ThingMaker.MakeThing(original.def, original.Stuff);
|
|
||||||
copy.stackCount = original.stackCount;
|
|
||||||
|
|
||||||
// 复制其他重要属性
|
|
||||||
if (original.def.useHitPoints)
|
|
||||||
{
|
|
||||||
copy.HitPoints = original.HitPoints;
|
|
||||||
}
|
|
||||||
|
|
||||||
copies.Add(copy);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
copies.Add(copy);
|
||||||
}
|
}
|
||||||
|
|
||||||
return copies;
|
return copies;
|
||||||
@@ -607,6 +606,12 @@ namespace ArachnaeSwarm
|
|||||||
|
|
||||||
private IntVec3 GetDropCenter(FlyOver flyOver)
|
private IntVec3 GetDropCenter(FlyOver flyOver)
|
||||||
{
|
{
|
||||||
|
// 如果使用贸易空投点,直接使用原版方法(已包含位置验证)
|
||||||
|
if (Props.useTradeDropSpot)
|
||||||
|
{
|
||||||
|
return DropCellFinder.TradeDropSpot(flyOver.Map);
|
||||||
|
}
|
||||||
|
|
||||||
// 计算投掷中心位置(基于当前飞行位置 + 偏移)
|
// 计算投掷中心位置(基于当前飞行位置 + 偏移)
|
||||||
Vector3 currentPos = Vector3.Lerp(
|
Vector3 currentPos = Vector3.Lerp(
|
||||||
flyOver.startPosition.ToVector3(),
|
flyOver.startPosition.ToVector3(),
|
||||||
@@ -615,11 +620,17 @@ namespace ArachnaeSwarm
|
|||||||
);
|
);
|
||||||
|
|
||||||
IntVec3 dropCenter = currentPos.ToIntVec3() + Props.dropOffset;
|
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;
|
return dropCenter;
|
||||||
|
|||||||
Reference in New Issue
Block a user