osu/osu.Game.Rulesets.Osu/Difficulty/Skills/Aim.cs

129 lines
5.0 KiB
C#
Raw Normal View History

// 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 osu.Game.Rulesets.Difficulty.Preprocessing;
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-25 03:02:33 +00:00
using osu.Framework.Utils;
using osuTK;
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 correctly aim at every object in the map with a uniform CircleSize and normalized distances.
/// </summary>
2021-06-14 17:18:49 +00:00
public class Aim : OsuStrainSkill
2018-04-13 09:19:50 +00:00
{
public Aim(Mod[] mods)
: base(mods)
{
}
2021-09-25 03:02:33 +00:00
protected override int HistoryLength => 2;
private const double wide_angle_multiplier = 1.0;
private const double acute_angle_multiplier = 1.0;
private const double rhythm_variance_multiplier = 1.0;
2021-08-17 13:39:18 +00:00
private double currentStrain = 1;
2018-04-13 09:19:50 +00:00
2021-08-17 13:39:18 +00:00
private double skillMultiplier => 26.25;
private double strainDecayBase => 0.15;
private double strainValueOf(DifficultyHitObject current)
2018-12-08 06:01:26 +00:00
{
2021-09-25 03:02:33 +00:00
if (current.BaseObject is Spinner || Previous.Count <= 1)
2019-02-18 05:58:33 +00:00
return 0;
2021-09-25 03:02:33 +00:00
var osuCurrObj = (OsuDifficultyHitObject)current;
var osuPrevObj = (OsuDifficultyHitObject)Previous[0];
var osuLastObj = (OsuDifficultyHitObject)Previous[1];
2018-12-24 03:41:04 +00:00
2021-09-25 03:02:33 +00:00
var currVector = Vector2.Divide(osuCurrObj.JumpVector, (float)osuCurrObj.StrainTime);
var prevVector = Vector2.Divide(osuPrevObj.JumpVector, (float)osuPrevObj.StrainTime);
2019-01-29 07:35:20 +00:00
2021-09-25 03:02:33 +00:00
// Start with regular velocity.
double aimStrain = currVector.Length;
2021-09-25 03:02:33 +00:00
if (Precision.AlmostEquals(osuCurrObj.StrainTime, osuPrevObj.StrainTime, 10)) // Rhythms are the same.
{
if (osuCurrObj.Angle != null)
2018-12-21 13:52:27 +00:00
{
2021-09-25 03:02:33 +00:00
double angle = osuCurrObj.Angle.Value;
// Rewarding angles, take the smaller velocity as base.
double angleBonus = Math.Min(currVector.Length, prevVector.Length);
2021-09-25 03:02:33 +00:00
double wideAngleBonus = calcWideAngleBonus(angle);
double acuteAngleBonus = calcAcuteAngleBonus(angle);
if (osuCurrObj.StrainTime > 100)
acuteAngleBonus = 0;
else
{
acuteAngleBonus *= Math.Min(2, Math.Pow((100 - osuCurrObj.StrainTime) / 15, 1.5));
wideAngleBonus *= Math.Pow(osuCurrObj.StrainTime / 100, 6);
}
if (acuteAngleBonus > wideAngleBonus)
angleBonus = Math.Min(angleBonus, 150 / osuCurrObj.StrainTime) * Math.Min(1, Math.Pow(Math.Min(osuCurrObj.JumpDistance, osuPrevObj.JumpDistance) / 150, 2));
angleBonus *= Math.Max(acuteAngleBonus * acute_angle_multiplier, wideAngleBonus * wide_angle_multiplier);
// add in angle velocity.
aimStrain += angleBonus;
2018-12-21 13:52:27 +00:00
}
2018-12-21 05:52:43 +00:00
}
2021-09-25 03:02:33 +00:00
else // There is a rhythm change
{
// Rewarding rhythm, take the smaller velocity as base.
double rhythmBonus = Math.Min(currVector.Length, prevVector.Length);
2018-12-21 05:52:43 +00:00
2021-09-25 03:02:33 +00:00
if (osuCurrObj.StrainTime + 10 < osuPrevObj.StrainTime && osuPrevObj.StrainTime > osuLastObj.StrainTime + 10)
// Don't want to reward for a rhythm change back to back (unless its a double, which is why this only checks for fast -> slow -> fast).
rhythmBonus = 0;
2019-01-29 07:35:20 +00:00
2021-09-25 03:02:33 +00:00
aimStrain += rhythmBonus * rhythm_variance_multiplier; // add in rhythm velocity.
}
return aimStrain;
}
private double calcWideAngleBonus(double angle)
{
if (angle < Math.PI / 3)
return 0;
if (angle < 2 * Math.PI / 3)
return Math.Pow(Math.Sin(1.5 * (angle - Math.PI / 3)), 2);
return 0.25 + 0.75 * Math.Pow(Math.Sin(1.5 * (Math.PI - angle)), 2);
2018-12-08 06:01:26 +00:00
}
2021-09-25 03:02:33 +00:00
private double calcAcuteAngleBonus(double angle)
{
if (angle < Math.PI / 3)
return 0.5 + 0.5 * Math.Pow(Math.Sin(1.5 * angle), 2);
if (angle < 2 * Math.PI / 3)
return Math.Pow(Math.Sin(1.5 * (2 * Math.PI / 3 - angle)), 2);
return 0;
}
private double applyDiminishingExp(double val) => Math.Pow(val, 0.99);
2021-08-17 13:39:18 +00:00
private double strainDecay(double ms) => Math.Pow(strainDecayBase, ms / 1000);
protected override double CalculateInitialStrain(double time) => currentStrain * 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
return currentStrain;
}
2018-04-13 09:19:50 +00:00
}
}