public static bool AutoImportArena(ArenaImportingBehaviour behaviour, ArenaInfo info = null) { var deck = info ?? DeckImporter.FromArena(); if (deck?.Deck.Cards.Sum(x => x.Count) != 30) { return(false); } Log.Info($"Found new complete {deck.Deck.Hero} arena deck!"); var recentArenaDecks = DeckList.Instance.Decks.Where(d => d.IsArenaDeck && d.Cards.Sum(x => x.Count) == 30).OrderByDescending( d => d.LastPlayedNewFirst).Take(15); if (recentArenaDecks.Any(d => d.Cards.All(c => deck.Deck.Cards.Any(c2 => c.Id == c2.Id && c.Count == c2.Count)))) { Log.Info("...but we already have that one. Discarding."); } else if (Core.Game.IgnoredArenaDecks.Contains(deck.Deck.Id)) { Log.Info("...but it was already discarded by the user. No automatic action taken."); } else if (behaviour == ArenaImportingBehaviour.AutoAsk) { MessageDialogs.ShowNewArenaDeckMessageAsync(Core.MainWindow, deck.Deck); return(true); } else if (behaviour == ArenaImportingBehaviour.AutoImportSave) { Log.Info("...auto saving new arena deck."); Core.MainWindow.ImportArenaDeck(deck.Deck); return(true); } return(false); }
public ArenaInfo GetArenaInfo() => DeckImporter.FromArena(false);
public async Task StartArenaImporting() { ProgressDialogController controller = null; if (!Core.Game.IsRunning) { Log.Info("Waiting for game..."); var result = await this.ShowMessageAsync("Importing arena deck", "Start Hearthstone and enter the 'Arena' screen.", MessageDialogStyle.AffirmativeAndNegative, new MessageDialogs.Settings() { AffirmativeButtonText = "Start Hearthstone", NegativeButtonText = "Cancel" }); if (result == MessageDialogResult.Negative) { return; } Helper.StartHearthstoneAsync().Forget(); controller = await this.ShowProgressAsync("Importing arena deck", "Waiting for Hearthstone...", true); while (!Core.Game.IsRunning) { if (controller.IsCanceled) { await controller.CloseAsync(); return; } await Task.Delay(500); } } if (Core.Game.CurrentMode != Mode.DRAFT) { if (controller == null) { controller = await this.ShowProgressAsync("Importing arena deck", "", true); } controller.SetMessage("Enter the 'Arena' screen."); Log.Info("Waiting for DRAFT screen..."); while (Core.Game.CurrentMode != Mode.DRAFT) { if (controller.IsCanceled) { await controller.CloseAsync(); return; } await Task.Delay(500); } } var deck = DeckImporter.FromArena()?.Deck; while (deck == null || deck.Cards.Sum(x => x.Count) < 30) { if (controller == null) { controller = await this.ShowProgressAsync("Importing arena deck", "", true); } if (controller.IsCanceled) { await controller.CloseAsync(); return; } controller.SetMessage($"Waiting for complete deck ({deck?.Cards.Sum(x => x.Count) ?? 0}/30 cards)..."); await Task.Delay(1000); deck = DeckImporter.FromArena(false)?.Deck; } if (controller != null) { await controller.CloseAsync(); } var recentArenaDecks = DeckList.Instance.Decks.Where(d => d.IsArenaDeck && d.Cards.Sum(x => x.Count) == 30).OrderByDescending(d => d.LastPlayedNewFirst).Take(15); var existing = recentArenaDecks.FirstOrDefault(d => d.Cards.All(c => deck.Cards.Any(c2 => c.Id == c2.Id && c.Count == c2.Count))); if (existing != null) { var result = await this.ShowMessageAsync("Deck already exists", "You seem to already have this deck.", MessageDialogStyle.AffirmativeAndNegative, new MessageDialogs.Settings() { AffirmativeButtonText = "Use existing", NegativeButtonText = "Import anyway" }); if (result == MessageDialogResult.Affirmative) { SelectDeck(existing, true); return; } } ImportArenaDeck(deck); }