This commit is contained in:
Tourswen
2025-10-02 22:27:05 +08:00
parent 09579a936f
commit 01c95d60a0
23 changed files with 392 additions and 262 deletions

View File

@@ -2,6 +2,10 @@
"Version": 1,
"WorkspaceRootPath": "E:\\SteamLibrary\\steamapps\\common\\RimWorld\\Mods\\ArachnaeSwarm\\Source\\ArachnaeSwarm\\",
"Documents": [
{
"AbsoluteMoniker": "D:0:0:{EAE0DB6B-E282-C812-7F5A-6D13E9D24581}|ArachnaeSwarm.csproj|e:\\steamlibrary\\steamapps\\common\\rimworld\\mods\\arachnaeswarm\\source\\arachnaeswarm\\building_comps\\ara_compinteractiveproducer\\compinteractiveproducer.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
"RelativeMoniker": "D:0:0:{EAE0DB6B-E282-C812-7F5A-6D13E9D24581}|ArachnaeSwarm.csproj|solutionrelative:building_comps\\ara_compinteractiveproducer\\compinteractiveproducer.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
},
{
"AbsoluteMoniker": "D:0:0:{EAE0DB6B-E282-C812-7F5A-6D13E9D24581}|ArachnaeSwarm.csproj|e:\\steamlibrary\\steamapps\\common\\rimworld\\mods\\arachnaeswarm\\source\\arachnaeswarm\\building_comps\\wula_mutifuelspawner\\comprefuelablenutrition_withkey.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
"RelativeMoniker": "D:0:0:{EAE0DB6B-E282-C812-7F5A-6D13E9D24581}|ArachnaeSwarm.csproj|solutionrelative:building_comps\\wula_mutifuelspawner\\comprefuelablenutrition_withkey.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
@@ -23,12 +27,25 @@
{
"$type": "Document",
"DocumentIndex": 0,
"Title": "CompInteractiveProducer.cs",
"DocumentMoniker": "E:\\SteamLibrary\\steamapps\\common\\RimWorld\\Mods\\ArachnaeSwarm\\Source\\ArachnaeSwarm\\Building_Comps\\ARA_CompInteractiveProducer\\CompInteractiveProducer.cs",
"RelativeDocumentMoniker": "Building_Comps\\ARA_CompInteractiveProducer\\CompInteractiveProducer.cs",
"ToolTip": "E:\\SteamLibrary\\steamapps\\common\\RimWorld\\Mods\\ArachnaeSwarm\\Source\\ArachnaeSwarm\\Building_Comps\\ARA_CompInteractiveProducer\\CompInteractiveProducer.cs",
"RelativeToolTip": "Building_Comps\\ARA_CompInteractiveProducer\\CompInteractiveProducer.cs",
"ViewState": "AgIAAAAAAAAAAAAAAAAAAB4AAAA0AAAAAAAAAA==",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
"WhenOpened": "2025-10-02T10:43:34.234Z",
"EditorCaption": ""
},
{
"$type": "Document",
"DocumentIndex": 1,
"Title": "CompRefuelableNutrition_WithKey.cs",
"DocumentMoniker": "E:\\SteamLibrary\\steamapps\\common\\RimWorld\\Mods\\ArachnaeSwarm\\Source\\ArachnaeSwarm\\Building_Comps\\WULA_MutiFuelSpawner\\CompRefuelableNutrition_WithKey.cs",
"RelativeDocumentMoniker": "Building_Comps\\WULA_MutiFuelSpawner\\CompRefuelableNutrition_WithKey.cs",
"ToolTip": "E:\\SteamLibrary\\steamapps\\common\\RimWorld\\Mods\\ArachnaeSwarm\\Source\\ArachnaeSwarm\\Building_Comps\\WULA_MutiFuelSpawner\\CompRefuelableNutrition_WithKey.cs",
"RelativeToolTip": "Building_Comps\\WULA_MutiFuelSpawner\\CompRefuelableNutrition_WithKey.cs",
"ViewState": "AgIAABwAAAAAAAAAAAAUwFsAAAAcAAAAAAAAAA==",
"ViewState": "AgIAAAAAAAAAAAAAAAAAAFsAAAAcAAAAAAAAAA==",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
"WhenOpened": "2025-10-02T06:18:10.518Z",
"EditorCaption": ""

View File

@@ -101,6 +101,22 @@ namespace ArachnaeSwarm
Log.Warning($"Could not find ProcessDef for {selectedProcessThingDef.defName} after loading. Resetting production.");
ResetProduction();
}
// 关键修复:检查时间戳是否有效
else if (productionUntilTick > 0)
{
// 如果生产结束时间已经过去,立即完成生产
if (Find.TickManager.TicksGame >= productionUntilTick)
{
Log.Warning($"Production time already passed for {selectedProcessThingDef.defName}. Finishing immediately.");
FinishProduction();
}
// 如果时间戳异常(比如超过游戏当前时间太多),重新计算
else if (productionUntilTick - Find.TickManager.TicksGame > _selectedProcess.productionTicks * 10)
{
Log.Warning($"Abnormal production time detected for {selectedProcessThingDef.defName}. Recalculating.");
productionUntilTick = Find.TickManager.TicksGame + _selectedProcess.productionTicks;
}
}
}
}
@@ -205,6 +221,14 @@ namespace ArachnaeSwarm
base.CompTick();
if (InProduction && productionUntilTick > 0)
{
// 关键修复:添加时间戳有效性检查
if (productionUntilTick <= 0)
{
Log.Error($"Invalid productionUntilTick: {productionUntilTick}. Resetting production.");
ResetProduction();
return;
}
if (FuelComp == null) return;
bool hasFuel = FuelComp.HasFuel;
@@ -212,6 +236,10 @@ namespace ArachnaeSwarm
if (!hasFuel)
{
parent.TakeDamage(new DamageInfo(DamageDefOf.Rotting, Props.damagePerTickWhenUnfueled));
// 修复:没有燃料时不推进生产,而是暂停
// 移除原来的 productionUntilTick++ 逻辑
return;
}
float ambientTemperature = parent.AmbientTemperature;
@@ -226,7 +254,8 @@ namespace ArachnaeSwarm
temperaturePenaltyPercent = Mathf.Min(1f, temperaturePenaltyPercent + tempDelta * Props.penaltyPerDegreePerTick);
}
if (Find.TickManager.TicksGame >= productionUntilTick)
// 修复:添加额外的边界检查
if (productionUntilTick > 0 && Find.TickManager.TicksGame >= productionUntilTick)
{
FinishProduction();
}
@@ -306,27 +335,37 @@ namespace ArachnaeSwarm
{
if (_selectedProcess == null)
{
Log.Warning("FinishProduction called but _selectedProcess is null. Resetting.");
ResetProduction();
return;
}
var qualityDetails = GetEstimatedQualityDetails();
QualityCategory finalQuality = qualityDetails.quality;
for (int i = 0; i < Props.spawnCount.RandomInRange; i++)
try
{
Thing product = ThingMaker.MakeThing(_selectedProcess.thingDef);
product.TryGetComp<CompQuality>()?.SetQuality(finalQuality, ArtGenerationContext.Colony);
GenPlace.TryPlaceThing(product, parent.Position, parent.Map, ThingPlaceMode.Near);
}
var qualityDetails = GetEstimatedQualityDetails();
QualityCategory finalQuality = qualityDetails.quality;
if (Props.destroyOnSpawn)
for (int i = 0; i < Props.spawnCount.RandomInRange; i++)
{
Thing product = ThingMaker.MakeThing(_selectedProcess.thingDef);
product.TryGetComp<CompQuality>()?.SetQuality(finalQuality, ArtGenerationContext.Colony);
GenPlace.TryPlaceThing(product, parent.Position, parent.Map, ThingPlaceMode.Near);
}
if (Props.destroyOnSpawn)
{
parent.Destroy(DestroyMode.Vanish);
}
}
catch (System.Exception ex)
{
parent.Destroy(DestroyMode.Vanish);
Log.Error($"Error in FinishProduction: {ex.Message}");
}
finally
{
ResetProduction();
}
ResetProduction();
}
private void ResetProduction()
@@ -378,6 +417,16 @@ namespace ArachnaeSwarm
icon = CancelIcon,
action = () => ResetProduction()
};
// 调试命令:强制完成生产
if (Prefs.DevMode)
{
yield return new Command_Action
{
defaultLabel = "Debug: Force Finish",
action = () => FinishProduction()
};
}
}
}
}

