1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-16 02:15:17 +08:00
osu-lazer/osu.Game.Rulesets.Osu/Difficulty/OsuDifficultyCalculator.cs

76 lines
2.5 KiB
C#
Raw Normal View History

2018-04-13 17:19:50 +08:00
// 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.Difficulty;
2018-04-13 17:19:50 +08:00
using osu.Game.Rulesets.Mods;
2018-05-15 16:36:29 +08:00
using osu.Game.Rulesets.Osu.Difficulty.Preprocessing;
using osu.Game.Rulesets.Osu.Difficulty.Skills;
2018-04-13 17:19:50 +08:00
using osu.Game.Rulesets.Osu.Objects;
2018-05-15 16:36:29 +08:00
namespace osu.Game.Rulesets.Osu.Difficulty
2018-04-13 17:19:50 +08:00
{
public class OsuDifficultyCalculator : DifficultyCalculator
2018-04-13 17:19:50 +08:00
{
private const int section_length = 400;
private const double difficulty_multiplier = 0.0675;
2018-04-19 19:44:38 +08:00
public OsuDifficultyCalculator(IBeatmap beatmap)
2018-04-13 17:19:50 +08:00
: base(beatmap)
{
}
2018-04-19 19:44:38 +08:00
public OsuDifficultyCalculator(IBeatmap beatmap, Mod[] mods)
2018-04-13 17:19:50 +08:00
: base(beatmap, mods)
{
}
public override double Calculate(Dictionary<string, double> categoryDifficulty = null)
{
OsuDifficultyBeatmap beatmap = new OsuDifficultyBeatmap((List<OsuHitObject>)Beatmap.HitObjects, TimeRate);
2018-04-13 17:19:50 +08:00
Skill[] skills =
{
new Aim(),
new Speed()
};
double sectionLength = section_length * TimeRate;
// The first object doesn't generate a strain, so we begin with an incremented section end
double currentSectionEnd = 2 * sectionLength;
2018-04-13 17:19:50 +08:00
foreach (OsuDifficultyHitObject h in beatmap)
{
while (h.BaseObject.StartTime > currentSectionEnd)
2018-04-13 17:19:50 +08:00
{
foreach (Skill s in skills)
{
s.SaveCurrentPeak();
s.StartNewSectionFrom(currentSectionEnd);
2018-04-13 17:19:50 +08:00
}
currentSectionEnd += sectionLength;
2018-04-13 17:19:50 +08:00
}
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;
}
}
}