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