Merge branch 'pocketmapfix' of https://git.ra3battle.cn/Kalospacer/WulaFallenEmpireRW into pocketmapfix

This commit is contained in:
2025-09-01 15:35:20 +08:00
2 changed files with 34 additions and 2 deletions

View File

@@ -45,4 +45,4 @@ namespace WulaFallenEmpire
return true; // 返回 true 来继续执行原始方法
}
}
}
}

View File

@@ -71,7 +71,7 @@ namespace WulaFallenEmpire
#endregion
#region
/// <summary>获取内部口袋地图</summary>
public Map PocketMap => pocketMap;
@@ -994,6 +994,38 @@ namespace WulaFallenEmpire
IntVec3 oldPos = this.Position;
base.SpawnSetup(map, respawningAfterLoad);
// [核心修复] 当穿梭机降落时,恢复其口袋地图的父级和在游戏中的注册状态
if (pocketMap != null && pocketMapGenerated)
{
// 验证口袋地图的父级对象是否存在于世界列表中
if (pocketMap.Parent is PocketMapParent pocketParent && !Find.World.pocketMaps.Contains(pocketParent))
{
Log.Warning($"[WULA] Pocket map parent for map ID {pocketMap.uniqueID} was not found in the world list. Re-adding it to prevent data loss.");
Find.World.pocketMaps.Add(pocketParent);
}
// 验证口袋地图本身是否存在于游戏地图列表中
if (!Find.Maps.Contains(pocketMap))
{
Log.Warning($"[WULA] Pocket map ID {pocketMap.uniqueID} was not found in the game's map list. Re-registering it.");
// 在重新添加前,进行安全检查,防止添加已损坏的地图
if (!Find.Maps.Contains(pocketMap) && (pocketMap.mapPawns == null || pocketMap.Tile < 0))
{
Log.Error("[WULA] Cannot re-register a corrupted pocket map. The contents of the pocket space are likely lost. This is a critical error.");
Messages.Message("WULA.PocketSpace.MapInvalidAndRecovering".Translate(), this, MessageTypeDefOf.NegativeEvent);
pocketMap = null;
pocketMapGenerated = false;
}
else
{
// 重新注册地图,使其再次“激活”
Current.Game.AddMap(pocketMap);
Log.Message($"[WULA] Pocket map {pocketMap.uniqueID} successfully re-registered.");
}
}
}
// 更新退出点目标,确保它指向当前的新地图
UpdateExitPointTarget();