This commit is contained in:
Tourswen
2025-11-06 02:14:36 +08:00
parent f01c35e95e
commit 762c5db4cf
29 changed files with 702 additions and 467 deletions

View File

@@ -1,4 +1,4 @@
// Building_GlobalWorkTable.cs (调整为每秒处理)
// Building_GlobalWorkTable.cs 中移除材质相关代码
using RimWorld;
using System.Collections.Generic;
using System.Linq;
@@ -15,7 +15,7 @@ namespace WulaFallenEmpire
private CompPowerTrader powerComp;
private CompBreakdownable breakdownableComp;
private int lastProcessTick = -1;
private const int ProcessInterval = 1; // 改为每tick处理以实现每秒1工作量
private const int ProcessInterval = 1;
public Building_GlobalWorkTable()
{
@@ -35,12 +35,10 @@ namespace WulaFallenEmpire
breakdownableComp = GetComp<CompBreakdownable>();
}
// 在 Building_GlobalWorkTable 类中修改 Tick 方法
protected override void Tick()
{
base.Tick();
// 修复改为每60 ticks1秒处理一次避免每tick处理导致的精度问题
if (Find.TickManager.TicksGame % 60 == 0 &&
Find.TickManager.TicksGame != lastProcessTick)
{
@@ -226,7 +224,7 @@ namespace WulaFallenEmpire
return validSpots;
}
// 新增:分配物品到空投舱
// 简化:分配物品到空投舱,移除材质相关代码
private List<List<Thing>> DistributeItemsToPods(GlobalStorageWorldComponent storage, int podCount)
{
List<List<Thing>> podContents = new List<List<Thing>>();
@@ -266,7 +264,7 @@ namespace WulaFallenEmpire
while (remainingCount > 0)
{
int stackSize = Mathf.Min(remainingCount, thingDef.stackLimit);
Thing thing = ThingMaker.MakeThing(thingDef);
Thing thing = ThingMaker.MakeThing(thingDef); // 不再传递材质参数
thing.stackCount = stackSize;
allItems.Add(thing);
remainingCount -= stackSize;
@@ -330,25 +328,6 @@ namespace WulaFallenEmpire
kind.defaultFactionDef != buildingFaction.def)
.ToList();
// 记录调试信息
if (DebugSettings.godMode)
{
Log.Message($"[DEBUG] PawnKind selection for {pawnType.defName}:");
Log.Message($" Building faction: {buildingFaction.def.defName}");
Log.Message($" Matching faction kinds: {matchingFactionKinds.Count}");
Log.Message($" No faction kinds: {noFactionKinds.Count}");
Log.Message($" Excluded kinds: {excludedKinds.Count}");
foreach (var kind in matchingFactionKinds)
Log.Message($" Matching: {kind.defName} (faction: {kind.defaultFactionDef?.defName ?? "null"})");
foreach (var kind in noFactionKinds)
Log.Message($" No faction: {kind.defName}");
foreach (var kind in excludedKinds)
Log.Message($" Excluded: {kind.defName} (faction: {kind.defaultFactionDef?.defName})");
}
// 优先级选择
PawnKindDef selectedKind = null;
@@ -356,15 +335,11 @@ namespace WulaFallenEmpire
if (matchingFactionKinds.Count > 0)
{
selectedKind = matchingFactionKinds.RandomElement();
if (DebugSettings.godMode)
Log.Message($"[DEBUG] Selected matching faction kind: {selectedKind.defName}");
}
// 2. 备选没有defaultFactionDef的PawnKind
else if (noFactionKinds.Count > 0)
{
selectedKind = noFactionKinds.RandomElement();
if (DebugSettings.godMode)
Log.Message($"[DEBUG] Selected no-faction kind: {selectedKind.defName}");
}
// 3. 没有符合条件的PawnKind
else
@@ -376,7 +351,6 @@ namespace WulaFallenEmpire
return selectedKind;
}
// 新增:创建空投舱
private bool CreateDropPod(IntVec3 dropCell, List<Thing> contents)
{

View File

@@ -1,4 +1,4 @@
// GlobalProductionOrder.cs (修正材质属性读取)
// GlobalProductionOrder.cs (移除所有材质相关代码)
using RimWorld;
using System.Collections.Generic;
using System.Linq;
@@ -15,9 +15,6 @@ namespace WulaFallenEmpire
public int currentCount = 0;
public bool paused = true;
// 材质选择:存储配方选择的材质(只有支持材质的配方才有)
public ThingDef chosenStuff = null;
// 生产状态
public ProductionState state = ProductionState.Waiting;
@@ -45,28 +42,6 @@ namespace WulaFallenEmpire
}
}
// 新增:检查订单是否已经开始生产(一旦开始就不能修改材质)
public bool HasStartedProduction => state == ProductionState.Producing || currentCount > 0;
// 修正:检查产物是否支持材质选择
public bool SupportsStuffChoice
{
get
{
if (recipe?.products == null || recipe.products.Count == 0)
return false;
var productDef = recipe.products[0].thingDef;
if (productDef == null)
return false;
// 检查产物是否有stuffCategories且costStuffCount > 0
return productDef.stuffCategories != null &&
productDef.stuffCategories.Count > 0 &&
productDef.costStuffCount > 0;
}
}
// 修正获取产物的ThingDef
public ThingDef ProductDef => recipe?.products?.Count > 0 ? recipe.products[0].thingDef : null;
@@ -78,62 +53,22 @@ namespace WulaFallenEmpire
Scribe_Values.Look(ref paused, "paused", true);
Scribe_Values.Look(ref _progress, "progress", 0f);
Scribe_Values.Look(ref state, "state", ProductionState.Waiting);
Scribe_Defs.Look(ref chosenStuff, "chosenStuff");
// 修复:加载后验证数据
if (Scribe.mode == LoadSaveMode.PostLoadInit)
{
progress = _progress;
UpdateState();
// 确保材质选择有效
if (SupportsStuffChoice && chosenStuff == null)
{
InitializeStuffChoice();
}
}
}
// 修正:初始化材质选择
public void InitializeStuffChoice()
{
if (!SupportsStuffChoice) return;
var availableStuff = GetAvailableStuffForProduct();
if (availableStuff.Count > 0)
{
chosenStuff = availableStuff[0];
}
}
// 修正:获取产物的可用材质列表
public List<ThingDef> GetAvailableStuffForProduct()
{
var availableStuff = new List<ThingDef>();
if (ProductDef?.stuffCategories != null)
{
foreach (var stuffCategory in ProductDef.stuffCategories)
{
var stuffInCategory = DefDatabase<ThingDef>.AllDefs
.Where(def => def.IsStuff && def.stuffProps?.categories != null && def.stuffProps.categories.Contains(stuffCategory))
.ToList();
availableStuff.AddRange(stuffInCategory);
}
}
return availableStuff.Distinct().ToList();
}
// 修正HasEnoughResources 方法,考虑选择的材质
// 简化HasEnoughResources 方法,移除材质检查
public bool HasEnoughResources()
{
var globalStorage = Find.World.GetComponent<GlobalStorageWorldComponent>();
if (globalStorage == null) return false;
// 检查固定消耗costList
// 检查固定消耗costList
foreach (var ingredient in recipe.ingredients)
{
bool hasEnoughForThisIngredient = false;
@@ -154,26 +89,16 @@ namespace WulaFallenEmpire
return false;
}
// 检查材质消耗(如果支持材质选择)
if (SupportsStuffChoice && chosenStuff != null)
{
int requiredStuffCount = ProductDef.costStuffCount;
int availableStuffCount = globalStorage.GetInputStorageCount(chosenStuff);
if (availableStuffCount < requiredStuffCount)
return false;
}
return true;
}
// 修正ConsumeResources 方法,考虑选择的材质
// 简化ConsumeResources 方法,移除材质消耗
public bool ConsumeResources()
{
var globalStorage = Find.World.GetComponent<GlobalStorageWorldComponent>();
if (globalStorage == null) return false;
// 消耗固定资源costList
// 消耗固定资源costList
foreach (var ingredient in recipe.ingredients)
{
bool consumedThisIngredient = false;
@@ -197,19 +122,10 @@ namespace WulaFallenEmpire
return false;
}
// 消耗材质(如果支持材质选择)
if (SupportsStuffChoice && chosenStuff != null)
{
int requiredStuffCount = ProductDef.costStuffCount;
if (!globalStorage.RemoveFromInputStorage(chosenStuff, requiredStuffCount))
return false;
}
return true;
}
// 修正GetIngredientsTooltip 方法,显示固定消耗和可选材质
// 简化GetIngredientsTooltip 方法,显示固定消耗
public string GetIngredientsTooltip()
{
StringBuilder sb = new StringBuilder();
@@ -240,34 +156,6 @@ namespace WulaFallenEmpire
}
}
// 材质消耗(如果支持材质选择)
if (SupportsStuffChoice)
{
sb.AppendLine();
sb.AppendLine("WULA_StuffMaterial".Translate() + ":");
if (chosenStuff != null)
{
int requiredStuffCount = ProductDef.costStuffCount;
int availableStuffCount = globalStorage?.GetInputStorageCount(chosenStuff) ?? 0;
string stuffDisplay = $"{requiredStuffCount} {chosenStuff.LabelCap}";
if (availableStuffCount >= requiredStuffCount)
{
sb.AppendLine($" <color=green>{stuffDisplay} (Selected)</color>");
}
else
{
sb.AppendLine($" <color=red>{stuffDisplay} (Selected)</color>");
}
}
else
{
sb.AppendLine($" <color=yellow>{"WULA_NoStuffSelected".Translate()}</color>");
}
}
// 产品
sb.AppendLine();
sb.AppendLine("WULA_Products".Translate() + ":");
@@ -279,13 +167,6 @@ namespace WulaFallenEmpire
// 工作量信息
sb.AppendLine();
sb.AppendLine("WULA_WorkAmount".Translate() + ": " + GetWorkAmount().ToStringWorkAmount());
// 添加材质选择状态信息
if (HasStartedProduction && SupportsStuffChoice)
{
sb.AppendLine();
sb.AppendLine("<color=yellow>Material choice is locked because production has started.</color>");
}
return sb.ToString();
}

