This commit is contained in:
2025-10-04 14:21:58 +08:00
parent 33e3081c69
commit 6f9996c5df
5 changed files with 263 additions and 164 deletions

View File

@@ -145,6 +145,7 @@
<Compile Include="Building_Comps\WULA_MutiFuelSpawner\IFuelSource.cs" />
<Compile Include="Building_Comps\WULA_MutiFuelSpawner\Patch_CompRefuelableWithKey.cs" />
<Compile Include="Building_Comps\CompNutritionToFuelConverter.cs" />
<Compile Include="Building_Comps\CompAutoEjector.cs" />
<Compile Include="Hediffs\ARA_ConfigurableMutant\Hediff_ConfigurableMutant.cs" />
<Compile Include="Hediffs\ARA_ConfigurableMutant\Hediff_NecroticVirus_Configurable.cs" />
<Compile Include="Hediffs\ARA_ConfigurableMutant\HediffComp_NecroticTransformation.cs" />

View File

@@ -0,0 +1,58 @@
using System;
using System.Linq;
using RimWorld;
using Verse;
namespace ArachnaeSwarm
{
// Properties for the new component
public class CompProperties_AutoEjector : CompProperties
{
public int checkInterval = 250; // Check roughly every 4 seconds
public float ejectAtPercent = 1.0f; // Eject when fuel reaches this percentage of max capacity (1.0 = 100%)
public Type targetComp = typeof(CompRefuelable); // The specific CompRefuelable class to target, can be overridden in XML
public CompProperties_AutoEjector()
{
this.compClass = typeof(CompAutoEjector);
}
}
// The component logic
public class CompAutoEjector : ThingComp
{
private CompProperties_AutoEjector Props => (CompProperties_AutoEjector)this.props;
private CompRefuelable refuelableComp;
public override void PostSpawnSetup(bool respawningAfterLoad)
{
base.PostSpawnSetup(respawningAfterLoad);
// Find the specific refuelable component specified in XML
this.refuelableComp = this.parent.GetComps<CompRefuelable>()
.FirstOrDefault(comp => comp.GetType() == this.Props.targetComp);
if (this.refuelableComp == null)
{
Log.Warning($"[ArachnaeSwarm] CompAutoEjector on {parent.def.defName} could not find a CompRefuelable of type '{this.Props.targetComp.FullName}' to monitor.");
}
}
public override void CompTick()
{
base.CompTick();
// Check if we have a valid refuelable comp and it's time to check
if (this.refuelableComp != null &&
this.parent.IsHashIntervalTick(this.Props.checkInterval))
{
// Check if fuel has reached or exceeded the configured percentage of the MAX capacity
if (this.refuelableComp.FuelPercentOfMax >= this.Props.ejectAtPercent)
{
// Call the public EjectFuel() method.
this.refuelableComp.EjectFuel();
}
}
}
}
}