From 01b5e393ca5136c54b014a2ee13d79f1ed8f3152 Mon Sep 17 00:00:00 2001 From: Citrinate Date: Sun, 7 Jul 2024 01:13:45 -0400 Subject: [PATCH] Improve booster command completion time estimates --- BoosterManager/Boosters/BoosterJob.cs | 8 +++++++- BoosterManager/Boosters/BoosterQueue.cs | 8 ++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/BoosterManager/Boosters/BoosterJob.cs b/BoosterManager/Boosters/BoosterJob.cs index f2b15d2..b7f5fb5 100644 --- a/BoosterManager/Boosters/BoosterJob.cs +++ b/BoosterManager/Boosters/BoosterJob.cs @@ -108,7 +108,13 @@ internal DateTime? LastBoosterCraftTime { Booster? lastQueuedBooster = Boosters.Where(booster => !booster.WasCrafted).OrderBy(booster => booster.GetAvailableAtTime()).LastOrDefault(); - return BoosterJobUtilities.MaxDateTime(lastQueuedBooster?.GetAvailableAtTime(), lastUnqueuedBoosterCraftTime); + if (lastQueuedBooster == null && lastUnqueuedBoosterCraftTime == null) { + return null; + } + + DateTime minDelayAdjustedTime = DateTime.Now.AddSeconds((UncraftedGameIDs.Distinct().Count() - 1) * BoosterQueue.MinDelayBetweenBoostersSeconds); + + return BoosterJobUtilities.MaxDateTime(BoosterJobUtilities.MaxDateTime(lastQueuedBooster?.GetAvailableAtTime(), lastUnqueuedBoosterCraftTime), minDelayAdjustedTime); } } } diff --git a/BoosterManager/Boosters/BoosterQueue.cs b/BoosterManager/Boosters/BoosterQueue.cs index 9bc2d8c..d4e74e7 100644 --- a/BoosterManager/Boosters/BoosterQueue.cs +++ b/BoosterManager/Boosters/BoosterQueue.cs @@ -19,7 +19,7 @@ internal sealed class BoosterQueue { internal uint AvailableGems => BoosterHandler.AllowCraftUntradableBoosters ? GooAmount : TradableGooAmount; internal event Action>? OnBoosterInfosUpdated; internal event Action? OnBoosterRemoved; - private const int MinDelayBetweenBoosters = 5; // Minimum delay, in seconds, between booster crafts + internal const int MinDelayBetweenBoostersSeconds = 5; // Minimum delay, in seconds, between booster crafts private const float BoosterInfosUpdateBackOffMultiplierDefault = 1.0F; private const float BoosterInfosUpdateBackOffMultiplierStep = 0.5F; private const int BoosterInfosUpdateBackOffMinMinutes = 1; @@ -120,8 +120,8 @@ private async Task Run() { // Wait until the next booster is ready to craft DateTime nextBoosterTime = booster.GetAvailableAtTime(); - if (nextBoosterTime < DateTime.Now.AddSeconds(MinDelayBetweenBoosters)) { - nextBoosterTime = DateTime.Now.AddSeconds(MinDelayBetweenBoosters); + if (nextBoosterTime < DateTime.Now.AddSeconds(MinDelayBetweenBoostersSeconds)) { + nextBoosterTime = DateTime.Now.AddSeconds(MinDelayBetweenBoostersSeconds); } UpdateTimer(nextBoosterTime); @@ -129,7 +129,7 @@ private async Task Run() { } finally { Utilities.InBackground( async() => { - await Task.Delay(TimeSpan.FromSeconds(MinDelayBetweenBoosters)).ConfigureAwait(false); + await Task.Delay(TimeSpan.FromSeconds(MinDelayBetweenBoostersSeconds)).ConfigureAwait(false); RunSemaphore.Release(); } );