Skip to content

Commit

Permalink
Improve booster command completion time estimates
Browse files Browse the repository at this point in the history
  • Loading branch information
Citrinate committed Jul 7, 2024
1 parent 35b8089 commit 01b5e39
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
8 changes: 7 additions & 1 deletion BoosterManager/Boosters/BoosterJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions BoosterManager/Boosters/BoosterQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ internal sealed class BoosterQueue {
internal uint AvailableGems => BoosterHandler.AllowCraftUntradableBoosters ? GooAmount : TradableGooAmount;
internal event Action<Dictionary<uint, Steam.BoosterInfo>>? OnBoosterInfosUpdated;
internal event Action<Booster, BoosterDequeueReason>? 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;
Expand Down Expand Up @@ -120,16 +120,16 @@ 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);
Bot.ArchiLogger.LogGenericInfo(String.Format(Strings.NextBoosterCraft, String.Format("{0:T}", nextBoosterTime)));
} finally {
Utilities.InBackground(
async() => {
await Task.Delay(TimeSpan.FromSeconds(MinDelayBetweenBoosters)).ConfigureAwait(false);
await Task.Delay(TimeSpan.FromSeconds(MinDelayBetweenBoostersSeconds)).ConfigureAwait(false);
RunSemaphore.Release();
}
);
Expand Down

0 comments on commit 01b5e39

Please sign in to comment.