Exemple #1
0
        private static Sc2ReplayPlayer[] ParsePlayers(dynamic details)
        {
            var playerCount = (int)details[0].Length;
            var players = new Sc2ReplayPlayer[playerCount];

            for (var i = 0; i < playerCount; i++)
            {
                var playerData = details[0][i];
                var player = new Sc2ReplayPlayer();
                player.Name = Encoding.UTF8.GetString(playerData[0]);

                // as of HOTS, player names and clan names are separated by <sp/> in the player name field within the replay
                if (player.Name.Contains("<sp/>"))
                {
                    var parts = player.Name.Split(new[] { "<sp/>" }, StringSplitOptions.None);
                    player.Clan = parts[0].Trim('[', ']'); // we also remove the surrounding [ and ] from the clan name
                    player.Name = parts[1];
                }

                player.BattleNetSubId = (int)playerData[1][2];
                player.BattleNetId = (int)playerData[1][4];

                var raceString = Encoding.ASCII.GetString(playerData[2]);
                player.Race = RaceParser.Parse(raceString);

                var color = new[]
                                   {
                                       (byte) playerData[3][0],
                                       (byte) playerData[3][1],
                                       (byte) playerData[3][2],
                                       (byte) playerData[3][3]
                                   };

                player.HexColor = color[0].ToString("X2") + color[1].ToString("X2") + color[2].ToString("X2");
                player.Team = (int)playerData[5];
                player.Won = (int)playerData[8] == 1; // 0 = inconclusive, 1 = win, 2 = loss


                players[i] = player;
            }

            return players;
        }
Exemple #2
0
 public Sc2Replay()
 {
     Players = new Sc2ReplayPlayer[0];
 }