feat(Storage) Storage feature done

This commit is contained in:
2022-04-24 21:34:02 -04:00
parent afaafbe713
commit adbf36da9f
37 changed files with 620 additions and 368 deletions
+28 -25
View File
@@ -14,18 +14,20 @@ public class BuildOrderService : IBuildOrderService
{
private readonly BuildOrderModel _buildOrder = new();
private readonly ITimingService _timingService;
private readonly IToastService _toastService;
private int _lastInterval;
public BuildOrderService(IToastService toastService)
public BuildOrderService(IToastService toastService, ITimingService timingService)
{
_toastService = toastService;
_timingService = timingService;
Reset();
}
public int BuildingInputDelay { get; set; } = 2;
public Dictionary<int, List<EntityModel>> StartedOrders => _buildOrder.StartedOrders;
public Dictionary<int, List<EntityModel>> CompletedOrders => _buildOrder.CompletedOrders;
public Dictionary<string, int> UniqueCompletedTimes => _buildOrder.UniqueCompletedTimes;
@@ -241,14 +243,12 @@ public class BuildOrderService : IBuildOrderService
_buildOrder.UniqueCompleted[entityRemoved.DataType]
.Remove(_buildOrder.UniqueCompleted[entityRemoved.DataType].Last());
if (entityRemoved.Production() != null
&& entityRemoved.Production()!.ProducedBy != null
&& entityRemoved.Supply() != null
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)
{
RemoveLast();
@@ -339,7 +339,7 @@ public class BuildOrderService : IBuildOrderService
public int? WillMeetTrainingQueue(EntityModel entity)
{
Console.WriteLine($"WillMeetTrainingQueue {entity.Info().Name}");
var supply = entity.Supply();
var production = entity.Production();
@@ -348,7 +348,7 @@ public class BuildOrderService : IBuildOrderService
if (supply == null || production == null || supply.Takes.Equals(0))
{
Console.WriteLine(supply == null ? "Was Null" : supply.Takes);
return 1;
}
@@ -358,47 +358,50 @@ public class BuildOrderService : IBuildOrderService
Console.WriteLine("Produced by Nothing");
return 1;
}
var uniqueCompleted = _buildOrder.UniqueCompleted[producedBy];
var shortestIncrement = int.MaxValue;
var trainingSlots = 0;
bool didDelay = false;
var didDelay = false;
foreach (var productionEntity in uniqueCompleted) trainingSlots += productionEntity.Supply()!.Grants;
while (true)
{
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} ");
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."});
}
_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");
Console.WriteLine("MaxValue");
return null;
}
}
@@ -421,7 +424,7 @@ public class BuildOrderService : IBuildOrderService
{
atInterval = interval;
if (entity.EntityType != EntityType.Army) atInterval += BuildingInputDelay;
if (entity.EntityType != EntityType.Army) atInterval += _timingService.BuildingInputDelay;
return true;
}
+7 -7
View File
@@ -6,20 +6,20 @@ public class EntityViewType
{
public static string Detailed = "Detailed";
public static string Plain = "Plain";
}
public class EntityDisplayService : IEntityDisplayService
{
private string _displayType;
public EntityDisplayService(IStorageService storageService)
{
_displayType = storageService.GetValue<bool>(StorageKeys.IsPlainView)
? EntityViewType.Plain : EntityViewType.Detailed;
_displayType = storageService.GetValue<bool>(StorageKeys.IsPlainView)
? EntityViewType.Plain
: EntityViewType.Detailed;
}
public List<string> DefaultChoices()
{
return new List<string> { EntityViewType.Detailed, EntityViewType.Plain };
@@ -42,7 +42,7 @@ public class EntityDisplayService : IEntityDisplayService
public void SetDisplayType(string displayType)
{
this._displayType = displayType;
_displayType = displayType;
NotifyDataChanged();
}
+12 -12
View File
@@ -16,12 +16,12 @@ public class EntityFilterService : IEntityFilterService
{
private readonly List<string> _entityChoices = new();
private readonly List<string> _factionChoices = new() { FactionType.Any, FactionType.QRath, FactionType.Aru };
private readonly List<string> _factionChoices = new() { DataType.Any, DataType.FACTION_QRath, DataType.FACTION_Aru };
private readonly List<string> _immortalChoices = new();
private string _entityType = EntityType.Army;
private string _searchText = "";
private string _selectedFaction = FactionType.Any;
private string _selectedImmortal = ImmortalType.Any;
private string _selectedFaction = DataType.Any;
private string _selectedImmortal = DataType.Any;
public EntityFilterService()
{
@@ -59,8 +59,8 @@ public class EntityFilterService : IEntityFilterService
{
if (_selectedFaction == factionType)
{
_selectedFaction = FactionType.None;
_selectedImmortal = ImmortalType.None;
_selectedFaction = DataType.None;
_selectedImmortal = DataType.None;
RefreshImmortalChoices();
RefreshEntityChoices();
@@ -71,7 +71,7 @@ public class EntityFilterService : IEntityFilterService
}
_selectedFaction = factionType;
_selectedImmortal = ImmortalType.Any;
_selectedImmortal = DataType.Any;
RefreshImmortalChoices();
RefreshEntityChoices();
@@ -84,7 +84,7 @@ public class EntityFilterService : IEntityFilterService
{
if (_selectedImmortal == immortalType)
{
_selectedImmortal = ImmortalType.None;
_selectedImmortal = DataType.None;
NotifyDataChanged(EntityFilterEvent.OnRefreshImmortal);
return true;
}
@@ -148,13 +148,13 @@ public class EntityFilterService : IEntityFilterService
_immortalChoices.Add(ImmortalType.Xol);
}*/
if (_selectedFaction == FactionType.QRath || _selectedFaction == FactionType.Any)
if (_selectedFaction == DataType.FACTION_QRath || _selectedFaction == DataType.Any)
{
_immortalChoices.Add(DataType.IMMORTAL_Orzum);
_immortalChoices.Add(DataType.IMMORTAL_Ajari);
}
if (_selectedFaction == FactionType.Aru || _selectedFaction == FactionType.Any)
if (_selectedFaction == DataType.FACTION_Aru || _selectedFaction == DataType.Any)
{
_immortalChoices.Add(DataType.IMMORTAL_Mala);
_immortalChoices.Add(DataType.IMMORTAL_Xol);
@@ -165,8 +165,8 @@ public class EntityFilterService : IEntityFilterService
{
_entityChoices.Clear();
if (_selectedFaction == FactionType.QRath || _selectedFaction == FactionType.Aru ||
_selectedFaction == FactionType.Any)
if (_selectedFaction == DataType.FACTION_QRath || _selectedFaction == DataType.FACTION_Aru ||
_selectedFaction == DataType.Any)
{
_entityChoices.Add(EntityType.Army);
_entityChoices.Add(EntityType.Immortal);
@@ -178,7 +178,7 @@ public class EntityFilterService : IEntityFilterService
_entityChoices.Add(EntityType.Worker);
}
if (_selectedFaction == FactionType.Any) _entityChoices.Add(EntityType.Any);
if (_selectedFaction == DataType.Any) _entityChoices.Add(EntityType.Any);
}
+41 -13
View File
@@ -1,13 +1,29 @@
using Model.Entity.Data;
using Model.Types;
using Services.Website;
namespace Services.Immortal;
public class ImmortalSelectionService : IImmortalSelectionService
public class ImmortalSelectionService : IImmortalSelectionService, IDisposable
{
private string _selectedFaction = FactionType.QRath;
private string _selectedFaction = DataType.FACTION_QRath;
private string _selectedImmortal = DataType.IMMORTAL_Orzum;
private readonly IStorageService _storageService;
public ImmortalSelectionService(IStorageService storageService)
{
_storageService = storageService;
_storageService.Subscribe(RefreshDefaults);
RefreshDefaults();
}
void IDisposable.Dispose()
{
_storageService.Unsubscribe(RefreshDefaults);
}
public void Subscribe(Action action)
{
OnChange += action;
@@ -18,37 +34,49 @@ public class ImmortalSelectionService : IImmortalSelectionService
OnChange -= action;
}
public string GetFactionType()
public string GetFaction()
{
return _selectedFaction;
}
public string GetImmortalType()
public string GetImmortal()
{
return _selectedImmortal;
}
public bool SelectFactionType(string factionType)
public bool SelectFaction(string faction)
{
if (_selectedFaction == factionType) return false;
_selectedFaction = factionType;
if (_selectedFaction == faction) return false;
_selectedFaction = faction;
if (_selectedFaction == FactionType.QRath) _selectedImmortal = DataType.IMMORTAL_Orzum;
if (_selectedFaction == DataType.FACTION_QRath) _selectedImmortal = DataType.IMMORTAL_Orzum;
if (_selectedFaction == FactionType.Aru) _selectedImmortal = DataType.IMMORTAL_Mala;
if (_selectedFaction == DataType.FACTION_Aru) _selectedImmortal = DataType.IMMORTAL_Mala;
NotifyDataChanged();
return true;
}
public bool SelectImmortalType(string immortalType)
public bool SelectImmortal(string immortal)
{
if (_selectedImmortal == immortalType) return false;
_selectedImmortal = immortalType;
if (_selectedImmortal == immortal) return false;
_selectedImmortal = immortal;
NotifyDataChanged();
return true;
}
private void RefreshDefaults()
{
var foundFaction = _storageService.GetValue<string?>(StorageKeys.SelectedFaction);
var foundImmortal = _storageService.GetValue<string?>(StorageKeys.SelectedImmortal);
if (foundFaction != null) _selectedFaction = foundFaction;
if (foundImmortal != null) _selectedImmortal = foundImmortal;
NotifyDataChanged();
}
private event Action OnChange = null!;
private void NotifyDataChanged()
+46 -2
View File
@@ -1,10 +1,27 @@
namespace Services.Immortal;
using Services.Website;
public class TimingService : ITimingService
namespace Services.Immortal;
public class TimingService : ITimingService, IDisposable
{
private readonly IStorageService _storageService;
private int attackTime = 1500;
private int travelTime = 30;
public TimingService(IStorageService storageService)
{
_storageService = storageService;
_storageService.Subscribe(RefreshDefaults);
RefreshDefaults();
}
void IDisposable.Dispose()
{
_storageService.Unsubscribe(RefreshDefaults);
}
public void Subscribe(Action? action)
{
OnChange += action;
@@ -15,6 +32,10 @@ public class TimingService : ITimingService
OnChange -= action;
}
public int BuildingInputDelay { get; set; } = 2;
public int WaitTime { get; set; } = 30;
public int WaitTo { get; set; } = 60;
public int GetAttackTime()
{
return attackTime;
@@ -43,6 +64,29 @@ public class TimingService : ITimingService
}
}
private void RefreshDefaults()
{
//TODO Timing has changed in Storage
//TODO Timing has changed in itself
var foundAttackTime = _storageService.GetValue<int?>(StorageKeys.AttackTime);
var foundTravelTime = _storageService.GetValue<int?>(StorageKeys.TravelTime);
var foundBuildInputDefault = _storageService.GetValue<int?>(StorageKeys.BuildInputDelay);
var foundWaitTime = _storageService.GetValue<int?>(StorageKeys.WaitTime);
var foundWaitTo = _storageService.GetValue<int?>(StorageKeys.WaitTo);
if (foundAttackTime != null) attackTime = (int)foundAttackTime;
if (foundTravelTime != null) travelTime = (int)foundTravelTime;
if (foundBuildInputDefault != null) BuildingInputDelay = (int)foundBuildInputDefault;
if (foundWaitTime != null) WaitTime = (int)foundWaitTime;
if (foundWaitTo != null) WaitTo = (int)foundWaitTo;
NotifyDataChanged();
}
private event Action? OnChange;
private void NotifyDataChanged()