feat(BuildCalc) Wait To button and some WIP code
This commit is contained in:
@@ -8,23 +8,98 @@ namespace Services.Immortal;
|
||||
|
||||
public class EconomyComparisionService : IEconomyComparisonService
|
||||
{
|
||||
public List<BuildToCompareModel> BuildsToCompare { get; set; }
|
||||
private readonly int IntervalMax = 1024;
|
||||
|
||||
public EconomyComparisionService()
|
||||
{
|
||||
BuildsToCompare = new List<BuildToCompareModel>()
|
||||
BuildsToCompare = new List<BuildToCompareModel>
|
||||
{
|
||||
new BuildToCompareModel { NumberOfTownHallExpansions = 0, Faction = DataType.FACTION_Aru, ChartColor = "green"},
|
||||
new BuildToCompareModel { NumberOfTownHallExpansions = 0, Faction = DataType.FACTION_Aru, ChartColor = "red"}
|
||||
new() { NumberOfTownHallExpansions = 0, Faction = DataType.FACTION_Aru, ChartColor = "green" },
|
||||
new() { NumberOfTownHallExpansions = 0, Faction = DataType.FACTION_Aru, ChartColor = "red" }
|
||||
};
|
||||
|
||||
BuildsToCompare[0].EconomyOverTimeModel = CalculateEconomy(BuildsToCompare[0], 0);
|
||||
BuildsToCompare[1].EconomyOverTimeModel = CalculateEconomy(BuildsToCompare[1], 0);
|
||||
BuildsToCompare[0].EconomyOverTimeModel = CalculateEconomy(BuildsToCompare[0]);
|
||||
BuildsToCompare[1].EconomyOverTimeModel = CalculateEconomy(BuildsToCompare[1]);
|
||||
}
|
||||
|
||||
public List<BuildToCompareModel> BuildsToCompare { get; set; }
|
||||
|
||||
|
||||
public void ChangeNumberOfTownHalls(int forPlayer, int toCount)
|
||||
{
|
||||
if (BuildsToCompare[forPlayer].NumberOfTownHallExpansions == toCount) return;
|
||||
|
||||
BuildsToCompare[forPlayer].NumberOfTownHallExpansions = toCount;
|
||||
|
||||
CalculateBuildOrder(BuildsToCompare[forPlayer]);
|
||||
|
||||
NotifyDataChanged();
|
||||
}
|
||||
|
||||
public void ChangeTownHallTiming(int forPlayer, int forTownHall, int toTiming)
|
||||
{
|
||||
if (BuildsToCompare[forPlayer].TimeToBuildTownHall[forTownHall] == toTiming) return;
|
||||
|
||||
BuildsToCompare[forPlayer].TimeToBuildTownHall[forTownHall] = toTiming;
|
||||
|
||||
CalculateBuildOrder(BuildsToCompare[forPlayer]);
|
||||
|
||||
NotifyDataChanged();
|
||||
}
|
||||
|
||||
public int GetTownHallCount(int forPlayer)
|
||||
{
|
||||
return BuildsToCompare[forPlayer].NumberOfTownHallExpansions;
|
||||
}
|
||||
|
||||
public int GetTownHallBuildTime(int forPlayer, int forTownHall)
|
||||
{
|
||||
return BuildsToCompare[forPlayer].TimeToBuildTownHall[forTownHall];
|
||||
}
|
||||
|
||||
public List<int> GetTownHallBuildTimes(int forPlayer)
|
||||
{
|
||||
return BuildsToCompare[forPlayer].TimeToBuildTownHall;
|
||||
}
|
||||
|
||||
public void ChangeFaction(int forPlayer, string toFaction)
|
||||
{
|
||||
if (BuildsToCompare[forPlayer].Faction.Equals(toFaction)) return;
|
||||
|
||||
BuildsToCompare[forPlayer].Faction = toFaction;
|
||||
NotifyDataChanged();
|
||||
}
|
||||
|
||||
public string GetFaction(int forPlayer)
|
||||
{
|
||||
return BuildsToCompare[forPlayer].Faction;
|
||||
}
|
||||
|
||||
public void ChangeColor(int forPlayer, string toColor)
|
||||
{
|
||||
if (BuildsToCompare[forPlayer].ChartColor.Equals(toColor)) return;
|
||||
|
||||
BuildsToCompare[forPlayer].ChartColor = toColor;
|
||||
NotifyDataChanged();
|
||||
}
|
||||
|
||||
public string GetColor(int forPlayer)
|
||||
{
|
||||
return BuildsToCompare[forPlayer].ChartColor;
|
||||
}
|
||||
|
||||
public void Subscribe(Action action)
|
||||
{
|
||||
OnChange += action;
|
||||
}
|
||||
|
||||
public void Unsubscribe(Action action)
|
||||
{
|
||||
OnChange -= action;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void CalculateBuildOrder(BuildToCompareModel buildToCompare)
|
||||
private void CalculateBuildOrder(BuildToCompareModel buildToCompare)
|
||||
{
|
||||
buildToCompare.BuildOrderModel = new BuildOrderModel(buildToCompare.Faction);
|
||||
|
||||
@@ -36,22 +111,23 @@ public class EconomyComparisionService : IEconomyComparisonService
|
||||
|
||||
Add(townHall, buildToCompare, time);
|
||||
Add(townHallMining2, buildToCompare, time + townHall.Production()!.BuildTime);
|
||||
Add(townHallMining3, buildToCompare, time + townHall.Production()!.BuildTime + townHallMining2.Production()!.BuildTime);
|
||||
Add(townHallMining3, buildToCompare,
|
||||
time + townHall.Production()!.BuildTime + townHallMining2.Production()!.BuildTime);
|
||||
}
|
||||
|
||||
CalculateEconomy(buildToCompare, 0);
|
||||
CalculateEconomy(buildToCompare);
|
||||
}
|
||||
|
||||
|
||||
public void Add(EntityModel entityModel, BuildToCompareModel buildToCompare, int atInterval)
|
||||
{
|
||||
BuildOrderModel buildOrder = buildToCompare.BuildOrderModel;
|
||||
|
||||
|
||||
var buildOrder = buildToCompare.BuildOrderModel;
|
||||
|
||||
|
||||
if (!buildOrder.StartedOrders.ContainsKey(atInterval))
|
||||
buildOrder.StartedOrders.Add(atInterval, new List<EntityModel>());
|
||||
|
||||
var production = entityModel.Production();
|
||||
|
||||
|
||||
var completedTime = atInterval;
|
||||
if (production != null) completedTime += production.BuildTime;
|
||||
|
||||
@@ -64,17 +140,12 @@ public class EconomyComparisionService : IEconomyComparisonService
|
||||
NotifyDataChanged();
|
||||
}
|
||||
|
||||
private int IntervalMax = 1024;
|
||||
|
||||
private List<EconomyModel> CalculateEconomy(BuildToCompareModel buildToCompare, int fromInterval = 0)
|
||||
{
|
||||
// We don't consider things mining at zero seconds
|
||||
if (fromInterval == 0)
|
||||
{
|
||||
fromInterval = 1;
|
||||
}
|
||||
|
||||
BuildOrderModel buildOrder = buildToCompare.BuildOrderModel;
|
||||
if (fromInterval == 0) fromInterval = 1;
|
||||
|
||||
var buildOrder = buildToCompare.BuildOrderModel;
|
||||
|
||||
List<EconomyModel> buildEconomyOverTime = buildToCompare.EconomyOverTimeModel;
|
||||
|
||||
@@ -195,93 +266,7 @@ public class EconomyComparisionService : IEconomyComparisonService
|
||||
return buildEconomyOverTime;
|
||||
}
|
||||
|
||||
|
||||
public void ChangeNumberOfTownHalls(int forPlayer, int toCount)
|
||||
{
|
||||
if (BuildsToCompare[forPlayer].NumberOfTownHallExpansions == toCount)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
BuildsToCompare[forPlayer].NumberOfTownHallExpansions = toCount;
|
||||
|
||||
CalculateBuildOrder(BuildsToCompare[forPlayer]);
|
||||
|
||||
NotifyDataChanged();
|
||||
}
|
||||
|
||||
public void ChangeTownHallTiming(int forPlayer, int forTownHall, int toTiming)
|
||||
{
|
||||
if (BuildsToCompare[forPlayer].TimeToBuildTownHall[forTownHall] == toTiming)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
BuildsToCompare[forPlayer].TimeToBuildTownHall[forTownHall] = toTiming;
|
||||
|
||||
CalculateBuildOrder(BuildsToCompare[forPlayer]);
|
||||
|
||||
NotifyDataChanged();
|
||||
}
|
||||
|
||||
public int GetTownHallCount(int forPlayer)
|
||||
{
|
||||
return BuildsToCompare[forPlayer].NumberOfTownHallExpansions;
|
||||
}
|
||||
|
||||
public int GetTownHallBuildTime(int forPlayer, int forTownHall)
|
||||
{
|
||||
return BuildsToCompare[forPlayer].TimeToBuildTownHall[forTownHall];
|
||||
}
|
||||
|
||||
public List<int> GetTownHallBuildTimes(int forPlayer)
|
||||
{
|
||||
return BuildsToCompare[forPlayer].TimeToBuildTownHall;
|
||||
}
|
||||
|
||||
public void ChangeFaction(int forPlayer, string toFaction)
|
||||
{
|
||||
if (BuildsToCompare[forPlayer].Faction.Equals(toFaction))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
BuildsToCompare[forPlayer].Faction = toFaction;
|
||||
NotifyDataChanged();
|
||||
}
|
||||
|
||||
public string GetFaction(int forPlayer)
|
||||
{
|
||||
return BuildsToCompare[forPlayer].Faction;
|
||||
}
|
||||
|
||||
public void ChangeColor(int forPlayer, string toColor)
|
||||
{
|
||||
if (BuildsToCompare[forPlayer].ChartColor.Equals(toColor))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
BuildsToCompare[forPlayer].ChartColor = toColor;
|
||||
NotifyDataChanged();
|
||||
}
|
||||
|
||||
public string GetColor(int forPlayer)
|
||||
{
|
||||
return BuildsToCompare[forPlayer].ChartColor;
|
||||
}
|
||||
|
||||
public void Subscribe(Action action)
|
||||
{
|
||||
OnChange += action;
|
||||
}
|
||||
|
||||
public void Unsubscribe(Action action)
|
||||
{
|
||||
OnChange -= action;
|
||||
}
|
||||
|
||||
|
||||
private event Action OnChange = null!;
|
||||
|
||||
private void NotifyDataChanged()
|
||||
|
||||
Reference in New Issue
Block a user