Exemplo n.º 1
0
        /// <summary>
        /// Receives notification that game state has ended
        /// </summary>
        /// <param name="gameNumber"></param>
        /// <param name="gameRecord"></param>
        public void OnGameEnded(int gameNumber, GameRecord gameRecord)
        {
            // Game ended. Grab game result
            Log.WriteLine("Game no. {0} Result: {1}", gameNumber, gameRecord.Result);

            if (string.IsNullOrEmpty(Constants.PlayBackDeckPath) && gameRecord.OpponentDeck.Count > 0)
            {
                var gameLog = CurrentPlayState.StopGameLog();
                if (gameRecord.IsExpedition())
                {
                    gameRecord.NumWins   = CurrentExpedition.NumberOfWins + (gameRecord.Result == "Win" ? 1 : 0);
                    gameRecord.NumLosses = CurrentExpedition.NumberOfLosses + (gameRecord.Result != "Win" ? 1 : 0);
                }
                GameHistory.AddGameRecord(gameRecord, true, gameLog);
                Utilities.CallActionSafelyAndWait(DecksListCtrl, new Action(() =>
                {
                    DecksListCtrl.AddToDeckList(gameRecord, true);
                }));
            }

            OnPlayerDeckSet(new List <CardWithCount>(), "");
        }
Exemplo n.º 2
0
        private void DecksListCtrl_SelectionChanged(object sender, EventArgs e)
        {
            GameRecord gr = DecksListCtrl.SelectedItem;

            if (gr == null)
            {
                HighlightedGameLogControl.Clear();
                HighlightedDeckControl.ClearDeck();
                HighlightedDeckPanel.Visible = false;
                return;
            }

            // Highlight the deck
            string deckName = null;

            if (!gr.IsExpedition() && gr.MyDeckName != GameRecord.DefaultConstructedDeckName)
            {
                deckName = gr.MyDeckName;
            }
            HighlightedGameLogControl.LoadGames(gr.GetDeckSignature(), deckName, Properties.Settings.Default.HideAIGames);
            HighlightedDeckControl.SetDeck(gr.MyDeck);
            HighlightedDeckControl.Title        = gr.ToString();
            HighlightedDeckStatsDisplay.TheDeck = gr.MyDeck;

            // Fix the size
            Size bestDeckSize = HighlightedDeckControl.GetBestSize();

            HighlightedDeckControl.SetBounds(0, 0, bestDeckSize.Width, bestDeckSize.Height, BoundsSpecified.Size);
            int deckStatsHeight = HighlightedDeckStatsDisplay.GetBestHeight(bestDeckSize.Width);

            HighlightedDeckStatsDisplay.SetBounds(HighlightedDeckControl.Left, HighlightedDeckControl.Top + bestDeckSize.Height, bestDeckSize.Width, deckStatsHeight, BoundsSpecified.All);

            HighlightedGameLogControl.Invalidate();
            HighlightedDeckControl.Invalidate();
            HighlightedDeckStatsDisplay.Invalidate();
            HighlightedDeckPanel.Visible = true;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Load game record from file
        /// </summary>
        /// <param name="path">file path</param>
        /// <param name="matchingDeckSignature">deck signature to match, if specified</param>
        /// <returns>Game record, or null if signature did not match</returns>
        public static GameRecord LoadFromFile(string path, string matchingDeckSignature = null)
        {
            var        json   = Utilities.ReadLocalFile(path);
            GameRecord result = new GameRecord();
            Dictionary <string, JsonElement> gameRecord = JsonSerializer.Deserialize <Dictionary <string, JsonElement> >(json);

            result.MyDeckCode           = gameRecord["MyDeckCode"].ToString();
            result.ExpeditionSignature  = gameRecord["ExpeditionState"].ToString();
            result.ExpeditionDraftPicks = null;
            if (gameRecord.ContainsKey("ExpeditionDraftPicks") && gameRecord["ExpeditionDraftPicks"].ValueKind == JsonValueKind.Array)
            {
                var picks = gameRecord["ExpeditionDraftPicks"].ToObject <Dictionary <string, JsonElement>[]>();
                result.ExpeditionDraftPicks = new ExpeditionPick[picks.Length];
                for (int i = 0; i < picks.Length; i++)
                {
                    result.ExpeditionDraftPicks[i] = new ExpeditionPick(picks[i]);
                }
            }

            // Check if deck signature matches
            if (matchingDeckSignature != null && result.GetDeckSignature() != matchingDeckSignature)
            {
                return(null);
            }

            result.MyDeckName = gameRecord["MyDeckName"].ToString();
            if (!string.IsNullOrEmpty(result.MyDeckCode))
            {
                // Map the deck name for constructed decks only
                try { result.MyDeckName = GameHistory.DeckNames[result.MyDeckCode]; } catch { }
            }

            result.MyDeck       = Utilities.DeckFromStringCodeList(gameRecord["MyDeck"].ToObject <string[]>());
            result.OpponentName = gameRecord["OpponentName"].ToString();
            result.OpponentIsAI = false;
            try
            {
                result.OpponentName = GameHistory.AIDeckNames[result.OpponentName];
                result.OpponentIsAI = true;
            }
            catch { }
            result.OpponentDeck     = Utilities.DeckFromStringCodeList(gameRecord["OpponentDeck"].ToObject <string[]>());
            result.Result           = gameRecord["Result"].ToString();
            result.Notes            = gameRecord["Notes"].ToString();
            result.Timestamp        = gameRecord["Timestamp"].ToObject <DateTime>();
            result.Log              = gameRecord["Log"].ToString();
            result.GameLogFile      = path;
            result.GamePlaybackFile = path.Substring(0, path.Length - 4) + ".playback";
            if (!File.Exists(result.GamePlaybackFile))
            {
                result.GamePlaybackFile = "";
            }

            // Extract expedition record
            if (result.IsExpedition())
            {
                string deckName   = result.MyDeckName;
                int    scoreIndex = deckName.LastIndexOf('-');
                if (scoreIndex > 0)
                {
                    result.NumWins   = deckName[scoreIndex - 1] - '0';
                    result.NumLosses = deckName[scoreIndex + 1] - '0';
                }
            }
            return(result);
        }