public static async Task <bool> ShowAddGameDialog(this MetroWindow window, Deck deck) { if (deck == null) { return(false); } var dialog = new AddGameDialog(deck); await window.ShowMetroDialogAsync(dialog, new MetroDialogSettings { AffirmativeButtonText = "save", NegativeButtonText = "cancel" }); var game = await dialog.WaitForButtonPressAsync(); await window.HideMetroDialogAsync(dialog); if (game == null) { return(false); } deck.DeckStats.AddGameResult(game); if (Config.Instance.HearthStatsAutoUploadNewGames) { if (game.GameMode == GameMode.Arena) { HearthStatsManager.UploadArenaMatchAsync(game, deck, true, true).Forget(); } else { HearthStatsManager.UploadMatchAsync(game, deck.GetSelectedDeckVersion(), true, true).Forget(); } } DeckStatsList.Save(); Core.MainWindow.DeckPickerList.UpdateDecks(forceUpdate: new[] { deck }); return(true); }
private async void BtnAddNewGame_Click(object sender, RoutedEventArgs e) { if (_deck == null) { return; } var dialog = new AddGameDialog(_deck); await Helper.MainWindow.ShowMetroDialogAsync(dialog, new MetroDialogSettings { AffirmativeButtonText = "save", NegativeButtonText = "cancel" }); var game = await dialog.WaitForButtonPressAsync(); await Helper.MainWindow.HideMetroDialogAsync(dialog); if (game != null) { _deck.DeckStats.AddGameResult(game); if (Config.Instance.HearthStatsAutoUploadNewGames) { if (game.GameMode == GameMode.Arena) { HearthStatsManager.UploadArenaMatchAsync(game, _deck, true, true); } else { HearthStatsManager.UploadMatchAsync(game, _deck.GetSelectedDeckVersion(), true, true); } } Refresh(); } DeckStatsList.Save(); Helper.MainWindow.DeckPickerList.UpdateDecks(forceUpdate: new[] { _deck }); }
private void GameResultToast_OnUnloaded(object sender, RoutedEventArgs e) { if (!_edited) { return; } DeckStatsList.Save(); if (!Config.Instance.HearthStatsAutoUploadNewGames || !HearthStatsAPI.IsLoggedIn) { return; } var deck = DeckList.Instance.Decks.FirstOrDefault(d => d.DeckId == _game.DeckId); if (deck == null) { return; } if (_game.HasHearthStatsId) { if (_game.GameMode == GameMode.Arena) { HearthStatsManager.UpdateArenaMatchAsync(_game, deck, true, true); } else { HearthStatsManager.UpdateMatchAsync(_game, deck.GetVersion(_game.PlayerDeckVersion), true, true); } } else { if (_game.GameMode == GameMode.Arena) { HearthStatsManager.UploadArenaMatchAsync(_game, deck, true, true).Forget(); } else { HearthStatsManager.UploadMatchAsync(_game, deck.GetVersion(_game.PlayerDeckVersion), true, true).Forget(); } } }
private void StoryboardFadeOut_OnCompleted(object sender, EventArgs e) { if (_edited) { DeckStatsList.Save(); if (Config.Instance.HearthStatsAutoUploadNewGames && HearthStatsAPI.IsLoggedIn) { var deck = DeckList.Instance.Decks.FirstOrDefault(d => d.DeckId == _game.DeckId); if (deck != null) { if (_game.HasHearthStatsId) { if (_game.GameMode == GameMode.Arena) { HearthStatsManager.UpdateArenaMatchAsync(_game, deck, true, true); } else { HearthStatsManager.UpdateMatchAsync(_game, deck.GetVersion(_game.PlayerDeckVersion), true, true); } } else { if (_game.GameMode == GameMode.Arena) { HearthStatsManager.UploadArenaMatchAsync(_game, deck, true, true).Forget(); } else { HearthStatsManager.UploadMatchAsync(_game, deck.GetVersion(_game.PlayerDeckVersion), true, true).Forget(); } } } } } Close(); }
#pragma warning disable 4014 public static async void HandleGameEnd() { Helper.MainWindow.Overlay.HideTimers(); if (Game.CurrentGameStats == null) { return; } if (Game.CurrentGameMode == GameMode.Spectator && !Config.Instance.RecordSpectator) { Logger.WriteLine("Game is in Spectator mode, discarded. (Record Spectator disabled)", "GameEventHandler"); _assignedDeck = null; return; } var player = Game.Entities.FirstOrDefault(e => e.Value.IsPlayer); var opponent = Game.Entities.FirstOrDefault(e => e.Value.HasTag(GAME_TAG.PLAYER_ID) && !e.Value.IsPlayer); if (player.Value != null) { Game.CurrentGameStats.PlayerName = player.Value.Name; } if (opponent.Value != null && CardIds.HeroIdDict.ContainsValue(Game.CurrentGameStats.OpponentHero)) { Game.CurrentGameStats.OpponentName = opponent.Value.Name; } else { Game.CurrentGameStats.OpponentName = Game.CurrentGameStats.OpponentHero; } Game.CurrentGameStats.Turns = HsLogReader.Instance.GetTurnNumber(); if (Config.Instance.DiscardZeroTurnGame && Game.CurrentGameStats.Turns < 1) { Logger.WriteLine("Game has 0 turns, discarded. (DiscardZeroTurnGame)", "GameEventHandler"); _assignedDeck = null; GameEvents.OnGameEnd.Execute(); return; } Game.CurrentGameStats.GameEnd(); GameEvents.OnGameEnd.Execute(); var selectedDeck = DeckList.Instance.ActiveDeck; if (selectedDeck != null) { if (Config.Instance.DiscardGameIfIncorrectDeck && !Game.PlayerDrawn.All( c => c.IsStolen || selectedDeck.GetSelectedDeckVersion().Cards.Any(c2 => c.Id == c2.Id && c.Count <= c2.Count))) { if (Config.Instance.AskBeforeDiscardingGame) { var discardDialog = new DiscardGameDialog(Game.CurrentGameStats); discardDialog.Topmost = true; discardDialog.ShowDialog(); if (discardDialog.Result == DiscardGameDialogResult.Discard) { Logger.WriteLine("Assigned current game to NO deck - selected deck does not match cards played (dialogresult: discard)", "GameEventHandler"); Game.CurrentGameStats.DeleteGameFile(); _assignedDeck = null; return; } if (discardDialog.Result == DiscardGameDialogResult.MoveToOther) { var moveDialog = new MoveGameDialog(DeckList.Instance.Decks.Where(d => d.Class == Game.CurrentGameStats.PlayerHero)); moveDialog.Topmost = true; moveDialog.ShowDialog(); var targetDeck = moveDialog.SelectedDeck; if (targetDeck != null) { selectedDeck = targetDeck; Game.CurrentGameStats.PlayerDeckVersion = moveDialog.SelectedVersion; Game.CurrentGameStats.HearthStatsDeckVersionId = targetDeck.GetVersion(moveDialog.SelectedVersion).HearthStatsDeckVersionId; //...continue as normal } else { Logger.WriteLine("No deck selected in move game dialog after discard dialog, discarding game", "GameEventHandler"); Game.CurrentGameStats.DeleteGameFile(); _assignedDeck = null; return; } } } else { Logger.WriteLine("Assigned current game to NO deck - selected deck does not match cards played (no dialog)", "GameEventHandler"); Game.CurrentGameStats.DeleteGameFile(); _assignedDeck = null; return; } } else { Game.CurrentGameStats.PlayerDeckVersion = DeckList.Instance.ActiveDeckVersion.Version; Game.CurrentGameStats.HearthStatsDeckVersionId = DeckList.Instance.ActiveDeckVersion.HearthStatsDeckVersionId; } _lastGame = Game.CurrentGameStats; selectedDeck.DeckStats.AddGameResult(_lastGame); selectedDeck.StatsUpdated(); if (Config.Instance.ShowNoteDialogAfterGame && !Config.Instance.NoteDialogDelayed && !_showedNoteDialog) { _showedNoteDialog = true; new NoteDialog(Game.CurrentGameStats); } Logger.WriteLine("Assigned current game to deck: " + selectedDeck.Name, "GameStats"); _assignedDeck = selectedDeck; // Unarchive the active deck after we have played a game with it if (_assignedDeck.Archived) { Logger.WriteLine("Automatically unarchiving deck " + selectedDeck.Name + " after assigning current game", "GameEventHandler"); Helper.MainWindow.ArchiveDeck(_assignedDeck, false); } if (HearthStatsAPI.IsLoggedIn && Config.Instance.HearthStatsAutoUploadNewGames) { if (Game.CurrentGameMode == GameMode.None) { await GameModeDetection(300); //give the user 5 minutes to get out of the victory/defeat screen } if (Game.CurrentGameMode == GameMode.Casual) { await HsLogReader.Instance.RankedDetection(); } if (Game.CurrentGameMode == GameMode.Ranked && !_lastGame.HasRank) { await RankDetection(5); } await GameModeSaved(15); if (Game.CurrentGameMode == GameMode.Arena) { HearthStatsManager.UploadArenaMatchAsync(_lastGame, selectedDeck, background: true); } else { HearthStatsManager.UploadMatchAsync(_lastGame, selectedDeck, background: true); } } _lastGame = null; } else { DefaultDeckStats.Instance.GetDeckStats(Game.PlayingAs).AddGameResult(Game.CurrentGameStats); Logger.WriteLine(string.Format("Assigned current deck to default {0} deck.", Game.PlayingAs), "GameStats"); _assignedDeck = null; } }
#pragma warning disable 4014 public static async void HandleGameEnd() { Helper.MainWindow.Overlay.HideTimers(); if (Game.CurrentGameStats == null) { return; } var player = Game.Entities.FirstOrDefault(e => e.Value.IsPlayer); var opponent = Game.Entities.FirstOrDefault(e => e.Value.HasTag(GAME_TAG.PLAYER_ID) && !e.Value.IsPlayer); if (player.Value != null) { Game.CurrentGameStats.PlayerName = player.Value.Name; } if (opponent.Value != null) { Game.CurrentGameStats.OpponentName = opponent.Value.Name; } Game.CurrentGameStats.Turns = HsLogReader.Instance.GetTurnNumber(); if (Config.Instance.DiscardZeroTurnGame && Game.CurrentGameStats.Turns < 1) { Logger.WriteLine("Game has 0 turns, discarded. (DiscardZeroTurnGame)", "GameEventHandler"); _assignedDeck = null; return; } Game.CurrentGameStats.GameEnd(); var selectedDeck = DeckList.Instance.ActiveDeckVersion; if (selectedDeck != null) { if (Config.Instance.DiscardGameIfIncorrectDeck && !Game.PlayerDrawn.All( c => c.IsStolen || selectedDeck.GetSelectedDeckVersion().Cards.Any(c2 => c.Id == c2.Id && c.Count <= c2.Count))) { Logger.WriteLine("Assigned current game to NO deck - selected deck does not match cards played", "GameEventHandler"); Game.CurrentGameStats.DeleteGameFile(); _assignedDeck = null; return; } Game.CurrentGameStats.PlayerDeckVersion = selectedDeck.Version; Game.CurrentGameStats.HearthStatsDeckVersionId = selectedDeck.HearthStatsDeckVersionId; _lastGame = Game.CurrentGameStats; selectedDeck.DeckStats.AddGameResult(_lastGame); if (Config.Instance.ShowNoteDialogAfterGame && !Config.Instance.NoteDialogDelayed && !_showedNoteDialog) { _showedNoteDialog = true; new NoteDialog(Game.CurrentGameStats); } Logger.WriteLine("Assigned current game to deck: " + selectedDeck.Name, "GameStats"); _assignedDeck = selectedDeck; if (HearthStatsAPI.IsLoggedIn && Config.Instance.HearthStatsAutoUploadNewGames) { if (Game.CurrentGameMode == GameMode.None) { await GameModeDetection(300); //give the user 5 minutes to get out of the victory/defeat screen } if (Game.CurrentGameMode == GameMode.Casual) { await HsLogReader.Instance.RankedDetection(); } if (Game.CurrentGameMode == GameMode.Ranked && !_lastGame.HasRank) { await RankDetection(5); } await GameModeSaved(15); if (Game.CurrentGameMode == GameMode.Arena) { HearthStatsManager.UploadArenaMatchAsync(_lastGame, selectedDeck, background: true); } else { HearthStatsManager.UploadMatchAsync(_lastGame, selectedDeck, background: true); } } _lastGame = null; } else { DefaultDeckStats.Instance.GetDeckStats(Game.PlayingAs).AddGameResult(Game.CurrentGameStats); Logger.WriteLine(string.Format("Assigned current deck to default {0} deck.", Game.PlayingAs), "GameStats"); _assignedDeck = null; } }