1
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
using System.Linq;
|
||||
using HarmonyLib;
|
||||
using RimWorld.Planet;
|
||||
using System.Linq;
|
||||
using Verse;
|
||||
using WulaFallenEmpire;
|
||||
|
||||
namespace WulaFallenEmpire
|
||||
{
|
||||
@@ -11,7 +12,7 @@ namespace WulaFallenEmpire
|
||||
[HarmonyPrefix]
|
||||
public static bool Prefix(MapParent __instance)
|
||||
{
|
||||
// 如果该 MapParent 没有地图,则直接放行,执行原方法(虽然原方法也会检查 HasMap,但这里提前返回更清晰)
|
||||
// 如果该 MapParent 没有地图,则直接放行
|
||||
if (!__instance.HasMap)
|
||||
{
|
||||
return true;
|
||||
@@ -19,25 +20,34 @@ namespace WulaFallenEmpire
|
||||
|
||||
try
|
||||
{
|
||||
// 在当前地图上查找所有武装穿梭机
|
||||
// 检查是否有活跃的观察者正在监测这个地图
|
||||
bool isBeingObserved = Building_MapObserver.activeObservers
|
||||
.Any(observer => observer.IsObservingMap(__instance));
|
||||
|
||||
if (isBeingObserved)
|
||||
{
|
||||
// 如果地图正在被监测,阻止地图被移除
|
||||
Log.Message($"[MapObserver] 阻止地图移除: {__instance.Label} 正在被监测");
|
||||
return false;
|
||||
}
|
||||
|
||||
// 原有的穿梭机检查逻辑(保留你的原有功能)
|
||||
foreach (var shuttle in __instance.Map.listerBuildings.AllBuildingsColonistOfClass<Building_ArmedShuttleWithPocket>())
|
||||
{
|
||||
// 检查穿梭机是否有已生成的口袋地图,并且该地图里是否有人
|
||||
if (shuttle != null && shuttle.PocketMapGenerated && shuttle.PocketMap != null && shuttle.PocketMap.mapPawns.AnyPawnBlockingMapRemoval)
|
||||
{
|
||||
// 如果找到了这样的穿梭机,则阻止原方法 CheckRemoveMapNow 的执行,从而阻止地图被移除。
|
||||
// Log.Message($"[WULA] Prevented removal of map '{__instance.Map}' because shuttle '{shuttle.Label}' still contains pawns in its pocket dimension.");
|
||||
return false; // 返回 false 以跳过原方法的执行
|
||||
Log.Message($"[WULA] 阻止地图移除: 穿梭机 '{shuttle.Label}' 的口袋维度中仍有生物");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (System.Exception ex)
|
||||
{
|
||||
Log.Error($"[WULA] Error in MapParent_CheckRemoveMapNow_Patch Prefix: {ex}");
|
||||
Log.Error($"[MapObserver] MapParent_CheckRemoveMapNow_Patch 错误: {ex}");
|
||||
}
|
||||
|
||||
// 如果没有找到需要保护的穿梭机,则允许原方法 CheckRemoveMapNow 继续执行其正常的逻辑
|
||||
// 如果没有找到需要保护的情况,允许原方法继续执行
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user