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
2018-12-18 00:38:02 +00:00
using System ;
2019-02-12 07:03:28 +00:00
using osu.Game.Rulesets.Difficulty.Preprocessing ;
2021-02-06 04:06:16 +00:00
using osu.Game.Rulesets.Mods ;
2018-05-15 08:36:29 +00:00
using osu.Game.Rulesets.Osu.Difficulty.Preprocessing ;
2019-02-18 05:58:33 +00:00
using osu.Game.Rulesets.Osu.Objects ;
2021-09-12 16:08:17 +00:00
using osu.Framework.Utils ;
2018-04-13 09:19:50 +00:00
2018-05-15 08:36:29 +00:00
namespace osu.Game.Rulesets.Osu.Difficulty.Skills
2018-04-13 09:19:50 +00:00
{
/// <summary>
/// Represents the skill required to press keys with regards to keeping up with the speed at which objects need to be hit.
/// </summary>
2021-06-14 17:18:49 +00:00
public class Speed : OsuStrainSkill
2018-04-13 09:19:50 +00:00
{
2019-02-12 07:03:28 +00:00
private const double single_spacing_threshold = 125 ;
2021-10-05 23:39:01 +00:00
private const double rhythm_multiplier = 0.75 ;
2021-09-25 02:52:10 +00:00
private const int history_time_max = 5000 ; // 5 seconds of calculatingRhythmBonus max.
2021-09-29 19:14:54 +00:00
private const double min_speed_bonus = 75 ; // ~200BPM
private const double speed_balancing_factor = 40 ;
2021-08-17 13:39:18 +00:00
2021-08-19 14:12:03 +00:00
private double skillMultiplier = > 1375 ;
2021-08-17 13:39:18 +00:00
private double strainDecayBase = > 0.3 ;
2021-11-08 00:53:51 +00:00
private double currentStrain ;
private double currentRhythm ;
2021-08-17 13:39:18 +00:00
2021-06-16 13:13:46 +00:00
protected override int ReducedSectionCount = > 5 ;
2021-08-17 14:39:43 +00:00
protected override double DifficultyMultiplier = > 1.04 ;
2021-08-17 13:39:18 +00:00
protected override int HistoryLength = > 32 ;
2021-09-15 09:29:30 +00:00
private readonly double greatWindow ;
2018-12-18 00:51:49 +00:00
2021-09-15 09:52:50 +00:00
public Speed ( Mod [ ] mods , double hitWindowGreat )
2021-02-06 04:06:16 +00:00
: base ( mods )
{
2021-09-15 09:52:50 +00:00
greatWindow = hitWindowGreat ;
2021-02-06 04:06:16 +00:00
}
2021-08-17 13:39:18 +00:00
/// <summary>
/// Calculates a rhythm multiplier for the difficulty of the tap associated with historic data of the current <see cref="OsuDifficultyHitObject"/>.
/// </summary>
2021-10-03 04:35:37 +00:00
private double calculateRhythmBonus ( DifficultyHitObject current )
2018-04-13 09:19:50 +00:00
{
2021-08-17 19:25:49 +00:00
if ( current . BaseObject is Spinner )
return 0 ;
2021-10-03 04:35:37 +00:00
int previousIslandSize = 0 ;
2021-08-19 14:12:03 +00:00
double rhythmComplexitySum = 0 ;
2021-10-03 04:35:37 +00:00
int islandSize = 1 ;
2021-09-29 19:14:54 +00:00
double startRatio = 0 ; // store the ratio of the current start of an island to buff for tighter rhythms
2021-08-17 13:39:18 +00:00
bool firstDeltaSwitch = false ;
2021-12-14 16:16:10 +00:00
int rhythmStart = 0 ;
2021-12-13 20:25:29 +00:00
while ( rhythmStart < Previous . Count - 2 & & current . StartTime - Previous [ rhythmStart ] . StartTime < history_time_max )
rhythmStart + + ;
for ( int i = rhythmStart ; i > 0 ; i - - )
2021-08-17 13:39:18 +00:00
{
2021-10-03 17:06:59 +00:00
OsuDifficultyHitObject currObj = ( OsuDifficultyHitObject ) Previous [ i - 1 ] ;
OsuDifficultyHitObject prevObj = ( OsuDifficultyHitObject ) Previous [ i ] ;
OsuDifficultyHitObject lastObj = ( OsuDifficultyHitObject ) Previous [ i + 1 ] ;
2021-09-12 16:08:17 +00:00
2021-12-14 23:36:45 +00:00
double currHistoricalDecay = ( history_time_max - ( current . StartTime - currObj . StartTime ) ) / history_time_max ; // scales note 0 to 1 from history to now
2021-08-17 13:39:18 +00:00
2021-12-14 23:36:45 +00:00
currHistoricalDecay = Math . Min ( ( double ) ( Previous . Count - i ) / Previous . Count , currHistoricalDecay ) ; // either we're limited by time or limited by object count.
2021-08-17 13:39:18 +00:00
2021-12-14 23:36:45 +00:00
double currDelta = currObj . StrainTime ;
double prevDelta = prevObj . StrainTime ;
double lastDelta = lastObj . StrainTime ;
double currRatio = 1.0 + 6.0 * Math . Min ( 0.5 , Math . Pow ( Math . Sin ( Math . PI / ( Math . Min ( prevDelta , currDelta ) / Math . Max ( prevDelta , currDelta ) ) ) , 2 ) ) ; // fancy function to calculate rhythmbonuses.
2021-08-17 13:39:18 +00:00
2021-12-14 23:36:45 +00:00
double windowPenalty = Math . Min ( 1 , Math . Max ( 0 , Math . Abs ( prevDelta - currDelta ) - greatWindow * 0.6 ) / ( greatWindow * 0.6 ) ) ;
2021-08-17 13:39:18 +00:00
2021-12-14 23:36:45 +00:00
windowPenalty = Math . Min ( 1 , windowPenalty ) ;
2021-10-05 23:39:01 +00:00
2021-12-14 23:36:45 +00:00
double effectiveRatio = windowPenalty * currRatio ;
2021-08-17 13:39:18 +00:00
2021-12-14 23:36:45 +00:00
if ( firstDeltaSwitch )
{
if ( ! ( prevDelta > 1.25 * currDelta | | prevDelta * 1.25 < currDelta ) )
2021-08-17 13:39:18 +00:00
{
2021-12-14 23:36:45 +00:00
if ( islandSize < 7 )
islandSize + + ; // island is still progressing, count size.
}
else
{
if ( Previous [ i - 1 ] . BaseObject is Slider ) // bpm change is into slider, this is easy acc window
effectiveRatio * = 0.125 ;
2021-08-17 13:39:18 +00:00
2021-12-14 23:36:45 +00:00
if ( Previous [ i ] . BaseObject is Slider ) // bpm change was from a slider, this is easier typically than circle -> circle
effectiveRatio * = 0.25 ;
2021-08-17 13:39:18 +00:00
2021-12-14 23:36:45 +00:00
if ( previousIslandSize = = islandSize ) // repeated island size (ex: triplet -> triplet)
effectiveRatio * = 0.25 ;
2021-08-17 13:39:18 +00:00
2021-12-14 23:36:45 +00:00
if ( previousIslandSize % 2 = = islandSize % 2 ) // repeated island polartiy (2 -> 4, 3 -> 5)
effectiveRatio * = 0.50 ;
2021-09-29 19:14:54 +00:00
2021-12-14 23:36:45 +00:00
if ( lastDelta > prevDelta + 10 & & prevDelta > currDelta + 10 ) // previous increase happened a note ago, 1/1->1/2-1/4, dont want to buff this.
effectiveRatio * = 0.125 ;
2021-08-21 17:23:17 +00:00
2021-12-14 23:36:45 +00:00
rhythmComplexitySum + = Math . Sqrt ( effectiveRatio * startRatio ) * currHistoricalDecay * Math . Sqrt ( 4 + islandSize ) / 2 * Math . Sqrt ( 4 + previousIslandSize ) / 2 ;
2021-09-29 19:14:54 +00:00
2021-12-14 23:36:45 +00:00
startRatio = effectiveRatio ;
2021-08-17 13:39:18 +00:00
2021-12-14 23:36:45 +00:00
previousIslandSize = islandSize ; // log the last island size.
2021-08-17 13:39:18 +00:00
2021-12-14 23:36:45 +00:00
if ( prevDelta * 1.25 < currDelta ) // we're slowing down, stop counting
firstDeltaSwitch = false ; // if we're speeding up, this stays true and we keep counting island size.
2021-08-17 13:39:18 +00:00
2021-10-03 04:35:37 +00:00
islandSize = 1 ;
2021-08-17 13:39:18 +00:00
}
}
2021-12-14 23:36:45 +00:00
else if ( prevDelta > 1.25 * currDelta ) // we want to be speeding up.
{
// Begin counting island until we change speed again.
firstDeltaSwitch = true ;
startRatio = effectiveRatio ;
islandSize = 1 ;
}
2021-08-17 13:39:18 +00:00
}
2021-09-29 19:14:54 +00:00
return Math . Sqrt ( 4 + rhythmComplexitySum * rhythm_multiplier ) / 2 ; //produces multiplier that can be applied to strain. range [1, infinity) (not really though)
2021-08-17 13:39:18 +00:00
}
2021-10-03 17:06:59 +00:00
private double strainValueOf ( DifficultyHitObject current )
2021-08-17 13:47:45 +00:00
{
if ( current . BaseObject is Spinner )
return 0 ;
2021-08-17 13:39:18 +00:00
2021-09-25 02:52:10 +00:00
// derive strainTime for calculation
var osuCurrObj = ( OsuDifficultyHitObject ) current ;
var osuPrevObj = Previous . Count > 0 ? ( OsuDifficultyHitObject ) Previous [ 0 ] : null ;
double strainTime = osuCurrObj . StrainTime ;
2021-09-15 10:12:36 +00:00
double greatWindowFull = greatWindow * 2 ;
2021-09-15 10:24:48 +00:00
double speedWindowRatio = strainTime / greatWindowFull ;
2021-09-03 01:39:21 +00:00
2021-09-15 10:12:36 +00:00
// Aim to nerf cheesy rhythms (Very fast consecutive doubles with large deltatimes between)
2021-09-25 02:52:10 +00:00
if ( osuPrevObj ! = null & & strainTime < greatWindowFull & & osuPrevObj . StrainTime > strainTime )
strainTime = Interpolation . Lerp ( osuPrevObj . StrainTime , strainTime , speedWindowRatio ) ;
2021-08-29 16:19:26 +00:00
2021-09-02 15:48:34 +00:00
// Cap deltatime to the OD 300 hitwindow.
2021-09-15 11:03:47 +00:00
// 0.93 is derived from making sure 260bpm OD8 streams aren't nerfed harshly, whilst 0.92 limits the effect of the cap.
2021-09-15 11:36:15 +00:00
strainTime / = Math . Clamp ( ( strainTime / greatWindowFull ) / 0.93 , 0.92 , 1 ) ;
2021-09-02 15:48:34 +00:00
2021-09-25 02:52:10 +00:00
// derive speedBonus for calculation
2021-08-17 19:25:49 +00:00
double speedBonus = 1.0 ;
2021-09-15 10:24:48 +00:00
if ( strainTime < min_speed_bonus )
2021-09-25 02:52:10 +00:00
speedBonus = 1 + 0.75 * Math . Pow ( ( min_speed_bonus - strainTime ) / speed_balancing_factor , 2 ) ;
2021-08-17 19:25:49 +00:00
2021-11-24 03:37:16 +00:00
double travelDistance = osuPrevObj ? . TravelDistance ? ? 0 ;
2021-12-08 06:53:44 +00:00
double distance = Math . Min ( single_spacing_threshold , travelDistance + osuCurrObj . MinimumJumpDistance ) ;
2021-08-17 19:25:49 +00:00
2021-10-03 17:06:59 +00:00
return ( speedBonus + speedBonus * Math . Pow ( distance / single_spacing_threshold , 3.5 ) ) / strainTime ;
}
2021-09-12 16:08:17 +00:00
2021-10-03 17:06:59 +00:00
private double strainDecay ( double ms ) = > Math . Pow ( strainDecayBase , ms / 1000 ) ;
protected override double CalculateInitialStrain ( double time ) = > ( currentStrain * currentRhythm ) * strainDecay ( time - Previous [ 0 ] . StartTime ) ;
protected override double StrainValueAt ( DifficultyHitObject current )
{
currentStrain * = strainDecay ( current . DeltaTime ) ;
currentStrain + = strainValueOf ( current ) * skillMultiplier ;
2021-08-17 13:39:18 +00:00
2021-10-03 17:06:59 +00:00
currentRhythm = calculateRhythmBonus ( current ) ;
2021-08-17 13:39:18 +00:00
2021-10-03 17:06:59 +00:00
return currentStrain * currentRhythm ;
2018-04-13 09:19:50 +00:00
}
}
}