Files
ArachnaeSwarm/Source/ArachnaeSwarm/PowerArmor/Harmony_ThingWithComps_GetFloatMenuOptions.cs
2025-10-12 18:16:36 +08:00

59 lines
2.3 KiB
C#

using HarmonyLib;
using RimWorld;
using System.Collections.Generic;
using Verse;
using Verse.AI;
namespace ArachnaeSwarm
{
[HarmonyPatch(typeof(ThingWithComps), "GetFloatMenuOptions")]
public static class Harmony_ThingWithComps_GetFloatMenuOptions
{
[HarmonyPostfix]
public static IEnumerable<FloatMenuOption> Postfix(IEnumerable<FloatMenuOption> values, ThingWithComps __instance, Pawn selPawn)
{
// First, return all original options
foreach (var value in values)
{
yield return value;
}
// --- DEBUG LOGGING ---
// Use a more specific check to avoid log spam
if (__instance.def.defName != null && __instance.def.defName.StartsWith("ARA_"))
{
Log.Message($"[PA_Debug] GetFloatMenuOptions Postfix triggered for: {__instance.def.defName}");
}
// Check if the thing is our power armor building
var comp = __instance.GetComp<CompPowerArmorStation>();
if (comp == null && __instance.def.defName != null && __instance.def.defName.StartsWith("ARA_"))
{
Log.Message($"[PA_Debug] CompPowerArmorStation is NULL for {__instance.def.defName}");
}
if (comp != null)
{
Log.Message($"[PA_Debug] CompPowerArmorStation FOUND for {__instance.def.defName}. Checking reachability.");
// Check if the pawn can interact
if (!selPawn.CanReserveAndReach(__instance, PathEndMode.InteractionCell, Danger.Deadly))
{
yield return new FloatMenuOption("CannotEnterPowerArmor".Translate() + ": " + "CannotReach".Translate(), null);
}
else
{
// Action to give the job
void enterAction()
{
Job job = JobMaker.MakeJob(DefDatabase<JobDef>.GetNamed("ARA_EnterPowerArmor"), __instance);
selPawn.jobs.TryTakeOrderedJob(job, JobTag.Misc);
}
yield return new FloatMenuOption("EnterPowerArmor".Translate(__instance.Label), enterAction);
}
}
}
}
}