人格核心

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 @@
// 在 Building_GlobalWorkTable.cs 中移除材质相关代码
// 在 Building_GlobalWorkTable.cs 中添加材质处理逻辑
using RimWorld;
using System.Collections.Generic;
using System.Linq;
@@ -17,6 +17,13 @@ namespace WulaFallenEmpire
private int lastProcessTick = -1;
private const int ProcessInterval = 1;
// 材质映射定义
private static readonly Dictionary<StuffCategoryDef, ThingDef> StuffCategoryMapping = new Dictionary<StuffCategoryDef, ThingDef>
{
{ StuffCategoryDefOf.Metallic, ThingDefOf.Plasteel }, // 金属类 -> 玻璃钢
{ StuffCategoryDefOf.Fabric, ThingDefOf_WULA.Hyperweave } // 布革类 -> 超织物
};
public Building_GlobalWorkTable()
{
globalOrderStack = new GlobalProductionOrderStack(this);
@@ -214,7 +221,7 @@ namespace WulaFallenEmpire
if (!validSpots.Contains(cell) && cell.Standable(map))
{
validSpots.Add(cell);
if (validSpots.Count >= maxSpots)
break;
}
@@ -224,7 +231,7 @@ namespace WulaFallenEmpire
return validSpots;
}
// 简化:分配物品到空投舱,移除材质相关代码
// 新增:分配物品到空投舱,包含材质处理
private List<List<Thing>> DistributeItemsToPods(GlobalStorageWorldComponent storage, int podCount)
{
List<List<Thing>> podContents = new List<List<Thing>>();
@@ -264,8 +271,7 @@ namespace WulaFallenEmpire
while (remainingCount > 0)
{
int stackSize = Mathf.Min(remainingCount, thingDef.stackLimit);
Thing thing = ThingMaker.MakeThing(thingDef); // 不再传递材质参数
thing.stackCount = stackSize;
Thing thing = CreateThingWithMaterial(thingDef, stackSize);
allItems.Add(thing);
remainingCount -= stackSize;
}
@@ -292,6 +298,57 @@ namespace WulaFallenEmpire
return podContents;
}
// 新增:创建物品并应用材质规则
private Thing CreateThingWithMaterial(ThingDef thingDef, int stackCount)
{
// 检查物品是否需要材质
if (thingDef.MadeFromStuff)
{
// 获取物品可用的材质类别
var stuffCategories = thingDef.stuffCategories;
if (stuffCategories != null && stuffCategories.Count > 0)
{
// 检查是否有金属类材质需求
var metallicCategory = stuffCategories.FirstOrDefault(sc =>
sc.defName == "Metallic" || sc.defName.Contains("Metallic"));
// 检查是否有布革类材质需求
var fabricCategory = stuffCategories.FirstOrDefault(sc =>
sc.defName == "Fabric" || sc.defName.Contains("Fabric") ||
sc.defName == "Leathery" || sc.defName.Contains("Leather"));
// 应用材质规则
ThingDef selectedStuff = null;
if (metallicCategory != null)
{
// 金属类 -> 玻璃钢
selectedStuff = ThingDefOf.Plasteel;
Log.Message($"[Material Rule] {thingDef.defName} requires metallic, using Plasteel");
}
else if (fabricCategory != null)
{
// 布革类 -> 超织物
selectedStuff = ThingDefOf_WULA.Hyperweave;
Log.Message($"[Material Rule] {thingDef.defName} requires fabric/leather, using Hyperweave");
}
// 创建带有指定材质的物品
if (selectedStuff != null)
{
Thing thing = ThingMaker.MakeThing(thingDef, selectedStuff);
thing.stackCount = stackCount;
return thing;
}
}
}
// 默认情况:创建无材质的物品
Thing defaultThing = ThingMaker.MakeThing(thingDef);
defaultThing.stackCount = stackCount;
return defaultThing;
}
// 在 Building_GlobalWorkTable.cs 中修改 GetRandomPawnKindForType 方法
private PawnKindDef GetRandomPawnKindForType(ThingDef pawnType)
{

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();