1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-21 04:03:00 +08:00
osu-lazer/osu.Game.Rulesets.Osu/Difficulty/Skills/Flashlight.cs

102 lines
3.7 KiB
C#
Raw Normal View History

2021-11-18 06:47:41 +08:00
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
2021-08-08 21:56:03 +08:00
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Linq;
2021-08-08 21:56:03 +08:00
using osu.Game.Rulesets.Difficulty.Preprocessing;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Osu.Mods;
2021-08-08 21:56:03 +08:00
using osu.Game.Rulesets.Osu.Difficulty.Preprocessing;
using osu.Game.Rulesets.Osu.Objects;
namespace osu.Game.Rulesets.Osu.Difficulty.Skills
{
/// <summary>
/// Represents the skill required to memorise and hit every object in a map with the Flashlight mod enabled.
/// </summary>
public class Flashlight : OsuStrainSkill
{
public Flashlight(Mod[] mods)
2021-08-08 21:56:03 +08:00
: base(mods)
{
hidden = mods.Any(m => m is OsuModHidden);
2021-08-08 21:56:03 +08:00
}
private double skillMultiplier => 0.05;
private double strainDecayBase => 0.15;
2021-08-08 21:56:03 +08:00
protected override double DecayWeight => 1.0;
private readonly bool hidden;
2021-11-22 05:59:41 +08:00
private const double max_opacity_bonus = 0.4;
private const double hidden_bonus = 0.2;
private double currentStrain;
2021-08-08 21:56:03 +08:00
private double strainValueOf(DifficultyHitObject current)
2021-08-08 21:56:03 +08:00
{
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;
2021-09-14 08:23:11 +08:00
double cumulativeStrainTime = 0.0;
2021-08-08 21:56:03 +08:00
double result = 0.0;
2021-12-21 11:39:34 +08:00
OsuDifficultyHitObject lastObj = osuCurrent;
// This is iterating backwards in time from the current object.
for (int i = 0; i < Math.Min(current.Position, 10); i++)
2021-08-08 21:56:03 +08:00
{
var currentObj = (OsuDifficultyHitObject)current.Previous(i);
var currentHitObject = (OsuHitObject)(currentObj.BaseObject);
2021-08-08 21:56:03 +08:00
if (!(currentObj.BaseObject is Spinner))
2021-08-10 14:06:20 +08:00
{
double jumpDistance = (osuHitObject.StackedPosition - currentHitObject.EndPosition).Length;
2021-08-09 06:31:28 +08:00
cumulativeStrainTime += lastObj.StrainTime;
2021-08-08 21:56:03 +08:00
2021-09-14 08:23:11 +08:00
// 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);
2021-08-08 21:56:03 +08:00
2021-09-14 08:23:11 +08:00
// 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);
2021-08-08 21:56:03 +08:00
// Bonus based on how visible the object is.
2022-05-12 16:19:07 +08:00
double opacityBonus = 1.0 + max_opacity_bonus * (1.0 - osuCurrent.OpacityAt(currentHitObject.StartTime, hidden));
2021-12-21 17:10:19 +08:00
result += stackNerf * opacityBonus * scalingFactor * jumpDistance / cumulativeStrainTime;
2021-08-08 21:56:03 +08:00
}
lastObj = currentObj;
2021-08-08 21:56:03 +08:00
}
result = Math.Pow(smallDistNerf * result, 2.0);
// Additional bonus for Hidden due to there being no approach circles.
if (hidden)
2021-11-12 18:42:27 +08:00
result *= 1.0 + hidden_bonus;
return result;
}
private double strainDecay(double ms) => Math.Pow(strainDecayBase, ms / 1000);
protected override double CalculateInitialStrain(double time, DifficultyHitObject current) => currentStrain * strainDecay(time - current.Previous(0).StartTime);
protected override double StrainValueAt(DifficultyHitObject current)
{
currentStrain *= strainDecay(current.DeltaTime);
currentStrain += strainValueOf(current) * skillMultiplier;
return currentStrain;
}
2021-08-08 21:56:03 +08:00
}
}