整理一下

This commit is contained in:
2025-08-29 16:10:25 +08:00
parent d759562b83
commit dce9a31cd6
51 changed files with 52 additions and 52 deletions

View File

@@ -0,0 +1,25 @@
using Verse;
namespace WulaFallenEmpire
{
/// <summary>
/// This CompProperties class is used in the XML defs to add the CompForceTargetable to a Thing.
/// </summary>
public class CompProperties_ForceTargetable : CompProperties
{
public CompProperties_ForceTargetable()
{
this.compClass = typeof(CompForceTargetable);
}
}
/// <summary>
/// A simple marker component. Any Building_TurretGun that has this component
/// will be forcefully made targetable by players via a Harmony patch.
/// </summary>
public class CompForceTargetable : ThingComp
{
// This component doesn't need any specific logic.
// Its mere presence on a turret is checked by the Harmony patch.
}
}

View File

@@ -0,0 +1,28 @@
using HarmonyLib;
using Verse;
using RimWorld;
namespace WulaFallenEmpire
{
[HarmonyPatch(typeof(Building_TurretGun), "get_CanSetForcedTarget")]
public static class Patch_Building_TurretGun_CanSetForcedTarget
{
/// <summary>
/// Postfix patch to allow turrets with CompForceTargetable to be manually targeted.
/// </summary>
public static void Postfix(Building_TurretGun __instance, ref bool __result)
{
// If the result is already true, no need to do anything.
if (__result)
{
return;
}
// Check if the turret has our marker component and belongs to the player.
if (__instance.GetComp<CompForceTargetable>() != null && __instance.Faction == Faction.OfPlayer)
{
__result = true;
}
}
}
}

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;
}
}
}