private static async void AutoSelectDeckById(IGame game) { var selectedDeckId = GetSelectedDeckId(game.CurrentMode); if (selectedDeckId <= 0) { if (game.CurrentMode == ADVENTURE) { while (game.IsDungeonMatch == null) { await Task.Delay(500); } if (game.IsDungeonMatch.Value) { return; } } Log.Info("No selected deck found, using no-deck mode"); Core.MainWindow.SelectDeck(null, true); return; } DeckManager.AutoImportConstructed(false, game.CurrentMode == TAVERN_BRAWL); var selectedDeck = DeckList.Instance.Decks.FirstOrDefault(x => x.HsId == selectedDeckId); if (selectedDeck == null) { Log.Warn($"No deck with id={selectedDeckId} found"); return; } Log.Info("Found selected deck: " + selectedDeck.Name); var hsDeck = DeckImporter.ConstructedDecksCache.FirstOrDefault(x => x.Id == selectedDeckId); var selectedVersion = selectedDeck.GetSelectedDeckVersion(); if (hsDeck != null && !selectedVersion.Cards.All(c => hsDeck.Cards.Any(c2 => c.Id == c2.Id && c.Count == c2.Count))) { var nonSelectedVersions = selectedDeck.VersionsIncludingSelf.Where(v => v != selectedVersion.Version).Select(selectedDeck.GetVersion); var version = nonSelectedVersions.FirstOrDefault(v => v.Cards.All(c => hsDeck.Cards.Any(c2 => c.Id == c2.Id && c.Count == c2.Count))); if (version != null) { selectedDeck.SelectVersion(version); Log.Info("Switching to version: " + version.Version.ShortVersionString); } } else if (Equals(selectedDeck, DeckList.Instance.ActiveDeck)) { Log.Info("Already using the correct deck"); return; } Core.MainWindow.SelectDeck(selectedDeck, true); }
private static void AutoSelectDeckById(bool import) { var selectedDeckId = Reflection.GetSelectedDeckInMenu(); if (selectedDeckId <= 0) { return; } var selectedDeck = DeckList.Instance.Decks.FirstOrDefault(x => x.HsId == selectedDeckId); if (selectedDeck == null) { if (import && DeckManager.AutoImportConstructed(true)) { AutoSelectDeckById(false); return; } Log.Warn($"No deck with id={selectedDeckId} found"); return; } Log.Info("Found selected deck: " + selectedDeck.Name); var hsDeck = DeckImporter.ConstructedDecksCache.FirstOrDefault(x => x.Id == selectedDeckId); if (hsDeck != null && !selectedDeck.Cards.All(c => hsDeck.Cards.Any(c2 => c.Id == c2.Id && c.Count == c2.Count))) { var version = selectedDeck.Versions.FirstOrDefault(v => v.Cards.All(c => hsDeck.Cards.Any(c2 => c.Id == c2.Id && c.Count == c2.Count))); if (version != null) { selectedDeck.SelectVersion(version); Log.Info("Switching to version: " + version.Version.ShortVersionString); } else { if (import && DeckManager.AutoImportConstructed(true)) { AutoSelectDeckById(false); return; } Log.Warn("Could not find deck with matching cards."); } } else if (Equals(selectedDeck, DeckList.Instance.ActiveDeck)) { Log.Info("Already using the correct deck"); return; } Log.Info($"Switching to selected deck: {selectedDeck.Name} + {selectedDeck.Version.ShortVersionString}"); Core.MainWindow.SelectDeck(selectedDeck, true); }
private static void AutoSelectDeckById(Mode mode) { var selectedDeckId = Reflection.GetSelectedDeckInMenu(); if (selectedDeckId <= 0) { if (mode != TAVERN_BRAWL || (selectedDeckId = Reflection.GetEditedDeck()?.Id ?? 0) == 0) { Log.Info("No selected deck found, using no-deck mode"); Core.MainWindow.SelectDeck(null, true); return; } } DeckManager.AutoImportConstructed(false, mode == TAVERN_BRAWL); var selectedDeck = DeckList.Instance.Decks.FirstOrDefault(x => x.HsId == selectedDeckId); if (selectedDeck == null) { Log.Warn($"No deck with id={selectedDeckId} found"); return; } Log.Info("Found selected deck: " + selectedDeck.Name); var hsDeck = DeckImporter.ConstructedDecksCache.FirstOrDefault(x => x.Id == selectedDeckId); if (hsDeck != null && !selectedDeck.Cards.All(c => hsDeck.Cards.Any(c2 => c.Id == c2.Id && c.Count == c2.Count))) { var version = selectedDeck.Versions.FirstOrDefault(v => v.Cards.All(c => hsDeck.Cards.Any(c2 => c.Id == c2.Id && c.Count == c2.Count))); if (version != null) { selectedDeck.SelectVersion(version); Log.Info("Switching to version: " + version.Version.ShortVersionString); } } else if (Equals(selectedDeck, DeckList.Instance.ActiveDeck)) { Log.Info("Already using the correct deck"); return; } Core.MainWindow.SelectDeck(selectedDeck, true); }