2019-02-12 07:03:28 +00:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
2022-06-17 07:37:17 +00:00
|
|
|
#nullable disable
|
|
|
|
|
2019-02-12 07:03:28 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
using osu.Game.Rulesets.Difficulty;
|
|
|
|
using osu.Game.Rulesets.Difficulty.Preprocessing;
|
|
|
|
using osu.Game.Rulesets.Difficulty.Skills;
|
|
|
|
using osu.Game.Rulesets.Mods;
|
|
|
|
using osu.Game.Rulesets.Osu.Difficulty.Preprocessing;
|
|
|
|
using osu.Game.Rulesets.Osu.Difficulty.Skills;
|
|
|
|
using osu.Game.Rulesets.Osu.Mods;
|
|
|
|
using osu.Game.Rulesets.Osu.Objects;
|
2019-09-06 06:24:00 +00:00
|
|
|
using osu.Game.Rulesets.Osu.Scoring;
|
|
|
|
using osu.Game.Rulesets.Scoring;
|
2019-02-12 07:03:28 +00:00
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Osu.Difficulty
|
|
|
|
{
|
|
|
|
public class OsuDifficultyCalculator : DifficultyCalculator
|
|
|
|
{
|
|
|
|
private const double difficulty_multiplier = 0.0675;
|
|
|
|
|
2024-10-07 13:38:41 +00:00
|
|
|
public override int Version => 20241007;
|
2019-02-12 07:03:28 +00:00
|
|
|
|
2021-11-15 09:23:03 +00:00
|
|
|
public OsuDifficultyCalculator(IRulesetInfo ruleset, IWorkingBeatmap beatmap)
|
2019-02-12 07:03:28 +00:00
|
|
|
: base(ruleset, beatmap)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-02-19 08:38:33 +00:00
|
|
|
protected override DifficultyAttributes CreateDifficultyAttributes(IBeatmap beatmap, Mod[] mods, Skill[] skills, double clockRate)
|
2019-02-12 07:03:28 +00:00
|
|
|
{
|
2019-02-19 08:38:33 +00:00
|
|
|
if (beatmap.HitObjects.Count == 0)
|
2021-11-21 03:12:24 +00:00
|
|
|
return new OsuDifficultyAttributes { Mods = mods };
|
2019-02-12 07:03:28 +00:00
|
|
|
|
|
|
|
double aimRating = Math.Sqrt(skills[0].DifficultyValue()) * difficulty_multiplier;
|
2021-11-10 00:59:28 +00:00
|
|
|
double aimRatingNoSliders = Math.Sqrt(skills[1].DifficultyValue()) * difficulty_multiplier;
|
|
|
|
double speedRating = Math.Sqrt(skills[2].DifficultyValue()) * difficulty_multiplier;
|
2022-06-29 07:29:17 +00:00
|
|
|
double speedNotes = ((Speed)skills[2]).RelevantNoteCount();
|
2024-02-10 15:25:03 +00:00
|
|
|
|
|
|
|
double flashlightRating = 0.0;
|
|
|
|
|
|
|
|
if (mods.Any(h => h is OsuModFlashlight))
|
|
|
|
flashlightRating = Math.Sqrt(skills[3].DifficultyValue()) * difficulty_multiplier;
|
2021-11-10 00:59:28 +00:00
|
|
|
|
2021-11-12 08:31:25 +00:00
|
|
|
double sliderFactor = aimRating > 0 ? aimRatingNoSliders / aimRating : 1;
|
2021-08-01 13:27:05 +00:00
|
|
|
|
2024-11-07 11:56:42 +00:00
|
|
|
double aimDifficultyStrainCount = ((OsuStrainSkill)skills[0]).CountTopWeightedStrains();
|
|
|
|
double speedDifficultyStrainCount = ((OsuStrainSkill)skills[2]).CountTopWeightedStrains();
|
2021-12-26 23:51:49 +00:00
|
|
|
|
2022-01-19 19:31:11 +00:00
|
|
|
if (mods.Any(m => m is OsuModTouchDevice))
|
2022-09-14 14:40:22 +00:00
|
|
|
{
|
2022-01-19 19:31:11 +00:00
|
|
|
aimRating = Math.Pow(aimRating, 0.8);
|
2022-09-14 14:40:22 +00:00
|
|
|
flashlightRating = Math.Pow(flashlightRating, 0.8);
|
|
|
|
}
|
2022-01-19 19:31:11 +00:00
|
|
|
|
2021-10-06 15:53:33 +00:00
|
|
|
if (mods.Any(h => h is OsuModRelax))
|
2022-07-04 16:59:30 +00:00
|
|
|
{
|
2022-07-13 21:42:50 +00:00
|
|
|
aimRating *= 0.9;
|
2021-10-06 15:53:33 +00:00
|
|
|
speedRating = 0.0;
|
2022-07-13 21:42:50 +00:00
|
|
|
flashlightRating *= 0.7;
|
2022-07-04 16:59:30 +00:00
|
|
|
}
|
2021-10-06 15:53:33 +00:00
|
|
|
|
2024-08-05 13:08:30 +00:00
|
|
|
double baseAimPerformance = OsuStrainSkill.DifficultyToPerformance(aimRating);
|
|
|
|
double baseSpeedPerformance = OsuStrainSkill.DifficultyToPerformance(speedRating);
|
2021-09-15 09:03:42 +00:00
|
|
|
double baseFlashlightPerformance = 0.0;
|
2021-09-21 03:43:29 +00:00
|
|
|
|
2021-09-15 09:03:42 +00:00
|
|
|
if (mods.Any(h => h is OsuModFlashlight))
|
2024-08-05 13:08:30 +00:00
|
|
|
baseFlashlightPerformance = Flashlight.DifficultyToPerformance(flashlightRating);
|
2021-09-21 03:43:29 +00:00
|
|
|
|
2021-09-15 09:03:42 +00:00
|
|
|
double basePerformance =
|
|
|
|
Math.Pow(
|
|
|
|
Math.Pow(baseAimPerformance, 1.1) +
|
|
|
|
Math.Pow(baseSpeedPerformance, 1.1) +
|
|
|
|
Math.Pow(baseFlashlightPerformance, 1.1), 1.0 / 1.1
|
|
|
|
);
|
2021-09-21 03:43:29 +00:00
|
|
|
|
2023-06-01 04:22:37 +00:00
|
|
|
double starRating = basePerformance > 0.00001
|
|
|
|
? Math.Cbrt(OsuPerformanceCalculator.PERFORMANCE_BASE_MULTIPLIER) * 0.027 * (Math.Cbrt(100000 / Math.Pow(2, 1 / 1.1) * basePerformance) + 4)
|
|
|
|
: 0;
|
2019-02-12 07:03:28 +00:00
|
|
|
|
2021-10-09 09:08:57 +00:00
|
|
|
double preempt = IBeatmapDifficultyInfo.DifficultyRange(beatmap.Difficulty.ApproachRate, 1800, 1200, 450) / clockRate;
|
2021-10-08 10:50:31 +00:00
|
|
|
double drainRate = beatmap.Difficulty.DrainRate;
|
2019-02-12 07:03:28 +00:00
|
|
|
|
2020-10-02 17:34:41 +00:00
|
|
|
int hitCirclesCount = beatmap.HitObjects.Count(h => h is HitCircle);
|
2021-10-13 17:04:34 +00:00
|
|
|
int sliderCount = beatmap.HitObjects.Count(h => h is Slider);
|
2020-12-08 13:09:48 +00:00
|
|
|
int spinnerCount = beatmap.HitObjects.Count(h => h is Spinner);
|
2020-10-02 17:34:41 +00:00
|
|
|
|
2022-09-06 16:10:32 +00:00
|
|
|
HitWindows hitWindows = new OsuHitWindows();
|
|
|
|
hitWindows.SetDifficulty(beatmap.Difficulty.OverallDifficulty);
|
|
|
|
|
|
|
|
double hitWindowGreat = hitWindows.WindowFor(HitResult.Great) / clockRate;
|
|
|
|
|
2023-06-23 16:03:18 +00:00
|
|
|
OsuDifficultyAttributes attributes = new OsuDifficultyAttributes
|
2019-02-19 08:38:33 +00:00
|
|
|
{
|
|
|
|
StarRating = starRating,
|
2019-02-19 08:39:30 +00:00
|
|
|
Mods = mods,
|
2021-12-17 20:39:03 +00:00
|
|
|
AimDifficulty = aimRating,
|
|
|
|
SpeedDifficulty = speedRating,
|
2021-10-11 01:12:57 +00:00
|
|
|
SpeedNoteCount = speedNotes,
|
2021-12-17 20:39:03 +00:00
|
|
|
FlashlightDifficulty = flashlightRating,
|
2021-11-10 00:59:28 +00:00
|
|
|
SliderFactor = sliderFactor,
|
2021-12-26 23:51:49 +00:00
|
|
|
AimDifficultStrainCount = aimDifficultyStrainCount,
|
|
|
|
SpeedDifficultStrainCount = speedDifficultyStrainCount,
|
2019-02-19 08:38:33 +00:00
|
|
|
ApproachRate = preempt > 1200 ? (1800 - preempt) / 120 : (1200 - preempt) / 150 + 5,
|
|
|
|
OverallDifficulty = (80 - hitWindowGreat) / 6,
|
2021-09-24 14:02:19 +00:00
|
|
|
DrainRate = drainRate,
|
2024-09-22 12:01:58 +00:00
|
|
|
MaxCombo = beatmap.GetMaxCombo(),
|
2020-10-03 14:52:33 +00:00
|
|
|
HitCircleCount = hitCirclesCount,
|
2021-10-13 17:04:34 +00:00
|
|
|
SliderCount = sliderCount,
|
2020-12-08 13:09:48 +00:00
|
|
|
SpinnerCount = spinnerCount,
|
2019-02-19 08:38:33 +00:00
|
|
|
};
|
2023-06-23 16:03:18 +00:00
|
|
|
|
|
|
|
return attributes;
|
2019-02-12 07:03:28 +00:00
|
|
|
}
|
|
|
|
|
2019-02-19 08:40:35 +00:00
|
|
|
protected override IEnumerable<DifficultyHitObject> CreateDifficultyHitObjects(IBeatmap beatmap, double clockRate)
|
2019-02-12 07:03:28 +00:00
|
|
|
{
|
2022-05-22 15:26:22 +00:00
|
|
|
List<DifficultyHitObject> objects = new List<DifficultyHitObject>();
|
|
|
|
|
2019-02-12 07:03:28 +00:00
|
|
|
// The first jump is formed by the first two hitobjects of the map.
|
|
|
|
// If the map has less than two OsuHitObjects, the enumerator will not return anything.
|
|
|
|
for (int i = 1; i < beatmap.HitObjects.Count; i++)
|
|
|
|
{
|
|
|
|
var lastLast = i > 1 ? beatmap.HitObjects[i - 2] : null;
|
2022-06-10 09:28:14 +00:00
|
|
|
objects.Add(new OsuDifficultyHitObject(beatmap.HitObjects[i], beatmap.HitObjects[i - 1], lastLast, clockRate, objects, objects.Count));
|
2019-02-12 07:03:28 +00:00
|
|
|
}
|
|
|
|
|
2022-05-22 15:26:22 +00:00
|
|
|
return objects;
|
2019-02-12 07:03:28 +00:00
|
|
|
}
|
|
|
|
|
2021-09-15 09:52:50 +00:00
|
|
|
protected override Skill[] CreateSkills(IBeatmap beatmap, Mod[] mods, double clockRate)
|
2019-02-12 07:03:28 +00:00
|
|
|
{
|
2024-02-10 15:25:03 +00:00
|
|
|
var skills = new List<Skill>
|
2021-09-15 09:52:50 +00:00
|
|
|
{
|
2021-11-10 00:59:28 +00:00
|
|
|
new Aim(mods, true),
|
|
|
|
new Aim(mods, false),
|
2024-02-10 15:25:03 +00:00
|
|
|
new Speed(mods)
|
2021-09-15 09:52:50 +00:00
|
|
|
};
|
2024-02-10 15:25:03 +00:00
|
|
|
|
|
|
|
if (mods.Any(h => h is OsuModFlashlight))
|
|
|
|
skills.Add(new Flashlight(mods));
|
|
|
|
|
|
|
|
return skills.ToArray();
|
2021-09-15 09:52:50 +00:00
|
|
|
}
|
2019-02-12 07:03:28 +00:00
|
|
|
|
|
|
|
protected override Mod[] DifficultyAdjustmentMods => new Mod[]
|
|
|
|
{
|
2022-01-19 19:31:11 +00:00
|
|
|
new OsuModTouchDevice(),
|
2019-02-12 07:03:28 +00:00
|
|
|
new OsuModDoubleTime(),
|
|
|
|
new OsuModHalfTime(),
|
|
|
|
new OsuModEasy(),
|
|
|
|
new OsuModHardRock(),
|
2021-09-15 09:03:42 +00:00
|
|
|
new OsuModFlashlight(),
|
2021-11-30 01:39:48 +00:00
|
|
|
new MultiMod(new OsuModFlashlight(), new OsuModHidden())
|
2019-02-12 07:03:28 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|