Ejemplo n.º 1
0
        /// <summary>
        /// Shows detailed information on the Hostile Worlds match with the
        /// specified index within the log list.
        /// </summary>
        /// <param name="index">
        /// the index of the match to show detailed information on
        /// </param>
        public void ShowLogInfo(int index)
        {
            // fetch the log to show information on
            HostileWorldsLog hwlog = boundLogs[index];
            DataGridView     table = matchForm.DataGridView;

            // create a column for the description and one for each player
            table.ColumnCount = hwlog.Players.Count + 1;
            table.Rows.Clear();

            // initialize columns
            table.Columns[0].SortMode = DataGridViewColumnSortMode.NotSortable;

            for (int i = 0; i < hwlog.Players.Count; i++)
            {
                table.Columns[i + 1].Name       = hwlog.Players[i];
                table.Columns[i + 1].HeaderText = hwlog.Players[i];
                table.Columns[i + 1].SortMode   = DataGridViewColumnSortMode.NotSortable;
            }

            // add squad composition of all players
            string[] tableRow;

            AddEmptyTableRow(table, hwlog.Players.Count + 1, "Squad Compositition");
            AddEmptyTableRow(table, hwlog.Players.Count + 1);

            foreach (string squadMemberClass in hwlog.SquadComposition[hwlog.Players[0]].Keys.ToArray())
            {
                // add one row for each squad member class
                tableRow = new string[hwlog.Players.Count + 1];

                tableRow[0] = squadMemberClass;

                // fill columns with squad composition
                for (int i = 0; i < hwlog.Players.Count; i++)
                {
                    tableRow[i + 1] = hwlog.SquadComposition[hwlog.Players[i]][squadMemberClass].ToString();
                }

                table.Rows.Add(tableRow);
            }

            AddEmptyTableRow(table, hwlog.Players.Count + 1);

            // add ability distribution of all players
            AddEmptyTableRow(table, hwlog.Players.Count + 1, "Ability Distribution");
            AddEmptyTableRow(table, hwlog.Players.Count + 1);

            foreach (string abilityName in hwlog.AbilityDistribution[hwlog.Players[0]].Keys.ToArray())
            {
                // add one row for each ability
                tableRow = new string[hwlog.Players.Count + 1];

                tableRow[0] = abilityName;

                // fill columns with ability distribution
                for (int i = 0; i < hwlog.Players.Count; i++)
                {
                    tableRow[i + 1] = hwlog.AbilityDistribution[hwlog.Players[i]][abilityName].ToString();
                }

                table.Rows.Add(tableRow);
            }

            AddEmptyTableRow(table, hwlog.Players.Count + 1);

            // add other player data
            AddEmptyTableRow(table, hwlog.Players.Count + 1, "Other Player Data");
            AddEmptyTableRow(table, hwlog.Players.Count + 1);

            // add player APM
            tableRow    = new string[hwlog.Players.Count + 1];
            tableRow[0] = "APM";

            for (int i = 0; i < hwlog.Players.Count; i++)
            {
                tableRow[i + 1] = (hwlog.Actions[hwlog.Players[i]] * 60 / hwlog.MatchTime).ToString();
            }

            table.Rows.Add(tableRow);

            // add winner
            tableRow    = new string[hwlog.Players.Count + 1];
            tableRow[0] = "Winner";

            for (int i = 0; i < hwlog.Players.Count; i++)
            {
                tableRow[i + 1] = hwlog.Players[i].Equals(hwlog.Winner) ? "yes" : "no";
            }

            table.Rows.Add(tableRow);

            // resize columns
            table.AutoResizeColumns();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Parses all Hostile Worlds match logs from the passed stream.
        /// </summary>
        /// <param name="stream">
        /// to stream to parse the match logs from
        /// </param>
        /// <returns>
        /// a list of all valid Hostile Worlds match logs found
        /// </returns>
        public List <HostileWorldsLog> ParseLogFromStream(Stream stream)
        {
            // prepare new list of logs for all matches in the passed log file
            List <HostileWorldsLog> hwlogs = new List <HostileWorldsLog>();
            HostileWorldsLog        hwlog  = null;

            // initialize stream reader
            StreamReader sr = new StreamReader(stream);

            string logLine;
            int    index;

            string dateTime = "";
            string version  = "";

            // read entire log file
            while ((logLine = sr.ReadLine()) != null)
            {
                if ((index = logLine.LastIndexOf(LOGLINE_DATETIME)) > 0)
                {
                    // parse date and time
                    dateTime = logLine.Substring(index + LOGLINE_DATETIME.Length);
                }
                else if ((index = logLine.LastIndexOf(LOGLINE_VERSION)) > 0)
                {
                    // parse Hostile Worlds version
                    version = logLine.Substring(index + LOGLINE_VERSION.Length);
                }
                else if (logLine.Contains(LOGLINE_NEWMATCH))
                {
                    // prepare new match log
                    hwlog          = new HostileWorldsLog();
                    hwlog.DateTime = dateTime;
                    hwlog.Version  = version;

                    hwlogs.Add(hwlog);
                }
                else if ((index = logLine.LastIndexOf(LOGLINE_MAP)) > 0)
                {
                    // parse map name
                    hwlog.Map = logLine.Substring(index + LOGLINE_MAP.Length);
                }
                else if ((index = logLine.LastIndexOf(LOGLINE_FORMAT)) > 0)
                {
                    // parse matchup
                    hwlog.Format = logLine.Substring(index + LOGLINE_FORMAT.Length);
                }
                else if ((index = logLine.LastIndexOf(LOGLINE_PLAYER)) > 0)
                {
                    // parse player name
                    string playerName = logLine.Substring(index + LOGLINE_PLAYER.Length);
                    hwlog.Players.Add(playerName);

                    // create new table column for the ability distribution of that player
                    hwlog.AbilityDistribution.Add(playerName, new Dictionary <string, int>());

                    foreach (string abilityName in abilities)
                    {
                        hwlog.AbilityDistribution[playerName].Add(abilityName, 0);
                    }

                    // create new table column for the squad composition of that player
                    hwlog.SquadComposition.Add(playerName, new Dictionary <string, int>());

                    foreach (string squadMemberClass in squadMemberClasses)
                    {
                        hwlog.SquadComposition[playerName].Add(squadMemberClass, 0);
                    }
                }
                else if ((index = logLine.LastIndexOf(LOGLINE_MATCHTIME)) > 0)
                {
                    // parse match length
                    hwlog.MatchTime = Int32.Parse(logLine.Substring(index + LOGLINE_MATCHTIME.Length));
                }
                else if ((index = logLine.LastIndexOf(LOGLINE_WINNER)) > 0)
                {
                    // parse winner
                    hwlog.Winner = logLine.Substring(index + LOGLINE_WINNER.Length);
                }
                else if (logLine.Contains(LOGLINE_MATCHENDED))
                {
                    // remember that this match has properly finished
                    hwlog.MatchFinished = true;
                }
                else if ((index = logLine.LastIndexOf(LOGLINE_SQUADMEMBERCALLED_PREFIX)) > 0)
                {
                    // parse squad member class name
                    string squadMemberClass = logLine.Substring(index + LOGLINE_SQUADMEMBERCALLED_PREFIX.Length + 1);
                    squadMemberClass = squadMemberClass.Split(new char[] { '\"' })[0];

                    // parse player name
                    index = logLine.LastIndexOf(LOGLINE_SQUADMEMBERCALLED_INFIX);
                    string playerName = logLine.Substring(index + LOGLINE_SQUADMEMBERCALLED_INFIX.Length);

                    try
                    {
                        // update player squad member composition
                        hwlog.SquadComposition[playerName][squadMemberClass]++;
                    }
                    catch (Exception)
                    {
                        controller.ShowErrorDialog(playerName + " has called unknown squad member class " + squadMemberClass + ".");
                    }
                }
                else if ((index = logLine.LastIndexOf(LOGLINE_ABILITYUSED_PREFIX)) > 0)
                {
                    // parse ability name
                    string abilityName = logLine.Substring(index + LOGLINE_ABILITYUSED_PREFIX.Length + 1);
                    abilityName = abilityName.Split(new char[] { '\"' })[0];

                    // parse player name
                    index = logLine.LastIndexOf(LOGLINE_ABILITYUSED_INFIX);
                    string playerName = logLine.Substring(index + LOGLINE_ABILITYUSED_INFIX.Length);

                    try
                    {
                        // update player ability distribution
                        hwlog.AbilityDistribution[playerName][abilityName]++;
                    }
                    catch (Exception)
                    {
                        controller.ShowErrorDialog(playerName + " has used unknown ability " + abilityName + ".");
                    }
                }
                else if ((index = logLine.LastIndexOf(LOGLINE_ACTIONS)) > 0)
                {
                    string   actionsLog      = logLine.Substring(index + LOGLINE_ACTIONS.Length);
                    string[] actionsLogParts = actionsLog.Split(new char[] { ' ' });

                    // parse actions
                    string playerName = actionsLogParts[0];

                    // parse player name
                    int actions = Int32.Parse(actionsLogParts[1]);

                    hwlog.Actions[playerName] = actions;
                }
            }

            // close stream reader
            sr.Close();

            return(hwlogs);
        }