人格核心

This commit is contained in:
2025-11-07 12:01:35 +08:00
parent 551875764b
commit 50364ca23b
16 changed files with 1068 additions and 119 deletions

View File

@@ -1,4 +1,4 @@
// GlobalProductionOrder.cs (移除所有材质相关代码)
// GlobalProductionOrder.cs (修复成本计算使用产物的costList)
using RimWorld;
using System.Collections.Generic;
using System.Linq;
@@ -62,13 +62,47 @@ namespace WulaFallenEmpire
}
}
// 简化HasEnoughResources 方法,移除材质检查
// 新增:获取产物的成本列表
private Dictionary<ThingDef, int> GetProductCostList()
{
var costDict = new Dictionary<ThingDef, int>();
if (ProductDef?.costList != null)
{
foreach (var cost in ProductDef.costList)
{
if (costDict.ContainsKey(cost.thingDef))
costDict[cost.thingDef] += cost.count;
else
costDict[cost.thingDef] = cost.count;
}
}
return costDict;
}
// 修复HasEnoughResources 方法使用产物的costList
public bool HasEnoughResources()
{
var globalStorage = Find.World.GetComponent<GlobalStorageWorldComponent>();
if (globalStorage == null) return false;
// 只检查固定消耗costList
// 首先检查产物的costList对于武器等物品
var productCostList = GetProductCostList();
if (productCostList.Count > 0)
{
foreach (var kvp in productCostList)
{
int requiredCount = kvp.Value;
int availableCount = globalStorage.GetInputStorageCount(kvp.Key);
if (availableCount < requiredCount)
return false;
}
return true;
}
// 如果没有costList则回退到配方的ingredients对于加工类配方
foreach (var ingredient in recipe.ingredients)
{
bool hasEnoughForThisIngredient = false;
@@ -92,13 +126,25 @@ namespace WulaFallenEmpire
return true;
}
// 简化ConsumeResources 方法,移除材质消耗
// 修复ConsumeResources 方法,使用产物的costList
public bool ConsumeResources()
{
var globalStorage = Find.World.GetComponent<GlobalStorageWorldComponent>();
if (globalStorage == null) return false;
// 只消耗固定资源costList
// 首先消耗产物的costList对于武器等物品
var productCostList = GetProductCostList();
if (productCostList.Count > 0)
{
foreach (var kvp in productCostList)
{
if (!globalStorage.RemoveFromInputStorage(kvp.Key, kvp.Value))
return false;
}
return true;
}
// 如果没有costList则消耗配方的ingredients对于加工类配方
foreach (var ingredient in recipe.ingredients)
{
bool consumedThisIngredient = false;
@@ -125,22 +171,25 @@ namespace WulaFallenEmpire
return true;
}
// 简化GetIngredientsTooltip 方法,显示固定消耗
// 修复GetIngredientsTooltip 方法,显示正确的成本信息
public string GetIngredientsTooltip()
{
StringBuilder sb = new StringBuilder();
sb.AppendLine(recipe.LabelCap);
sb.AppendLine();
// 固定消耗costList
sb.AppendLine("WULA_FixedIngredients".Translate() + ":");
var globalStorage = Find.World.GetComponent<GlobalStorageWorldComponent>();
foreach (var ingredient in recipe.ingredients)
// 首先显示产物的costList对于武器等物品
var productCostList = GetProductCostList();
if (productCostList.Count > 0)
{
foreach (var thingDef in ingredient.filter.AllowedThingDefs)
sb.AppendLine("WULA_FixedIngredients".Translate() + ":");
foreach (var kvp in productCostList)
{
int requiredCount = ingredient.CountRequiredOfFor(thingDef, recipe);
ThingDef thingDef = kvp.Key;
int requiredCount = kvp.Value;
int availableCount = globalStorage?.GetInputStorageCount(thingDef) ?? 0;
string itemDisplay = $"{requiredCount} {thingDef.LabelCap}";
@@ -155,6 +204,31 @@ namespace WulaFallenEmpire
}
}
}
else
{
// 如果没有costList显示配方的ingredients对于加工类配方
sb.AppendLine("WULA_FixedIngredients".Translate() + ":");
foreach (var ingredient in recipe.ingredients)
{
foreach (var thingDef in ingredient.filter.AllowedThingDefs)
{
int requiredCount = ingredient.CountRequiredOfFor(thingDef, recipe);
int availableCount = globalStorage?.GetInputStorageCount(thingDef) ?? 0;
string itemDisplay = $"{requiredCount} {thingDef.LabelCap}";
if (availableCount >= requiredCount)
{
sb.AppendLine($" <color=green>{itemDisplay}</color>");
}
else
{
sb.AppendLine($" <color=red>{itemDisplay}</color>");
}
}
}
}
// 产品
sb.AppendLine();