Skip to content

Commit

Permalink
Add support for ASF plugin updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Citrinate committed Mar 17, 2024
1 parent edbe8a4 commit 37cc704
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
4 changes: 3 additions & 1 deletion BoosterManager/BoosterManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@

namespace BoosterManager {
[Export(typeof(IPlugin))]
public sealed class BoosterManager : IASF, IBotModules, IBotCommand2, IBotTradeOfferResults {
public sealed class BoosterManager : IASF, IBotModules, IBotCommand2, IBotTradeOfferResults, IGitHubPluginUpdates {
public string Name => nameof(BoosterManager);
public string RepositoryName => "Citrinate/BoosterManager";
public bool CanUpdate => !BoosterHandler.IsCraftingOneTimeBoosters();
public Version Version => typeof(BoosterManager).Assembly.GetName().Version ?? new Version("0");

public Task OnLoaded() {
Expand Down
2 changes: 1 addition & 1 deletion BoosterManager/Boosters/BoosterQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ internal string GetStatus() {
private bool FilterBoosterByType(Booster booster, BoosterType type) => type == BoosterType.Any || booster.Type == type;
private HashSet<Booster> GetBoosters(BoosterType type, bool? wasCrafted = null) => Boosters.Values.Where(booster => (wasCrafted == null || booster.WasCrafted == wasCrafted) && FilterBoosterByType(booster, type)).ToHashSet<Booster>();
private HashSet<uint> GetBoosterIDs(BoosterType type, bool? wasCrafted = null) => GetBoosters(type, wasCrafted).Select(booster => booster.GameID).ToHashSet<uint>();
private int GetNumBoosters(BoosterType type, bool? wasCrafted = null) => GetBoosters(type, wasCrafted).Count;
internal int GetNumBoosters(BoosterType type, bool? wasCrafted = null) => GetBoosters(type, wasCrafted).Count;
internal int GetGemsNeeded(BoosterType type, bool? wasCrafted = null) => GetBoosters(type, wasCrafted).Sum(booster => (int) booster.Info.Price);
internal void ForceUpdateBoosterInfos() => OnBoosterInfosUpdated -= ForceUpdateBoosterInfos;
private static int GetMillisecondsFromNow(DateTime then) => Math.Max(0, (int) (then - DateTime.Now).TotalMilliseconds);
Expand Down
4 changes: 4 additions & 0 deletions BoosterManager/Handlers/BoosterHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,10 @@ internal void StartMarketTimer(uint minutes) {
);
}

internal static bool IsCraftingOneTimeBoosters() {
return BoosterHandlers.Any(handler => handler.Value.BoosterQueue.GetNumBoosters(BoosterType.OneTime, wasCrafted: false) > 0);
}

private static int GetMillisecondsFromNow(DateTime then) => Math.Max(0, (int) (then - DateTime.Now).TotalMilliseconds);
}
}

0 comments on commit 37cc704

Please sign in to comment.