修穿梭机空间
This commit is contained in:
Binary file not shown.
48
Source/WulaFallenEmpire/Harmony/MapLifecycle_Patches.cs
Normal file
48
Source/WulaFallenEmpire/Harmony/MapLifecycle_Patches.cs
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
using System;
|
||||||
|
using HarmonyLib;
|
||||||
|
using RimWorld.Planet;
|
||||||
|
using Verse;
|
||||||
|
|
||||||
|
namespace WulaFallenEmpire
|
||||||
|
{
|
||||||
|
[HarmonyPatch(typeof(MapParent), "ShouldRemoveMapNow")]
|
||||||
|
[HarmonyPriority(600)]
|
||||||
|
public static class MapParent_ShouldRemoveMapNow_Patch
|
||||||
|
{
|
||||||
|
public static void Postfix(ref bool __result, MapParent __instance)
|
||||||
|
{
|
||||||
|
if (!__result)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (__instance.HasMap && WulaMapProtectionHelper.ShouldProtectMap(__instance.Map))
|
||||||
|
{
|
||||||
|
__result = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception arg)
|
||||||
|
{
|
||||||
|
Log.Error($"[WULA] Error in MapParent_ShouldRemoveMapNow_Patch: {arg}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HarmonyPatch(typeof(Game), "DeinitAndRemoveMap")]
|
||||||
|
[HarmonyPatch(new Type[] { typeof(Map), typeof(bool) })]
|
||||||
|
[HarmonyPriority(600)]
|
||||||
|
public static class Game_DeinitAndRemoveMap_Patch
|
||||||
|
{
|
||||||
|
[HarmonyPrefix]
|
||||||
|
private static bool PreventMapRemoval(Map map)
|
||||||
|
{
|
||||||
|
if (WulaMapProtectionHelper.ShouldProtectMap(map))
|
||||||
|
{
|
||||||
|
Log.Message("[WULA] Map destruction prevented by WulaMapProtectionHelper at Game.DeinitAndRemoveMap level.");
|
||||||
|
return false; // 返回 false 来阻止原始方法的执行
|
||||||
|
}
|
||||||
|
return true; // 返回 true 来继续执行原始方法
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
28
Source/WulaFallenEmpire/Harmony/WulaMapProtectionHelper.cs
Normal file
28
Source/WulaFallenEmpire/Harmony/WulaMapProtectionHelper.cs
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using Verse;
|
||||||
|
|
||||||
|
namespace WulaFallenEmpire
|
||||||
|
{
|
||||||
|
public static class WulaMapProtectionHelper
|
||||||
|
{
|
||||||
|
public static bool ShouldProtectMap(Map map)
|
||||||
|
{
|
||||||
|
if (map == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// 检查地图上是否存在一个口袋空间已经初始化的武装穿梭机
|
||||||
|
return map.listerThings.AllThings.OfType<Building_ArmedShuttleWithPocket>()
|
||||||
|
.Any(shuttle => shuttle != null && shuttle.Spawned && shuttle.PocketMapGenerated);
|
||||||
|
}
|
||||||
|
catch (Exception arg)
|
||||||
|
{
|
||||||
|
Log.Error($"[WULA] Error in WulaMapProtectionHelper.ShouldProtectMap: {arg}");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -356,7 +356,6 @@ namespace WulaFallenEmpire
|
|||||||
command_Toggle.isActive = () => holdFire;
|
command_Toggle.isActive = () => holdFire;
|
||||||
yield return command_Toggle;
|
yield return command_Toggle;
|
||||||
}
|
}
|
||||||
Log.Message($"[WULA] Stage 2: Launch Sequence - Providing launch gizmos for {this.Label}.");
|
|
||||||
// The following gizmos are already provided by Building_PassengerShuttle's GetGizmos()
|
// The following gizmos are already provided by Building_PassengerShuttle's GetGizmos()
|
||||||
// foreach (Gizmo gizmo in ShuttleComp.CompGetGizmosExtra()) yield return gizmo;
|
// foreach (Gizmo gizmo in ShuttleComp.CompGetGizmosExtra()) yield return gizmo;
|
||||||
// foreach (Gizmo gizmo in LaunchableComp.CompGetGizmosExtra()) yield return gizmo;
|
// foreach (Gizmo gizmo in LaunchableComp.CompGetGizmosExtra()) yield return gizmo;
|
||||||
|
|||||||
@@ -162,7 +162,7 @@ namespace WulaFallenEmpire
|
|||||||
Log.Message($"[WULA-DEBUG] ExposeData called, mode: {Scribe.mode}");
|
Log.Message($"[WULA-DEBUG] ExposeData called, mode: {Scribe.mode}");
|
||||||
|
|
||||||
base.ExposeData();
|
base.ExposeData();
|
||||||
Scribe_Deep.Look(ref pocketMap, "pocketMap");
|
Scribe_References.Look(ref pocketMap, "pocketMap");
|
||||||
Scribe_Values.Look(ref pocketMapGenerated, "pocketMapGenerated", false);
|
Scribe_Values.Look(ref pocketMapGenerated, "pocketMapGenerated", false);
|
||||||
Scribe_Values.Look(ref pocketMapSize, "pocketMapSize", new IntVec2(80, 80));
|
Scribe_Values.Look(ref pocketMapSize, "pocketMapSize", new IntVec2(80, 80));
|
||||||
Scribe_Defs.Look(ref mapGenerator, "mapGenerator");
|
Scribe_Defs.Look(ref mapGenerator, "mapGenerator");
|
||||||
@@ -453,7 +453,8 @@ namespace WulaFallenEmpire
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
protected virtual Map GeneratePocketMapInt()
|
protected virtual Map GeneratePocketMapInt()
|
||||||
{
|
{
|
||||||
return PocketMapUtility.GeneratePocketMap(new IntVec3(pocketMapSize.x, 1, pocketMapSize.z), mapGenerator, null, this.Map);
|
// [核心修复] 将 sourceMap 设置为 null,彻底斩断口袋地图与创建它的主地图的生命周期联系。
|
||||||
|
return PocketMapUtility.GeneratePocketMap(new IntVec3(pocketMapSize.x, 1, pocketMapSize.z), mapGenerator, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -994,6 +995,9 @@ namespace WulaFallenEmpire
|
|||||||
|
|
||||||
base.SpawnSetup(map, respawningAfterLoad);
|
base.SpawnSetup(map, respawningAfterLoad);
|
||||||
|
|
||||||
|
// 更新退出点目标,确保它指向当前的新地图
|
||||||
|
UpdateExitPointTarget();
|
||||||
|
|
||||||
// 验证关键组件
|
// 验证关键组件
|
||||||
CompTransporter transporter = this.GetComp<CompTransporter>();
|
CompTransporter transporter = this.GetComp<CompTransporter>();
|
||||||
if (transporter == null)
|
if (transporter == null)
|
||||||
@@ -1005,9 +1009,6 @@ namespace WulaFallenEmpire
|
|||||||
Log.Message($"[WULA-DEBUG] CompTransporter found with {transporter.innerContainer?.Count ?? 0} items");
|
Log.Message($"[WULA-DEBUG] CompTransporter found with {transporter.innerContainer?.Count ?? 0} items");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 更新退出点目标(处理穿梭机重新部署的情况)
|
|
||||||
UpdateExitPointTarget();
|
|
||||||
|
|
||||||
// 如果是从飞行状态恢复,重新启用传送功能
|
// 如果是从飞行状态恢复,重新启用传送功能
|
||||||
if (transportDisabled)
|
if (transportDisabled)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -203,6 +203,10 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Verb\Verb_Excalibur\Thing_ExcaliburBeam.cs" />
|
<Compile Include="Verb\Verb_Excalibur\Thing_ExcaliburBeam.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Include="Harmony\MapLifecycle_Patches.cs" />
|
||||||
|
<Compile Include="Harmony\WulaMapProtectionHelper.cs" />
|
||||||
|
</ItemGroup>
|
||||||
<ItemGroup />
|
<ItemGroup />
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
<!-- 自定义清理任务,删除obj文件夹中的临时文件 -->
|
<!-- 自定义清理任务,删除obj文件夹中的临时文件 -->
|
||||||
|
|||||||
Reference in New Issue
Block a user