feat(BuildCalc) Finished training capacity feature
This commit is contained in:
+2
-3
@@ -1,5 +1,4 @@
|
|||||||
@inject HttpClient httpClient
|
@inject IVariableService VariableService
|
||||||
@inject IVariableService variableService
|
|
||||||
|
|
||||||
<Router AppAssembly="@typeof(App).Assembly">
|
<Router AppAssembly="@typeof(App).Assembly">
|
||||||
<Found Context="routeData">
|
<Found Context="routeData">
|
||||||
@@ -76,7 +75,7 @@
|
|||||||
|
|
||||||
protected override async Task OnInitializedAsync()
|
protected override async Task OnInitializedAsync()
|
||||||
{
|
{
|
||||||
await variableService.Load();
|
await VariableService.Load();
|
||||||
isLoaded = true;
|
isLoaded = true;
|
||||||
StateHasChanged();
|
StateHasChanged();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ public class BuildOrderModel
|
|||||||
public Dictionary<string, int> UniqueCompletedCount { get; set; } = new();
|
public Dictionary<string, int> UniqueCompletedCount { get; set; } = new();
|
||||||
public Dictionary<int, int> SupplyCountTimes { get; set; } = new();
|
public Dictionary<int, int> SupplyCountTimes { get; set; } = new();
|
||||||
|
|
||||||
public Dictionary<string, Dictionary<int, List<EntityModel>>> UniqueCompleted { get; set; } = new();
|
public Dictionary<string, List<EntityModel>> UniqueCompleted { get; set; } = new();
|
||||||
|
|
||||||
public List<TrainingCapacityUsedModel> TrainingCapacityUsed { get; set; } = new();
|
public List<TrainingCapacityUsedModel> TrainingCapacityUsed { get; set; } = new();
|
||||||
|
|
||||||
|
|||||||
@@ -77,10 +77,7 @@ public class BuildOrderService : IBuildOrderService
|
|||||||
_buildOrder.UniqueCompletedCount[entity.DataType]++;
|
_buildOrder.UniqueCompletedCount[entity.DataType]++;
|
||||||
|
|
||||||
if (!_buildOrder.UniqueCompleted.ContainsKey(entity.DataType))
|
if (!_buildOrder.UniqueCompleted.ContainsKey(entity.DataType))
|
||||||
_buildOrder.UniqueCompleted.Add(entity.DataType, new Dictionary<int, List<EntityModel>>());
|
_buildOrder.UniqueCompleted.Add(entity.DataType, new List<EntityModel>());
|
||||||
|
|
||||||
if (!_buildOrder.UniqueCompleted[entity.DataType].ContainsKey(completedTime))
|
|
||||||
_buildOrder.UniqueCompleted[entity.DataType].Add(completedTime, new List<EntityModel>());
|
|
||||||
|
|
||||||
if (entity.Production()?.ProducedBy != null)
|
if (entity.Production()?.ProducedBy != null)
|
||||||
_buildOrder.TrainingCapacityUsed.Add(new TrainingCapacityUsedModel
|
_buildOrder.TrainingCapacityUsed.Add(new TrainingCapacityUsedModel
|
||||||
@@ -91,7 +88,7 @@ public class BuildOrderService : IBuildOrderService
|
|||||||
UsedBuilding = entity.Production()!.ProducedBy
|
UsedBuilding = entity.Production()!.ProducedBy
|
||||||
});
|
});
|
||||||
|
|
||||||
_buildOrder.UniqueCompleted[entity.DataType][completedTime].Add(entity);
|
_buildOrder.UniqueCompleted[entity.DataType].Add(entity);
|
||||||
|
|
||||||
if (entity.Supply() != null && entity.Supply()!.Takes > 0)
|
if (entity.Supply() != null && entity.Supply()!.Takes > 0)
|
||||||
_buildOrder.CurrentSupplyUsed += entity.Supply()!.Takes;
|
_buildOrder.CurrentSupplyUsed += entity.Supply()!.Takes;
|
||||||
@@ -190,6 +187,7 @@ public class BuildOrderService : IBuildOrderService
|
|||||||
if (!HandleSupply(entity, ref atInterval)) return false;
|
if (!HandleSupply(entity, ref atInterval)) return false;
|
||||||
if (!HandleRequirements(entity, ref atInterval)) return false;
|
if (!HandleRequirements(entity, ref atInterval)) return false;
|
||||||
if (!HandleEconomy(entity, withEconomy, ref atInterval)) return false;
|
if (!HandleEconomy(entity, withEconomy, ref atInterval)) return false;
|
||||||
|
if (!HandleTrainingQueue(entity, ref atInterval)) return false;
|
||||||
|
|
||||||
Add(entity, atInterval);
|
Add(entity, atInterval);
|
||||||
|
|
||||||
@@ -236,11 +234,21 @@ public class BuildOrderService : IBuildOrderService
|
|||||||
if (entityRemoved.Supply()?.Takes > 0)
|
if (entityRemoved.Supply()?.Takes > 0)
|
||||||
_buildOrder.CurrentSupplyUsed -= entityRemoved.Supply()!.Takes;
|
_buildOrder.CurrentSupplyUsed -= entityRemoved.Supply()!.Takes;
|
||||||
|
|
||||||
|
|
||||||
_buildOrder.UniqueCompletedCount[entityRemoved!.DataType]--;
|
_buildOrder.UniqueCompletedCount[entityRemoved!.DataType]--;
|
||||||
if (_buildOrder.UniqueCompletedCount[entityRemoved!.DataType] == 0)
|
if (_buildOrder.UniqueCompletedCount[entityRemoved!.DataType] == 0)
|
||||||
UniqueCompletedTimes.Remove(entityRemoved.DataType);
|
UniqueCompletedTimes.Remove(entityRemoved.DataType);
|
||||||
|
|
||||||
|
_buildOrder.UniqueCompleted[entityRemoved.DataType]
|
||||||
|
.Remove(_buildOrder.UniqueCompleted[entityRemoved.DataType].Last());
|
||||||
|
|
||||||
|
if (entityRemoved.Production() != null
|
||||||
|
&& entityRemoved.Production()!.ProducedBy != null
|
||||||
|
&& entityRemoved.Supply() != null
|
||||||
|
&& entityRemoved.Supply()!.Takes > 0)
|
||||||
|
{
|
||||||
|
_buildOrder.TrainingCapacityUsed.Remove(_buildOrder.TrainingCapacityUsed.Last());
|
||||||
|
}
|
||||||
|
|
||||||
if (entityRemoved.Info().Descriptive == DescriptiveType.Worker)
|
if (entityRemoved.Info().Descriptive == DescriptiveType.Worker)
|
||||||
{
|
{
|
||||||
RemoveLast();
|
RemoveLast();
|
||||||
@@ -330,35 +338,70 @@ public class BuildOrderService : IBuildOrderService
|
|||||||
|
|
||||||
public int? WillMeetTrainingQueue(EntityModel entity)
|
public int? WillMeetTrainingQueue(EntityModel entity)
|
||||||
{
|
{
|
||||||
|
Console.WriteLine($"WillMeetTrainingQueue {entity.Info().Name}");
|
||||||
|
|
||||||
var supply = entity.Supply();
|
var supply = entity.Supply();
|
||||||
var production = entity.Production();
|
var production = entity.Production();
|
||||||
if (supply == null || production == null || supply.Takes.Equals(0)) return 1;
|
|
||||||
|
var checkedInterval = _lastInterval;
|
||||||
|
|
||||||
|
if (supply == null || production == null || supply.Takes.Equals(0))
|
||||||
|
{
|
||||||
|
Console.WriteLine(supply == null ? "Was Null" : supply.Takes);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
var producedBy = production.ProducedBy;
|
var producedBy = production.ProducedBy;
|
||||||
if (producedBy == null)
|
if (producedBy == null)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Produced by Nothing");
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
var uniqueCompleted = _buildOrder.UniqueCompleted[producedBy];
|
|
||||||
|
|
||||||
|
|
||||||
foreach (var used in _buildOrder.TrainingCapacityUsed)
|
|
||||||
{
|
|
||||||
//used.UsedBuilding
|
|
||||||
}
|
}
|
||||||
|
var uniqueCompleted = _buildOrder.UniqueCompleted[producedBy];
|
||||||
|
|
||||||
foreach (var atTime in uniqueCompleted)
|
var shortestIncrement = int.MaxValue;
|
||||||
|
var trainingSlots = 0;
|
||||||
|
bool didDelay = false;
|
||||||
|
|
||||||
|
foreach (var productionEntity in uniqueCompleted) trainingSlots += productionEntity.Supply()!.Grants;
|
||||||
|
|
||||||
|
|
||||||
|
while (true)
|
||||||
{
|
{
|
||||||
foreach (var productionEntity in uniqueCompleted[atTime.Key])
|
var usedSlots = 0;
|
||||||
|
foreach (var used in _buildOrder.TrainingCapacityUsed)
|
||||||
|
if (checkedInterval >= used.StartingUsageTime && checkedInterval < used.StopUsageTime)
|
||||||
|
{
|
||||||
|
usedSlots += used.UsedSlots;
|
||||||
|
var duration = used.StopUsageTime - used.StartingUsageTime;
|
||||||
|
if (duration < shortestIncrement) shortestIncrement = duration;
|
||||||
|
|
||||||
|
Console.WriteLine($"Used slots {used.UsedSlots} Duration {duration} Start {used.StartingUsageTime} Stop {used.StopUsageTime} ");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (usedSlots + supply.Takes <= trainingSlots)
|
||||||
|
{
|
||||||
|
if (didDelay)
|
||||||
|
{
|
||||||
|
_toastService.AddToast(new ToastModel{Title = "Waited", SeverityType = SeverityType.Information, Message = $"Had to wait {checkedInterval - _lastInterval}s for Training Queue."});
|
||||||
|
}
|
||||||
|
|
||||||
|
Console.WriteLine($"Time {checkedInterval} did Delay {didDelay}");
|
||||||
|
|
||||||
|
return checkedInterval;
|
||||||
|
}
|
||||||
|
checkedInterval += shortestIncrement;
|
||||||
|
didDelay = true;
|
||||||
|
|
||||||
|
if (shortestIncrement == int.MaxValue)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
Console.WriteLine($"MaxValue");
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var supplyAtTime in _buildOrder.SupplyCountTimes)
|
|
||||||
if (supply.Takes + _buildOrder.CurrentSupplyUsed < supplyAtTime.Key)
|
|
||||||
return supplyAtTime.Value;
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private event Action OnChange = null!;
|
private event Action OnChange = null!;
|
||||||
@@ -422,19 +465,19 @@ public class BuildOrderService : IBuildOrderService
|
|||||||
|
|
||||||
private bool HandleTrainingQueue(EntityModel entity, ref int atInterval)
|
private bool HandleTrainingQueue(EntityModel entity, ref int atInterval)
|
||||||
{
|
{
|
||||||
var minSupplyInterval = WillMeetSupply(entity);
|
var minTrainingQueueInterval = WillMeetTrainingQueue(entity);
|
||||||
if (minSupplyInterval == null)
|
if (minTrainingQueueInterval == null)
|
||||||
{
|
{
|
||||||
_toastService.AddToast(new ToastModel
|
_toastService.AddToast(new ToastModel
|
||||||
{
|
{
|
||||||
Title = "Supply Cap Reached", Message = "Build more supply!",
|
Title = "Invalid", Message = "Invalid Training Queue error",
|
||||||
SeverityType = SeverityType.Error
|
SeverityType = SeverityType.Error
|
||||||
});
|
});
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (minSupplyInterval > atInterval) atInterval = (int)minSupplyInterval;
|
if (minTrainingQueueInterval > atInterval) atInterval = (int)minTrainingQueueInterval;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user