// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using System; using System.Collections.Generic; using System.Linq; using osu.Framework.Utils; using osu.Game.Rulesets.Difficulty.Preprocessing; using osu.Game.Rulesets.Difficulty.Skills; using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Osu.Difficulty.Evaluators; using osu.Game.Rulesets.Osu.Difficulty.Preprocessing; namespace osu.Game.Rulesets.Osu.Difficulty.Skills { public class ReadingLowAR : GraphSkill { private readonly List difficulties = new List(); //private double skillMultiplier => 5.5; private double skillMultiplier => 2.3; public ReadingLowAR(Mod[] mods) : base(mods) { } public override void Process(DifficultyHitObject current) { double currentDifficulty = ReadingEvaluator.EvaluateDensityDifficultyOf(current) * skillMultiplier; difficulties.Add(currentDifficulty); if (current.Index == 0) CurrentSectionEnd = Math.Ceiling(current.StartTime / SectionLength) * SectionLength; while (current.StartTime > CurrentSectionEnd) { StrainPeaks.Add(CurrentSectionPeak); CurrentSectionPeak = 0; CurrentSectionEnd += SectionLength; } CurrentSectionPeak = Math.Max(currentDifficulty, CurrentSectionPeak); } private double reducedNoteCount => 5; private double reducedNoteBaseline => 0.7; public override double DifficultyValue() { double difficulty = 0; // Sections with 0 difficulty are excluded to avoid worst-case time complexity of the following sort (e.g. /b/2351871). // These sections will not contribute to the difficulty. var peaks = difficulties.Where(p => p > 0); List values = peaks.OrderByDescending(d => d).ToList(); for (int i = 0; i < Math.Min(values.Count, reducedNoteCount); i++) { double scale = Math.Log10(Interpolation.Lerp(1, 10, Math.Clamp(i / reducedNoteCount, 0, 1))); values[i] *= Interpolation.Lerp(reducedNoteBaseline, 1.0, scale); } values = values.OrderByDescending(d => d).ToList(); // Difficulty is the weighted sum of the highest strains from every section. // We're sorting from highest to lowest strain. for (int i = 0; i < values.Count; i++) { difficulty += values[i] / (i + 1); } return difficulty; } } public class ReadingHighAR : GraphSkill { public ReadingHighAR(Mod[] mods) : base(mods) { aimComponent = new HighARAimComponent(mods); speedComponent = new HighARSpeedComponent(mods); } private HighARAimComponent aimComponent; private HighARSpeedComponent speedComponent; private readonly List difficulties = new List(); public override void Process(DifficultyHitObject current) { aimComponent.Process(current); speedComponent.Process(current); double power = OsuDifficultyCalculator.SumPower; double mergedDifficulty = Math.Pow( Math.Pow(aimComponent.CurrentSectionPeak, power) + Math.Pow(speedComponent.CurrentSectionPeak, power), 1.0 / power); difficulties.Add(mergedDifficulty); if (current.Index == 0) CurrentSectionEnd = Math.Ceiling(current.StartTime / SectionLength) * SectionLength; while (current.StartTime > CurrentSectionEnd) { StrainPeaks.Add(CurrentSectionPeak); CurrentSectionPeak = 0; CurrentSectionEnd += SectionLength; } CurrentSectionPeak = Math.Max(mergedDifficulty, CurrentSectionPeak); } public override double DifficultyValue() { double power = OsuDifficultyCalculator.SumPower; return Math.Pow( Math.Pow(aimComponent.DifficultyValue(), power) + Math.Pow(speedComponent.DifficultyValue(), power), 1.0 / power); } } public class HighARAimComponent : OsuStrainSkill { public HighARAimComponent(Mod[] mods) : base(mods) { } private double currentStrain; // private double currentRhythm; private double skillMultiplier => 13; private double strainDecayBase => 0.15; private double strainDecay(double ms) => Math.Pow(strainDecayBase, ms / 1000); protected override double CalculateInitialStrain(double time, DifficultyHitObject current) => currentStrain * strainDecay(time - current.Previous(0).StartTime); protected override double StrainValueAt(DifficultyHitObject current) { currentStrain *= strainDecay(current.DeltaTime); double aimDifficulty = AimEvaluator.EvaluateDifficultyOf(current, true, ((OsuDifficultyHitObject)current).Preempt); aimDifficulty *= ReadingEvaluator.EvaluateHighARDifficultyOf(current, true); currentStrain += aimDifficulty * skillMultiplier; // currentRhythm = RhythmEvaluator.EvaluateDifficultyOf(current); double totalStrain = currentStrain; return totalStrain; } } public class HighARSpeedComponent : OsuStrainSkill { private double skillMultiplier => 650; private double strainDecayBase => 0.3; private double currentStrain; private double currentRhythm; public HighARSpeedComponent(Mod[] mods) : base(mods) { } private double strainDecay(double ms) => Math.Pow(strainDecayBase, ms / 1000); protected override double CalculateInitialStrain(double time, DifficultyHitObject current) => (currentStrain * currentRhythm) * strainDecay(time - current.Previous(0).StartTime); protected override double StrainValueAt(DifficultyHitObject current) { OsuDifficultyHitObject currODHO = (OsuDifficultyHitObject)current; currentStrain *= strainDecay(currODHO.StrainTime); double speedDifficulty = SpeedEvaluator.EvaluateDifficultyOf(current) * skillMultiplier; speedDifficulty *= ReadingEvaluator.EvaluateHighARDifficultyOf(current, false); currentStrain += speedDifficulty; currentRhythm = currODHO.RhythmDifficulty; // currentRhythm *= currentRhythm; // Squaring is broken cuz rhythm is broken (((( double totalStrain = currentStrain * currentRhythm; return totalStrain; } } public class ReadingHidden : GraphSkill { public ReadingHidden(Mod[] mods) : base(mods) { } private readonly List difficulties = new List(); private double skillMultiplier => 2.3; public override void Process(DifficultyHitObject current) { double currentDifficulty = ReadingEvaluator.EvaluateHiddenDifficultyOf(current) * skillMultiplier; difficulties.Add(currentDifficulty); if (current.Index == 0) CurrentSectionEnd = Math.Ceiling(current.StartTime / SectionLength) * SectionLength; while (current.StartTime > CurrentSectionEnd) { StrainPeaks.Add(CurrentSectionPeak); CurrentSectionPeak = 0; CurrentSectionEnd += SectionLength; } CurrentSectionPeak = Math.Max(currentDifficulty, CurrentSectionPeak); } public override double DifficultyValue() { double difficulty = 0; // Sections with 0 difficulty are excluded to avoid worst-case time complexity of the following sort (e.g. /b/2351871). // These sections will not contribute to the difficulty. var peaks = difficulties.Where(p => p > 0); List values = peaks.OrderByDescending(d => d).ToList(); // Difficulty is the weighted sum of the highest strains from every section. // We're sorting from highest to lowest strain. for (int i = 0; i < values.Count; i++) { difficulty += values[i] / (i + 1); } return difficulty; } } }