全局指挥组件

This commit is contained in:
2025-08-01 11:13:40 +08:00
parent e34397e63b
commit 16b2a83afd
6 changed files with 64 additions and 12 deletions

View File

@@ -0,0 +1,41 @@
using HarmonyLib;
using Verse;
namespace WulaFallenEmpire
{
/// <summary>
/// A CompProperties class that, when added to a Pawn's ThingDef, grants them global command range.
/// </summary>
public class CompProperties_GlobalMechCommand : CompProperties
{
public CompProperties_GlobalMechCommand()
{
this.compClass = typeof(CompGlobalMechCommand);
}
}
/// <summary>
/// The actual Comp that does nothing but act as a marker.
/// </summary>
public class CompGlobalMechCommand : ThingComp
{
// This component doesn't need to do anything. Its presence is what matters.
}
[HarmonyPatch(typeof(MechanitorUtility), "InMechanitorCommandRange")]
public static class MechanitorUtility_InMechanitorCommandRange_Patch
{
[HarmonyPrefix]
public static bool Prefix(Pawn mech, ref bool __result)
{
// Check if the pawn's def has the CompProperties_GlobalMechCommand
if (mech.def.HasComp(typeof(CompGlobalMechCommand)))
{
__result = true; // Grant global command range
return false; // Skip original method
}
return true; // Execute original method
}
}
}