public void Setup()
        {
            _campaignServiceRecord = JsonConvert.DeserializeObject<CampaignServiceRecord>(File.ReadAllText(Config.CampaignServiceRecordJsonPath));

            var mock = new Mock<IHaloSession>();
            mock.Setup(m => m.Get<CampaignServiceRecord>(It.IsAny<string>()))
                .ReturnsAsync(_campaignServiceRecord);

            _mockSession = mock.Object;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Get the Customstats.
        /// </summary>
        public async void UpdateOverview()
        {
            var client = new HaloClient(DevAcc);

            using (var session = client.StartSession())
            {
                // Get the current Base-Informations
                CustomServiceRecord = await session.Query(new GetCustomServiceRecord().ForPlayer(Gamertag));
                WarzoneServiceRecord = await session.Query(new GetWarzoneServiceRecord().ForPlayer(Gamertag));
                ArenaServiceRecord = await session.Query(new GetArenaServiceRecord().ForPlayer(Gamertag));
                CampaignServiceRecord = await session.Query(new GetCampaignServiceRecord().ForPlayer(Gamertag));

                // Calculate the "All-Modes" total played time
                var totalPlayTime = WarzoneServiceRecord.Results[0].Result.WarzoneStat.TotalTimePlayed +
                                    ArenaServiceRecord.Results[0].Result.ArenaStats.TotalTimePlayed +
                                    CampaignServiceRecord.Results[0].Result.CampaignStat.TotalTimePlayed;

                // Parse the total played time to a custom string
                var totalPlayTimeString = $"{totalPlayTime.Days}D {totalPlayTime.Hours}Hr {totalPlayTime.Minutes}Min";

                // Calculate the "All-Modes" total kills
                var totalKills = CustomServiceRecord.Results[0].Result.CustomStats.TotalKills +
                                 WarzoneServiceRecord.Results[0].Result.WarzoneStat.TotalKills +
                                 ArenaServiceRecord.Results[0].Result.ArenaStats.TotalKills;

                // Calculate the "All-Modes" total deaths
                var totalDeath = CustomServiceRecord.Results[0].Result.CustomStats.TotalDeaths +
                                 WarzoneServiceRecord.Results[0].Result.WarzoneStat.TotalDeaths +
                                 ArenaServiceRecord.Results[0].Result.ArenaStats.TotalDeaths;

                // Calculate the "All-Modes" total assists
                var totalAssists = CustomServiceRecord.Results[0].Result.CustomStats.TotalAssists +
                                   WarzoneServiceRecord.Results[0].Result.WarzoneStat.TotalAssists +
                                   ArenaServiceRecord.Results[0].Result.ArenaStats.TotalAssists;

                // Calculate the "All-Modes" total headshots
                var totalHeadshots = CustomServiceRecord.Results[0].Result.CustomStats.TotalHeadshots +
                                     WarzoneServiceRecord.Results[0].Result.WarzoneStat.TotalHeadshots +
                                     ArenaServiceRecord.Results[0].Result.ArenaStats.TotalHeadshots;

                // Calculate the "All-Modes" total TotalShots
                var totalShotsFired = CustomServiceRecord.Results[0].Result.CustomStats.TotalShotsFired +
                                      WarzoneServiceRecord.Results[0].Result.WarzoneStat.TotalShotsFired +
                                      ArenaServiceRecord.Results[0].Result.ArenaStats.TotalShotsFired;

                // Calculate the "All-Modes" total headshots
                var totalShotsLanded = CustomServiceRecord.Results[0].Result.CustomStats.TotalShotsLanded +
                                       WarzoneServiceRecord.Results[0].Result.WarzoneStat.TotalShotsLanded +
                                       ArenaServiceRecord.Results[0].Result.ArenaStats.TotalShotsLanded;

                // Calculate the "All-Modes" total assassinations
                var totalAssassinations = CustomServiceRecord.Results[0].Result.CustomStats.TotalAssassinations +
                                          WarzoneServiceRecord.Results[0].Result.WarzoneStat.TotalAssassinations +
                                          ArenaServiceRecord.Results[0].Result.ArenaStats.TotalAssassinations;

                // Calculate the "All-Modes" total game-counts
                var totalGames = CustomServiceRecord.Results[0].Result.CustomStats.TotalGamesCompleted +
                                 WarzoneServiceRecord.Results[0].Result.WarzoneStat.TotalGamesCompleted +
                                 ArenaServiceRecord.Results[0].Result.ArenaStats.TotalGamesCompleted;

                // Calculate the "All-Modes" total wins
                var totalWon = CustomServiceRecord.Results[0].Result.CustomStats.TotalGamesWon +
                               WarzoneServiceRecord.Results[0].Result.WarzoneStat.TotalGamesWon +
                               ArenaServiceRecord.Results[0].Result.ArenaStats.TotalGamesWon;

                // Calculate the "All-Modes" total losts
                var totalLost = CustomServiceRecord.Results[0].Result.CustomStats.TotalGamesLost +
                                WarzoneServiceRecord.Results[0].Result.WarzoneStat.TotalGamesLost +
                                ArenaServiceRecord.Results[0].Result.ArenaStats.TotalGamesLost;

                // Grab gamers current SpartanRank
                var currentSpartanRank = CustomServiceRecord.Results[0].Result.SpartanRank;

                // Grab gamers current XP
                var currentSpartanXp = CustomServiceRecord.Results[0].Result.Xp;

                // Grab gamers current SpartanRank's progress percentage
                var percentSpartanRankCurrent = SpartanRankGetPercentage(currentSpartanXp,currentSpartanRank);

                // Grab gamers current emblem
                var playerImgEmblem =
                    await session.Query(new GetEmblemImage().ForPlayer(Gamertag));

                // Grab gamers current avatar
                var playerImgSpartanImage =
                    await session.Query(new GetSpartanImage().ForPlayer(Gamertag));

                // Calculate total Kill / Death
                float totalKillsDeath = totalKills/(float) totalDeath;

                // Calculate total Kill+Assist / Death
                float totalKillsWithAssistsDeath = (totalKills + (float) totalAssists)/totalDeath;

                // Calculate TotalShot Accuracy
                float playersTotalAccuracy = 100*(totalShotsLanded/(float) totalShotsFired);

                TopMedals = WarzoneServiceRecord.Results[0].Result.WarzoneStat.MedalAwards;
                TopMedals.AddRange(ArenaServiceRecord.Results[0].Result.ArenaStats.MedalAwards.ToList());
                TopMedals=TopMedals.OrderByDescending(o => o.Count).ToList();


                //UI-Updates
                UiSetPlayerEmblem(playerImgEmblem.Image, pictureBox1);
                UiSetPlayerSpartanImage(playerImgSpartanImage.Image, pictureBox2);
                UiUpdateLabel(Resources.prefixSrWithSpace + currentSpartanRank, l_rank_);
                UiUpdateLabel(Gamertag, l_gamertag_, Color.White);
                UiUpdateLabel(Resources.prefixTotalTimePlayedWithNewline + totalPlayTimeString, l_time_played);
                UiUpdateLabel("Kills: \t" + totalKills.ToString("#,###"), l_totalKills);
                UiUpdateLabel("Deaths: \t" + totalDeath.ToString("#,###"), l_totalDeaths);
                UiUpdateLabel("Assists: \t" + totalAssists.ToString("#,###"), l_totalAssists);
                UiUpdateLabel("K/D: \t" + totalKillsDeath.ToString("0.00"), l_killsDeath);
                UiUpdateLabel("K+A/D: \t" + totalKillsWithAssistsDeath.ToString("0.00"), l_killsAssistsDeath);
                UiUpdateLabel("Headshots: \t" + totalHeadshots.ToString("#,###"), l_headshots);
                UiUpdateLabel("Assassinations: \t" + totalAssassinations.ToString("#,###"), l_assassinations);
                UiUpdateLabel("Total Match-Count: \t" + totalGames.ToString("#,###"), l_totalMatchesCount);
                UiUpdateLabel("Total Matches Won: \t" + totalWon.ToString("#,###"), l_totalMatchesWon, Color.DarkGreen);
                UiUpdateLabel("Total Matches Lost: \t" + totalLost.ToString("#,###"), l_totalMatchesLost, Color.Red);
                UiUpdateLabel("Total Shots Fired: \t" + totalShotsFired.ToString("#,###"), l_totalShotsFired);
                UiUpdateLabel("Total Shots Landed: \t" + totalShotsLanded.ToString("#,###"), l_totalShotsLanded);
                UiUpdateLabel("Shot Accuracy: \t" + playersTotalAccuracy.ToString("0.00") + " %", l_totalShotsAccuracy);
                Invoke((MethodInvoker)delegate {
                    circularProgressBar1.Caption = Resources.prefixSrWithSpace + "\n" + percentSpartanRankCurrent.ToString("0.00") + " %";
                    circularProgressBar1.Value = (float)(percentSpartanRankCurrent);
                });


                var bitmap2 = Tools.BitmapFromUrl(Tools.GetMedalFromMedalList(Medals, TopMedals[0].MedalId).SpriteLocation.SpriteSheetUri);
                for (var max = 0; max < 10; max++)
                {
                    var medalx = Tools.GetMedalFromMedalList(Medals, TopMedals[max].MedalId);
                    var cloneRect = Tools.MedalSpriteRectangle(medalx);
                    var cloneBitmap = Tools.GetSpriteFromImage(bitmap2, cloneRect);
                    Invoke((MethodInvoker)delegate { TopMedalPicBoxes[max].Image = Tools.ScaleImage(cloneBitmap, 64, 64); });
                    UiUpdateLabel(Medals.First(item => item.Id == TopMedals[max].MedalId).Name + "\n[ " + TopMedals[max].Count.ToString("#,###") + " ]", TopMedalLabels[max]);
                }
                
                
            }
            UpdateWarzone();
        }