From cca02a8016088c645a64b6102f37120b83d0d300 Mon Sep 17 00:00:00 2001 From: StanR Date: Tue, 21 Dec 2021 13:08:31 +0300 Subject: [PATCH] Create PerformanceAttributes --- .../Difficulty/CatchPerformanceAttributes.cs | 11 ++++++++ .../Difficulty/CatchPerformanceCalculator.cs | 11 +++----- .../Difficulty/ManiaPerformanceAttributes.cs | 20 ++++++++++++++ .../Difficulty/ManiaPerformanceCalculator.cs | 17 +++++------- .../Difficulty/OsuPerformanceAttributes.cs | 26 +++++++++++++++++++ .../Difficulty/OsuPerformanceCalculator.cs | 22 +++++++--------- .../Difficulty/TaikoPerformanceAttributes.cs | 17 ++++++++++++ .../Difficulty/TaikoPerformanceCalculator.cs | 16 +++++------- .../Difficulty/PerformanceAttributes.cs | 16 ++++++++++++ .../Difficulty/PerformanceCalculator.cs | 2 +- osu.Game/Scoring/ScorePerformanceCache.cs | 2 +- .../Play/HUD/PerformancePointsCounter.cs | 2 +- 12 files changed, 119 insertions(+), 43 deletions(-) create mode 100644 osu.Game.Rulesets.Catch/Difficulty/CatchPerformanceAttributes.cs create mode 100644 osu.Game.Rulesets.Mania/Difficulty/ManiaPerformanceAttributes.cs create mode 100644 osu.Game.Rulesets.Osu/Difficulty/OsuPerformanceAttributes.cs create mode 100644 osu.Game.Rulesets.Taiko/Difficulty/TaikoPerformanceAttributes.cs create mode 100644 osu.Game/Rulesets/Difficulty/PerformanceAttributes.cs diff --git a/osu.Game.Rulesets.Catch/Difficulty/CatchPerformanceAttributes.cs b/osu.Game.Rulesets.Catch/Difficulty/CatchPerformanceAttributes.cs new file mode 100644 index 0000000000..1335fc2d23 --- /dev/null +++ b/osu.Game.Rulesets.Catch/Difficulty/CatchPerformanceAttributes.cs @@ -0,0 +1,11 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using osu.Game.Rulesets.Difficulty; + +namespace osu.Game.Rulesets.Catch.Difficulty +{ + public class CatchPerformanceAttributes : PerformanceAttributes + { + } +} diff --git a/osu.Game.Rulesets.Catch/Difficulty/CatchPerformanceCalculator.cs b/osu.Game.Rulesets.Catch/Difficulty/CatchPerformanceCalculator.cs index d3f3445ff1..e224675977 100644 --- a/osu.Game.Rulesets.Catch/Difficulty/CatchPerformanceCalculator.cs +++ b/osu.Game.Rulesets.Catch/Difficulty/CatchPerformanceCalculator.cs @@ -28,7 +28,7 @@ namespace osu.Game.Rulesets.Catch.Difficulty { } - public override double Calculate(Dictionary categoryDifficulty = null) + public override PerformanceAttributes Calculate() { mods = Score.Mods; @@ -90,13 +90,10 @@ namespace osu.Game.Rulesets.Catch.Difficulty if (mods.Any(m => m is ModNoFail)) value *= 0.90; - if (categoryDifficulty != null) + return new CatchPerformanceAttributes { - categoryDifficulty.Add("AR", Attributes.ApproachRate); - categoryDifficulty.Add("Max Combo", Attributes.MaxCombo); - } - - return value; + Total = value + }; } private double accuracy() => totalHits() == 0 ? 0 : Math.Clamp((double)totalSuccessfulHits() / totalHits(), 0, 1); diff --git a/osu.Game.Rulesets.Mania/Difficulty/ManiaPerformanceAttributes.cs b/osu.Game.Rulesets.Mania/Difficulty/ManiaPerformanceAttributes.cs new file mode 100644 index 0000000000..da9634ba47 --- /dev/null +++ b/osu.Game.Rulesets.Mania/Difficulty/ManiaPerformanceAttributes.cs @@ -0,0 +1,20 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using Newtonsoft.Json; +using osu.Game.Rulesets.Difficulty; + +namespace osu.Game.Rulesets.Mania.Difficulty +{ + public class ManiaPerformanceAttributes : PerformanceAttributes + { + [JsonProperty("difficulty")] + public double Difficulty { get; set; } + + [JsonProperty("accuracy")] + public double Accuracy { get; set; } + + [JsonProperty("scaled_score")] + public double ScaledScore { get; set; } + } +} diff --git a/osu.Game.Rulesets.Mania/Difficulty/ManiaPerformanceCalculator.cs b/osu.Game.Rulesets.Mania/Difficulty/ManiaPerformanceCalculator.cs index 6bf0a5acb4..cb4c3fffa4 100644 --- a/osu.Game.Rulesets.Mania/Difficulty/ManiaPerformanceCalculator.cs +++ b/osu.Game.Rulesets.Mania/Difficulty/ManiaPerformanceCalculator.cs @@ -32,7 +32,7 @@ namespace osu.Game.Rulesets.Mania.Difficulty { } - public override double Calculate(Dictionary categoryDifficulty = null) + public override PerformanceAttributes Calculate() { mods = Score.Mods; scaledScore = Score.TotalScore; @@ -69,16 +69,13 @@ namespace osu.Game.Rulesets.Mania.Difficulty Math.Pow(accValue, 1.1), 1.0 / 1.1 ) * multiplier; - if (categoryDifficulty != null) + return new ManiaPerformanceAttributes { - categoryDifficulty.Add("Difficulty", difficultyValue); - categoryDifficulty.Add("Accuracy", accValue); - categoryDifficulty.Add("Scaled Score", scaledScore); - categoryDifficulty.Add("Great Hit Window", Attributes.GreatHitWindow); - categoryDifficulty.Add("Max Combo", Attributes.MaxCombo); - } - - return totalValue; + Difficulty = difficultyValue, + Accuracy = accValue, + ScaledScore = scaledScore, + Total = totalValue + }; } private double computeDifficultyValue() diff --git a/osu.Game.Rulesets.Osu/Difficulty/OsuPerformanceAttributes.cs b/osu.Game.Rulesets.Osu/Difficulty/OsuPerformanceAttributes.cs new file mode 100644 index 0000000000..6c7760d144 --- /dev/null +++ b/osu.Game.Rulesets.Osu/Difficulty/OsuPerformanceAttributes.cs @@ -0,0 +1,26 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using Newtonsoft.Json; +using osu.Game.Rulesets.Difficulty; + +namespace osu.Game.Rulesets.Osu.Difficulty +{ + public class OsuPerformanceAttributes : PerformanceAttributes + { + [JsonProperty("aim")] + public double Aim { get; set; } + + [JsonProperty("speed")] + public double Speed { get; set; } + + [JsonProperty("accuracy")] + public double Accuracy { get; set; } + + [JsonProperty("flashlight")] + public double Flashlight { get; set; } + + [JsonProperty("effective_miss_count")] + public double EffectiveMissCount { get; set; } + } +} diff --git a/osu.Game.Rulesets.Osu/Difficulty/OsuPerformanceCalculator.cs b/osu.Game.Rulesets.Osu/Difficulty/OsuPerformanceCalculator.cs index 96c92bdb0d..53c0b68bcb 100644 --- a/osu.Game.Rulesets.Osu/Difficulty/OsuPerformanceCalculator.cs +++ b/osu.Game.Rulesets.Osu/Difficulty/OsuPerformanceCalculator.cs @@ -32,7 +32,7 @@ namespace osu.Game.Rulesets.Osu.Difficulty { } - public override double Calculate(Dictionary categoryDifficulty = null) + public override PerformanceAttributes Calculate() { mods = Score.Mods; accuracy = Score.Accuracy; @@ -72,19 +72,15 @@ namespace osu.Game.Rulesets.Osu.Difficulty Math.Pow(flashlightValue, 1.1), 1.0 / 1.1 ) * multiplier; - if (categoryDifficulty != null) + return new OsuPerformanceAttributes { - categoryDifficulty.Add("Aim", aimValue); - categoryDifficulty.Add("Speed", speedValue); - categoryDifficulty.Add("Accuracy", accuracyValue); - categoryDifficulty.Add("Flashlight", flashlightValue); - categoryDifficulty.Add("OD", Attributes.OverallDifficulty); - categoryDifficulty.Add("AR", Attributes.ApproachRate); - categoryDifficulty.Add("Max Combo", Attributes.MaxCombo); - categoryDifficulty.Add("Effective Miss Count", effectiveMissCount); - } - - return totalValue; + Aim = aimValue, + Speed = speedValue, + Accuracy = accuracyValue, + Flashlight = flashlightValue, + EffectiveMissCount = effectiveMissCount, + Total = totalValue + }; } private double computeAimValue() diff --git a/osu.Game.Rulesets.Taiko/Difficulty/TaikoPerformanceAttributes.cs b/osu.Game.Rulesets.Taiko/Difficulty/TaikoPerformanceAttributes.cs new file mode 100644 index 0000000000..80552880ea --- /dev/null +++ b/osu.Game.Rulesets.Taiko/Difficulty/TaikoPerformanceAttributes.cs @@ -0,0 +1,17 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using Newtonsoft.Json; +using osu.Game.Rulesets.Difficulty; + +namespace osu.Game.Rulesets.Taiko.Difficulty +{ + public class TaikoPerformanceAttributes : PerformanceAttributes + { + [JsonProperty("difficulty")] + public double Difficulty { get; set; } + + [JsonProperty("accuracy")] + public double Accuracy { get; set; } + } +} diff --git a/osu.Game.Rulesets.Taiko/Difficulty/TaikoPerformanceCalculator.cs b/osu.Game.Rulesets.Taiko/Difficulty/TaikoPerformanceCalculator.cs index d287998f3b..3df512e5db 100644 --- a/osu.Game.Rulesets.Taiko/Difficulty/TaikoPerformanceCalculator.cs +++ b/osu.Game.Rulesets.Taiko/Difficulty/TaikoPerformanceCalculator.cs @@ -27,7 +27,7 @@ namespace osu.Game.Rulesets.Taiko.Difficulty { } - public override double Calculate(Dictionary categoryDifficulty = null) + public override PerformanceAttributes Calculate() { mods = Score.Mods; countGreat = Score.Statistics.GetValueOrDefault(HitResult.Great); @@ -52,16 +52,12 @@ namespace osu.Game.Rulesets.Taiko.Difficulty Math.Pow(accuracyValue, 1.1), 1.0 / 1.1 ) * multiplier; - if (categoryDifficulty != null) + return new TaikoPerformanceAttributes { - categoryDifficulty.Add("Difficulty", difficultyValue); - categoryDifficulty.Add("Accuracy", accuracyValue); - categoryDifficulty.Add("AR", Attributes.ApproachRate); - categoryDifficulty.Add("Great Hit Window", Attributes.GreatHitWindow); - categoryDifficulty.Add("Max Combo", Attributes.MaxCombo); - } - - return totalValue; + Difficulty = difficultyValue, + Accuracy = accuracyValue, + Total = totalValue + }; } private double computeDifficultyValue() diff --git a/osu.Game/Rulesets/Difficulty/PerformanceAttributes.cs b/osu.Game/Rulesets/Difficulty/PerformanceAttributes.cs new file mode 100644 index 0000000000..025b38257c --- /dev/null +++ b/osu.Game/Rulesets/Difficulty/PerformanceAttributes.cs @@ -0,0 +1,16 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using Newtonsoft.Json; + +namespace osu.Game.Rulesets.Difficulty +{ + public class PerformanceAttributes + { + /// + /// Calculated score performance points. + /// + [JsonProperty("pp")] + public double Total { get; set; } + } +} diff --git a/osu.Game/Rulesets/Difficulty/PerformanceCalculator.cs b/osu.Game/Rulesets/Difficulty/PerformanceCalculator.cs index 58427f6945..abfe8a6db1 100644 --- a/osu.Game/Rulesets/Difficulty/PerformanceCalculator.cs +++ b/osu.Game/Rulesets/Difficulty/PerformanceCalculator.cs @@ -37,6 +37,6 @@ namespace osu.Game.Rulesets.Difficulty TimeRate = track.Rate; } - public abstract double Calculate(Dictionary categoryDifficulty = null); + public abstract PerformanceAttributes Calculate(); } } diff --git a/osu.Game/Scoring/ScorePerformanceCache.cs b/osu.Game/Scoring/ScorePerformanceCache.cs index 79fb47f4b0..b855343505 100644 --- a/osu.Game/Scoring/ScorePerformanceCache.cs +++ b/osu.Game/Scoring/ScorePerformanceCache.cs @@ -44,7 +44,7 @@ namespace osu.Game.Scoring var calculator = score.Ruleset.CreateInstance().CreatePerformanceCalculator(attributes.Value.Attributes, score); - return calculator?.Calculate(); + return calculator?.Calculate().Total; } public readonly struct PerformanceCacheLookup diff --git a/osu.Game/Screens/Play/HUD/PerformancePointsCounter.cs b/osu.Game/Screens/Play/HUD/PerformancePointsCounter.cs index 854f255269..908e6a27b8 100644 --- a/osu.Game/Screens/Play/HUD/PerformancePointsCounter.cs +++ b/osu.Game/Screens/Play/HUD/PerformancePointsCounter.cs @@ -129,7 +129,7 @@ namespace osu.Game.Screens.Play.HUD var calculator = gameplayState.Ruleset.CreatePerformanceCalculator(attrib, scoreInfo); - Current.Value = (int)Math.Round(calculator?.Calculate() ?? 0, MidpointRounding.AwayFromZero); + Current.Value = (int)Math.Round(calculator?.Calculate().Total ?? 0, MidpointRounding.AwayFromZero); IsValid = true; }