临时提交

This commit is contained in:
2025-06-22 20:39:47 +08:00
parent b3d1135e23
commit d274ae0fec
24 changed files with 603 additions and 50 deletions

View File

@ -44,8 +44,33 @@ public partial class ProductionProcessor : Node
var productionLine = ProductionLineManager.Instance?.GetProductionLine(activeLine.ProductionLineId);
if (productionLine == null) return;
// 特殊处理如果是发电设备powerGeneration > 0 且 productionTime <= 0跳过生产处理
if (productionLine.PowerGeneration > 0 && productionLine.ProductionTime <= 0)
{
// 发电设备不需要生产周期,直接返回
// 发电量已经在添加建筑时注册到PowerManager了
return;
}
// 获取电力满足率
float powerRatio = 1.0f;
var powerManager = PowerManager.Instance;
if (powerManager != null)
{
powerRatio = powerManager.GetPowerRatio();
}
// 根据电力满足率调整生产速度
float adjustedDeltaTime = deltaTime * powerRatio;
// 如果电力不足,减慢生产速度
if (powerRatio < 1.0f)
{
GD.Print($"产线 {productionLine.Name} 电力不足,生产速度调整为 {powerRatio * 100:F1}%");
}
// 更新生产时间
activeLine.RemainingTime -= deltaTime;
activeLine.RemainingTime -= adjustedDeltaTime;
if (activeLine.RemainingTime <= 0)
{
@ -62,12 +87,32 @@ public partial class ProductionProcessor : Node
activeLine.RemainingTime = productionLine.ProductionTime;
GD.Print($"产线 {productionLine.Name} 完成一轮生产,{activeLine.BuildingCount} 个建筑同时运行");
// 如果是发电设备通知PowerManager发电机运行
if (productionLine.PowerGeneration > 0)
{
if (powerManager != null)
{
string generatorId = $"{activeLine.ProductionLineId}_{activeLine.BuildingCount}";
powerManager.UpdateGeneratorStatus(generatorId, true);
}
}
}
else
{
// 原料不足,暂停生产
activeLine.RemainingTime = 0.1f; // 短暂等待后再检查
GD.Print($"产线 {productionLine.Name} 原料不足,暂停生产");
// 如果是发电设备通知PowerManager发电机异常
if (productionLine.PowerGeneration > 0)
{
if (powerManager != null)
{
string generatorId = $"{activeLine.ProductionLineId}_{activeLine.BuildingCount}";
powerManager.UpdateGeneratorStatus(generatorId, false);
}
}
}
}
}
@ -77,6 +122,12 @@ public partial class ProductionProcessor : Node
var inventoryManager = InventoryManager.Instance;
if (inventoryManager == null) return false;
// 如果没有输入材料需求如发电设备直接返回true
if (productionLine.Recipe.Inputs == null || productionLine.Recipe.Inputs.Count == 0)
{
return true;
}
// 检查所有输入材料
foreach (var input in productionLine.Recipe.Inputs)
{
@ -143,7 +194,12 @@ public partial class ProductionProcessor : Node
}
float progress = 0;
if (activeLine.IsActive && productionLine.ProductionTime > 0)
// 发电设备的进度条始终显示100%
if (productionLine.PowerGeneration > 0 && productionLine.ProductionTime <= 0)
{
progress = 1.0f; // 发电设备进度始终为100%
}
else if (activeLine.IsActive && productionLine.ProductionTime > 0)
{
progress = 1.0f - (activeLine.RemainingTime / productionLine.ProductionTime);
}