diff --git a/osu.Server.DifficultyCalculator/ServerDifficultyCalculator.cs b/osu.Server.DifficultyCalculator/ServerDifficultyCalculator.cs index 15e28ce..bd80faa 100644 --- a/osu.Server.DifficultyCalculator/ServerDifficultyCalculator.cs +++ b/osu.Server.DifficultyCalculator/ServerDifficultyCalculator.cs @@ -12,6 +12,7 @@ using osu.Game.Beatmaps.Legacy; using osu.Game.Rulesets; using osu.Game.Rulesets.Mods; +using osu.Game.Rulesets.Objects.Legacy; using osu.Game.Rulesets.Scoring.Legacy; using osu.Server.DifficultyCalculator.Commands; @@ -67,7 +68,7 @@ public void Process(WorkingBeatmap beatmap, ProcessingMode mode) public void ProcessLegacyAttributes(WorkingBeatmap beatmap) => run(beatmap, processLegacyAttributes); - private void run(WorkingBeatmap beatmap, Action callback) + private void run(WorkingBeatmap beatmap, Action callback) { try { @@ -89,10 +90,10 @@ private void run(WorkingBeatmap beatmap, Action r.RulesetInfo.OnlineID == beatmap.BeatmapInfo.Ruleset.OnlineID)) - callback(new ProcessableBeatmap(beatmap, beatmap.BeatmapInfo.Ruleset.CreateInstance(), ranked), conn); + callback(new ProcessableItem(beatmap, beatmap.BeatmapInfo.Ruleset.CreateInstance(), ranked), conn); } } catch (Exception e) @@ -101,14 +102,14 @@ private void run(WorkingBeatmap beatmap, Action(); @@ -130,8 +131,8 @@ private void processDifficulty(ProcessableBeatmap beatmap, MySqlConnection conn) { parameters.Add(new { - BeatmapId = beatmap.BeatmapID, - Mode = beatmap.RulesetID, + BeatmapId = item.BeatmapID, + Mode = item.RulesetID, Mods = (int)legacyMods, Attribute = mapping.attributeId, Value = Convert.ToSingle(mapping.value) @@ -145,35 +146,53 @@ private void processDifficulty(ProcessableBeatmap beatmap, MySqlConnection conn) parameters.ToArray()); } - if (legacyMods == LegacyMods.None && beatmap.Ruleset.RulesetInfo.Equals(beatmap.Beatmap.BeatmapInfo.Ruleset)) + if (legacyMods == LegacyMods.None && item.Ruleset.RulesetInfo.Equals(item.WorkingBeatmap.BeatmapInfo.Ruleset)) { - double beatLength = beatmap.Beatmap.Beatmap.GetMostCommonBeatLength(); + double beatLength = item.WorkingBeatmap.Beatmap.GetMostCommonBeatLength(); double bpm = beatLength > 0 ? 60000 / beatLength : 0; + int countCircle = 0; + int countSlider = 0; + int countSpinner = 0; + + foreach (var obj in item.WorkingBeatmap.Beatmap.HitObjects.OfType()) + { + if ((obj.LegacyType & LegacyHitObjectType.Circle) > 0) + countCircle++; + if ((obj.LegacyType & LegacyHitObjectType.Slider) > 0) + countSlider++; + if ((obj.LegacyType & LegacyHitObjectType.Spinner) > 0) + countSpinner++; + } + object param = new { - BeatmapId = beatmap.BeatmapID, + BeatmapId = item.BeatmapID, Diff = attribute.StarRating, - AR = beatmap.Beatmap.BeatmapInfo.Difficulty.ApproachRate, - OD = beatmap.Beatmap.BeatmapInfo.Difficulty.OverallDifficulty, - HP = beatmap.Beatmap.BeatmapInfo.Difficulty.DrainRate, - CS = beatmap.Beatmap.BeatmapInfo.Difficulty.CircleSize, + AR = item.WorkingBeatmap.BeatmapInfo.Difficulty.ApproachRate, + OD = item.WorkingBeatmap.BeatmapInfo.Difficulty.OverallDifficulty, + HP = item.WorkingBeatmap.BeatmapInfo.Difficulty.DrainRate, + CS = item.WorkingBeatmap.BeatmapInfo.Difficulty.CircleSize, BPM = Math.Round(bpm, 2), MaxCombo = attribute.MaxCombo, + CountCircle = countCircle, + CountSlider = countSlider, + CountSpinner = countSpinner, + CountTotal = countCircle + countSlider + countSpinner }; if (AppSettings.INSERT_BEATMAPS) { conn.Execute( - "INSERT INTO `osu_beatmaps` (`beatmap_id`, `difficultyrating`, `diff_approach`, `diff_overall`, `diff_drain`, `diff_size`, `bpm`, `max_combo`) " - + "VALUES (@BeatmapId, @Diff, @AR, @OD, @HP, @CS, @BPM, @MaxCombo) " - + "ON DUPLICATE KEY UPDATE `difficultyrating` = @Diff, `diff_approach` = @AR, `diff_overall` = @OD, `diff_drain` = @HP, `diff_size` = @CS, `bpm` = @BPM, `max_combo` = @MaxCombo", + "INSERT INTO `osu_beatmaps` (`beatmap_id`, `difficultyrating`, `diff_approach`, `diff_overall`, `diff_drain`, `diff_size`, `bpm`, `max_combo`, `countNormal`, `countSlider`, `countSpinner`, `countTotal`) " + + "VALUES (@BeatmapId, @Diff, @AR, @OD, @HP, @CS, @BPM, @MaxCombo, @CountCircle, @CountSlider, @CountSpinner, @CountTotal) " + + "ON DUPLICATE KEY UPDATE `difficultyrating` = @Diff, `diff_approach` = @AR, `diff_overall` = @OD, `diff_drain` = @HP, `diff_size` = @CS, `bpm` = @BPM, `max_combo` = @MaxCombo, `countNormal` = @CountCircle, `countSlider` = @CountSlider, `countSpinner` = @CountSpinner, `countTotal` = @CountTotal", param); } else { conn.Execute( - "UPDATE `osu_beatmaps` SET `difficultyrating` = @Diff, `diff_approach` = @AR, `diff_overall` = @OD, `diff_drain` = @HP, `diff_size` = @CS, `bpm` = @BPM , `max_combo` = @MaxCombo " + "UPDATE `osu_beatmaps` SET `difficultyrating` = @Diff, `diff_approach` = @AR, `diff_overall` = @OD, `diff_drain` = @HP, `diff_size` = @CS, `bpm` = @BPM , `max_combo` = @MaxCombo, `countNormal` = @CountCircle, `countSlider` = @CountSlider, `countSpinner` = @CountSpinner, `countTotal` = @CountTotal " + "WHERE `beatmap_id` = @BeatmapId", param); } @@ -181,13 +200,13 @@ private void processDifficulty(ProcessableBeatmap beatmap, MySqlConnection conn) } } - private void processLegacyAttributes(ProcessableBeatmap beatmap, MySqlConnection conn) + private void processLegacyAttributes(ProcessableItem item, MySqlConnection conn) { - Mod? classicMod = beatmap.Ruleset.CreateMod(); + Mod? classicMod = item.Ruleset.CreateMod(); Mod[] mods = classicMod != null ? new[] { classicMod } : Array.Empty(); - ILegacyScoreSimulator simulator = ((ILegacyRuleset)beatmap.Ruleset).CreateLegacyScoreSimulator(); - LegacyScoreAttributes attributes = simulator.Simulate(beatmap.Beatmap, beatmap.Beatmap.GetPlayableBeatmap(beatmap.Ruleset.RulesetInfo, mods)); + ILegacyScoreSimulator simulator = ((ILegacyRuleset)item.Ruleset).CreateLegacyScoreSimulator(); + LegacyScoreAttributes attributes = simulator.Simulate(item.WorkingBeatmap, item.WorkingBeatmap.GetPlayableBeatmap(item.Ruleset.RulesetInfo, mods)); if (dryRun) return; @@ -198,8 +217,8 @@ private void processLegacyAttributes(ProcessableBeatmap beatmap, MySqlConnection + "ON DUPLICATE KEY UPDATE `legacy_accuracy_score` = @AccuracyScore, `legacy_combo_score` = @ComboScore, `legacy_bonus_score_ratio` = @BonusScoreRatio, `legacy_bonus_score` = @BonusScore, `max_combo` = @MaxCombo", new { - BeatmapId = beatmap.BeatmapID, - Mode = beatmap.RulesetID, + BeatmapId = item.BeatmapID, + Mode = item.RulesetID, AccuracyScore = attributes.AccuracyScore, ComboScore = attributes.ComboScore, BonusScoreRatio = attributes.BonusScoreRatio, @@ -231,9 +250,9 @@ private static List getRulesets() return rulesetsToProcess; } - private readonly record struct ProcessableBeatmap(WorkingBeatmap Beatmap, Ruleset Ruleset, bool Ranked) + private readonly record struct ProcessableItem(WorkingBeatmap WorkingBeatmap, Ruleset Ruleset, bool Ranked) { - public int BeatmapID => Beatmap.BeatmapInfo.OnlineID; + public int BeatmapID => WorkingBeatmap.BeatmapInfo.OnlineID; public int RulesetID => Ruleset.RulesetInfo.OnlineID; } } diff --git a/osu.Server.DifficultyCalculator/osu.Server.DifficultyCalculator.csproj b/osu.Server.DifficultyCalculator/osu.Server.DifficultyCalculator.csproj index f644314..ff0328f 100644 --- a/osu.Server.DifficultyCalculator/osu.Server.DifficultyCalculator.csproj +++ b/osu.Server.DifficultyCalculator/osu.Server.DifficultyCalculator.csproj @@ -13,15 +13,15 @@ - - - - - - - - - + + + + + + + + + diff --git a/osu.Server.Queues.BeatmapProcessor/osu.Server.Queues.BeatmapProcessor.csproj b/osu.Server.Queues.BeatmapProcessor/osu.Server.Queues.BeatmapProcessor.csproj index 586e4fd..8ea87f3 100644 --- a/osu.Server.Queues.BeatmapProcessor/osu.Server.Queues.BeatmapProcessor.csproj +++ b/osu.Server.Queues.BeatmapProcessor/osu.Server.Queues.BeatmapProcessor.csproj @@ -11,7 +11,7 @@ - +