예제 #1
0
        /// <summary>
        /// Constructor
        /// </summary>
        public static void LoadAllGames(IProgressDisplay pdc)
        {
            // Load all known deck names
            DeckNames = new Dictionary <string, string>();
            if (File.Exists(Constants.GetLocalDeckNamesFilePath()))
            {
                try
                {
                    var json = Utilities.ReadLocalFile(Constants.GetLocalDeckNamesFilePath());
                    Dictionary <string, JsonElement> deckNames = JsonSerializer.Deserialize <Dictionary <string, JsonElement> >(json);
                    DeckNames = deckNames["DeckNames"].ToObject <Dictionary <string, string> >();
                }
                catch
                {
                    if (File.Exists(Constants.GetLocalDeckNamesFilePath() + ".backup"))
                    {
                        try
                        {
                            var json = Utilities.ReadLocalFile(Constants.GetLocalDeckNamesFilePath() + ".backup");
                            Dictionary <string, JsonElement> deckNames = JsonSerializer.Deserialize <Dictionary <string, JsonElement> >(json);
                            DeckNames = deckNames["DeckNames"].ToObject <Dictionary <string, string> >();
                        }
                        catch { }
                    }
                }
            }

            // Load all games
            Games = new List <GameRecord>();
            if (Directory.Exists(Constants.GetLocalGamesPath()))
            {
                DirectoryInfo dirInfo      = new DirectoryInfo(Constants.GetLocalGamesPath());
                FileInfo[]    files        = dirInfo.GetFiles("*.txt");
                var           filesInOrder = files.OrderBy(x => x.CreationTime);
                for (int i = 0; i < filesInOrder.Count(); i++)
                {
                    filesInOrder.Count();
                    try
                    {
                        AddGameRecord(GameRecord.LoadFromFile(filesInOrder.ElementAt(i).FullName));
                    }
                    catch
                    {
                        // Skip bad records
                    }
                    pdc.Update("Loading game records...", 100.0 * (i + 1) / filesInOrder.Count());
                    //Thread.Yield();
                }
            }
        }
예제 #2
0
        private void DecksListCtrl_ExpeditionHistory(object sender, EventArgs e)
        {
            //GameRecord gr = DecksListCtrl.SelectedItem;
            var        deckSignature = DecksListCtrl.SelectedItem.GetDeckSignature();
            var        allGames      = GameHistory.Games.FindAll(x => deckSignature == x.GetDeckSignature()).ToList();
            GameRecord gr            = allGames[0];

            if (gr.ExpeditionDraftPicks != null)
            {
                ExpeditionHistory history = new ExpeditionHistory();
                history.DraftPicks = gr.ExpeditionDraftPicks;
                history.ShowDialog();
            }
        }
예제 #3
0
        private void GameLogDisplay_Paint(object sender, PaintEventArgs e)
        {
            Color highlightBackColor = Color.FromArgb(
                (ForeColor.R + 3 * BackColor.R) / 4,
                (ForeColor.G + 3 * BackColor.G) / 4,
                (ForeColor.B + 3 * BackColor.B) / 4);

            int       top         = CellMargin;
            Rectangle currentRect = new Rectangle(0, top, 0, top + CellHeight);

            foreach (var col in Columns)
            {
                currentRect.X     = currentRect.Right + CellMargin;
                currentRect.Width = col.Width;
                TextRenderer.DrawText(e.Graphics, col.Title, TitleFont, currentRect, ForeColor, col.TextFormat);
            }
            e.Graphics.DrawLine(new Pen(ForeColor, 1), new Point(CellMargin, currentRect.Bottom), new Point(currentRect.Right, currentRect.Bottom));

            currentRect = new Rectangle(0, top, 0, top + CellHeight);
            Color lineColor = Color.FromArgb(
                (ForeColor.R + 3 * BackColor.R) / 4,
                (ForeColor.G + 3 * BackColor.G) / 4,
                (ForeColor.B + 3 * BackColor.B) / 4);

            for (int i = 0; i < Games.Count; i++)
            {
                GameRecord game = Games[i];
                currentRect.X     = 0;
                currentRect.Width = 0;
                currentRect.Y    += CellHeight + CellMargin;
                if (i == HighlightedCell.Y)
                {
                    e.Graphics.FillRectangle(new SolidBrush(highlightBackColor), GetCellRectangle(-1, HighlightedCell.Y));
                }
                for (int j = 0; j < Columns.Length; j++)
                {
                    var col = Columns[j];
                    currentRect.X     = currentRect.Right + CellMargin;
                    currentRect.Width = col.Width;
                    string text = game.ReadPropertyAsString(col.PropertyName);

                    TextRenderer.DrawText(e.Graphics, text,
                                          ListFont,
                                          currentRect,
                                          ForeColor,
                                          col.TextFormat);
                }
                e.Graphics.DrawLine(new Pen(lineColor, 1), new Point(CellMargin, currentRect.Bottom), new Point(currentRect.Right, currentRect.Bottom));
            }
        }
