Beispiel #1
0
        /// <summary>
        /// Do not use this lightly, this contains making changes
        /// to the class via reflection and might be risky.
        ///
        /// This is a temporary implementation since HistoryEndPoint
        /// library need a setter update for this or a complete rewrite
        /// in order to update score values for ez mod (ez mod = doubled)
        /// </summary>
        /// <param name="score"></param>
        /// <returns></returns>
        private void ModifyScore(ref HistoryJson.Score score, int newVal)
        {
            try
            {
                Type t = typeof(HistoryJson.Score);
                System.Reflection.PropertyInfo propInfo = t.GetProperties().FirstOrDefault(p => p.Name.Contains("score", StringComparison.CurrentCultureIgnoreCase));

                //If we cannot write this we just gonna get the private setter and use that
                if (!propInfo.CanWrite)
                {
                    propInfo = t.GetProperty("score", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
                    propInfo.SetValue(score, new int?(newVal));
                    return;
                }

                //just change value
                propInfo.SetValue(score, new int?(newVal));
            }
            catch (Exception ex)
            {
                Logger.Log("Exception at temp impl modifyScore in analyzer" + Environment.NewLine + ex.ToString());
            }
        }
Beispiel #2
0
        /// <summary>
        /// calculates the highest ranking players and beatmap play counts
        /// </summary>
        /// <param name="games"><see cref="GetData.GetMatches(HistoryJson.History)"/></param>
        /// <returns>Tuple { Tuple { HighestScore, HighestScoreBeatmap, HighestScoreRanking }[], BeatmapPlayCount } }</returns>
        public Tuple <Tuple <HistoryJson.Score, HistoryJson.BeatMap, Rank[]>[], BeatmapPlayCount[]> CalculateHighestRankingAndPlayCount(HistoryJson.Game[] games, HistoryJson.History history, bool calculateMVP = false)
        {
            HistoryJson.Score   highestScore        = null;
            HistoryJson.BeatMap highestScoreBeatmap = null;
            List <Player>       highestScoreRanking = new List <Player>();
            List <Rank>         sortedRanksScore    = new List <Rank>();

            HistoryJson.Score   highestAccuracy        = null;
            HistoryJson.BeatMap highestAccuracyBeatmap = null;
            List <Rank>         sortedRanksAccuracy    = new List <Rank>();

            StringComparer curCultIgnore = StringComparer.CurrentCultureIgnoreCase;

            List <HistoryJson.Score> scores     = new List <HistoryJson.Score>();
            List <BeatmapPlayCount>  playCounts = new List <BeatmapPlayCount>();

            int warmupCounter = 0;
            List <HistoryJson.Score> hAcc;
            List <HistoryJson.Score> hScore;
            List <HistoryJson.Score> hMisses;
            List <HistoryJson.Score> hCombo;
            List <HistoryJson.Score> h300;

            bool doubleAllScores;

            foreach (HistoryJson.Game game in games)
            {
                doubleAllScores = false;
                List <HistoryJson.Score> gameScores = game.scores;

                if (gameScores == null)
                {
                    continue;
                }
                else if (Program.Config.WarmupMatchCount > 0 && warmupCounter < Program.Config.WarmupMatchCount)
                {
                    warmupCounter++;
                    continue;
                }

                int playCountIndex = playCounts.FindIndex(bpc => bpc.BeatMap.id.Value == game.beatmap.id.Value);

                if (playCountIndex > -1)
                {
                    playCounts[playCountIndex].Count++;
                }
                else
                {
                    playCounts.Add(new BeatmapPlayCount()
                    {
                        BeatMap = game.beatmap,
                        Count   = 1,
                    });
                }

                if (game.mods.Contains("ez", curCultIgnore))
                {
                    doubleAllScores = true;
                }

                for (int i = 0; i < game.scores.Count; i++)
                {
                    HistoryJson.Score score         = game.scores[i];
                    Player            CurrentPlayer = highestScoreRanking.Find(player => player.UserId == score.user_id.Value);

                    if (doubleAllScores || score.mods.Contains("EZ", curCultIgnore))
                    {
                        ModifyScore(ref score, score.score.Value * 2);
                    }

                    if (CurrentPlayer == null)
                    {
                        CurrentPlayer          = new Player();
                        CurrentPlayer.UserId   = score.user_id.Value;
                        CurrentPlayer.UserName = GetData.GetUser(score, history).Username;
                        CurrentPlayer.Scores   = new HistoryJson.Score[] { score };
                        highestScoreRanking.Add(CurrentPlayer);
                    }
                    else
                    {
                        List <HistoryJson.Score> scoresPlayer = CurrentPlayer.Scores.ToList();
                        scoresPlayer.Add(score);
                        CurrentPlayer.Scores = scoresPlayer.ToArray();
                    }

                    if (highestScore == null || score.score.Value > highestScore.score.Value)
                    {
                        highestScore        = score;
                        highestScoreBeatmap = game.beatmap;
                    }

                    if (highestAccuracy == null || highestAccuracy.accuracy.Value < score.accuracy.Value)
                    {
                        highestAccuracy        = score;
                        highestAccuracyBeatmap = game.beatmap;
                    }
                }

                if (calculateMVP)
                {
                    hAcc    = game.scores.OrderBy(f => f.accuracy.Value).ToList();
                    hScore  = game.scores.OrderBy(f => f.score.Value).ToList();
                    hMisses = game.scores.OrderByDescending(f => f.statistics.count_miss.Value).ToList();
                    hCombo  = game.scores.OrderBy(f => f.max_combo.Value).ToList();
                    h300    = game.scores.OrderBy(f => f.statistics.count_300.Value).ToList();

                    int x;
                    for (int i = hAcc.Count - 1; i > 0; i--)
                    {
                        if (i < hAcc.Count - 1)
                        {
                            x = i + 1;
                            while (x < hAcc.Count - 1 && hAcc[i].accuracy.Value == hAcc[x].accuracy.Value)
                            {
                                x++;
                            }

                            highestScoreRanking.Find(p => p.UserId == hAcc[i].user_id.Value).MVPScore += x * _accMulti;
                            continue;
                        }

                        highestScoreRanking.Find(p => p.UserId == hAcc[i].user_id.Value).MVPScore += i * _accMulti;
                    }

                    for (int i = hScore.Count - 1; i > 0; i--)
                    {
                        if (i < hScore.Count - 1)
                        {
                            x = i + 1;
                            while (x < hScore.Count - 1 && hScore[i].score.Value == hScore[x].score.Value)
                            {
                                x++;
                            }

                            highestScoreRanking.Find(p => p.UserId == hScore[i].user_id.Value).MVPScore += x * _scoreMulti;
                            continue;
                        }

                        highestScoreRanking.Find(p => p.UserId == hScore[i].user_id.Value).MVPScore += i * _scoreMulti;
                    }

                    for (int i = hMisses.Count - 1; i > 0; i--)
                    {
                        if (i < hMisses.Count - 1)
                        {
                            x = i + 1;
                            while (x < hMisses.Count - 1 && hMisses[i].statistics.count_miss.Value == hMisses[x].statistics.count_miss.Value)
                            {
                                x++;
                            }

                            highestScoreRanking.Find(p => p.UserId == hMisses[i].user_id.Value).MVPScore -= x * _missesMulti;
                            continue;
                        }

                        highestScoreRanking.Find(p => p.UserId == hMisses[i].user_id.Value).MVPScore -= i * _missesMulti;
                    }

                    for (int i = hCombo.Count - 1; i > 0; i--)
                    {
                        if (i < hCombo.Count - 1)
                        {
                            x = i + 1;
                            while (x < hCombo.Count - 1 && hCombo[i].max_combo.Value == hCombo[x].max_combo.Value)
                            {
                                x++;
                            }

                            highestScoreRanking.Find(p => p.UserId == hCombo[i].user_id.Value).MVPScore += x * _comboMulti;
                            continue;
                        }

                        highestScoreRanking.Find(p => p.UserId == hCombo[i].user_id.Value).MVPScore += i * _comboMulti;
                    }

                    for (int i = h300.Count - 1; i > 0; i--)
                    {
                        if (i < h300.Count - 1)
                        {
                            x = i + 1;
                            while (x < h300.Count - 1 && h300[i].max_combo.Value == h300[x].max_combo.Value)
                            {
                                x++;
                            }

                            highestScoreRanking.Find(p => p.UserId == h300[i].user_id.Value).MVPScore += x * _300Multi;
                            continue;
                        }

                        highestScoreRanking.Find(p => p.UserId == h300[i].user_id.Value).MVPScore += i * _300Multi;
                    }
                }
            }

            highestScoreRanking.ForEach(ob =>
            {
                ob.CalculateAverageAccuracy();
                ob.GetHighestScore();
            });

            highestScoreRanking = highestScoreRanking.OrderByDescending(player => player.HighestScore.score.Value).ToList();

            for (int i = 0; i < highestScoreRanking.Count; i++)
            {
                Rank rank = new Rank()
                {
                    Player = highestScoreRanking[i],
                    Place  = i + 1
                };

                sortedRanksScore.Add(rank);
            }
            ;

            sortedRanksAccuracy = sortedRanksScore.OrderByDescending(r => r.Player.AverageAccuracy).ToList();

            for (int i = 0; i < sortedRanksAccuracy.Count; i++)
            {
                sortedRanksAccuracy[i].Place = i + 1;
            }

            return(new Tuple <Tuple <HistoryJson.Score, HistoryJson.BeatMap, Rank[]>[], BeatmapPlayCount[]>(
                       new Tuple <HistoryJson.Score, HistoryJson.BeatMap, Rank[]>[]
            {
                new Tuple <HistoryJson.Score, HistoryJson.BeatMap, Rank[]>(highestScore, highestScoreBeatmap, sortedRanksScore.ToArray()),
                new Tuple <HistoryJson.Score, HistoryJson.BeatMap, Rank[]>(highestAccuracy, highestAccuracyBeatmap, sortedRanksAccuracy.ToArray()),
            },
                       playCounts.ToArray()));
        }