1
This commit is contained in:
@@ -0,0 +1,94 @@
|
||||
using HarmonyLib;
|
||||
using RimWorld;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using Verse;
|
||||
namespace WulaFallenEmpire
|
||||
{
|
||||
[HarmonyPatch(typeof(ScenPart_PlayerPawnsArriveMethod))]
|
||||
[HarmonyPatch("DoDropPods")]
|
||||
public static class ScenPart_PlayerPawnsArriveMethod_ReflectionPatch
|
||||
{
|
||||
/// <summary>
|
||||
/// 使用反射来直接调用正确的方法
|
||||
/// </summary>
|
||||
[HarmonyPrefix]
|
||||
public static bool Prefix(ScenPart_PlayerPawnsArriveMethod __instance, Map map, List<Thing> startingItems)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 获取私有字段 "method"
|
||||
FieldInfo methodField = typeof(ScenPart_PlayerPawnsArriveMethod).GetField("method", BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
PlayerPawnsArriveMethod method = (PlayerPawnsArriveMethod)methodField.GetValue(__instance);
|
||||
// 重新创建物品分组逻辑
|
||||
List<List<Thing>> thingGroups = new List<List<Thing>>();
|
||||
|
||||
foreach (Pawn startingPawn in Find.GameInitData.startingAndOptionalPawns)
|
||||
{
|
||||
List<Thing> pawnGroup = new List<Thing>();
|
||||
pawnGroup.Add(startingPawn);
|
||||
thingGroups.Add(pawnGroup);
|
||||
}
|
||||
int itemIndex = 0;
|
||||
foreach (Thing startingItem in startingItems)
|
||||
{
|
||||
if (startingItem.def.CanHaveFaction)
|
||||
{
|
||||
startingItem.SetFactionDirect(Faction.OfPlayer);
|
||||
}
|
||||
thingGroups[itemIndex].Add(startingItem);
|
||||
itemIndex++;
|
||||
if (itemIndex >= thingGroups.Count)
|
||||
{
|
||||
itemIndex = 0;
|
||||
}
|
||||
}
|
||||
// 使用反射调用正确的 DropThingGroupsNear 方法(11个参数版本)
|
||||
MethodInfo dropMethod = typeof(DropPodUtility).GetMethod("DropThingGroupsNear", new System.Type[]
|
||||
{
|
||||
typeof(IntVec3),
|
||||
typeof(Map),
|
||||
typeof(List<List<Thing>>),
|
||||
typeof(int),
|
||||
typeof(bool),
|
||||
typeof(bool),
|
||||
typeof(bool),
|
||||
typeof(bool),
|
||||
typeof(bool),
|
||||
typeof(bool),
|
||||
typeof(Faction)
|
||||
});
|
||||
if (dropMethod != null)
|
||||
{
|
||||
dropMethod.Invoke(null, new object[]
|
||||
{
|
||||
MapGenerator.PlayerStartSpot,
|
||||
map,
|
||||
thingGroups,
|
||||
110,
|
||||
Find.GameInitData.QuickStarted || method != PlayerPawnsArriveMethod.DropPods,
|
||||
true, // leaveSlag
|
||||
true, // canRoofPunch
|
||||
true, // forbid
|
||||
false, // allowFogged
|
||||
false, // canTransfer
|
||||
Faction.OfPlayer // faction
|
||||
});
|
||||
Log.Message("[WULA] Successfully called DropThingGroupsNear with faction parameter via reflection");
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Error("[WULA] Could not find 11-parameter DropThingGroupsNear method");
|
||||
}
|
||||
// 返回 false 来跳过原方法的执行
|
||||
return false;
|
||||
}
|
||||
catch (System.Exception ex)
|
||||
{
|
||||
Log.Error($"[WULA] Error in DoDropPods prefix: {ex}");
|
||||
// 如果出错,让原方法继续执行
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
using HarmonyLib;
|
||||
using RimWorld;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Verse;
|
||||
|
||||
namespace WulaFallenEmpire
|
||||
{
|
||||
[HarmonyPatch(typeof(ThingDefGenerator_Corpses))]
|
||||
[HarmonyPatch("GenerateCorpseDef")]
|
||||
public static class WulaSpeciesCorpsePatch
|
||||
{
|
||||
/// <summary>
|
||||
/// 在生成尸体定义后,对 WulaSpecies 进行特殊处理
|
||||
/// </summary>
|
||||
[HarmonyPostfix]
|
||||
public static void ModifyWulaSpeciesCorpse(ThingDef pawnDef, ref ThingDef __result)
|
||||
{
|
||||
// 检查是否是 WulaSpecies 种族
|
||||
if (pawnDef?.defName == "WulaSpecies")
|
||||
{
|
||||
ApplyWulaSpeciesCorpseModifications(__result);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 应用 WulaSpecies 尸体的特殊修改
|
||||
/// </summary>
|
||||
private static void ApplyWulaSpeciesCorpseModifications(ThingDef corpseDef)
|
||||
{
|
||||
if (corpseDef == null) return;
|
||||
|
||||
Log.Message($"[WulaSpecies] Starting corpse modification for WulaSpecies");
|
||||
|
||||
// 1. 移除腐烂组件(如果存在)
|
||||
RemoveCompProperties(corpseDef, typeof(CompProperties_Rottable));
|
||||
|
||||
// 2. 移除污物生成组件(如果存在)
|
||||
RemoveCompProperties(corpseDef, typeof(CompProperties_SpawnerFilth));
|
||||
|
||||
// 3. 修改可食用属性,设置为 NeverForNutrition
|
||||
if (corpseDef.ingestible != null)
|
||||
{
|
||||
corpseDef.ingestible.preferability = FoodPreferability.NeverForNutrition;
|
||||
Log.Message($"[WulaSpecies] Set ingestible preferability to NeverForNutrition");
|
||||
}
|
||||
|
||||
// 4. 移除 HarbingerTreeConsumable 组件(如果存在)
|
||||
RemoveCompProperties(corpseDef, typeof(CompProperties), "CompHarbingerTreeConsumable");
|
||||
|
||||
Log.Message($"[WulaSpecies] Completed corpse modification for WulaSpecies");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 移除指定类型的组件属性
|
||||
/// </summary>
|
||||
private static void RemoveCompProperties(ThingDef thingDef, System.Type compType, string compClassName = null)
|
||||
{
|
||||
if (thingDef.comps == null) return;
|
||||
|
||||
var compsToRemove = new List<CompProperties>();
|
||||
|
||||
foreach (var comp in thingDef.comps)
|
||||
{
|
||||
if (comp.GetType() == compType)
|
||||
{
|
||||
compsToRemove.Add(comp);
|
||||
Log.Message($"[WulaSpecies] Found and will remove component: {comp.GetType().Name}");
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(compClassName) && comp.compClass?.Name == compClassName)
|
||||
{
|
||||
compsToRemove.Add(comp);
|
||||
Log.Message($"[WulaSpecies] Found and will remove component by class name: {compClassName}");
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var comp in compsToRemove)
|
||||
{
|
||||
thingDef.comps.Remove(comp);
|
||||
Log.Message($"[WulaSpecies] Removed component: {comp.GetType().Name}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user