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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
using HarmonyLib;
|
||||
using RimWorld;
|
||||
using Verse;
|
||||
|
||||
namespace WulaFallenEmpire
|
||||
{
|
||||
[HarmonyPatch(typeof(FloatMenuOptionProvider), "SelectedPawnValid")]
|
||||
public static class Patch_FloatMenuOptionProvider_SelectedPawnValid
|
||||
{
|
||||
[HarmonyPostfix]
|
||||
public static void Postfix(Pawn pawn, FloatMenuContext context, ref bool __result)
|
||||
{
|
||||
// 如果已经有效,不需要修改
|
||||
if (__result)
|
||||
return;
|
||||
|
||||
// 检查是否是机械族且被原版逻辑拒绝
|
||||
if (!pawn.RaceProps.IsMechanoid)
|
||||
return;
|
||||
|
||||
// 检查是否有自主机械组件
|
||||
var comp = pawn.GetComp<CompAutonomousMech>();
|
||||
if (comp == null || !comp.CanWorkAutonomously)
|
||||
return;
|
||||
|
||||
// 对于自主机械族,直接返回true,跳过机械族限制
|
||||
// 其他条件已经在原版方法中检查过了
|
||||
__result = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
using HarmonyLib;
|
||||
using RimWorld;
|
||||
using Verse;
|
||||
|
||||
namespace WulaFallenEmpire
|
||||
{
|
||||
[HarmonyPatch(typeof(Pawn), "get_IsColonyMechPlayerControlled")]
|
||||
public static class Patch_IsColonyMechPlayerControlled
|
||||
{
|
||||
[HarmonyPostfix]
|
||||
public static void Postfix(Pawn __instance, ref bool __result)
|
||||
{
|
||||
// 如果原版已经返回true,不需要修改
|
||||
if (__result)
|
||||
return;
|
||||
|
||||
// 检查是否是殖民地机械
|
||||
if (!__instance.IsColonyMech)
|
||||
return;
|
||||
|
||||
// 检查是否有自主机械组件
|
||||
var comp = __instance.GetComp<CompAutonomousMech>();
|
||||
if (comp == null)
|
||||
return;
|
||||
|
||||
// 如果机械族处于自主战斗模式,则视为玩家控制
|
||||
if (comp.CanFightAutonomously)
|
||||
{
|
||||
__result = true;
|
||||
return;
|
||||
}
|
||||
|
||||
// 如果机械族处于自主工作模式,也视为玩家控制(用于工作相关判定)
|
||||
if (comp.CanWorkAutonomously)
|
||||
{
|
||||
__result = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
using HarmonyLib;
|
||||
using RimWorld;
|
||||
using Verse;
|
||||
|
||||
namespace WulaFallenEmpire
|
||||
{
|
||||
[HarmonyPatch(typeof(Pawn_DraftController), "get_ShowDraftGizmo")]
|
||||
public static class Patch_Pawn_DraftController_ShowDraftGizmo
|
||||
{
|
||||
public static void Postfix(Pawn_DraftController __instance, ref bool __result)
|
||||
{
|
||||
Pawn pawn = __instance.pawn;
|
||||
|
||||
if (!__result && pawn != null && pawn.IsColonyMech)
|
||||
{
|
||||
var comp = pawn.GetComp<CompAutonomousMech>();
|
||||
if (comp != null && comp.CanBeAutonomous)
|
||||
{
|
||||
__result = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(MechanitorUtility), "CanDraftMech")]
|
||||
public static class Patch_MechanitorUtility_CanDraftMech
|
||||
{
|
||||
public static void Postfix(Pawn mech, ref AcceptanceReport __result)
|
||||
{
|
||||
if (!__result && mech != null && mech.IsColonyMech)
|
||||
{
|
||||
var comp = mech.GetComp<CompAutonomousMech>();
|
||||
if (comp != null && comp.CanBeAutonomous)
|
||||
{
|
||||
__result = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(CompOverseerSubject), "CompInspectStringExtra")]
|
||||
public static class Patch_CompOverseerSubject_CompInspectStringExtra
|
||||
{
|
||||
public static void Postfix(CompOverseerSubject __instance, ref string __result)
|
||||
{
|
||||
Pawn mech = __instance.parent as Pawn;
|
||||
if (mech != null && mech.IsColonyMech)
|
||||
{
|
||||
var comp = mech.GetComp<CompAutonomousMech>();
|
||||
if (comp != null && comp.ShouldSuppressUncontrolledWarning)
|
||||
{
|
||||
string autonomousStatus = comp.GetAutonomousStatusString();
|
||||
if (!string.IsNullOrEmpty(autonomousStatus))
|
||||
{
|
||||
__result = autonomousStatus;
|
||||
}
|
||||
else
|
||||
{
|
||||
__result = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
using HarmonyLib;
|
||||
using RimWorld;
|
||||
using Verse;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
|
||||
namespace WulaFallenEmpire
|
||||
{
|
||||
// 修复红色名字问题 - 直接修补 PawnNameColorUtility.PawnNameColorOf 方法
|
||||
[HarmonyPatch(typeof(PawnNameColorUtility), "PawnNameColorOf")]
|
||||
public static class Patch_PawnNameColorUtility_PawnNameColorOf
|
||||
{
|
||||
public static void Postfix(Pawn pawn, ref Color __result)
|
||||
{
|
||||
if (pawn != null && pawn.IsColonyMech)
|
||||
{
|
||||
var comp = pawn.GetComp<CompAutonomousMech>();
|
||||
if (comp != null && comp.ShouldSuppressUncontrolledWarning)
|
||||
{
|
||||
// 使用正常的白色名字
|
||||
__result = Color.white;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user