/// <param name="deck">HearthMirror deck object</param> /// <param name="matches">Local decks with HsId OR 30 matching cards</param> /// <param name="localDecks">All local decks</param> public ImportedDeck(Mirror.Objects.Deck deck, List <Deck> matches, IList <Deck> localDecks) { Deck = deck; matches = matches ?? new List <Deck>(); var hero = Hearthstone.Database.GetCardFromId(deck.Hero); if (string.IsNullOrEmpty(hero?.PlayerClass) || hero.Id == Hearthstone.Database.UnknownCardId) { Log.Error("No hero found for id " + deck.Hero); return; } Class = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(hero.PlayerClass.ToLower()); var localOptions = localDecks.Where(d => d.Class == Class && !d.Archived && !d.IsArenaDeck) .Select(x => new ExistingDeck(x, deck)); var matchesOptions = matches.Select(x => new ExistingDeck(x, deck)).ToList(); var importOptions = matchesOptions.Concat(localOptions) .GroupBy(x => new { x.Deck.DeckId, x.Deck.Version }).Select(g => g.First()) .OrderByDescending(x => x.Deck.HsId == deck.Id) .ThenByDescending(x => x.MatchingCards) .ThenByDescending(x => x.Deck.LastPlayed); ImportOptions = New.Concat(importOptions); SelectedIndex = matchesOptions.Any(x => !x.ShouldBeNewDeck) ? 1 : 0; }
public ExistingDeck(Deck deck, Mirror.Objects.Deck newDeck) { Deck = deck; var tmp = new Deck { Cards = new ObservableCollection <Card>(newDeck.Cards.Select(x => new Card { Id = x.Id, Count = x.Count })) }; MatchingCards = 0; if (deck.HasVersions) { var counts = deck.VersionsIncludingSelf.Select(v => GetMatchingCards(tmp, deck.GetVersion(v))); if (counts.Any(c => c == 30)) { MatchingCards = 30; } } if (MatchingCards != 30) { MatchingCards = GetMatchingCards(tmp, deck); } NewVersion = MatchingCards == 30 ? new SerializableVersion(0, 0) : (MatchingCards < 26 ? SerializableVersion.IncreaseMajor(deck.Version) : SerializableVersion.IncreaseMinor(deck.Version)); ShouldBeNewDeck = MatchingCards < 15; }
public static async void ShowNewArenaDeckMessageAsync(this MetroWindow window, Mirror.Objects.Deck deck) { if (_awaitingMainWindowOpen) { return; } _awaitingMainWindowOpen = true; if (window.WindowState == WindowState.Minimized) { Core.TrayIcon.ShowMessage("New arena deck detected!"); } while (window.Visibility != Visibility.Visible || window.WindowState == WindowState.Minimized) { await Task.Delay(100); } var result = await window.ShowMessageAsync("New arena deck detected!", "You can change this behaviour to \"auto save&import\" or \"manual\" in [options > tracker > importing]", MessageDialogStyle.AffirmativeAndNegative, new Settings { AffirmativeButtonText = "Import", NegativeButtonText = "Cancel" }); if (result == MessageDialogResult.Affirmative) { Log.Info("...saving new arena deck."); Core.MainWindow.ImportArenaDeck(deck); } else { Log.Info("...discarded by user."); } Core.Game.IgnoredArenaDecks.Add(deck.Id); _awaitingMainWindowOpen = false; }