diff --git a/osu.Game.Tests/Beatmaps/Formats/LegacyScoreDecoderTest.cs b/osu.Game.Tests/Beatmaps/Formats/LegacyScoreDecoderTest.cs index 8ca141bb4f71..c986a48d8d57 100644 --- a/osu.Game.Tests/Beatmaps/Formats/LegacyScoreDecoderTest.cs +++ b/osu.Game.Tests/Beatmaps/Formats/LegacyScoreDecoderTest.cs @@ -422,6 +422,80 @@ public void AccuracyAndRankOfLazerScoreWithoutLegacyReplaySoloScoreInfoUsesBestE }); } + [Test] + public void TestTotalScoreWithoutModsReadIfPresent() + { + var ruleset = new OsuRuleset().RulesetInfo; + + var scoreInfo = TestResources.CreateTestScoreInfo(ruleset); + scoreInfo.Mods = new Mod[] + { + new OsuModDoubleTime { SpeedChange = { Value = 1.1 } } + }; + scoreInfo.OnlineID = 123123; + scoreInfo.ClientVersion = "2023.1221.0"; + scoreInfo.TotalScoreWithoutMods = 1_000_000; + scoreInfo.TotalScore = 1_020_000; + + var beatmap = new TestBeatmap(ruleset); + var score = new Score + { + ScoreInfo = scoreInfo, + Replay = new Replay + { + Frames = new List + { + new OsuReplayFrame(2000, OsuPlayfield.BASE_SIZE / 2, OsuAction.LeftButton) + } + } + }; + + var decodedAfterEncode = encodeThenDecode(LegacyBeatmapDecoder.LATEST_VERSION, score, beatmap); + + Assert.Multiple(() => + { + Assert.That(decodedAfterEncode.ScoreInfo.TotalScoreWithoutMods, Is.EqualTo(1_000_000)); + Assert.That(decodedAfterEncode.ScoreInfo.TotalScore, Is.EqualTo(1_020_000)); + }); + } + + [Test] + public void TestTotalScoreWithoutModsBackwardsPopulatedIfMissing() + { + var ruleset = new OsuRuleset().RulesetInfo; + + var scoreInfo = TestResources.CreateTestScoreInfo(ruleset); + scoreInfo.Mods = new Mod[] + { + new OsuModDoubleTime { SpeedChange = { Value = 1.1 } } + }; + scoreInfo.OnlineID = 123123; + scoreInfo.ClientVersion = "2023.1221.0"; + scoreInfo.TotalScoreWithoutMods = 0; + scoreInfo.TotalScore = 1_020_000; + + var beatmap = new TestBeatmap(ruleset); + var score = new Score + { + ScoreInfo = scoreInfo, + Replay = new Replay + { + Frames = new List + { + new OsuReplayFrame(2000, OsuPlayfield.BASE_SIZE / 2, OsuAction.LeftButton) + } + } + }; + + var decodedAfterEncode = encodeThenDecode(LegacyBeatmapDecoder.LATEST_VERSION, score, beatmap); + + Assert.Multiple(() => + { + Assert.That(decodedAfterEncode.ScoreInfo.TotalScoreWithoutMods, Is.EqualTo(1_000_000)); + Assert.That(decodedAfterEncode.ScoreInfo.TotalScore, Is.EqualTo(1_020_000)); + }); + } + private static Score encodeThenDecode(int beatmapVersion, Score score, TestBeatmap beatmap) { var encodeStream = new MemoryStream(); diff --git a/osu.Game/Database/RealmAccess.cs b/osu.Game/Database/RealmAccess.cs index 057bbe02e60d..63f61228f320 100644 --- a/osu.Game/Database/RealmAccess.cs +++ b/osu.Game/Database/RealmAccess.cs @@ -92,8 +92,9 @@ public class RealmAccess : IDisposable /// 38 2023-12-10 Add EndTimeObjectCount and TotalObjectCount to BeatmapInfo. /// 39 2023-12-19 Migrate any EndTimeObjectCount and TotalObjectCount values of 0 to -1 to better identify non-calculated values. /// 40 2023-12-21 Add ScoreInfo.Version to keep track of which build scores were set on. + /// 41 2024-04-17 Add ScoreInfo.TotalScoreWithoutMods for future mod multiplier rebalances. /// - private const int schema_version = 40; + private const int schema_version = 41; /// /// Lock object which is held during sections, blocking realm retrieval during blocking periods. @@ -1130,6 +1131,12 @@ void convertOnlineIDs() where T : RealmObject } break; + + case 41: + foreach (var score in migration.NewRealm.All()) + LegacyScoreDecoder.PopulateTotalScoreWithoutMods(score); + + break; } Logger.Log($"Migration completed in {stopwatch.ElapsedMilliseconds}ms"); diff --git a/osu.Game/Database/StandardisedScoreMigrationTools.cs b/osu.Game/Database/StandardisedScoreMigrationTools.cs index 6f2f8d64fa6b..7d09ebdb40c8 100644 --- a/osu.Game/Database/StandardisedScoreMigrationTools.cs +++ b/osu.Game/Database/StandardisedScoreMigrationTools.cs @@ -16,6 +16,7 @@ using osu.Game.Rulesets.Scoring; using osu.Game.Rulesets.Scoring.Legacy; using osu.Game.Scoring; +using osu.Game.Scoring.Legacy; namespace osu.Game.Database { @@ -248,6 +249,7 @@ public static void UpdateFromLegacy(ScoreInfo score, WorkingBeatmap beatmap) score.Accuracy = computeAccuracy(score, scoreProcessor); score.Rank = computeRank(score, scoreProcessor); score.TotalScore = convertFromLegacyTotalScore(score, ruleset, beatmap); + LegacyScoreDecoder.PopulateTotalScoreWithoutMods(score); } /// diff --git a/osu.Game/Online/API/Requests/Responses/SoloScoreInfo.cs b/osu.Game/Online/API/Requests/Responses/SoloScoreInfo.cs index 64caddb2fc1d..36f1311f9dde 100644 --- a/osu.Game/Online/API/Requests/Responses/SoloScoreInfo.cs +++ b/osu.Game/Online/API/Requests/Responses/SoloScoreInfo.cs @@ -33,6 +33,9 @@ public class SoloScoreInfo : IScoreInfo [JsonProperty("total_score")] public long TotalScore { get; set; } + [JsonProperty("total_score_without_mods")] + public long TotalScoreWithoutMods { get; set; } + [JsonProperty("accuracy")] public double Accuracy { get; set; } @@ -206,6 +209,7 @@ public ScoreInfo ToScoreInfo(Mod[] mods, IBeatmapInfo? beatmap = null) Ruleset = new RulesetInfo { OnlineID = RulesetID }, Passed = Passed, TotalScore = TotalScore, + TotalScoreWithoutMods = TotalScoreWithoutMods, LegacyTotalScore = LegacyTotalScore, Accuracy = Accuracy, MaxCombo = MaxCombo, @@ -239,6 +243,7 @@ public ScoreInfo ToScoreInfo(Mod[] mods, IBeatmapInfo? beatmap = null) { Rank = score.Rank, TotalScore = score.TotalScore, + TotalScoreWithoutMods = score.TotalScoreWithoutMods, Accuracy = score.Accuracy, PP = score.PP, MaxCombo = score.MaxCombo, diff --git a/osu.Game/Rulesets/Scoring/ScoreProcessor.cs b/osu.Game/Rulesets/Scoring/ScoreProcessor.cs index 9d12daad049e..70d7f0fe3767 100644 --- a/osu.Game/Rulesets/Scoring/ScoreProcessor.cs +++ b/osu.Game/Rulesets/Scoring/ScoreProcessor.cs @@ -56,6 +56,14 @@ public partial class ScoreProcessor : JudgementProcessor /// public readonly BindableLong TotalScore = new BindableLong { MinValue = 0 }; + /// + /// The total number of points awarded for the score without including mod multipliers. + /// + /// + /// The purpose of this property is to enable future lossless rebalances of mod multipliers. + /// + public readonly BindableLong TotalScoreWithoutMods = new BindableLong { MinValue = 0 }; + /// /// The current accuracy. /// @@ -363,7 +371,8 @@ private void updateScore() double comboProgress = maximumComboPortion > 0 ? currentComboPortion / maximumComboPortion : 1; double accuracyProcess = maximumAccuracyJudgementCount > 0 ? (double)currentAccuracyJudgementCount / maximumAccuracyJudgementCount : 1; - TotalScore.Value = (long)Math.Round(ComputeTotalScore(comboProgress, accuracyProcess, currentBonusPortion) * scoreMultiplier); + TotalScoreWithoutMods.Value = (long)Math.Round(ComputeTotalScore(comboProgress, accuracyProcess, currentBonusPortion)); + TotalScore.Value = (long)Math.Round(TotalScoreWithoutMods.Value * scoreMultiplier); } private void updateRank() @@ -446,6 +455,7 @@ public virtual void PopulateScore(ScoreInfo score) score.MaximumStatistics[result] = MaximumResultCounts.GetValueOrDefault(result); // Populate total score after everything else. + score.TotalScoreWithoutMods = TotalScoreWithoutMods.Value; score.TotalScore = TotalScore.Value; } diff --git a/osu.Game/Scoring/Legacy/LegacyReplaySoloScoreInfo.cs b/osu.Game/Scoring/Legacy/LegacyReplaySoloScoreInfo.cs index 60bec687f4b9..c99f10441827 100644 --- a/osu.Game/Scoring/Legacy/LegacyReplaySoloScoreInfo.cs +++ b/osu.Game/Scoring/Legacy/LegacyReplaySoloScoreInfo.cs @@ -46,6 +46,9 @@ public class LegacyReplaySoloScoreInfo [JsonProperty("user_id")] public int UserID = -1; + [JsonProperty("total_score_without_mods")] + public long? TotalScoreWithoutMods { get; set; } + public static LegacyReplaySoloScoreInfo FromScore(ScoreInfo score) => new LegacyReplaySoloScoreInfo { OnlineID = score.OnlineID, @@ -55,6 +58,7 @@ public class LegacyReplaySoloScoreInfo ClientVersion = score.ClientVersion, Rank = score.Rank, UserID = score.User.OnlineID, + TotalScoreWithoutMods = score.TotalScoreWithoutMods > 0 ? score.TotalScoreWithoutMods : null, }; } } diff --git a/osu.Game/Scoring/Legacy/LegacyScoreDecoder.cs b/osu.Game/Scoring/Legacy/LegacyScoreDecoder.cs index 00e294fdcdf7..4c709aa6455c 100644 --- a/osu.Game/Scoring/Legacy/LegacyScoreDecoder.cs +++ b/osu.Game/Scoring/Legacy/LegacyScoreDecoder.cs @@ -133,6 +133,11 @@ public Score Parse(Stream stream) decodedRank = readScore.Rank; if (readScore.UserID > 1) score.ScoreInfo.RealmUser.OnlineID = readScore.UserID; + + if (readScore.TotalScoreWithoutMods is long totalScoreWithoutMods) + score.ScoreInfo.TotalScoreWithoutMods = totalScoreWithoutMods; + else + PopulateTotalScoreWithoutMods(score.ScoreInfo); }); } } @@ -244,6 +249,16 @@ public static void PopulateMaximumStatistics(ScoreInfo score, WorkingBeatmap wor #pragma warning restore CS0618 } + public static void PopulateTotalScoreWithoutMods(ScoreInfo score) + { + double modMultiplier = 1; + + foreach (var mod in score.Mods) + modMultiplier *= mod.ScoreMultiplier; + + score.TotalScoreWithoutMods = (long)Math.Round(score.TotalScore / modMultiplier); + } + private void readLegacyReplay(Replay replay, StreamReader reader) { float lastTime = beatmapOffset; diff --git a/osu.Game/Scoring/ScoreInfo.cs b/osu.Game/Scoring/ScoreInfo.cs index fd9810779217..92c18c9c1eb4 100644 --- a/osu.Game/Scoring/ScoreInfo.cs +++ b/osu.Game/Scoring/ScoreInfo.cs @@ -65,8 +65,19 @@ public class ScoreInfo : RealmObject, IHasGuidPrimaryKey, IHasRealmFiles, ISoftD public bool DeletePending { get; set; } + /// + /// The total number of points awarded for the score. + /// public long TotalScore { get; set; } + /// + /// The total number of points awarded for the score without including mod multipliers. + /// + /// + /// The purpose of this property is to enable future lossless rebalances of mod multipliers. + /// + public long TotalScoreWithoutMods { get; set; } + /// /// The version of processing applied to calculate total score as stored in the database. /// If this does not match ,