2022-05-28 20:28:04 +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.
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
#nullable disable
|
|
|
|
|
2022-05-28 20:29:09 +08:00
|
|
|
using System;
|
|
|
|
using osu.Game.Rulesets.Difficulty.Preprocessing;
|
|
|
|
using osu.Game.Rulesets.Osu.Difficulty.Preprocessing;
|
|
|
|
using osu.Game.Rulesets.Osu.Objects;
|
|
|
|
|
2022-05-28 20:28:04 +08:00
|
|
|
namespace osu.Game.Rulesets.Osu.Difficulty.Evaluators
|
|
|
|
{
|
2022-05-28 20:29:09 +08:00
|
|
|
public static class FlashlightEvaluator
|
2022-05-28 20:28:04 +08:00
|
|
|
{
|
2022-05-28 20:29:09 +08:00
|
|
|
private const double max_opacity_bonus = 0.4;
|
|
|
|
private const double hidden_bonus = 0.2;
|
|
|
|
|
2022-07-17 14:27:55 +08:00
|
|
|
private const double min_velocity = 0.5;
|
|
|
|
private const double slider_multiplier = 1.3;
|
|
|
|
|
2022-05-28 21:09:08 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Evaluates the difficulty of memorising and hitting an object, based on:
|
|
|
|
/// <list type="bullet">
|
2022-07-18 13:59:20 +08:00
|
|
|
/// <item><description>distance between a number of previous objects and the current object,</description></item>
|
2022-05-28 21:09:08 +08:00
|
|
|
/// <item><description>the visual opacity of the current object,</description></item>
|
2022-07-17 15:02:30 +08:00
|
|
|
/// <item><description>length and speed of the current object (for sliders),</description></item>
|
2022-05-28 21:09:08 +08:00
|
|
|
/// <item><description>and whether the hidden mod is enabled.</description></item>
|
|
|
|
/// </list>
|
|
|
|
/// </summary>
|
2022-05-28 20:29:09 +08:00
|
|
|
public static double EvaluateDifficultyOf(DifficultyHitObject current, bool hidden)
|
|
|
|
{
|
|
|
|
if (current.BaseObject is Spinner)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
var osuCurrent = (OsuDifficultyHitObject)current;
|
|
|
|
var osuHitObject = (OsuHitObject)(osuCurrent.BaseObject);
|
|
|
|
|
|
|
|
double scalingFactor = 52.0 / osuHitObject.Radius;
|
|
|
|
double smallDistNerf = 1.0;
|
|
|
|
double cumulativeStrainTime = 0.0;
|
|
|
|
|
|
|
|
double result = 0.0;
|
|
|
|
|
|
|
|
OsuDifficultyHitObject lastObj = osuCurrent;
|
|
|
|
|
|
|
|
// This is iterating backwards in time from the current object.
|
2022-06-13 19:27:02 +08:00
|
|
|
for (int i = 0; i < Math.Min(current.Index, 10); i++)
|
2022-05-28 20:29:09 +08:00
|
|
|
{
|
|
|
|
var currentObj = (OsuDifficultyHitObject)current.Previous(i);
|
|
|
|
var currentHitObject = (OsuHitObject)(currentObj.BaseObject);
|
|
|
|
|
|
|
|
if (!(currentObj.BaseObject is Spinner))
|
|
|
|
{
|
|
|
|
double jumpDistance = (osuHitObject.StackedPosition - currentHitObject.EndPosition).Length;
|
|
|
|
|
|
|
|
cumulativeStrainTime += lastObj.StrainTime;
|
|
|
|
|
|
|
|
// We want to nerf objects that can be easily seen within the Flashlight circle radius.
|
|
|
|
if (i == 0)
|
|
|
|
smallDistNerf = Math.Min(1.0, jumpDistance / 75.0);
|
|
|
|
|
|
|
|
// We also want to nerf stacks so that only the first object of the stack is accounted for.
|
|
|
|
double stackNerf = Math.Min(1.0, (currentObj.LazyJumpDistance / scalingFactor) / 25.0);
|
|
|
|
|
|
|
|
// Bonus based on how visible the object is.
|
|
|
|
double opacityBonus = 1.0 + max_opacity_bonus * (1.0 - osuCurrent.OpacityAt(currentHitObject.StartTime, hidden));
|
|
|
|
|
|
|
|
result += stackNerf * opacityBonus * scalingFactor * jumpDistance / cumulativeStrainTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
lastObj = currentObj;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = Math.Pow(smallDistNerf * result, 2.0);
|
|
|
|
|
|
|
|
// Additional bonus for Hidden due to there being no approach circles.
|
|
|
|
if (hidden)
|
|
|
|
result *= 1.0 + hidden_bonus;
|
|
|
|
|
2022-07-17 14:27:55 +08:00
|
|
|
double sliderBonus = 0.0;
|
|
|
|
|
2022-07-18 13:59:00 +08:00
|
|
|
if (osuCurrent.BaseObject is Slider osuSlider)
|
2022-07-17 14:27:55 +08:00
|
|
|
{
|
|
|
|
// Invert the scaling factor to determine the true travel distance independent of circle size.
|
2022-07-23 12:40:16 +08:00
|
|
|
double pixelTravelDistance = osuSlider.LazyTravelDistance / scalingFactor;
|
2022-07-17 14:27:55 +08:00
|
|
|
|
|
|
|
// Reward sliders based on velocity.
|
|
|
|
sliderBonus = Math.Pow(Math.Max(0.0, pixelTravelDistance / osuCurrent.TravelTime - min_velocity), 0.5);
|
|
|
|
|
|
|
|
// Longer sliders require more memorisation.
|
|
|
|
sliderBonus *= pixelTravelDistance;
|
2022-07-17 14:56:05 +08:00
|
|
|
|
2022-07-18 14:14:06 +08:00
|
|
|
// Nerf sliders with repeats, as less memorisation is required.
|
2022-07-17 14:56:05 +08:00
|
|
|
if (osuSlider.RepeatCount > 0)
|
2022-07-18 14:14:06 +08:00
|
|
|
sliderBonus /= (osuSlider.RepeatCount + 1);
|
2022-07-17 14:27:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
result += sliderBonus * slider_multiplier;
|
|
|
|
|
2022-05-28 20:29:09 +08:00
|
|
|
return result;
|
|
|
|
}
|
2022-05-28 20:28:04 +08:00
|
|
|
}
|
|
|
|
}
|