临时提交
This commit is contained in:
@ -26,6 +26,7 @@ public partial class ProductionLineManager : Node
|
||||
public string Description { get; set; }
|
||||
public float ProductionTime { get; set; }
|
||||
public int PowerConsumption { get; set; }
|
||||
public int PowerGeneration { get; set; } = 0; // 新增:发电量
|
||||
public List<ProductionRecipeItem> BuildingRequirements { get; set; } = new List<ProductionRecipeItem>();
|
||||
public ProductionRecipe Recipe { get; set; } = new ProductionRecipe();
|
||||
}
|
||||
@ -44,6 +45,7 @@ public partial class ProductionLineManager : Node
|
||||
public bool IsActive { get; set; } = false; // 是否激活
|
||||
public float ProductionRate { get; set; } = 0; // 每秒产出率
|
||||
public int TotalPowerConsumption { get; set; } = 0; // 总功耗
|
||||
public int TotalPowerGeneration { get; set; } = 0; // 总发电量
|
||||
}
|
||||
|
||||
private ProductionLineData productionLineData;
|
||||
@ -191,19 +193,59 @@ public partial class ProductionLineManager : Node
|
||||
activeProductionLines[productionLineId] = new ActiveProductionLine
|
||||
{
|
||||
ProductionLineId = productionLineId,
|
||||
RemainingTime = productionLine.ProductionTime // 从完整的生产时间开始
|
||||
RemainingTime = productionLine.PowerGeneration > 0 && productionLine.ProductionTime <= 0
|
||||
? 0 // 发电设备不需要生产时间
|
||||
: productionLine.ProductionTime // 普通生产设备从完整的生产时间开始
|
||||
};
|
||||
GD.Print($"创建新产线 {productionLine.Name},初始剩余时间: {productionLine.ProductionTime}s");
|
||||
|
||||
if (productionLine.PowerGeneration > 0 && productionLine.ProductionTime <= 0)
|
||||
{
|
||||
GD.Print($"创建新发电设备 {productionLine.Name},无需生产周期");
|
||||
}
|
||||
else
|
||||
{
|
||||
GD.Print($"创建新产线 {productionLine.Name},初始剩余时间: {productionLine.ProductionTime}s");
|
||||
}
|
||||
}
|
||||
|
||||
var activeLine = activeProductionLines[productionLineId];
|
||||
activeLine.BuildingCount += count;
|
||||
activeLine.IsActive = true;
|
||||
activeLine.ProductionRate = activeLine.BuildingCount / productionLine.ProductionTime; // 每秒产出率
|
||||
|
||||
// 重新计算产出率:发电设备特殊处理
|
||||
if (productionLine.PowerGeneration > 0 && productionLine.ProductionTime <= 0)
|
||||
{
|
||||
// 发电设备不产出物品,产出率设为0
|
||||
activeLine.ProductionRate = 0;
|
||||
}
|
||||
else if (productionLine.ProductionTime > 0)
|
||||
{
|
||||
activeLine.ProductionRate = activeLine.BuildingCount / productionLine.ProductionTime;
|
||||
}
|
||||
else
|
||||
{
|
||||
activeLine.ProductionRate = 0; // 避免除零
|
||||
}
|
||||
|
||||
activeLine.TotalPowerConsumption = activeLine.BuildingCount * productionLine.PowerConsumption;
|
||||
activeLine.TotalPowerGeneration = activeLine.BuildingCount * productionLine.PowerGeneration;
|
||||
|
||||
// 如果是发电设备,通知PowerManager
|
||||
if (productionLine.PowerGeneration > 0)
|
||||
{
|
||||
var powerManager = PowerManager.Instance;
|
||||
if (powerManager != null)
|
||||
{
|
||||
// 使用更简单的generatorId,避免重复问题
|
||||
string generatorId = $"{productionLineId}";
|
||||
float totalGeneration = productionLine.PowerGeneration * activeLine.BuildingCount;
|
||||
powerManager.AddGenerator(generatorId, totalGeneration);
|
||||
GD.Print($"发电设备 {productionLine.Name} 已添加到电网: +{totalGeneration}W");
|
||||
}
|
||||
}
|
||||
|
||||
GD.Print($"成功添加 {count} 个设备到产线 {productionLine.Name}");
|
||||
GD.Print($"当前产线状态: {activeLine.BuildingCount} 个建筑, 产出率: {activeLine.ProductionRate:F2}/s, 功耗: {activeLine.TotalPowerConsumption}W");
|
||||
GD.Print($"当前产线状态: {activeLine.BuildingCount} 个建筑, 产出率: {activeLine.ProductionRate:F2}/s, 功耗: {activeLine.TotalPowerConsumption}W, 发电: {activeLine.TotalPowerGeneration}W");
|
||||
}
|
||||
|
||||
public void RemoveBuilding(string productionLineId, int count = 1)
|
||||
@ -220,6 +262,18 @@ public partial class ProductionLineManager : Node
|
||||
count = Mathf.Min(count, activeLine.BuildingCount);
|
||||
if (count <= 0) return;
|
||||
|
||||
// 如果是发电设备,先通知PowerManager移除发电量
|
||||
if (productionLine.PowerGeneration > 0)
|
||||
{
|
||||
var powerManager = PowerManager.Instance;
|
||||
if (powerManager != null)
|
||||
{
|
||||
string generatorId = $"{productionLineId}";
|
||||
float totalGeneration = productionLine.PowerGeneration * activeLine.BuildingCount;
|
||||
powerManager.RemoveGenerator(generatorId);
|
||||
}
|
||||
}
|
||||
|
||||
activeLine.BuildingCount -= count;
|
||||
|
||||
if (activeLine.BuildingCount <= 0)
|
||||
@ -227,11 +281,40 @@ public partial class ProductionLineManager : Node
|
||||
activeLine.IsActive = false;
|
||||
activeLine.ProductionRate = 0;
|
||||
activeLine.TotalPowerConsumption = 0;
|
||||
activeLine.TotalPowerGeneration = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
activeLine.ProductionRate = activeLine.BuildingCount / productionLine.ProductionTime;
|
||||
// 重新计算产出率:发电设备特殊处理
|
||||
if (productionLine.PowerGeneration > 0 && productionLine.ProductionTime <= 0)
|
||||
{
|
||||
// 发电设备不产出物品,产出率设为0
|
||||
activeLine.ProductionRate = 0;
|
||||
}
|
||||
else if (productionLine.ProductionTime > 0)
|
||||
{
|
||||
activeLine.ProductionRate = activeLine.BuildingCount / productionLine.ProductionTime;
|
||||
}
|
||||
else
|
||||
{
|
||||
activeLine.ProductionRate = 0; // 避免除零
|
||||
}
|
||||
|
||||
activeLine.TotalPowerConsumption = activeLine.BuildingCount * productionLine.PowerConsumption;
|
||||
activeLine.TotalPowerGeneration = activeLine.BuildingCount * productionLine.PowerGeneration;
|
||||
|
||||
// 如果是发电设备且还有剩余建筑,重新添加到PowerManager
|
||||
if (productionLine.PowerGeneration > 0)
|
||||
{
|
||||
var powerManager = PowerManager.Instance;
|
||||
if (powerManager != null)
|
||||
{
|
||||
string newGeneratorId = $"{productionLineId}";
|
||||
float totalGeneration = productionLine.PowerGeneration * activeLine.BuildingCount;
|
||||
powerManager.AddGenerator(newGeneratorId, totalGeneration);
|
||||
GD.Print($"发电设备 {productionLine.Name} 已添加到电网: +{totalGeneration}W");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 归还建筑材料到库存
|
||||
@ -246,7 +329,7 @@ public partial class ProductionLineManager : Node
|
||||
}
|
||||
|
||||
GD.Print($"移除 {count} 个设备从产线 {productionLine.Name}");
|
||||
GD.Print($"当前产线状态: {activeLine.BuildingCount} 个建筑, 产出率: {activeLine.ProductionRate:F2}/s, 功耗: {activeLine.TotalPowerConsumption}W");
|
||||
GD.Print($"当前产线状态: {activeLine.BuildingCount} 个建筑, 产出率: {activeLine.ProductionRate:F2}/s, 功耗: {activeLine.TotalPowerConsumption}W, 发电: {activeLine.TotalPowerGeneration}W");
|
||||
}
|
||||
|
||||
public ActiveProductionLine GetActiveProductionLine(string productionLineId)
|
||||
|
||||
Reference in New Issue
Block a user