View File

@@ -1,11 +1,11 @@
// GlobalStorageWorldComponent.cs (移除材质相关存储)
using LudeonTK;
using RimWorld;
using RimWorld.Planet;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using Verse;
using UnityEngine;
namespace WulaFallenEmpire
{
@@ -111,6 +111,7 @@ namespace WulaFallenEmpire
Log.Message("Added test resources to global storage");
}
}
[DebugAction("WULA", "Spawn All Products", actionType = DebugActionType.Action)]
public static void DebugSpawnAllProducts()
{

View File

@@ -1,4 +1,4 @@
// ITab_GlobalBills.cs (添加图标支持)
// ITab_GlobalBills.cs (移除材质选择功能)
using System.Collections.Generic;
using System.Linq;
using System.Text;
@@ -57,13 +57,6 @@ namespace WulaFallenEmpire
{
Find.WindowStack.Add(new FloatMenu(GenerateRecipeOptions()));
}
// 绘制鼠标悬停信息 - 使用简单的Tooltip方式
if (mouseoverOrder != null)
{
// 使用Tooltip显示材料信息不绘制额外窗口
// 信息已经在DoOrderRow中的TooltipHandler显示
}
}
// 新增:存储查看按钮
@@ -72,8 +65,6 @@ namespace WulaFallenEmpire
// 绘制按钮
if (Widgets.ButtonText(rect, "WULA_ViewStorage".Translate()))
{
// 点击按钮时也可以做一些事情,比如打开详细存储窗口
// 暂时只显示Tooltip
SoundDefOf.Click.PlayOneShotOnCamera();
}
@@ -111,7 +102,6 @@ namespace WulaFallenEmpire
{
foreach (var kvp in inputItems)
{
// 使用正确的图标格式并保留名称
sb.AppendLine($" {kvp.Value} {kvp.Key.LabelCap}");
}
}
@@ -136,21 +126,13 @@ namespace WulaFallenEmpire
{
foreach (var kvp in outputItems)
{
// 使用正确的图标格式并保留名称
sb.AppendLine($" {kvp.Value} {kvp.Key.LabelCap}");
}
}
// 添加存储统计信息
sb.AppendLine();
sb.AppendLine("WULA_StorageStats".Translate());
sb.AppendLine($" {inputItems.Count} {("WULA_InputItems".Translate())}");
sb.AppendLine($" {outputItems.Count} {("WULA_OutputItems".Translate())}");
return sb.ToString();
}
// 修改:将开发者模式按钮改为上帝模式按钮
private void DoGodModeButtons(Rect rect)
{
@@ -182,7 +164,6 @@ namespace WulaFallenEmpire
globalStorage.AddToInputStorage(componentDef, 100);
Messages.Message("Added 200 Steel and 100 Components to global storage", MessageTypeDefOf.PositiveEvent);
Log.Message("[GOD MODE] Added test resources");
}
}
@@ -227,7 +208,6 @@ namespace WulaFallenEmpire
}
Messages.Message($"Spawned {totalSpawned} items at worktable location", MessageTypeDefOf.PositiveEvent);
Log.Message($"[GOD MODE] Spawned {totalSpawned} output products");
}
}
@@ -271,7 +251,9 @@ namespace WulaFallenEmpire
Widgets.EndScrollView();
return result;
}// 在 ITab_GlobalBills.cs 中修正材质选择功能
}
// 简化DoOrderRow 方法,移除材质选择按钮
private bool DoOrderRow(Rect rect, GlobalProductionOrder order)
{
Widgets.DrawHighlightIfMouseover(rect);
@@ -351,17 +333,6 @@ namespace WulaFallenEmpire
Rect pauseButtonRect = new Rect(currentX - buttonWidth, buttonY, buttonWidth, 25f);
currentX -= (buttonWidth + buttonSpacing);
// 材质选择按钮(如果支持材质选择且未开始生产)
Rect stuffButtonRect = new Rect(0f, 0f, 0f, 0f);
bool showStuffButton = false;
if (order.SupportsStuffChoice && !order.HasStartedProduction)
{
showStuffButton = true;
stuffButtonRect = new Rect(currentX - buttonWidth, buttonY, buttonWidth, 25f);
currentX -= (buttonWidth + buttonSpacing);
}
// 上帝模式:立刻完成按钮
Rect completeButtonRect = new Rect(currentX - buttonWidth, buttonY, buttonWidth, 25f);
@@ -381,29 +352,6 @@ namespace WulaFallenEmpire
SoundDefOf.Click.PlayOneShotOnCamera();
}
// 绘制材质选择按钮
if (showStuffButton)
{
string stuffButtonText = order.chosenStuff != null ?
order.chosenStuff.LabelCap :
"WULA_ChooseStuff".Translate();
if (Widgets.ButtonText(stuffButtonRect, stuffButtonText))
{
ShowStuffSelectionMenu(order);
SoundDefOf.Click.PlayOneShotOnCamera();
}
// 为材质选择按钮添加Tooltip
if (Mouse.IsOver(stuffButtonRect))
{
string tooltip = order.chosenStuff != null ?
$"WULA_CurrentStuff".Translate(order.chosenStuff.LabelCap) :
"WULA_ChooseStuffTooltip".Translate();
TooltipHandler.TipRegion(stuffButtonRect, tooltip);
}
}
// 绘制上帝模式按钮(仅上帝模式下可见)
if (DebugSettings.godMode && order.state != GlobalProductionOrder.ProductionState.Completed)
{
@@ -438,104 +386,8 @@ namespace WulaFallenEmpire
return Mouse.IsOver(rect);
}
// 修正:显示材质选择菜单
private void ShowStuffSelectionMenu(GlobalProductionOrder order)
{
if (order.HasStartedProduction)
{
Messages.Message("WULA_CannotChangeStuffAfterStart".Translate(), MessageTypeDefOf.RejectInput);
return;
}
if (!order.SupportsStuffChoice)
{
Messages.Message("WULA_RecipeDoesNotSupportStuff".Translate(), MessageTypeDefOf.RejectInput);
return;
}
var availableStuff = order.GetAvailableStuffForProduct();
if (availableStuff.Count == 0)
{
Messages.Message("WULA_NoStuffAvailable".Translate(), MessageTypeDefOf.RejectInput);
return;
}
List<FloatMenuOption> options = new List<FloatMenuOption>();
var globalStorage = Find.World.GetComponent<GlobalStorageWorldComponent>();
foreach (var stuffDef in availableStuff)
{
var stuffDefCopy = stuffDef;
// 计算所需数量
int requiredStuffCount = order.ProductDef.costStuffCount;
int availableCount = globalStorage?.GetInputStorageCount(stuffDefCopy) ?? 0;
// 构建显示文本
string label = $"{stuffDefCopy.LabelCap} ({requiredStuffCount} needed)";
if (availableCount < requiredStuffCount)
{
label += $" <color=red>(Only {availableCount} available)</color>";
}
else
{
label += $" <color=green>({availableCount} available)</color>";
}
// 添加材质属性信息
if (stuffDefCopy.stuffProps != null)
{
label += $"\n - {"WULA_Commonality".Translate()}: {stuffDefCopy.stuffProps.commonality}";
if (stuffDefCopy.stuffProps.stuffAdjective != null)
{
label += $"\n - {"WULA_Adjective".Translate()}: {stuffDefCopy.stuffProps.stuffAdjective}";
}
}
options.Add(new FloatMenuOption(
label: label,
action: () =>
{
order.chosenStuff = stuffDefCopy;
Messages.Message($"WULA_StuffSelected".Translate(stuffDefCopy.LabelCap), MessageTypeDefOf.TaskCompletion);
},
shownItemForIcon: stuffDefCopy
));
}
// 添加"自动选择"选项
options.Add(new FloatMenuOption(
label: "WULA_AutoSelectStuff".Translate(),
action: () =>
{
// 选择库存最充足的材质
var bestStuff = availableStuff
.OrderByDescending(stuff => globalStorage?.GetInputStorageCount(stuff) ?? 0)
.ThenBy(stuff => stuff.stuffProps?.commonality ?? 1f)
.FirstOrDefault();
if (bestStuff != null)
{
order.chosenStuff = bestStuff;
Messages.Message($"WULA_StuffAutoSelected".Translate(bestStuff.LabelCap), MessageTypeDefOf.TaskCompletion);
}
}
));
// 添加"清除选择"选项(如果当前有选择)
if (order.chosenStuff != null)
{
options.Add(new FloatMenuOption(
label: "WULA_ClearStuffSelection".Translate(),
action: () =>
{
order.chosenStuff = null;
Messages.Message("WULA_StuffSelectionCleared".Translate(), MessageTypeDefOf.TaskCompletion);
}
));
}
Find.WindowStack.Add(new FloatMenu(options));
}
// 修正:在添加订单时初始化材质选择
// 简化:在添加订单时移除材质初始化
private List<FloatMenuOption> GenerateRecipeOptions()
{
var options = new List<FloatMenuOption>();
@@ -555,15 +407,8 @@ namespace WulaFallenEmpire
paused = true
};
// 初始化材质选择(如果支持)
if (newOrder.SupportsStuffChoice)
{
newOrder.InitializeStuffChoice();
}
SelTable.globalOrderStack.AddOrder(newOrder);
SoundDefOf.Click.PlayOneShotOnCamera();
Log.Message($"[DEBUG] Added order for {recipe.defName}");
},
shownItemForIcon: recipe.UIIconThing,
thingStyle: null,
@@ -659,7 +504,6 @@ namespace WulaFallenEmpire
// 显示完成消息
Messages.Message($"GOD MODE: Completed order for {order.recipe.LabelCap} ({remainingCount} units)", MessageTypeDefOf.PositiveEvent);
Log.Message($"[GOD MODE] Force completed order: {order.recipe.defName}, produced {remainingCount} units");
}
public override void TabUpdate()