mirror of
https://github.com/osukey/osukey.git
synced 2025-08-02 22:26:41 +09:00
Fix async exception by using difficulty calculator directly
This commit is contained in:
@ -3,11 +3,10 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
using osu.Framework.Extensions;
|
||||
using osu.Framework.Logging;
|
||||
using osu.Framework.Platform;
|
||||
using osu.Game.Beatmaps;
|
||||
@ -32,17 +31,15 @@ namespace osu.Game.Scoring
|
||||
|
||||
private readonly RulesetStore rulesets;
|
||||
private readonly Func<BeatmapManager> beatmaps;
|
||||
private readonly BeatmapDifficultyCache? difficultyCache;
|
||||
|
||||
private readonly IAPIProvider api;
|
||||
|
||||
public ScoreImporter(RulesetStore rulesets, Func<BeatmapManager> beatmaps, Storage storage, RealmAccess realm, IAPIProvider api, BeatmapDifficultyCache? difficultyCache = null)
|
||||
public ScoreImporter(RulesetStore rulesets, Func<BeatmapManager> beatmaps, Storage storage, RealmAccess realm, IAPIProvider api)
|
||||
: base(storage, realm)
|
||||
{
|
||||
this.rulesets = rulesets;
|
||||
this.beatmaps = beatmaps;
|
||||
this.api = api;
|
||||
this.difficultyCache = difficultyCache;
|
||||
}
|
||||
|
||||
protected override ScoreInfo? CreateModel(ArchiveReader archive)
|
||||
@ -77,7 +74,7 @@ namespace osu.Game.Scoring
|
||||
if (model.BeatmapInfo == null) throw new ArgumentNullException(nameof(model.BeatmapInfo));
|
||||
if (model.Ruleset == null) throw new ArgumentNullException(nameof(model.Ruleset));
|
||||
|
||||
PopulateMaximumStatistics(model).WaitSafely();
|
||||
PopulateMaximumStatistics(model);
|
||||
|
||||
if (string.IsNullOrEmpty(model.StatisticsJson))
|
||||
model.StatisticsJson = JsonConvert.SerializeObject(model.Statistics);
|
||||
@ -90,19 +87,22 @@ namespace osu.Game.Scoring
|
||||
/// Populates the <see cref="ScoreInfo.MaximumStatistics"/> for a given <see cref="ScoreInfo"/>.
|
||||
/// </summary>
|
||||
/// <param name="score">The score to populate the statistics of.</param>
|
||||
public async Task PopulateMaximumStatistics(ScoreInfo score)
|
||||
public void PopulateMaximumStatistics(ScoreInfo score)
|
||||
{
|
||||
if (score.MaximumStatistics.Select(kvp => kvp.Value).Sum() > 0)
|
||||
return;
|
||||
|
||||
var beatmap = score.BeatmapInfo.Detach();
|
||||
var ruleset = score.Ruleset.Detach();
|
||||
var rulesetInstance = ruleset.CreateInstance();
|
||||
|
||||
Debug.Assert(rulesetInstance != null);
|
||||
|
||||
// Populate the maximum statistics.
|
||||
HitResult maxBasicResult = ruleset.CreateInstance().GetHitResults()
|
||||
.Select(h => h.result)
|
||||
.Where(h => h.IsBasic())
|
||||
.OrderByDescending(Judgement.ToNumericResult).First();
|
||||
HitResult maxBasicResult = rulesetInstance.GetHitResults()
|
||||
.Select(h => h.result)
|
||||
.Where(h => h.IsBasic())
|
||||
.OrderByDescending(Judgement.ToNumericResult).First();
|
||||
|
||||
foreach ((HitResult result, int count) in score.Statistics)
|
||||
{
|
||||
@ -134,18 +134,14 @@ namespace osu.Game.Scoring
|
||||
return;
|
||||
|
||||
#pragma warning disable CS0618
|
||||
if (difficultyCache == null)
|
||||
throw new InvalidOperationException($"Cannot populate legacy score statistics without a {nameof(BeatmapDifficultyCache)}.");
|
||||
|
||||
// In osu! and osu!mania, some judgements affect combo but aren't stored to scores.
|
||||
// A special hit result is used to pad out the combo value to match, based on the max combo from the difficulty attributes.
|
||||
StarDifficulty? difficulty = await difficultyCache.GetDifficultyAsync(beatmap, ruleset, score.Mods);
|
||||
if (difficulty == null)
|
||||
throw new InvalidOperationException("Failed to populate maximum statistics due to missing difficulty attributes.");
|
||||
var calculator = rulesetInstance.CreateDifficultyCalculator(beatmaps().GetWorkingBeatmap(beatmap));
|
||||
var attributes = calculator.Calculate(score.Mods);
|
||||
|
||||
int maxComboFromStatistics = score.MaximumStatistics.Where(kvp => kvp.Key.AffectsCombo()).Select(kvp => kvp.Value).DefaultIfEmpty(0).Sum();
|
||||
if (difficulty.Value.MaxCombo > maxComboFromStatistics)
|
||||
score.MaximumStatistics[HitResult.LegacyComboIncrease] = difficulty.Value.MaxCombo - maxComboFromStatistics;
|
||||
if (attributes.MaxCombo > maxComboFromStatistics)
|
||||
score.MaximumStatistics[HitResult.LegacyComboIncrease] = attributes.MaxCombo - maxComboFromStatistics;
|
||||
#pragma warning restore CS0618
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user