2019-01-24 08:43:03 +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.
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
2020-05-18 06:10:59 +00:00
|
|
|
using osu.Framework.Extensions;
|
2018-04-13 09:19:50 +00:00
|
|
|
using osu.Game.Beatmaps;
|
2018-05-15 08:38:04 +00:00
|
|
|
using osu.Game.Rulesets.Difficulty;
|
2018-04-13 09:19:50 +00:00
|
|
|
using osu.Game.Rulesets.Mods;
|
|
|
|
using osu.Game.Rulesets.Osu.Mods;
|
|
|
|
using osu.Game.Rulesets.Osu.Objects;
|
|
|
|
using osu.Game.Rulesets.Scoring;
|
2018-11-28 07:12:57 +00:00
|
|
|
using osu.Game.Scoring;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
2018-05-17 07:58:22 +00:00
|
|
|
namespace osu.Game.Rulesets.Osu.Difficulty
|
2018-04-13 09:19:50 +00:00
|
|
|
{
|
2018-04-19 13:04:12 +00:00
|
|
|
public class OsuPerformanceCalculator : PerformanceCalculator
|
2018-04-13 09:19:50 +00:00
|
|
|
{
|
2018-06-14 07:04:48 +00:00
|
|
|
public new OsuDifficultyAttributes Attributes => (OsuDifficultyAttributes)base.Attributes;
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
private readonly int countHitCircles;
|
|
|
|
private readonly int beatmapMaxCombo;
|
|
|
|
|
|
|
|
private Mod[] mods;
|
2018-05-14 02:52:22 +00:00
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
private double accuracy;
|
|
|
|
private int scoreMaxCombo;
|
2018-05-16 03:46:31 +00:00
|
|
|
private int countGreat;
|
|
|
|
private int countGood;
|
|
|
|
private int countMeh;
|
2018-04-13 09:19:50 +00:00
|
|
|
private int countMiss;
|
|
|
|
|
2018-11-30 06:18:52 +00:00
|
|
|
public OsuPerformanceCalculator(Ruleset ruleset, WorkingBeatmap beatmap, ScoreInfo score)
|
|
|
|
: base(ruleset, beatmap, score)
|
2018-04-13 09:19:50 +00:00
|
|
|
{
|
|
|
|
countHitCircles = Beatmap.HitObjects.Count(h => h is HitCircle);
|
|
|
|
|
2018-10-11 10:53:07 +00:00
|
|
|
beatmapMaxCombo = Beatmap.HitObjects.Count;
|
2018-05-11 13:06:16 +00:00
|
|
|
// Add the ticks + tail of the slider. 1 is subtracted because the "headcircle" would be counted twice (once for the slider itself in the line above)
|
|
|
|
beatmapMaxCombo += Beatmap.HitObjects.OfType<Slider>().Sum(s => s.NestedHitObjects.Count - 1);
|
2018-04-13 09:19:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public override double Calculate(Dictionary<string, double> categoryRatings = null)
|
|
|
|
{
|
2018-11-30 06:18:52 +00:00
|
|
|
mods = Score.Mods;
|
|
|
|
accuracy = Score.Accuracy;
|
|
|
|
scoreMaxCombo = Score.MaxCombo;
|
2020-05-18 06:10:59 +00:00
|
|
|
countGreat = Score.Statistics.GetOrDefault(HitResult.Great);
|
|
|
|
countGood = Score.Statistics.GetOrDefault(HitResult.Good);
|
|
|
|
countMeh = Score.Statistics.GetOrDefault(HitResult.Meh);
|
|
|
|
countMiss = Score.Statistics.GetOrDefault(HitResult.Miss);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
// Don't count scores made with supposedly unranked mods
|
|
|
|
if (mods.Any(m => !m.Ranked))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
// Custom multipliers for NoFail and SpunOut.
|
2019-11-26 10:34:23 +00:00
|
|
|
double multiplier = 1.12; // This is being adjusted to keep the final pp value scaled around what it used to be when changing things
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
if (mods.Any(m => m is OsuModNoFail))
|
2019-11-26 10:34:23 +00:00
|
|
|
multiplier *= 0.90;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
if (mods.Any(m => m is OsuModSpunOut))
|
2019-11-26 10:34:23 +00:00
|
|
|
multiplier *= 0.95;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
double aimValue = computeAimValue();
|
|
|
|
double speedValue = computeSpeedValue();
|
|
|
|
double accuracyValue = computeAccuracyValue();
|
|
|
|
double totalValue =
|
|
|
|
Math.Pow(
|
2019-11-26 10:34:23 +00:00
|
|
|
Math.Pow(aimValue, 1.1) +
|
|
|
|
Math.Pow(speedValue, 1.1) +
|
|
|
|
Math.Pow(accuracyValue, 1.1), 1.0 / 1.1
|
2018-04-13 09:19:50 +00:00
|
|
|
) * multiplier;
|
|
|
|
|
|
|
|
if (categoryRatings != null)
|
|
|
|
{
|
|
|
|
categoryRatings.Add("Aim", aimValue);
|
|
|
|
categoryRatings.Add("Speed", speedValue);
|
|
|
|
categoryRatings.Add("Accuracy", accuracyValue);
|
2018-06-14 07:27:05 +00:00
|
|
|
categoryRatings.Add("OD", Attributes.OverallDifficulty);
|
|
|
|
categoryRatings.Add("AR", Attributes.ApproachRate);
|
2018-05-14 02:15:37 +00:00
|
|
|
categoryRatings.Add("Max Combo", beatmapMaxCombo);
|
2018-04-13 09:19:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return totalValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
private double computeAimValue()
|
|
|
|
{
|
2019-01-31 02:51:40 +00:00
|
|
|
double rawAim = Attributes.AimStrain;
|
|
|
|
|
|
|
|
if (mods.Any(m => m is OsuModTouchDevice))
|
|
|
|
rawAim = Math.Pow(rawAim, 0.8);
|
|
|
|
|
2019-11-26 10:34:23 +00:00
|
|
|
double aimValue = Math.Pow(5.0 * Math.Max(1.0, rawAim / 0.0675) - 4.0, 3.0) / 100000.0;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
// Longer maps are worth more
|
2019-11-26 10:34:23 +00:00
|
|
|
double lengthBonus = 0.95 + 0.4 * Math.Min(1.0, totalHits / 2000.0) +
|
|
|
|
(totalHits > 2000 ? Math.Log10(totalHits / 2000.0) * 0.5 : 0.0);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
aimValue *= lengthBonus;
|
|
|
|
|
|
|
|
// Penalize misses exponentially. This mainly fixes tag4 maps and the likes until a per-hitobject solution is available
|
2019-11-26 10:34:23 +00:00
|
|
|
aimValue *= Math.Pow(0.97, countMiss);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
// Combo scaling
|
|
|
|
if (beatmapMaxCombo > 0)
|
2019-11-26 10:34:23 +00:00
|
|
|
aimValue *= Math.Min(Math.Pow(scoreMaxCombo, 0.8) / Math.Pow(beatmapMaxCombo, 0.8), 1.0);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
2019-11-26 10:34:23 +00:00
|
|
|
double approachRateFactor = 1.0;
|
2019-04-01 03:16:05 +00:00
|
|
|
|
2019-11-26 10:34:23 +00:00
|
|
|
if (Attributes.ApproachRate > 10.33)
|
|
|
|
approachRateFactor += 0.3 * (Attributes.ApproachRate - 10.33);
|
|
|
|
else if (Attributes.ApproachRate < 8.0)
|
2018-04-13 09:19:50 +00:00
|
|
|
{
|
2019-11-26 10:34:23 +00:00
|
|
|
approachRateFactor += 0.01 * (8.0 - Attributes.ApproachRate);
|
2018-04-13 09:19:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
aimValue *= approachRateFactor;
|
|
|
|
|
2018-05-15 02:53:11 +00:00
|
|
|
// We want to give more reward for lower AR when it comes to aim and HD. This nerfs high AR and buffs lower AR.
|
2018-04-13 09:19:50 +00:00
|
|
|
if (mods.Any(h => h is OsuModHidden))
|
2019-11-26 10:34:23 +00:00
|
|
|
aimValue *= 1.0 + 0.04 * (12.0 - Attributes.ApproachRate);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
if (mods.Any(h => h is OsuModFlashlight))
|
|
|
|
{
|
2018-12-24 05:14:28 +00:00
|
|
|
// Apply object-based bonus for flashlight.
|
2019-11-26 10:34:23 +00:00
|
|
|
aimValue *= 1.0 + 0.35 * Math.Min(1.0, totalHits / 200.0) +
|
2019-02-28 04:31:40 +00:00
|
|
|
(totalHits > 200
|
2019-11-26 10:34:23 +00:00
|
|
|
? 0.3 * Math.Min(1.0, (totalHits - 200) / 300.0) +
|
|
|
|
(totalHits > 500 ? (totalHits - 500) / 1200.0 : 0.0)
|
|
|
|
: 0.0);
|
2018-04-13 09:19:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Scale the aim value with accuracy _slightly_
|
2019-11-26 10:34:23 +00:00
|
|
|
aimValue *= 0.5 + accuracy / 2.0;
|
2018-04-13 09:19:50 +00:00
|
|
|
// It is important to also consider accuracy difficulty when doing that
|
2019-11-26 10:34:23 +00:00
|
|
|
aimValue *= 0.98 + Math.Pow(Attributes.OverallDifficulty, 2) / 2500;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
return aimValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
private double computeSpeedValue()
|
|
|
|
{
|
2019-11-26 10:34:23 +00:00
|
|
|
double speedValue = Math.Pow(5.0 * Math.Max(1.0, Attributes.SpeedStrain / 0.0675) - 4.0, 3.0) / 100000.0;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
// Longer maps are worth more
|
2019-11-26 10:34:23 +00:00
|
|
|
speedValue *= 0.95 + 0.4 * Math.Min(1.0, totalHits / 2000.0) +
|
|
|
|
(totalHits > 2000 ? Math.Log10(totalHits / 2000.0) * 0.5 : 0.0);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
// Penalize misses exponentially. This mainly fixes tag4 maps and the likes until a per-hitobject solution is available
|
2019-11-26 10:34:23 +00:00
|
|
|
speedValue *= Math.Pow(0.97, countMiss);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
// Combo scaling
|
|
|
|
if (beatmapMaxCombo > 0)
|
2019-11-26 10:34:23 +00:00
|
|
|
speedValue *= Math.Min(Math.Pow(scoreMaxCombo, 0.8) / Math.Pow(beatmapMaxCombo, 0.8), 1.0);
|
2019-01-09 08:47:39 +00:00
|
|
|
|
2019-11-26 10:34:23 +00:00
|
|
|
double approachRateFactor = 1.0;
|
|
|
|
if (Attributes.ApproachRate > 10.33)
|
|
|
|
approachRateFactor += 0.3 * (Attributes.ApproachRate - 10.33);
|
2019-01-09 08:42:48 +00:00
|
|
|
|
|
|
|
speedValue *= approachRateFactor;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
2018-05-12 06:46:25 +00:00
|
|
|
if (mods.Any(m => m is OsuModHidden))
|
2019-11-26 10:34:23 +00:00
|
|
|
speedValue *= 1.0 + 0.04 * (12.0 - Attributes.ApproachRate);
|
2018-05-12 06:46:25 +00:00
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
// Scale the speed value with accuracy _slightly_
|
2019-11-26 10:34:23 +00:00
|
|
|
speedValue *= 0.02 + accuracy;
|
2018-04-13 09:19:50 +00:00
|
|
|
// It is important to also consider accuracy difficulty when doing that
|
2019-11-26 10:34:23 +00:00
|
|
|
speedValue *= 0.96 + Math.Pow(Attributes.OverallDifficulty, 2) / 1600;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
return speedValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
private double computeAccuracyValue()
|
|
|
|
{
|
|
|
|
// This percentage only considers HitCircles of any value - in this part of the calculation we focus on hitting the timing hit window
|
|
|
|
double betterAccuracyPercentage;
|
|
|
|
int amountHitObjectsWithAccuracy = countHitCircles;
|
|
|
|
|
|
|
|
if (amountHitObjectsWithAccuracy > 0)
|
2020-05-18 10:22:03 +00:00
|
|
|
betterAccuracyPercentage = ((countGreat - (totalHits - amountHitObjectsWithAccuracy)) * 6 + countGood * 2 + countMeh) / (double)(amountHitObjectsWithAccuracy * 6);
|
2018-04-13 09:19:50 +00:00
|
|
|
else
|
|
|
|
betterAccuracyPercentage = 0;
|
|
|
|
|
|
|
|
// It is possible to reach a negative accuracy with this formula. Cap it at zero - zero points
|
|
|
|
if (betterAccuracyPercentage < 0)
|
|
|
|
betterAccuracyPercentage = 0;
|
|
|
|
|
|
|
|
// Lots of arbitrary values from testing.
|
|
|
|
// Considering to use derivation from perfect accuracy in a probabilistic manner - assume normal distribution
|
2019-11-26 10:34:23 +00:00
|
|
|
double accuracyValue = Math.Pow(1.52163, Attributes.OverallDifficulty) * Math.Pow(betterAccuracyPercentage, 24) * 2.83;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
// Bonus for many hitcircles - it's harder to keep good accuracy up for longer
|
2019-11-26 10:34:23 +00:00
|
|
|
accuracyValue *= Math.Min(1.15, Math.Pow(amountHitObjectsWithAccuracy / 1000.0, 0.3));
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
if (mods.Any(m => m is OsuModHidden))
|
2019-11-26 10:34:23 +00:00
|
|
|
accuracyValue *= 1.08;
|
2018-04-13 09:19:50 +00:00
|
|
|
if (mods.Any(m => m is OsuModFlashlight))
|
2019-11-26 10:34:23 +00:00
|
|
|
accuracyValue *= 1.02;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
return accuracyValue;
|
|
|
|
}
|
|
|
|
|
2020-05-18 09:45:32 +00:00
|
|
|
private int totalHits => countGreat + countGood + countMeh + countMiss;
|
|
|
|
private int totalSuccessfulHits => countGreat + countGood + countMeh;
|
2018-04-13 09:19:50 +00:00
|
|
|
}
|
|
|
|
}
|