// 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 osu.Game.Rulesets.Difficulty.Skills; using osu.Game.Rulesets.Mods; using System.Linq; using osu.Framework.Utils; using System.Xml.Linq; namespace osu.Game.Rulesets.Osu.Difficulty.Skills { public abstract class OsuStrainSkill : StrainSkill { /// /// The default multiplier applied by to the final difficulty value after all other calculations. /// May be overridden via . /// public const double DEFAULT_DIFFICULTY_MULTIPLIER = 1.06; /// /// The number of sections with the highest strains, which the peak strain reductions will apply to. /// This is done in order to decrease their impact on the overall difficulty of the map for this skill. /// protected virtual int ReducedSectionCount => 10; /// /// The baseline multiplier applied to the section with the biggest strain. /// protected virtual double ReducedStrainBaseline => 0.75; /// /// The final multiplier to be applied to after all other calculations. /// protected virtual double DifficultyMultiplier => DEFAULT_DIFFICULTY_MULTIPLIER; protected virtual double StrainDecayBase => 0.15; protected double StrainDecay(double ms) => Math.Pow(StrainDecayBase, ms / 1000); protected OsuStrainSkill(Mod[] mods) : base(mods) { } public override double DifficultyValue() { double difficulty = 0; double weight = 1; // Sections with 0 strain 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 = GetCurrentStrainPeaks().Where(p => p > 0); List strains = peaks.OrderDescending().ToList(); // We are reducing the highest strains first to account for extreme difficulty spikes for (int i = 0; i < Math.Min(strains.Count, ReducedSectionCount); i++) { double scale = Math.Log10(Interpolation.Lerp(1, 10, Math.Clamp((float)i / ReducedSectionCount, 0, 1))); strains[i] *= Interpolation.Lerp(ReducedStrainBaseline, 1.0, scale); } // Difficulty is the weighted sum of the highest strains from every section. // We're sorting from highest to lowest strain. foreach (double strain in strains.OrderDescending()) { difficulty += strain * weight; weight *= DecayWeight; } return difficulty * DifficultyMultiplier; } /// /// Converts difficulty value from to base performance. /// public static double DifficultyToPerformance(double difficulty) => Math.Pow(5.0 * Math.Max(1.0, difficulty / 0.0675) - 4.0, 3.0) / 100000.0; /// /// Converts base performance to difficulty value.s /// public static double PerformanceToDifficulty(double performance) => (Math.Pow(100000.0 * performance, 1.0 / 3.0) + 4.0) / 5.0 * 0.0675; } }