diff --git a/1.6/Assemblies/WulaFallenEmpire.dll b/1.6/Assemblies/WulaFallenEmpire.dll index 08ded61b..23dcb6dc 100644 Binary files a/1.6/Assemblies/WulaFallenEmpire.dll and b/1.6/Assemblies/WulaFallenEmpire.dll differ diff --git a/1.6/Defs/ThingDefs/WULA_Item.xml b/1.6/Defs/ThingDefs/WULA_Item.xml index 0a1458cb..78871d87 100644 --- a/1.6/Defs/ThingDefs/WULA_Item.xml +++ b/1.6/Defs/ThingDefs/WULA_Item.xml @@ -32,6 +32,13 @@ 200 None + +
  • + WULA_IngestWulaEnergy + 从能量核心中摄取能量 + true +
  • +
  • 12.0 diff --git a/1.6/Defs/WulaMiscSettingDefs/WulaCaravanEnergyDefs.xml b/1.6/Defs/WulaMiscSettingDefs/WulaCaravanEnergyDefs.xml new file mode 100644 index 00000000..a46109e1 --- /dev/null +++ b/1.6/Defs/WulaMiscSettingDefs/WulaCaravanEnergyDefs.xml @@ -0,0 +1,11 @@ + + + + WulaCaravanEnergySettings + + + 0.3 + WULA_Charge_Cube + WULA_ChargingHediff + + diff --git a/1.6/Defs/WulaHullDefs/WulaHullDef.xml b/1.6/Defs/WulaMiscSettingDefs/WulaHullDef.xml similarity index 100% rename from 1.6/Defs/WulaHullDefs/WulaHullDef.xml rename to 1.6/Defs/WulaMiscSettingDefs/WulaHullDef.xml diff --git a/About/PublishedFileId.txt b/About/PublishedFileId.txt index 1f3d0fca..5f6f9042 100644 --- a/About/PublishedFileId.txt +++ b/About/PublishedFileId.txt @@ -1 +1 @@ -3296602837 \ No newline at end of file +3528588530 \ No newline at end of file diff --git a/Source/WulaFallenEmpire/HarmonyPatches/Caravan_NeedsTracker_TrySatisfyPawnNeeds_Patch.cs b/Source/WulaFallenEmpire/HarmonyPatches/Caravan_NeedsTracker_TrySatisfyPawnNeeds_Patch.cs new file mode 100644 index 00000000..55658735 --- /dev/null +++ b/Source/WulaFallenEmpire/HarmonyPatches/Caravan_NeedsTracker_TrySatisfyPawnNeeds_Patch.cs @@ -0,0 +1,70 @@ +using HarmonyLib; +using RimWorld; +using RimWorld.Planet; +using Verse; + +namespace WulaFallenEmpire.HarmonyPatches +{ + [HarmonyPatch(typeof(Caravan_NeedsTracker), "TrySatisfyPawnNeeds")] + public static class Caravan_NeedsTracker_TrySatisfyPawnNeeds_Patch + { + [HarmonyPostfix] + public static void Postfix(Caravan_NeedsTracker __instance, Pawn pawn) + { + // Check if the pawn is valid and has needs + if (pawn == null || pawn.Dead || pawn.needs == null) + { + return; + } + + // Try to get the custom energy need + Need_WulaEnergy wulaEnergyNeed = pawn.needs.TryGetNeed(); + if (wulaEnergyNeed == null) + { + return; + } + + // Get settings from XML + WulaCaravanEnergyDef settings = DefDatabase.GetNamed("WulaCaravanEnergySettings", false); + if (settings == null) + { + // Log an error only once to avoid spamming the log + Log.ErrorOnce("[WulaFallenEmpire] WulaCaravanEnergySettings Def not found. Caravan energy consumption will not work.", "WulaCaravanEnergySettingsNotFound".GetHashCode()); + return; + } + + // Check if the pawn is already charging, if so, do nothing. + if (pawn.health.hediffSet.HasHediff(HediffDef.Named(settings.hediffDefNameToAdd))) + { + return; + } + + // Check if the pawn actually needs energy, based on the threshold from XML. + if (wulaEnergyNeed.CurLevelPercentage >= settings.consumeThreshold) + { + return; + } + + // Find an energy core in the caravan's inventory based on the defName from XML + Thing energyCore = CaravanInventoryUtility.AllInventoryItems(__instance.caravan).FirstOrFallback((Thing t) => t.def.defName == settings.energyItemDefName); + + if (energyCore != null) + { + // "Ingest" the energy core by applying the hediff, mimicking the IngestionOutcomeDoer. + Hediff hediff = HediffMaker.MakeHediff(HediffDef.Named(settings.hediffDefNameToAdd), pawn); + hediff.Severity = 1.0f; + pawn.health.AddHediff(hediff); + + // Instead of destroying the core, we replace it with a used one. + + // 1. Consume one energy core from the stack + energyCore.SplitOff(1).Destroy(); + + // 2. Add one used energy core to the caravan inventory + Thing usedCore = ThingMaker.MakeThing(ThingDef.Named("WULA_Charge_Cube_No_Power")); + usedCore.stackCount = 1; + CaravanInventoryUtility.GiveThing(__instance.caravan, usedCore); + } + } + } +} diff --git a/Source/WulaFallenEmpire/HarmonyPatches/FloatMenuOptionProvider_Ingest_Patch.cs b/Source/WulaFallenEmpire/HarmonyPatches/FloatMenuOptionProvider_Ingest_Patch.cs new file mode 100644 index 00000000..d4445a5b --- /dev/null +++ b/Source/WulaFallenEmpire/HarmonyPatches/FloatMenuOptionProvider_Ingest_Patch.cs @@ -0,0 +1,21 @@ +using HarmonyLib; +using RimWorld; +using Verse; + +namespace WulaFallenEmpire.HarmonyPatches +{ + [HarmonyPatch(typeof(FloatMenuOptionProvider_Ingest), "GetSingleOptionFor")] + public static class FloatMenuOptionProvider_Ingest_GetSingleOptionFor_Patch + { + [HarmonyPostfix] + public static void Postfix(ref FloatMenuOption __result, Thing clickedThing) + { + // If the standard "Ingest" option is for our energy core, nullify it. + // Our custom "摄取能量" option is added by CompUsable and is not affected by this provider. + if (__result != null && clickedThing != null && clickedThing.def.defName == "WULA_Charge_Cube") + { + __result = null; + } + } + } +} diff --git a/Source/WulaFallenEmpire/JobDriver_FeedWulaPatient.cs b/Source/WulaFallenEmpire/JobDriver_FeedWulaPatient.cs index 07e5d124..45160fb3 100644 --- a/Source/WulaFallenEmpire/JobDriver_FeedWulaPatient.cs +++ b/Source/WulaFallenEmpire/JobDriver_FeedWulaPatient.cs @@ -44,7 +44,44 @@ namespace WulaFallenEmpire yield return Toils_Goto.GotoThing(PatientInd, PathEndMode.Touch); yield return Toils_Ingest.ChewIngestible(Patient, 1.5f, FoodSourceInd, TargetIndex.None).FailOnCannotTouch(PatientInd, PathEndMode.Touch); - yield return Toils_Ingest.FinalizeIngest(Patient, FoodSourceInd); + + // Custom Finalize Ingest Logic + Toil finalizeToil = new Toil(); + finalizeToil.initAction = delegate + { + Pawn patient = Patient; + Thing food = Food; + if (patient == null || food == null) + { + return; + } + + // If it's not an energy core, use the default vanilla method. + if (food.def.defName != "WULA_Charge_Cube") + { + patient.needs.food.CurLevel += FoodUtility.GetNutrition(patient, food, food.def); + } + else + { + // Our custom logic for energy core + // 1. Apply the charging hediff + Hediff hediff = HediffMaker.MakeHediff(HediffDef.Named("WULA_ChargingHediff"), patient); + hediff.Severity = 1.0f; + patient.health.AddHediff(hediff); + + // 2. Spawn the used core + Thing usedCore = ThingMaker.MakeThing(ThingDef.Named("WULA_Charge_Cube_No_Power")); + GenPlace.TryPlaceThing(usedCore, pawn.Position, pawn.Map, ThingPlaceMode.Near); + } + + // Destroy the food item (it has been carried by the feeder) + if (!food.Destroyed) + { + food.Destroy(); + } + }; + finalizeToil.defaultCompleteMode = ToilCompleteMode.Instant; + yield return finalizeToil; } } } diff --git a/Source/WulaFallenEmpire/JobDriver_IngestWulaEnergy.cs b/Source/WulaFallenEmpire/JobDriver_IngestWulaEnergy.cs index d149644c..91be7094 100644 --- a/Source/WulaFallenEmpire/JobDriver_IngestWulaEnergy.cs +++ b/Source/WulaFallenEmpire/JobDriver_IngestWulaEnergy.cs @@ -67,7 +67,44 @@ namespace WulaFallenEmpire } yield return chew; - yield return Toils_Ingest.FinalizeIngest(pawn, IngestibleSourceInd); + + // Custom Finalize Ingest Logic + Toil finalizeToil = new Toil(); + finalizeToil.initAction = delegate + { + Pawn ingester = pawn; + Thing ingestible = IngestibleSource; + if (ingester == null || ingestible == null) + { + return; + } + + // If it's not an energy core, use the default vanilla method for safety, though this job should only target energy cores. + if (ingestible.def.defName != "WULA_Charge_Cube") + { + ingester.needs.food.CurLevel += FoodUtility.GetNutrition(ingester, ingestible, ingestible.def); + } + else + { + // Our custom logic for energy core + // 1. Apply the charging hediff + Hediff hediff = HediffMaker.MakeHediff(HediffDef.Named("WULA_ChargingHediff"), ingester); + hediff.Severity = 1.0f; + ingester.health.AddHediff(hediff); + + // 2. Spawn the used core + Thing usedCore = ThingMaker.MakeThing(ThingDef.Named("WULA_Charge_Cube_No_Power")); + GenPlace.TryPlaceThing(usedCore, ingester.Position, ingester.Map, ThingPlaceMode.Near); + } + + // Destroy the original food item + if (!ingestible.Destroyed) + { + ingestible.Destroy(); + } + }; + finalizeToil.defaultCompleteMode = ToilCompleteMode.Instant; + yield return finalizeToil; } private IEnumerable PrepareToIngestToils(Toil chewToil) diff --git a/Source/WulaFallenEmpire/WulaCaravanEnergyDef.cs b/Source/WulaFallenEmpire/WulaCaravanEnergyDef.cs new file mode 100644 index 00000000..8d76d81b --- /dev/null +++ b/Source/WulaFallenEmpire/WulaCaravanEnergyDef.cs @@ -0,0 +1,11 @@ +using Verse; + +namespace WulaFallenEmpire +{ + public class WulaCaravanEnergyDef : Def + { + public float consumeThreshold = 0.9f; + public string energyItemDefName; + public string hediffDefNameToAdd; + } +} diff --git a/Source/WulaFallenEmpire/WulaFallenEmpire.csproj b/Source/WulaFallenEmpire/WulaFallenEmpire.csproj index 21f71995..97b2c355 100644 --- a/Source/WulaFallenEmpire/WulaFallenEmpire.csproj +++ b/Source/WulaFallenEmpire/WulaFallenEmpire.csproj @@ -83,6 +83,9 @@ + + + @@ -91,4 +94,4 @@ - + \ No newline at end of file