Skip to content

Commit

Permalink
Merge branch 'split-legacy-scoring-attribs' into total-score-classic
Browse files Browse the repository at this point in the history
  • Loading branch information
bdach committed Sep 28, 2023
2 parents 9acf70d + f36b495 commit 84c371f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
using osu.Game.Online.API;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Difficulty;
using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Scoring;
Expand Down Expand Up @@ -570,42 +569,20 @@ private async Task<ScoreInfo> createReferenceScore(Ruleset ruleset, HighScore hi
return scoreInfo;
}

const int legacy_accuracy_score = 23;
const int legacy_combo_score = 25;
const int legacy_bonus_score_ratio = 27;

if (!dbAttributes.ContainsKey(legacy_accuracy_score) || !dbAttributes.ContainsKey(legacy_combo_score) || !dbAttributes.ContainsKey(legacy_bonus_score_ratio))
{
await Console.Error.WriteLineAsync($"{highScore.score_id}: Could not find legacy scoring values in the difficulty attributes of beatmap {highScore.beatmap_id}.");
return scoreInfo;
}

#pragma warning disable CS0618
// Pad the maximum combo.
if ((int)maxComboAttribute.value > maxComboFromStatistics)
scoreInfo.MaximumStatistics[HitResult.LegacyComboIncrease] = (int)maxComboAttribute.value - maxComboFromStatistics;
#pragma warning restore CS0618

int maximumLegacyAccuracyScore = (int)dbAttributes[legacy_accuracy_score].value;
int maximumLegacyComboScore = (int)dbAttributes[legacy_combo_score].value;
double maximumLegacyBonusRatio = dbAttributes[legacy_bonus_score_ratio].value;

// Although the combo-multiplied portion is stored into difficulty attributes, attributes are only present for mod combinations that affect difficulty.
// For example, an incoming highscore may be +HDHR, but only difficulty attributes for +HR exist in the database.
// To handle this case, the combo-multiplied portion is readjusted with the new mod multiplier.
if (difficultyMods != highScore.enabled_mods)
{
double difficultyAdjustmentModMultiplier = ruleset.ConvertFromLegacyMods((LegacyMods)difficultyMods).Select(m => m.ScoreMultiplier).Aggregate(1.0, (c, n) => c * n);
double modMultiplier = scoreInfo.Mods.Select(m => m.ScoreMultiplier).Aggregate(1.0, (c, n) => c * n);
maximumLegacyComboScore = (int)Math.Round(maximumLegacyComboScore * modMultiplier / difficultyAdjustmentModMultiplier);
}
BeatmapScoringAttributes scoreAttributes = await connection.QuerySingleAsync<BeatmapScoringAttributes>(
"SELECT * FROM osu_beatmap_scoring_attribs WHERE beatmap_id = @BeatmapId AND mode = @RulesetId", new
{
BeatmapId = highScore.beatmap_id,
RulesetId = ruleset.RulesetInfo.OnlineID
}, transaction);

scoreInfo.TotalScore = StandardisedScoreMigrationTools.ConvertFromLegacyTotalScore(scoreInfo, new DifficultyAttributes
{
LegacyAccuracyScore = maximumLegacyAccuracyScore,
LegacyComboScore = maximumLegacyComboScore,
LegacyBonusScoreRatio = maximumLegacyBonusRatio
});
scoreInfo.TotalScore = StandardisedScoreMigrationTools.ConvertFromLegacyTotalScore(scoreInfo, scoreAttributes.ToAttributes());

int baseScore = scoreInfo.Statistics.Where(kvp => kvp.Key.AffectsAccuracy()).Sum(kvp => kvp.Value * Judgement.ToNumericResult(kvp.Key));
int maxBaseScore = scoreInfo.MaximumStatistics.Where(kvp => kvp.Key.AffectsAccuracy()).Sum(kvp => kvp.Value * Judgement.ToNumericResult(kvp.Key));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using System;
using System.Diagnostics.CodeAnalysis;
using Dapper.Contrib.Extensions;
using osu.Game.Rulesets.Scoring.Legacy;

namespace osu.Server.Queues.ScoreStatisticsProcessor.Models
{
[SuppressMessage("ReSharper", "InconsistentNaming")]
[Serializable]
[Table("osu_beatmap_scoring_attribs")]
public class BeatmapScoringAttributes
{
[ExplicitKey]
public uint beatmap_id { get; set; }

public ushort mode { get; set; }

public int legacy_accuracy_score { get; set; }

public long legacy_combo_score { get; set; }

public float legacy_bonus_score_ratio { get; set; }

public LegacyScoreAttributes ToAttributes() => new LegacyScoreAttributes
{
AccuracyScore = legacy_accuracy_score,
ComboScore = legacy_combo_score,
BonusScoreRatio = legacy_bonus_score_ratio
};
}
}

0 comments on commit 84c371f

Please sign in to comment.