1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-23 21:27:25 +08:00
osu-lazer/osu.Game.Rulesets.Taiko/Difficulty/Skills/Rhythm.cs

116 lines
3.7 KiB
C#
Raw Normal View History

2020-06-08 15:30:26 +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.
using System;
using osu.Game.Rulesets.Difficulty.Preprocessing;
using osu.Game.Rulesets.Difficulty.Skills;
2020-08-19 01:13:18 +08:00
using osu.Game.Rulesets.Difficulty.Utils;
2020-06-08 15:30:26 +08:00
using osu.Game.Rulesets.Taiko.Difficulty.Preprocessing;
using osu.Game.Rulesets.Taiko.Objects;
namespace osu.Game.Rulesets.Taiko.Difficulty.Skills
{
public class Rhythm : Skill
{
protected override double SkillMultiplier => 10;
protected override double StrainDecayBase => 0;
2020-08-22 23:51:35 +08:00
2020-06-08 15:30:26 +08:00
private const double strain_decay = 0.96;
2020-08-22 23:51:35 +08:00
private const int rhythm_history_max_length = 8;
2020-06-08 15:30:26 +08:00
2020-08-19 01:13:18 +08:00
private readonly LimitedCapacityQueue<TaikoDifficultyHitObject> rhythmHistory = new LimitedCapacityQueue<TaikoDifficultyHitObject>(rhythm_history_max_length);
2020-06-08 15:30:26 +08:00
2020-08-22 23:51:35 +08:00
private double currentStrain;
2020-06-08 15:30:26 +08:00
private int notesSinceRhythmChange;
2020-08-22 23:51:35 +08:00
protected override double StrainValueOf(DifficultyHitObject current)
2020-06-08 15:30:26 +08:00
{
2020-08-22 23:51:35 +08:00
if (!(current.BaseObject is Hit))
{
resetRhythmStrain();
return 0.0;
}
currentStrain *= strain_decay;
TaikoDifficultyHitObject hitobject = (TaikoDifficultyHitObject)current;
notesSinceRhythmChange += 1;
if (hitobject.Rhythm.Difficulty == 0.0)
{
return 0.0;
}
double objectStrain = hitobject.Rhythm.Difficulty;
objectStrain *= repetitionPenalties(hitobject);
objectStrain *= patternLengthPenalty(notesSinceRhythmChange);
objectStrain *= speedPenalty(hitobject.DeltaTime);
notesSinceRhythmChange = 0;
currentStrain += objectStrain;
return currentStrain;
2020-06-08 15:30:26 +08:00
}
// Finds repetitions and applies penalties
private double repetitionPenalties(TaikoDifficultyHitObject hitobject)
{
double penalty = 1;
2020-08-19 01:13:18 +08:00
rhythmHistory.Enqueue(hitobject);
2020-06-08 15:30:26 +08:00
for (int l = 2; l <= rhythm_history_max_length / 2; l++)
{
for (int start = rhythmHistory.Count - l - 1; start >= 0; start--)
{
if (!samePattern(start, l))
continue;
2020-06-08 15:30:26 +08:00
int notesSince = hitobject.ObjectIndex - rhythmHistory[start].ObjectIndex;
penalty *= repetitionPenalty(notesSince);
break;
2020-06-08 15:30:26 +08:00
}
}
return penalty;
}
private bool samePattern(int start, int l)
{
for (int i = 0; i < l; i++)
{
if (rhythmHistory[start + i].Rhythm != rhythmHistory[rhythmHistory.Count - l + i].Rhythm)
return false;
}
return true;
}
2020-08-22 23:51:35 +08:00
private double repetitionPenalty(int notesSince) => Math.Min(1.0, 0.032 * notesSince);
2020-06-08 15:30:26 +08:00
private double patternLengthPenalty(int patternLength)
{
double shortPatternPenalty = Math.Min(0.15 * patternLength, 1.0);
2020-08-19 01:50:16 +08:00
double longPatternPenalty = Math.Clamp(2.5 - 0.15 * patternLength, 0.0, 1.0);
2020-06-08 15:30:26 +08:00
return Math.Min(shortPatternPenalty, longPatternPenalty);
}
// Penalty for notes so slow that alternating is not necessary.
private double speedPenalty(double noteLengthMs)
{
if (noteLengthMs < 80) return 1;
if (noteLengthMs < 210) return Math.Max(0, 1.4 - 0.005 * noteLengthMs);
resetRhythmStrain();
2020-06-08 15:30:26 +08:00
return 0.0;
}
private void resetRhythmStrain()
{
currentStrain = 0.0;
notesSinceRhythmChange = 0;
}
2020-06-08 15:30:26 +08:00
}
}