整理一下
This commit is contained in:
94
Source/WulaFallenEmpire/HarmonyPatches/IngestPatch.cs
Normal file
94
Source/WulaFallenEmpire/HarmonyPatches/IngestPatch.cs
Normal file
@@ -0,0 +1,94 @@
|
||||
using HarmonyLib;
|
||||
using RimWorld;
|
||||
using Verse;
|
||||
using System; // For Type
|
||||
|
||||
namespace WulaFallenEmpire
|
||||
{
|
||||
// Patch for WillEat(Pawn p, ThingDef food, ...)
|
||||
[HarmonyPatch(typeof(FoodUtility), "WillEat", new Type[] { typeof(Pawn), typeof(ThingDef), typeof(Pawn), typeof(bool), typeof(bool) })]
|
||||
public static class IngestPatch_ThingDef
|
||||
{
|
||||
[HarmonyPrefix]
|
||||
public static bool Prefix(Pawn p, ThingDef food, ref bool __result)
|
||||
{
|
||||
// 检查食物是否是能量核心
|
||||
ThingDefExtension_EnergySource ext = food.GetModExtension<ThingDefExtension_EnergySource>();
|
||||
if (ext != null)
|
||||
{
|
||||
// 如果是能量核心
|
||||
if (p.def.defName == "WulaSpecies")
|
||||
{
|
||||
// 如果是乌拉族,则认为愿意吃
|
||||
__result = true;
|
||||
return false; // 跳过原版方法
|
||||
}
|
||||
else
|
||||
{
|
||||
// 如果不是乌拉族,则不允许吃能量核心
|
||||
__result = false;
|
||||
return false; // 跳过原版方法
|
||||
}
|
||||
}
|
||||
return true; // 继续执行原版方法
|
||||
}
|
||||
}
|
||||
|
||||
// New Patch for WillEat(Pawn p, Thing food, ...)
|
||||
[HarmonyPatch(typeof(FoodUtility), "WillEat", new Type[] { typeof(Pawn), typeof(Thing), typeof(Pawn), typeof(bool), typeof(bool) })]
|
||||
public static class IngestPatch_Thing
|
||||
{
|
||||
[HarmonyPrefix]
|
||||
public static bool Prefix(Pawn p, Thing food, ref bool __result)
|
||||
{
|
||||
// 检查食物是否是能量核心
|
||||
ThingDefExtension_EnergySource ext = food.def.GetModExtension<ThingDefExtension_EnergySource>();
|
||||
if (ext != null)
|
||||
{
|
||||
// 如果是能量核心
|
||||
if (p.def.defName == "WulaSpecies")
|
||||
{
|
||||
// 如果是乌拉族,则认为愿意吃
|
||||
__result = true;
|
||||
return false; // 跳过原版方法
|
||||
}
|
||||
else
|
||||
{
|
||||
// 如果不是乌拉族,则不允许吃能量核心
|
||||
__result = false;
|
||||
return false; // 跳过原版方法
|
||||
}
|
||||
}
|
||||
return true; // 继续执行原版方法
|
||||
}
|
||||
}
|
||||
|
||||
// Patch for FoodUtility.FoodIsSuitable(Pawn p, ThingDef food)
|
||||
[HarmonyPatch(typeof(FoodUtility), "FoodIsSuitable", new Type[] { typeof(Pawn), typeof(ThingDef) })]
|
||||
public static class IngestPatch_FoodIsSuitable
|
||||
{
|
||||
[HarmonyPrefix]
|
||||
public static bool Prefix(Pawn p, ThingDef food, ref bool __result)
|
||||
{
|
||||
// 检查食物是否是能量核心
|
||||
ThingDefExtension_EnergySource ext = food.GetModExtension<ThingDefExtension_EnergySource>();
|
||||
if (ext != null)
|
||||
{
|
||||
// 如果是能量核心
|
||||
if (p.def.defName == "WulaSpecies")
|
||||
{
|
||||
// 如果是乌拉族,则认为食物是合适的
|
||||
__result = true;
|
||||
return false; // 跳过原版方法
|
||||
}
|
||||
else
|
||||
{
|
||||
// 如果不是乌拉族,则认为食物不合适
|
||||
__result = false;
|
||||
return false; // 跳过原版方法
|
||||
}
|
||||
}
|
||||
return true; // 继续执行原版方法
|
||||
}
|
||||
}
|
||||
}
|
||||
57
Source/WulaFallenEmpire/HarmonyPatches/MechanitorPatch.cs
Normal file
57
Source/WulaFallenEmpire/HarmonyPatches/MechanitorPatch.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using RimWorld;
|
||||
using Verse;
|
||||
using HarmonyLib; // 引入Harmony库
|
||||
|
||||
namespace WulaFallenEmpire
|
||||
{
|
||||
// 定义一个新的HediffCompProperties,用作标记,以赋予机械师能力
|
||||
public class HediffCompProperties_MakesMechanitor : HediffCompProperties
|
||||
{
|
||||
// 这个类本身不需要任何逻辑,它的存在就是为了在XML中被引用作为标记
|
||||
public HediffCompProperties_MakesMechanitor()
|
||||
{
|
||||
// compClass必须指向一个有效的HediffComp类。
|
||||
// 由于我们只想用这个Properties作为标记,我们可以指向一个通用的、空的HediffComp。
|
||||
// 但更简洁的方法是直接在补丁里检查Properties本身。
|
||||
// 为了避免运行时错误,我们暂时指向一个基础的HediffComp。
|
||||
// 实际上,在下面的补丁逻辑中,我们不会实例化这个compClass。
|
||||
this.compClass = typeof(HediffComp);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Harmony Patch类,用于修改MechanitorUtility.ShouldBeMechanitor方法
|
||||
[HarmonyPatch(typeof(MechanitorUtility), "ShouldBeMechanitor")]
|
||||
public static class MechanitorShouldBeMechanitorPatch
|
||||
{
|
||||
// Postfix方法将在原始方法执行后运行
|
||||
// originalResult 是原始方法的返回值
|
||||
// pawn 是原始方法的参数
|
||||
public static void Postfix(Pawn pawn, ref bool __result)
|
||||
{
|
||||
// 如果原始方法已经返回true,则无需进一步检查
|
||||
if (__result)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// 检查Biotech DLC是否激活且Pawn属于玩家安全派系
|
||||
if (ModsConfig.BiotechActive && pawn.Faction.IsPlayerSafe())
|
||||
{
|
||||
// 遍历Pawn的所有Hediff
|
||||
foreach (Hediff hediff in pawn.health.hediffSet.hediffs)
|
||||
{
|
||||
// 检查Hediff的定义中是否包含HediffCompProperties_MakesMechanitor
|
||||
if (hediff.def.comps?.Any(c => c is HediffCompProperties_MakesMechanitor) ?? false)
|
||||
{
|
||||
__result = true; // 如果找到,则将结果设置为true
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user