zc
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -1,4 +1,5 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using RimWorld;
|
using RimWorld;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using Verse;
|
using Verse;
|
||||||
@@ -133,5 +134,51 @@ namespace ArachnaeSwarm
|
|||||||
|
|
||||||
// 覆盖基类属性,确保 WorkGiver 扫描时拦截
|
// 覆盖基类属性,确保 WorkGiver 扫描时拦截
|
||||||
public new float TargetFuelLevel => allowAutoRefuel ? base.TargetFuelLevel : 0f;
|
public new float TargetFuelLevel => allowAutoRefuel ? base.TargetFuelLevel : 0f;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 覆盖基类方法,根据燃料物品的营养值来计算需要搬运的数量。
|
||||||
|
/// 原版方法假设每个物品=1燃料,这对营养燃料系统是错误的。
|
||||||
|
/// </summary>
|
||||||
|
public new int GetFuelCountToFullyRefuel()
|
||||||
|
{
|
||||||
|
float fuelNeeded = TargetFuelLevel - Fuel;
|
||||||
|
if (fuelNeeded <= 0.001f) return 0;
|
||||||
|
|
||||||
|
// 获取燃料过滤器中物品的平均营养值
|
||||||
|
float avgNutrition = GetAverageNutritionPerUnit();
|
||||||
|
if (avgNutrition <= 0.001f)
|
||||||
|
{
|
||||||
|
// 如果无法计算营养值,回退到原版行为
|
||||||
|
return Mathf.Max(Mathf.CeilToInt(fuelNeeded), 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 根据营养值计算需要的物品数量
|
||||||
|
int count = Mathf.CeilToInt(fuelNeeded / avgNutrition);
|
||||||
|
return Mathf.Max(count, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 计算燃料过滤器中允许的物品的平均营养值。
|
||||||
|
/// </summary>
|
||||||
|
private float GetAverageNutritionPerUnit()
|
||||||
|
{
|
||||||
|
var allowedDefs = Props.fuelFilter?.AllowedThingDefs;
|
||||||
|
if (allowedDefs == null || !allowedDefs.Any()) return 0f;
|
||||||
|
|
||||||
|
float totalNutrition = 0f;
|
||||||
|
int count = 0;
|
||||||
|
|
||||||
|
foreach (var thingDef in allowedDefs)
|
||||||
|
{
|
||||||
|
float nutrition = thingDef.GetStatValueAbstract(StatDefOf.Nutrition);
|
||||||
|
if (nutrition > 0f)
|
||||||
|
{
|
||||||
|
totalNutrition += nutrition;
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return count > 0 ? totalNutrition / count : 0f;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user