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;
|
2018-06-14 14:36:49 +08:00
|
|
|
|
using System.Linq;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Game.Beatmaps;
|
2018-05-15 16:38:04 +08:00
|
|
|
|
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
|
|
|
|
{
|
2018-04-19 21:04:12 +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-06-14 14:36:49 +08:00
|
|
|
|
public OsuDifficultyCalculator(Ruleset ruleset, WorkingBeatmap beatmap)
|
|
|
|
|
: base(ruleset, beatmap)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-14 14:36:49 +08:00
|
|
|
|
protected override DifficultyAttributes Calculate(IBeatmap beatmap, Mod[] mods, double timeRate)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2018-06-21 11:04:14 +08:00
|
|
|
|
if (!beatmap.HitObjects.Any())
|
|
|
|
|
return new OsuDifficultyAttributes(mods, 0);
|
|
|
|
|
|
2018-06-14 14:36:49 +08:00
|
|
|
|
OsuDifficultyBeatmap difficultyBeatmap = new OsuDifficultyBeatmap(beatmap.HitObjects.Cast<OsuHitObject>().ToList(), timeRate);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
Skill[] skills =
|
|
|
|
|
{
|
|
|
|
|
new Aim(),
|
|
|
|
|
new Speed()
|
|
|
|
|
};
|
|
|
|
|
|
2018-06-14 14:36:49 +08:00
|
|
|
|
double sectionLength = section_length * timeRate;
|
2018-05-15 20:26:06 +08:00
|
|
|
|
|
|
|
|
|
// The first object doesn't generate a strain, so we begin with an incremented section end
|
2018-10-08 15:46:58 +08:00
|
|
|
|
double currentSectionEnd = Math.Ceiling(beatmap.HitObjects.First().StartTime / sectionLength) * sectionLength;
|
2018-05-15 20:26:06 +08:00
|
|
|
|
|
2018-06-14 14:36:49 +08:00
|
|
|
|
foreach (OsuDifficultyHitObject h in difficultyBeatmap)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2018-05-15 20:26:06 +08:00
|
|
|
|
while (h.BaseObject.StartTime > currentSectionEnd)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
foreach (Skill s in skills)
|
|
|
|
|
{
|
|
|
|
|
s.SaveCurrentPeak();
|
2018-05-15 20:26:06 +08:00
|
|
|
|
s.StartNewSectionFrom(currentSectionEnd);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-05-15 20:26:06 +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;
|
|
|
|
|
|
2018-07-05 10:32:09 +08:00
|
|
|
|
// Todo: These int casts are temporary to achieve 1:1 results with osu!stable, and should be removed in the future
|
2018-06-14 15:27:05 +08:00
|
|
|
|
double hitWindowGreat = (int)(beatmap.HitObjects.First().HitWindows.Great / 2) / timeRate;
|
2018-07-05 10:32:09 +08:00
|
|
|
|
double preempt = (int)BeatmapDifficulty.DifficultyRange(beatmap.BeatmapInfo.BaseDifficulty.ApproachRate, 1800, 1200, 450) / timeRate;
|
2018-06-14 15:27:05 +08:00
|
|
|
|
|
2018-10-11 18:53:07 +08:00
|
|
|
|
int maxCombo = beatmap.HitObjects.Count;
|
2018-07-05 10:32:09 +08:00
|
|
|
|
// 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)
|
2018-06-14 15:27:05 +08:00
|
|
|
|
maxCombo += beatmap.HitObjects.OfType<Slider>().Sum(s => s.NestedHitObjects.Count - 1);
|
|
|
|
|
|
2018-06-14 14:36:49 +08:00
|
|
|
|
return new OsuDifficultyAttributes(mods, starRating)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2018-06-14 14:36:49 +08:00
|
|
|
|
AimStrain = aimRating,
|
2018-06-14 15:27:05 +08:00
|
|
|
|
SpeedStrain = speedRating,
|
2018-07-05 10:32:09 +08:00
|
|
|
|
ApproachRate = preempt > 1200 ? (1800 - preempt) / 120 : (1200 - preempt) / 150 + 5,
|
2018-06-14 15:27:05 +08:00
|
|
|
|
OverallDifficulty = (80 - hitWindowGreat) / 6,
|
|
|
|
|
MaxCombo = maxCombo
|
2018-06-14 14:36:49 +08:00
|
|
|
|
};
|
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
|
|
|
|
}
|
|
|
|
|
}
|