Browse Source

Rider cleanup suggestions in calculator

main
Jonathan 11 months ago
parent
commit
b8d2210cc5
  1. 2
      IGP/Pages/BuildCalculator/Parts/BuildChartComponent.razor
  2. 1
      Model/Entity/Data/DATA.cs
  3. 2
      Model/Entity/Data/Ids_Entity.cs
  4. 98
      Services/Immortal/EconomyService.cs

2
IGP/Pages/BuildCalculator/Parts/BuildChartComponent.razor

@ -23,10 +23,8 @@ else
var x = int.Parse(point.GetInterval(chart.HighestIntervalPoint, chart.IntervalDisplayMax)); var x = int.Parse(point.GetInterval(chart.HighestIntervalPoint, chart.IntervalDisplayMax));
if (takenPixels.ContainsKey(x)) continue; if (takenPixels.ContainsKey(x)) continue;
takenPixels.Add(x, true); takenPixels.Add(x, true);
<div style="position: absolute; <div style="position: absolute;
bottom:@point.GetValue(chart.HighestValuePoint, chart.ValueDisplayMax)px; bottom:@point.GetValue(chart.HighestValuePoint, chart.ValueDisplayMax)px;
left:@point.GetInterval(chart.HighestIntervalPoint, chart.IntervalDisplayMax)px; left:@point.GetInterval(chart.HighestIntervalPoint, chart.IntervalDisplayMax)px;

1
Model/Entity/Data/DATA.cs

