2019-02-18 13:54:21 +08: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.
|
|
|
|
|
2020-05-11 13:50:02 +08:00
|
|
|
using System;
|
2019-02-18 13:54:21 +08:00
|
|
|
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;
|
2019-09-06 14:24:00 +08:00
|
|
|
using osu.Game.Rulesets.Scoring;
|
2019-02-18 13:54:21 +08:00
|
|
|
using osu.Game.Rulesets.Taiko.Difficulty.Preprocessing;
|
|
|
|
using osu.Game.Rulesets.Taiko.Difficulty.Skills;
|
|
|
|
using osu.Game.Rulesets.Taiko.Mods;
|
|
|
|
using osu.Game.Rulesets.Taiko.Objects;
|
2019-09-06 14:24:00 +08:00
|
|
|
using osu.Game.Rulesets.Taiko.Scoring;
|
2019-02-18 13:54:21 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Taiko.Difficulty
|
|
|
|
{
|
|
|
|
public class TaikoDifficultyCalculator : DifficultyCalculator
|
|
|
|
{
|
2020-06-08 15:30:26 +08:00
|
|
|
private const double rhythm_skill_multiplier = 0.014;
|
|
|
|
private const double colour_skill_multiplier = 0.01;
|
|
|
|
private const double stamina_skill_multiplier = 0.02;
|
|
|
|
|
2019-02-18 13:54:21 +08:00
|
|
|
public TaikoDifficultyCalculator(Ruleset ruleset, WorkingBeatmap beatmap)
|
|
|
|
: base(ruleset, beatmap)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-05-22 19:50:21 +08:00
|
|
|
private double simpleColourPenalty(double staminaDifficulty, double colorDifficulty)
|
2020-05-11 13:50:02 +08:00
|
|
|
{
|
2020-05-24 10:48:56 +08:00
|
|
|
if (colorDifficulty <= 0) return 0.79 - 0.25;
|
2020-06-08 15:30:26 +08:00
|
|
|
|
2020-05-22 19:50:21 +08:00
|
|
|
return 0.79 - Math.Atan(staminaDifficulty / colorDifficulty - 12) / Math.PI / 2;
|
2020-05-11 13:50:02 +08:00
|
|
|
}
|
|
|
|
|
2020-08-19 01:59:28 +08:00
|
|
|
private double norm(double p, params double[] values)
|
2020-05-11 13:50:02 +08:00
|
|
|
{
|
2020-08-19 01:59:28 +08:00
|
|
|
return Math.Pow(values.Sum(x => Math.Pow(x, p)), 1 / p);
|
2020-05-11 13:50:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private double rescale(double sr)
|
|
|
|
{
|
2020-06-08 15:30:26 +08:00
|
|
|
if (sr < 0) return sr;
|
|
|
|
|
|
|
|
return 10.43 * Math.Log(sr / 8 + 1);
|
2020-05-11 13:50:02 +08:00
|
|
|
}
|
|
|
|
|
2020-08-19 02:14:00 +08:00
|
|
|
private double locallyCombinedDifficulty(
|
|
|
|
double staminaPenalty, Colour colour, Rhythm rhythm, Stamina staminaRight, Stamina staminaLeft)
|
2020-05-11 13:50:02 +08:00
|
|
|
{
|
|
|
|
double difficulty = 0;
|
|
|
|
double weight = 1;
|
|
|
|
List<double> peaks = new List<double>();
|
2020-05-11 13:53:42 +08:00
|
|
|
|
2020-05-11 13:50:02 +08:00
|
|
|
for (int i = 0; i < colour.StrainPeaks.Count; i++)
|
|
|
|
{
|
2020-06-08 15:30:26 +08:00
|
|
|
double colourPeak = colour.StrainPeaks[i] * colour_skill_multiplier;
|
|
|
|
double rhythmPeak = rhythm.StrainPeaks[i] * rhythm_skill_multiplier;
|
2020-08-19 02:14:00 +08:00
|
|
|
double staminaPeak = (staminaRight.StrainPeaks[i] + staminaLeft.StrainPeaks[i]) * stamina_skill_multiplier * staminaPenalty;
|
2020-05-11 13:50:02 +08:00
|
|
|
peaks.Add(norm(2, colourPeak, rhythmPeak, staminaPeak));
|
|
|
|
}
|
2020-05-11 13:53:42 +08:00
|
|
|
|
2020-05-11 13:50:02 +08:00
|
|
|
foreach (double strain in peaks.OrderByDescending(d => d))
|
|
|
|
{
|
|
|
|
difficulty += strain * weight;
|
|
|
|
weight *= 0.9;
|
|
|
|
}
|
|
|
|
|
|
|
|
return difficulty;
|
|
|
|
}
|
|
|
|
|
2019-02-19 16:45:16 +08:00
|
|
|
protected override DifficultyAttributes CreateDifficultyAttributes(IBeatmap beatmap, Mod[] mods, Skill[] skills, double clockRate)
|
2019-02-18 13:54:21 +08:00
|
|
|
{
|
2019-02-19 16:45:16 +08:00
|
|
|
if (beatmap.HitObjects.Count == 0)
|
2019-05-29 17:22:51 +08:00
|
|
|
return new TaikoDifficultyAttributes { Mods = mods, Skills = skills };
|
2019-02-19 16:45:16 +08:00
|
|
|
|
2020-08-19 02:14:00 +08:00
|
|
|
var colour = (Colour)skills[0];
|
|
|
|
var rhythm = (Rhythm)skills[1];
|
|
|
|
var staminaRight = (Stamina)skills[2];
|
|
|
|
var staminaLeft = (Stamina)skills[3];
|
|
|
|
|
|
|
|
double colourRating = colour.DifficultyValue() * colour_skill_multiplier;
|
|
|
|
double rhythmRating = rhythm.DifficultyValue() * rhythm_skill_multiplier;
|
|
|
|
double staminaRating = (staminaRight.DifficultyValue() + staminaLeft.DifficultyValue()) * stamina_skill_multiplier;
|
2020-05-22 19:50:21 +08:00
|
|
|
|
|
|
|
double staminaPenalty = simpleColourPenalty(staminaRating, colourRating);
|
|
|
|
staminaRating *= staminaPenalty;
|
|
|
|
|
2020-08-19 02:14:00 +08:00
|
|
|
double combinedRating = locallyCombinedDifficulty(staminaPenalty, colour, rhythm, staminaRight, staminaLeft);
|
2020-05-11 13:50:02 +08:00
|
|
|
double separatedRating = norm(1.5, colourRating, rhythmRating, staminaRating);
|
|
|
|
double starRating = 1.4 * separatedRating + 0.5 * combinedRating;
|
|
|
|
starRating = rescale(starRating);
|
|
|
|
|
2019-09-02 16:38:52 +08:00
|
|
|
HitWindows hitWindows = new TaikoHitWindows();
|
|
|
|
hitWindows.SetDifficulty(beatmap.BeatmapInfo.BaseDifficulty.OverallDifficulty);
|
|
|
|
|
2019-02-19 16:45:16 +08:00
|
|
|
return new TaikoDifficultyAttributes
|
|
|
|
{
|
2020-05-11 13:50:02 +08:00
|
|
|
StarRating = starRating,
|
2019-02-19 16:45:16 +08:00
|
|
|
Mods = mods,
|
2020-05-22 19:50:21 +08:00
|
|
|
StaminaStrain = staminaRating,
|
|
|
|
RhythmStrain = rhythmRating,
|
|
|
|
ColourStrain = colourRating,
|
2019-02-19 16:45:16 +08:00
|
|
|
// Todo: This int cast is temporary to achieve 1:1 results with osu!stable, and should be removed in the future
|
2020-06-08 15:30:26 +08:00
|
|
|
GreatHitWindow = (int)hitWindows.WindowFor(HitResult.Great) / clockRate,
|
2019-02-19 16:45:16 +08:00
|
|
|
MaxCombo = beatmap.HitObjects.Count(h => h is Hit),
|
2019-05-29 17:22:51 +08:00
|
|
|
Skills = skills
|
2019-02-19 16:45:16 +08:00
|
|
|
};
|
2019-02-18 13:54:21 +08:00
|
|
|
}
|
|
|
|
|
2019-02-19 16:45:16 +08:00
|
|
|
protected override IEnumerable<DifficultyHitObject> CreateDifficultyHitObjects(IBeatmap beatmap, double clockRate)
|
2019-02-18 13:54:21 +08:00
|
|
|
{
|
2020-05-11 13:50:02 +08:00
|
|
|
List<TaikoDifficultyHitObject> taikoDifficultyHitObjects = new List<TaikoDifficultyHitObject>();
|
2020-05-11 13:53:42 +08:00
|
|
|
|
2020-05-11 13:50:02 +08:00
|
|
|
for (int i = 2; i < beatmap.HitObjects.Count; i++)
|
|
|
|
{
|
2020-05-24 10:48:56 +08:00
|
|
|
// Check for negative durations
|
2020-08-22 23:34:08 +08:00
|
|
|
var currentAfterLast = beatmap.HitObjects[i].StartTime > beatmap.HitObjects[i - 1].StartTime;
|
|
|
|
var lastAfterSecondLast = beatmap.HitObjects[i - 1].StartTime > beatmap.HitObjects[i - 2].StartTime;
|
|
|
|
|
|
|
|
if (currentAfterLast && lastAfterSecondLast)
|
2020-06-08 15:30:26 +08:00
|
|
|
{
|
|
|
|
taikoDifficultyHitObjects.Add(
|
|
|
|
new TaikoDifficultyHitObject(
|
2020-08-22 23:10:31 +08:00
|
|
|
beatmap.HitObjects[i], beatmap.HitObjects[i - 1], beatmap.HitObjects[i - 2], clockRate, i
|
2020-06-08 15:30:26 +08:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2020-05-11 13:50:02 +08:00
|
|
|
}
|
2020-05-11 13:53:42 +08:00
|
|
|
|
2020-05-11 13:50:02 +08:00
|
|
|
new StaminaCheeseDetector().FindCheese(taikoDifficultyHitObjects);
|
2020-08-22 23:24:51 +08:00
|
|
|
return taikoDifficultyHitObjects;
|
2019-02-18 13:54:21 +08:00
|
|
|
}
|
|
|
|
|
2020-05-11 13:50:02 +08:00
|
|
|
protected override Skill[] CreateSkills(IBeatmap beatmap) => new Skill[]
|
|
|
|
{
|
|
|
|
new Colour(),
|
|
|
|
new Rhythm(),
|
|
|
|
new Stamina(true),
|
|
|
|
new Stamina(false),
|
|
|
|
};
|
2019-02-18 13:54:21 +08:00
|
|
|
|
|
|
|
protected override Mod[] DifficultyAdjustmentMods => new Mod[]
|
|
|
|
{
|
|
|
|
new TaikoModDoubleTime(),
|
|
|
|
new TaikoModHalfTime(),
|
|
|
|
new TaikoModEasy(),
|
|
|
|
new TaikoModHardRock(),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|