예제 #4
0
        bool DetectDeck()
        {
            bool result = false;

            if (TestMode)
            {
                result = true;
            }
            else
            {
                CurrentGameRecord = new GameRecord();
                CurrentConstructedDeck.Reload();
                CurrentExpedition.Reload();

                if (CurrentConstructedDeck.Cards.Count > 0 && !CurrentConstructedDeck.Cards.SequenceEqual(CurrentExpedition.Cards))
                {
                    FullPlayerDeck = Utilities.ConvertDeck(CurrentConstructedDeck.Cards);
                    Callback.OnPlayerDeckSet(CurrentConstructedDeck.Cards, CurrentConstructedDeck.DeckName);
                    CurrentGameRecord.MyDeck               = Utilities.Clone(CurrentConstructedDeck.Cards);
                    CurrentGameRecord.MyDeckName           = CurrentConstructedDeck.DeckName;
                    CurrentGameRecord.MyDeckCode           = CurrentConstructedDeck.DeckCode;
                    CurrentGameRecord.OpponentName         = OpponentName;
                    CurrentGameRecord.OpponentDeck         = new List <CardWithCount>();
                    CurrentGameRecord.Notes                = "";
                    CurrentGameRecord.Result               = "-";
                    CurrentGameRecord.ExpeditionSignature  = "";
                    CurrentGameRecord.ExpeditionDraftPicks = null;
                    result = true;
                }
                else if (CurrentExpedition.Cards.Count > 0)
                {
                    FullPlayerDeck = Utilities.ConvertDeck(CurrentExpedition.Cards);
                    string title = string.Format("Expedition {0}-{1}{2}", CurrentExpedition.NumberOfWins,
                                                 CurrentExpedition.NumberOfLosses, CurrentExpedition.IsEliminationGame ? "*" : "");
                    Callback.OnPlayerDeckSet(CurrentExpedition.Cards, title);
                    CurrentGameRecord.MyDeck               = Utilities.Clone(CurrentExpedition.Cards);
                    CurrentGameRecord.MyDeckName           = title;
                    CurrentGameRecord.MyDeckCode           = "";
                    CurrentGameRecord.OpponentName         = OpponentName;
                    CurrentGameRecord.OpponentDeck         = new List <CardWithCount>();
                    CurrentGameRecord.Notes                = "";
                    CurrentGameRecord.Result               = "-";
                    CurrentGameRecord.ExpeditionSignature  = CurrentExpedition.Signature;
                    CurrentGameRecord.ExpeditionDraftPicks = CurrentExpedition.DraftPicks;
                    result = true;
                }
            }

            return(result);
        }
예제 #5
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>(), "");
        }
예제 #6
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;
        }
예제 #7
0
        /// <summary>
        /// Adda game to history
        /// </summary>
        /// <param name="gr">Game record to add</param>
        /// <param name="shouldInvalidate">Should window be redrawn</param>
        public void AddGameRecord(GameRecord gr, bool shouldInvalidate = true)
        {
            GameTextRectangles.Insert(1, new Rectangle[Columns.Length]);
            // Move all existing rectangles down
            for (int i = 2; i < GameTextRectangles.Count; i++)
            {
                for (int j = 0; j < GameTextRectangles[i].Length; j++)
                {
                    GameTextRectangles[i][j].Offset(0, CellHeight + CellMargin);
                }
            }

            int left = CellMargin;

            for (int i = 0; i < Columns.Length; i++)
            {
                GameHistoryColumn col  = Columns[i];
                string            text = gr.ReadPropertyAsString(col.PropertyName);
                GameTextRectangles[1][i] = new Rectangle(new Point(left, CellMargin + CellHeight + CellMargin), TextRenderer.MeasureText(text, ListFont, CellRectangles[i].Size));
                left += col.Width + CellMargin;
                if (col.TextFormat.HasFlag(TextFormatFlags.VerticalCenter))
                {
                    GameTextRectangles[1][i].Offset(0, (CellHeight - GameTextRectangles[1][i].Height) / 2);
                }
                if (col.TextFormat.HasFlag(TextFormatFlags.HorizontalCenter))
                {
                    GameTextRectangles[1][i].Offset((CellRectangles[i].Width - GameTextRectangles[1][i].Width) / 2, 0);
                }
            }
            GameLogDisplay.Width  = BestWidth;
            GameLogDisplay.Height = BestHeight;

            if (shouldInvalidate)
            {
                Invalidate();
            }
        }
예제 #8
0
 /// <summary>
 /// Save game record to file
 /// </summary>
 /// <param name="path">file path</param>
 public void SaveToFile(string path)
 {
     GameRecord.SaveToFile(path, MyDeckName, MyDeckCode, MyDeck, OpponentName, OpponentDeck, Result, Notes, Timestamp, Log, ExpeditionSignature, ExpeditionDraftPicks);
 }
예제 #9
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);
        }