This commit is contained in:
2025-09-17 15:20:42 +08:00
parent 0c118ca8a6
commit 40be0d2faf
4 changed files with 19 additions and 10 deletions

Binary file not shown.

View File

@@ -39,11 +39,12 @@
<li>ARA_MorphableResearchBench</li>
</linkableBuildings>
<maxDistance>80</maxDistance> <!-- 供能范围 -->
<maxEfficiency>0.9</maxEfficiency>
</li>
<!-- 自身的燃料库 -->
<li Class="ArachnaeSwarm.CompProperties_RefuelableNutrition">
<fuelCapacity>1000.0</fuelCapacity>
<fuelCapacity>10000.0</fuelCapacity>
<fuelFilter>
<categories>
<li>Foods</li>
@@ -418,8 +419,7 @@
<Flammability>0.5</Flammability>
</statBases>
<costList>
<Steel>150</Steel>
<ComponentIndustrial>4</ComponentIndustrial>
<ARA_Carapace>50</ARA_Carapace>
</costList>
<altitudeLayer>Building</altitudeLayer>
<passability>PassThroughOnly</passability>
@@ -467,6 +467,8 @@
<li>ARA_BioforgeIncubator</li>
<li>ARA_BioforgeIncubator_Thing</li>
</linkableBuildings>
<maxSimultaneous>10</maxSimultaneous>
<maxDistance>20</maxDistance>
<statOffsets>
<NutrientTransmissionEfficiency>0.05</NutrientTransmissionEfficiency>
<ARA_IncubationSpeedFactor>0.1</ARA_IncubationSpeedFactor>

View File

@@ -9,6 +9,7 @@ namespace ArachnaeSwarm
public class CompNutrientProvider : CompFacility
{
private CompRefuelableNutrition selfRefuelable;
private new CompProperties_NutrientProvider Props => (CompProperties_NutrientProvider)props;
public override void PostSpawnSetup(bool respawningAfterLoad)
{
@@ -20,7 +21,7 @@ namespace ArachnaeSwarm
{
StringBuilder sb = new StringBuilder();
float efficiency = Mathf.Clamp(parent.GetStatValue(StatDef.Named("NutrientTransmissionEfficiency")), 0f, 0.1f);
float efficiency = Mathf.Clamp(parent.GetStatValue(StatDef.Named("NutrientTransmissionEfficiency")), 0f, Props.maxEfficiency);
sb.AppendLine("生物质传输效率".Translate() + ": " + efficiency.ToStringPercent());
sb.AppendLine("链接的建筑".Translate() + ":");
@@ -48,15 +49,12 @@ namespace ArachnaeSwarm
public override void CompTick()
{
base.CompTick();
// Log.Message($"[NutrientProvider] CompTick called for {parent.Label}."); // This will be too spammy
if (!parent.IsHashIntervalTick(250))
{
return;
}
Log.Message($"[NutrientProvider] Rare Tick Logic executing for {parent.Label}.");
if (selfRefuelable == null || !selfRefuelable.HasFuel)
{
return;
@@ -73,12 +71,18 @@ namespace ArachnaeSwarm
var consumerComp = targetBuilding.Comp;
float desiredLevel = GetDesiredFuelLevel(consumerComp);
float fuelNeeded = desiredLevel - consumerComp.Fuel;
if (fuelNeeded < 0.1f)
{
return;
}
float fuelToTransfer = Mathf.Min(fuelNeeded, selfRefuelable.Fuel);
float efficiency = Mathf.Clamp(parent.GetStatValue(StatDef.Named("NutrientTransmissionEfficiency")), 0f, 0.1f);
float efficiency = Mathf.Clamp(parent.GetStatValue(StatDef.Named("NutrientTransmissionEfficiency")), 0f, Props.maxEfficiency);
float finalCost = fuelToTransfer * (1 - efficiency);
Log.Message($"[NutrientProvider] Found target: {targetBuilding.Building.Label}. Fuel: {consumerComp.Fuel:F0}/{consumerComp.Props.fuelCapacity:F0}. Needs: {fuelNeeded:F2}. Transferring: {fuelToTransfer:F2}. Final cost: {finalCost:F2}");
// Log.Message($"[NutrientProvider] Found target: {targetBuilding.Building.Label}. Fuel: {consumerComp.Fuel:F0}/{consumerComp.Props.fuelCapacity:F0}. Needs: {fuelNeeded:F2}. Transferring: {fuelToTransfer:F2}. Final cost: {finalCost:F2}");
selfRefuelable.ConsumeFuel(finalCost);
consumerComp.ReceiveFuel(fuelToTransfer);
@@ -88,7 +92,7 @@ namespace ArachnaeSwarm
private bool NeedsFuel(CompRefuelableNutrition comp)
{
if (comp == null) return false;
return comp.Fuel < GetDesiredFuelLevel(comp);
return GetDesiredFuelLevel(comp) - comp.Fuel >= 0.1f;
}
private float GetDesiredFuelLevel(CompRefuelableNutrition comp)

View File

@@ -1,9 +1,12 @@
using RimWorld;
using Verse;
namespace ArachnaeSwarm
{
public class CompProperties_NutrientProvider : CompProperties_Facility
{
public float maxEfficiency = 0.9f;
public CompProperties_NutrientProvider()
{
compClass = typeof(CompNutrientProvider);