1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-08 20:17:27 +08:00
osu-lazer/osu.Game.Rulesets.Osu/Difficulty/OsuDifficultyCalculator.cs

95 lines
3.8 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.Linq;
2018-04-13 17:19:50 +08:00
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-06-06 15:20:17 +08:00
using osu.Game.Rulesets.Osu.Mods;
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;
public OsuDifficultyCalculator(Ruleset ruleset, WorkingBeatmap beatmap)
: base(ruleset, beatmap)
2018-04-13 17:19:50 +08:00
{
}
protected override DifficultyAttributes Calculate(IBeatmap beatmap, Mod[] mods, double timeRate)
2018-04-13 17:19:50 +08:00
{
if (!beatmap.HitObjects.Any())
return new OsuDifficultyAttributes(mods, 0);
OsuDifficultyBeatmap difficultyBeatmap = new OsuDifficultyBeatmap(beatmap.HitObjects.Cast<OsuHitObject>().ToList(), 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 = Math.Ceiling(beatmap.HitObjects.First().StartTime / sectionLength) * sectionLength;
foreach (OsuDifficultyHitObject h in difficultyBeatmap)
2018-04-13 17:19:50 +08:00
{
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);
}
2019-01-16 18:58:01 +08:00
// The peak strain will not be saved for the last section in the above loop
foreach (Skill s in skills)
s.SaveCurrentPeak();
2018-04-13 17:19:50 +08:00
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;
// Todo: These int casts are temporary to achieve 1:1 results with osu!stable, and should be removed in the future
double hitWindowGreat = (int)(beatmap.HitObjects.First().HitWindows.Great / 2) / timeRate;
double preempt = (int)BeatmapDifficulty.DifficultyRange(beatmap.BeatmapInfo.BaseDifficulty.ApproachRate, 1800, 1200, 450) / timeRate;
int maxCombo = beatmap.HitObjects.Count;
// Add the ticks + tail of the slider. 1 is subtracted because the head circle would be counted twice (once for the slider itself in the line above)
maxCombo += beatmap.HitObjects.OfType<Slider>().Sum(s => s.NestedHitObjects.Count - 1);
return new OsuDifficultyAttributes(mods, starRating)
2018-04-13 17:19:50 +08:00
{
AimStrain = aimRating,
SpeedStrain = speedRating,
ApproachRate = preempt > 1200 ? (1800 - preempt) / 120 : (1200 - preempt) / 150 + 5,
OverallDifficulty = (80 - hitWindowGreat) / 6,
MaxCombo = maxCombo
};
2018-04-13 17:19:50 +08:00
}
2018-06-06 15:20:17 +08:00
protected override Mod[] DifficultyAdjustmentMods => new Mod[]
{
new OsuModDoubleTime(),
new OsuModHalfTime(),
new OsuModEasy(),
new OsuModHardRock(),
};
2018-04-13 17:19:50 +08:00
}
}