@ -1457,7 +1457,6 @@ public abstract class DATA
.AddPart(new EntityIdUpgradeModel { Id = DataType.UPGRADE_PursuitLigaments }) .AddPart(new EntityIdUpgradeModel { Id = DataType.UPGRADE_PursuitLigaments })
.AddPart(new EntityIdPassiveModel { Id = DataType.PASSIVE_ExternalDigestion }) .AddPart(new EntityIdPassiveModel { Id = DataType.PASSIVE_ExternalDigestion })
.AddPart(new EntityIdPassiveModel { Id = DataType.PASSIVE_PursuitLigaments }) .AddPart(new EntityIdPassiveModel { Id = DataType.PASSIVE_PursuitLigaments })
.AddPart(new EntityIdPassiveModel { Id = DataType.PASSIVE_DenInstinct })
}, },
{ {
DataType.UNIT_Aarox, DataType.UNIT_Aarox,

2
Model/Entity/Data/Ids_Entity.cs

@ -208,8 +208,6 @@ public static class DataType
public static string PASSIVE_ExternalDigestion = "2563723b-4a75-4a17-a104-1f5ac3b79a06"; public static string PASSIVE_ExternalDigestion = "2563723b-4a75-4a17-a104-1f5ac3b79a06";
public static string PASSIVE_PursuitLigaments = "9f9676d5-cf6c-417d-9d08-ace400ccd39b"; public static string PASSIVE_PursuitLigaments = "9f9676d5-cf6c-417d-9d08-ace400ccd39b";
public static string PASSIVE_DenInstinct = "e5913d8b-a4de-40d8-a1ee-245f5b65990c";
public static string PASSIVE_OssifyingSwarm = "b8897247-8393-416e-b246-409a6b3263c2"; public static string PASSIVE_OssifyingSwarm = "b8897247-8393-416e-b246-409a6b3263c2";
public static string PASSIVE_CastingFromBlood = "c97d1cf1-67d9-402b-9fa1-1abb9bfd7bfd"; public static string PASSIVE_CastingFromBlood = "c97d1cf1-67d9-402b-9fa1-1abb9bfd7bfd";

98
Services/Immortal/EconomyService.cs

@ -1,14 +1,13 @@
using Model.Economy; using Model.Economy;
using Model.Entity; using Model.Entity;
using Model.Entity.Parts;
using Model.Types; using Model.Types;
namespace Services.Immortal; namespace Services.Immortal;
public class EconomyService : IEconomyService public class EconomyService : IEconomyService
{ {
private List<EconomyModel> buildEconomyOverTime = null!; private List<EconomyModel>? buildEconomyOverTime;
private Dictionary<string, List<EconomyModel>> specficEconomiesOverTime = null!;
public List<EconomyModel> GetOverTime() public List<EconomyModel> GetOverTime()
{ {
@ -30,15 +29,13 @@ public class EconomyService : IEconomyService
// We don't consider things mining at zero seconds // We don't consider things mining at zero seconds
if (fromInterval == 0) fromInterval = 1; if (fromInterval == 0) fromInterval = 1;
//TODO Break all this up
if (buildEconomyOverTime == null) if (buildEconomyOverTime == null)
{ {
buildEconomyOverTime = new List<EconomyModel>(); buildEconomyOverTime = [];
for (var interval = 0; interval < timing.GetAttackTime(); interval++) for (var interval = 0; interval < timing.GetAttackTime(); interval++)
buildEconomyOverTime.Add(new EconomyModel { Interval = interval }); buildEconomyOverTime.Add(new EconomyModel { Interval = interval });
} }
if (buildEconomyOverTime.Count > timing.GetAttackTime()) if (buildEconomyOverTime.Count > timing.GetAttackTime())
buildEconomyOverTime.RemoveRange(timing.GetAttackTime(), buildEconomyOverTime.RemoveRange(timing.GetAttackTime(),
buildEconomyOverTime.Count - timing.GetAttackTime()); buildEconomyOverTime.Count - timing.GetAttackTime());
@ -54,7 +51,7 @@ public class EconomyService : IEconomyService
CarryOverEconomyFromPreviousInterval(interval, economyAtSecond); CarryOverEconomyFromPreviousInterval(interval, economyAtSecond);
SetupCurrentInverval(buildOrder, economyAtSecond, interval); SetupCurrentInterval(buildOrder, economyAtSecond, interval);
AddPassivePyreGain(interval, economyAtSecond); AddPassivePyreGain(interval, economyAtSecond);
float freeWorkers = economyAtSecond.WorkerCount - economyAtSecond.BusyWorkerCount; float freeWorkers = economyAtSecond.WorkerCount - economyAtSecond.BusyWorkerCount;
var workersNeeded = AddFundsFromHarvestPoints(economyAtSecond, freeWorkers); var workersNeeded = AddFundsFromHarvestPoints(economyAtSecond, freeWorkers);
@ -70,12 +67,12 @@ public class EconomyService : IEconomyService
public EconomyModel GetEconomy(int atInterval) public EconomyModel GetEconomy(int atInterval)
{ {
if (atInterval >= buildEconomyOverTime.Count) return buildEconomyOverTime.Last(); return atInterval >= buildEconomyOverTime.Count
? buildEconomyOverTime.Last()
return buildEconomyOverTime[atInterval]; : buildEconomyOverTime[atInterval];
} }
private static void SetupCurrentInverval(IBuildOrderService buildOrder, EconomyModel economyAtSecond, int interval) private static void SetupCurrentInterval(IBuildOrderService buildOrder, EconomyModel economyAtSecond, int interval)
{ {
economyAtSecond.Interval = interval; economyAtSecond.Interval = interval;
economyAtSecond.HarvestPoints = economyAtSecond.HarvestPoints =
@ -86,66 +83,61 @@ public class EconomyService : IEconomyService
private static void HandledAddingNewHarvestPointsAndWorkersToEconomy(IBuildOrderService buildOrder, int interval, private static void HandledAddingNewHarvestPointsAndWorkersToEconomy(IBuildOrderService buildOrder, int interval,
EconomyModel economyAtSecond) EconomyModel economyAtSecond)
{ {
if (buildOrder.CompletedOrders.TryGetValue(interval, out var completedAtInterval)) if (!buildOrder.CompletedOrders.TryGetValue(interval, out var completedAtInterval)) return;
foreach (var newEntity in completedAtInterval) foreach (var newEntity in completedAtInterval)
{ {
var harvest = newEntity; economyAtSecond.HarvestPoints.Add(newEntity);
if (harvest != null) economyAtSecond.HarvestPoints.Add(harvest);
var production = newEntity.Production(); var production = newEntity.Production();
if (production != null && production.RequiresWorker) economyAtSecond.BusyWorkerCount -= 1; if (production is { RequiresWorker: true }) economyAtSecond.BusyWorkerCount -= 1;
} }
} }
private static void SubtractFundsOnRequestedOrders(IBuildOrderService buildOrder, int interval, private static void SubtractFundsOnRequestedOrders(IBuildOrderService buildOrder, int interval,
EconomyModel economyAtSecond) EconomyModel economyAtSecond)
{ {
if (buildOrder.StartedOrders.TryGetValue(interval, out var ordersAtTime)) if (!buildOrder.StartedOrders.TryGetValue(interval, out var ordersAtTime)) return;
foreach (var order in ordersAtTime)
{
var foundEntity = EntityModel.GetDictionary()[order.DataType];
var production = foundEntity.Production();
if (production != null) foreach (var production in
ordersAtTime.Select(order => EntityModel.GetDictionary()[order.DataType])
.Select(foundEntity => foundEntity.Production())
.OfType<EntityProductionModel>())
{ {
economyAtSecond.Alloy -= production.Alloy; economyAtSecond.Alloy -= production.Alloy;
economyAtSecond.Ether -= production.Ether; economyAtSecond.Ether -= production.Ether;
economyAtSecond.Pyre -= production.Pyre; economyAtSecond.Pyre -= production.Pyre;
var finishedAt = interval + production.BuildTime;
if (production.RequiresWorker) economyAtSecond.BusyWorkerCount += 1; if (production.RequiresWorker) economyAtSecond.BusyWorkerCount += 1;
if (production.ConsumesWorker) economyAtSecond.WorkerCount -= 1; if (production.ConsumesWorker) economyAtSecond.WorkerCount -= 1;
} }
} }
}
private static void MakeNeededNewWorkersRequests(int workersNeeded, EconomyModel economyAtSecond) private static void MakeNeededNewWorkersRequests(int workersNeeded, EconomyModel economyAtSecond)
{ {
if (workersNeeded > economyAtSecond.CreatingWorkerCount) if (workersNeeded <= economyAtSecond.CreatingWorkerCount) return;
{
economyAtSecond.CreatingWorkerCount += 1; economyAtSecond.CreatingWorkerCount += 1;
economyAtSecond.CreatingWorkerDelays.Add(20); economyAtSecond.CreatingWorkerDelays.Add(20);
} }
}
/** /**
* Returns amount of workers created * Returns number of workers created
*/ */
private static int CalculateCreatingWorkerCosts(EconomyModel economyAtSecond) private static int CalculateCreatingWorkerCosts(EconomyModel economyAtSecond)
{ {
var createdWorkers = 0; var createdWorkers = 0;
if (economyAtSecond.CreatingWorkerCount > 0) if (economyAtSecond.CreatingWorkerCount <= 0) return createdWorkers;
for (var i = 0; i < economyAtSecond.CreatingWorkerDelays.Count; i++) for (var i = 0; i < economyAtSecond.CreatingWorkerDelays.Count; i++)
if (economyAtSecond.CreatingWorkerDelays[i] > 0) if (economyAtSecond.CreatingWorkerDelays[i] > 0)
{ {
if (economyAtSecond.Alloy > 2.5f) if (!(economyAtSecond.Alloy > 2.5f)) continue;
{
economyAtSecond.Alloy -= 2.5f; economyAtSecond.Alloy -= 2.5f;
economyAtSecond.CreatingWorkerDelays[i]--; economyAtSecond.CreatingWorkerDelays[i]--;
} }
}
else else
{ {
economyAtSecond.CreatingWorkerCount -= 1; economyAtSecond.CreatingWorkerCount -= 1;
@ -165,33 +157,43 @@ public class EconomyService : IEconomyService
{ {
var workersNeeded = 0; var workersNeeded = 0;
foreach (var entity in economyAtSecond.HarvestPoints) foreach (var harvesterPoint in
economyAtSecond.HarvestPoints.Select(entity => entity.Harvest()))
{ {
var harvester = entity.Harvest(); switch (harvesterPoint.RequiresWorker)
if (harvester.RequiresWorker)
if (harvester.Resource == ResourceType.Alloy)
{ {
var usedWorkers = Math.Min(harvester.Slots, freeWorkers); case true:
economyAtSecond.Alloy += harvester.HarvestedPerInterval * usedWorkers; {
economyAtSecond.AlloyIncome += harvester.HarvestedPerInterval * usedWorkers; if (harvesterPoint.Resource == ResourceType.Alloy)
{
var usedWorkers = Math.Min(harvesterPoint.Slots, freeWorkers);
economyAtSecond.Alloy += harvesterPoint.HarvestedPerInterval * usedWorkers;
economyAtSecond.AlloyIncome += harvesterPoint.HarvestedPerInterval * usedWorkers;
freeWorkers -= usedWorkers; freeWorkers -= usedWorkers;
if (usedWorkers < harvester.Slots) workersNeeded += 1; if (usedWorkers < harvesterPoint.Slots) workersNeeded += 1;
} }
if (harvester.RequiresWorker == false) break;
}
case false:
{ {
if (harvester.Resource == ResourceType.Ether) switch (harvesterPoint.Resource)
{ {
economyAtSecond.Ether += harvester.HarvestedPerInterval * harvester.Slots; case ResourceType.Ether:
economyAtSecond.EtherIncome += harvester.HarvestedPerInterval * harvester.Slots; economyAtSecond.Ether += harvesterPoint.HarvestedPerInterval * harvesterPoint.Slots;
economyAtSecond.EtherIncome += harvesterPoint.HarvestedPerInterval * harvesterPoint.Slots;
break;
case ResourceType.Alloy:
economyAtSecond.Alloy += harvesterPoint.HarvestedPerInterval * harvesterPoint.Slots;
economyAtSecond.AlloyIncome += harvesterPoint.HarvestedPerInterval * harvesterPoint.Slots;
break;
case ResourceType.Pyre:
break; // Pyre Miner?
} }
if (harvester.Resource == ResourceType.Alloy) break;
{
economyAtSecond.Alloy += harvester.HarvestedPerInterval * harvester.Slots;
economyAtSecond.AlloyIncome += harvester.HarvestedPerInterval * harvester.Slots;
} }
} }
} }

Loading…
Cancel
Save