1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-12 08:27:26 +08:00
osu-lazer/osu.Game.Rulesets.Taiko/Difficulty/Skills/Rhythm.cs
2020-08-13 00:59:22 +09:00

116 lines
3.8 KiB
C#

// 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 System.Collections.Generic;
using osu.Game.Rulesets.Difficulty.Preprocessing;
using osu.Game.Rulesets.Difficulty.Skills;
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;
private const double strain_decay = 0.96;
private double currentStrain;
private readonly List<TaikoDifficultyHitObject> rhythmHistory = new List<TaikoDifficultyHitObject>();
private const int rhythm_history_max_length = 8;
private int notesSinceRhythmChange;
private double repetitionPenalty(int notesSince)
{
return Math.Min(1.0, 0.032 * notesSince);
}
// Finds repetitions and applies penalties
private double repetitionPenalties(TaikoDifficultyHitObject hitobject)
{
double penalty = 1;
rhythmHistory.Add(hitobject);
if (rhythmHistory.Count > rhythm_history_max_length)
rhythmHistory.RemoveAt(0);
for (int l = 2; l <= rhythm_history_max_length / 2; l++)
{
for (int start = rhythmHistory.Count - l - 1; start >= 0; start--)
{
bool samePattern = true;
for (int i = 0; i < l; i++)
{
if (rhythmHistory[start + i].Rhythm != rhythmHistory[rhythmHistory.Count - l + i].Rhythm)
{
samePattern = false;
}
}
if (samePattern) // Repetition found!
{
int notesSince = hitobject.ObjectIndex - rhythmHistory[start].ObjectIndex;
penalty *= repetitionPenalty(notesSince);
break;
}
}
}
return penalty;
}
private double patternLengthPenalty(int patternLength)
{
double shortPatternPenalty = Math.Min(0.15 * patternLength, 1.0);
double longPatternPenalty = Math.Max(Math.Min(2.5 - 0.15 * patternLength, 1.0), 0.0);
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);
currentStrain = 0.0;
notesSinceRhythmChange = 0;
return 0.0;
}
protected override double StrainValueOf(DifficultyHitObject current)
{
if (!(current.BaseObject is Hit))
{
currentStrain = 0.0;
notesSinceRhythmChange = 0;
return 0.0;
}
currentStrain *= strain_decay;
TaikoDifficultyHitObject hitobject = (TaikoDifficultyHitObject)current;
notesSinceRhythmChange += 1;
if (hitobject.Rhythm.IsRepeat)
{
return 0.0;
}
double objectStrain = hitobject.Rhythm.Difficulty;
objectStrain *= repetitionPenalties(hitobject);
objectStrain *= patternLengthPenalty(notesSinceRhythmChange);
objectStrain *= speedPenalty(hitobject.DeltaTime);
notesSinceRhythmChange = 0;
currentStrain += objectStrain;
return currentStrain;
}
}
}