View File

@@ -141,6 +141,13 @@ namespace ArachnaeSwarm
foreach(var order in producingOrders)
{
// 关键修复:检查时间戳有效性
if (order.productionUntilTick <= 0)
{
Log.Error($"Invalid productionUntilTick: {order.productionUntilTick} for {order.process?.thingDef?.defName}. Skipping.");
continue;
}
if(hasFuel && isTempSafe)
{
order.ticksUnderOptimalConditions++;
@@ -150,10 +157,8 @@ namespace ArachnaeSwarm
float tempDelta = (ambientTemperature > Props.maxSafeTemperature) ? ambientTemperature - Props.maxSafeTemperature : Props.minSafeTemperature - ambientTemperature;
order.temperaturePenaltyPercent = Mathf.Min(1f, order.temperaturePenaltyPercent + tempDelta * Props.penaltyPerDegreePerTick);
}
if (!hasFuel)
{
order.productionUntilTick++;
}
// 修复:移除原来的 order.productionUntilTick++ 逻辑
// 没有燃料时暂停生产
}
if (FuelComp != null)
@@ -217,14 +222,27 @@ namespace ArachnaeSwarm
private void FinishProduction(QueuedProcessOrder order)
{
var qualityDetails = GetEstimatedQualityDetails(order);
QualityCategory finalQuality = qualityDetails.quality;
for (int i = 0; i < Props.spawnCount.RandomInRange; i++)
if (order.process == null)
{
Thing product = ThingMaker.MakeThing(order.process.thingDef);
product.TryGetComp<CompQuality>()?.SetQuality(finalQuality, ArtGenerationContext.Colony);
GenPlace.TryPlaceThing(product, parent.Position, parent.Map, ThingPlaceMode.Near);
Log.Warning("FinishProduction called but order.process is null. Skipping.");
return;
}
try
{
var qualityDetails = GetEstimatedQualityDetails(order);
QualityCategory finalQuality = qualityDetails.quality;
for (int i = 0; i < Props.spawnCount.RandomInRange; i++)
{
Thing product = ThingMaker.MakeThing(order.process.thingDef);
product.TryGetComp<CompQuality>()?.SetQuality(finalQuality, ArtGenerationContext.Colony);
GenPlace.TryPlaceThing(product, parent.Position, parent.Map, ThingPlaceMode.Near);
}
}
catch (System.Exception ex)
{
Log.Error($"Error in FinishProduction for {order.process.thingDef.defName}: {ex.Message}");
}
}
@@ -306,6 +324,26 @@ namespace ArachnaeSwarm
Log.Warning($"CompQueuedInteractiveProducer: Could not find a matching ProcessDef for '{order.tempThingDefName}' after loading. The item may have been removed. Removing order.");
return true;
}
// 关键修复:检查加载后的时间戳有效性
if (order.productionUntilTick > 0)
{
// 如果生产结束时间已经过去,立即完成生产
if (Find.TickManager.TicksGame >= order.productionUntilTick)
{
Log.Warning($"Production time already passed for {order.tempThingDefName}. Finishing immediately.");
FinishProduction(order);
return true;
}
// 如果时间戳异常(比如超过游戏当前时间太多),重新计算
else if (order.productionUntilTick - Find.TickManager.TicksGame > order.process.productionTicks * 10)
{
Log.Warning($"Abnormal production time detected for {order.tempThingDefName}. Recalculating.");
float speedFactor = 1f + (FacilitiesComp?.GetStatOffset(StatDef.Named("ARA_IncubationSpeedFactor")) ?? 0f);
int modifiedDelay = (int)(order.process.productionTicks / speedFactor);
order.productionUntilTick = Find.TickManager.TicksGame + modifiedDelay;
}
}
return false;
});
@@ -419,4 +457,4 @@ namespace ArachnaeSwarm
return 10f;
}
}
}
}