1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 05:42:56 +08:00
osu-lazer/osu.Game.Rulesets.Osu/OsuDifficulty/OsuDifficultyCalculator.cs
Thomas Tan b04e2cbb5c Fix osu star rating calculation
The main bug was that the beatmap was not being processed prior to
having its Skill values calculated, causing stacking to be ignored in
difficulty calculation. The fix involves processing the beatmap with
OsuBeatmapProcessor.

Another minor bug was that sliders were not taking into account the
stacked position midway through the slider (PositionAt does not return
stacked position.), so I corrected by adding StackOffset.
2018-01-26 03:39:19 +08:00

79 lines
2.6 KiB
C#

// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using System.Collections.Generic;
using osu.Game.Beatmaps;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Osu.Beatmaps;
using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Rulesets.Osu.OsuDifficulty.Preprocessing;
using osu.Game.Rulesets.Osu.OsuDifficulty.Skills;
namespace osu.Game.Rulesets.Osu.OsuDifficulty
{
public class OsuDifficultyCalculator : DifficultyCalculator<OsuHitObject>
{
private const int section_length = 400;
private const double difficulty_multiplier = 0.0675;
public OsuDifficultyCalculator(Beatmap beatmap)
: base(beatmap)
{
}
public OsuDifficultyCalculator(Beatmap beatmap, Mod[] mods)
: base(beatmap, mods)
{
}
protected override void PreprocessHitObjects()
{
new OsuBeatmapProcessor().PostProcess(Beatmap);
}
public override double Calculate(Dictionary<string, double> categoryDifficulty = null)
{
OsuDifficultyBeatmap beatmap = new OsuDifficultyBeatmap(Beatmap.HitObjects, TimeRate);
Skill[] skills =
{
new Aim(),
new Speed()
};
double sectionEnd = section_length / TimeRate;
foreach (OsuDifficultyHitObject h in beatmap)
{
while (h.BaseObject.StartTime > sectionEnd)
{
foreach (Skill s in skills)
{
s.SaveCurrentPeak();
s.StartNewSectionFrom(sectionEnd);
}
sectionEnd += section_length;
}
foreach (Skill s in skills)
s.Process(h);
}
double aimRating = Math.Sqrt(skills[0].DifficultyValue()) * difficulty_multiplier;
double speedRating = Math.Sqrt(skills[1].DifficultyValue()) * difficulty_multiplier;
double starRating = aimRating + speedRating + Math.Abs(aimRating - speedRating) / 2;
if (categoryDifficulty != null)
{
categoryDifficulty.Add("Aim", aimRating);
categoryDifficulty.Add("Speed", speedRating);
}
return starRating;
}
protected override BeatmapConverter<OsuHitObject> CreateBeatmapConverter(Beatmap beatmap) => new OsuBeatmapConverter();
}
}