能量核心2补
This commit is contained in:
Binary file not shown.
@@ -32,6 +32,13 @@
|
||||
</ingestible>
|
||||
<allowedArchonexusCount>200</allowedArchonexusCount>
|
||||
<tradeability>None</tradeability>
|
||||
<comps>
|
||||
<li Class="CompProperties_Usable">
|
||||
<useJob>WULA_IngestWulaEnergy</useJob>
|
||||
<useLabel>从能量核心中摄取能量</useLabel>
|
||||
<showUseGizmo>true</showUseGizmo>
|
||||
</li>
|
||||
</comps>
|
||||
<modExtensions>
|
||||
<li Class="WulaFallenEmpire.ThingDefExtension_EnergySource">
|
||||
<energyAmount>12.0</energyAmount> <!-- Amount of energy this item provides -->
|
||||
|
||||
11
1.6/Defs/WulaMiscSettingDefs/WulaCaravanEnergyDefs.xml
Normal file
11
1.6/Defs/WulaMiscSettingDefs/WulaCaravanEnergyDefs.xml
Normal file
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<Defs>
|
||||
<WulaFallenEmpire.WulaCaravanEnergyDef>
|
||||
<defName>WulaCaravanEnergySettings</defName>
|
||||
<label>Wula Caravan Energy Settings</label>
|
||||
<!--乌拉远行队能量进食设置-->
|
||||
<consumeThreshold>0.3</consumeThreshold><!--低于0.3能量吃一个核心-->
|
||||
<energyItemDefName>WULA_Charge_Cube</energyItemDefName>
|
||||
<hediffDefNameToAdd>WULA_ChargingHediff</hediffDefNameToAdd>
|
||||
</WulaFallenEmpire.WulaCaravanEnergyDef>
|
||||
</Defs>
|
||||
@@ -1 +1 @@
|
||||
3296602837
|
||||
3528588530
|
||||
@@ -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<Need_WulaEnergy>();
|
||||
if (wulaEnergyNeed == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Get settings from XML
|
||||
WulaCaravanEnergyDef settings = DefDatabase<WulaCaravanEnergyDef>.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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<Toil> PrepareToIngestToils(Toil chewToil)
|
||||
|
||||
11
Source/WulaFallenEmpire/WulaCaravanEnergyDef.cs
Normal file
11
Source/WulaFallenEmpire/WulaCaravanEnergyDef.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using Verse;
|
||||
|
||||
namespace WulaFallenEmpire
|
||||
{
|
||||
public class WulaCaravanEnergyDef : Def
|
||||
{
|
||||
public float consumeThreshold = 0.9f;
|
||||
public string energyItemDefName;
|
||||
public string hediffDefNameToAdd;
|
||||
}
|
||||
}
|
||||
@@ -83,6 +83,9 @@
|
||||
<Compile Include="JobGiver_WulaGetEnergy.cs" />
|
||||
<Compile Include="JobGiver_WulaPackEnergy.cs" />
|
||||
<Compile Include="JobGiverDefExtension_WulaPackEnergy.cs" />
|
||||
<Compile Include="WulaCaravanEnergyDef.cs" />
|
||||
<Compile Include="HarmonyPatches\Caravan_NeedsTracker_TrySatisfyPawnNeeds_Patch.cs" />
|
||||
<Compile Include="HarmonyPatches\FloatMenuOptionProvider_Ingest_Patch.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
|
||||
@@ -91,4 +94,4 @@
|
||||
<RemoveDir Directories="$(ProjectDir)obj\Debug" />
|
||||
<RemoveDir Directories="$(ProjectDir)obj\Release" />
|
||||
</Target>
|
||||
</Project>
|
||||
</Project>
|
||||
Reference in New Issue
Block a user