This commit is contained in:
2025-08-21 19:31:17 +08:00
parent d0d125d095
commit 6e232e8eb7
11 changed files with 587 additions and 1 deletions

View File

@@ -0,0 +1,19 @@
using Verse;
namespace WulaFallenEmpire
{
public class CompMechWeapon : ThingComp
{
// You can add custom logic or fields here if needed for this component.
// For now, it primarily serves as a marker for mechanical units that can use MechWeapon features.
}
public class CompProperties_MechWeapon : CompProperties
{
public CompProperties_MechWeapon()
{
compClass = typeof(CompMechWeapon);
}
}
}

View File

@@ -0,0 +1,35 @@
using System.Collections.Generic;
using RimWorld;
using Verse;
using Verse.AI;
namespace WulaFallenEmpire
{
public class FloatMenuProvider_Mech : FloatMenuOptionProvider
{
protected override bool Drafted => true;
protected override bool Undrafted => true;
protected override bool Multiselect => false;
protected override bool MechanoidCanDo => true;
public override bool SelectedPawnValid(Pawn pawn, FloatMenuContext context)
{
return base.SelectedPawnValid(pawn, context) && pawn.HasComp<CompMechWeapon>();
}
public override IEnumerable<FloatMenuOption> GetOptionsFor(Thing clickedThing, FloatMenuContext context)
{
Pawn pawn = context.FirstSelectedPawn;
if (clickedThing.def.IsWeapon && pawn.CanReserveAndReach(clickedThing, PathEndMode.Touch, Danger.Deadly))
{
yield return new FloatMenuOption("Equip".Translate(clickedThing.Label), delegate
{
pawn.jobs.StartJob(JobMaker.MakeJob(JobDefOf.Equip, clickedThing));
});
}
}
}
}

View File

@@ -0,0 +1,19 @@
using HarmonyLib;
using RimWorld;
using Verse;
namespace WulaFallenEmpire
{
[HarmonyPatch(typeof(MechRepairUtility), "IsMissingWeapon")]
public class Patch_MissingWeapon
{
[HarmonyPostfix]
private static void PostFix(ref bool __result, Pawn mech)
{
if (mech.HasComp<CompMechWeapon>())
{
__result = false;
}
}
}
}

View File

@@ -0,0 +1,53 @@
using HarmonyLib;
using RimWorld;
using Verse;
namespace WulaFallenEmpire
{
[HarmonyPatch(typeof(Pawn), "DropAndForbidEverything")]
public class Patch_WeaponDrop
{
[HarmonyPrefix]
private static bool PreFix(ref Pawn __instance, bool keepInventoryAndEquipmentIfInBed, bool rememberPrimary)
{
if (__instance.HasComp<CompMechWeapon>())
{
if (!__instance.InContainerEnclosed)
{
if (__instance.SpawnedOrAnyParentSpawned)
{
if (__instance.carryTracker?.CarriedThing != null)
{
__instance.carryTracker.TryDropCarriedThing(__instance.PositionHeld, ThingPlaceMode.Near, out var _);
}
if (!keepInventoryAndEquipmentIfInBed || !__instance.InBed())
{
__instance.equipment?.DropAllEquipment(__instance.PositionHeld, forbid: true, rememberPrimary);
if (__instance.inventory != null && __instance.inventory.innerContainer.TotalStackCount > 0)
{
__instance.inventory.DropAllNearPawn(__instance.PositionHeld, forbid: true);
}
}
}
return false;
}
if (__instance.carryTracker?.CarriedThing != null)
{
__instance.carryTracker.innerContainer.TryTransferToContainer(__instance.carryTracker.CarriedThing, __instance.holdingOwner);
}
if (__instance.equipment?.Primary != null)
{
__instance.equipment.TryTransferEquipmentToContainer(__instance.equipment.Primary, __instance.holdingOwner);
}
Pawn_InventoryTracker inventory = __instance.inventory;
if (inventory == null)
{
return false;
}
inventory.innerContainer.TryTransferAllToContainer(__instance.holdingOwner);
return false;
}
return true;
}
}
}