osu/osu.Game.Rulesets.Taiko/Difficulty/Skills/Rhythm.cs

114 lines
3.7 KiB
C#
Raw Normal View History

2020-06-08 07:30:26 +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.
using System;
using osu.Game.Rulesets.Difficulty.Preprocessing;
using osu.Game.Rulesets.Difficulty.Skills;
2020-08-18 17:13:18 +00:00
using osu.Game.Rulesets.Difficulty.Utils;
2020-06-08 07:30:26 +00: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;
private const double strain_decay = 0.96;
private double currentStrain;
2020-08-18 17:13:18 +00:00
private readonly LimitedCapacityQueue<TaikoDifficultyHitObject> rhythmHistory = new LimitedCapacityQueue<TaikoDifficultyHitObject>(rhythm_history_max_length);
2020-06-08 07:30:26 +00:00
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;
2020-08-18 17:13:18 +00:00
rhythmHistory.Enqueue(hitobject);
2020-06-08 07:30:26 +00: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 07:30:26 +00:00
int notesSince = hitobject.ObjectIndex - rhythmHistory[start].ObjectIndex;
penalty *= repetitionPenalty(notesSince);
break;
2020-06-08 07:30:26 +00: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-06-08 07:30:26 +00:00
private double patternLengthPenalty(int patternLength)
{
double shortPatternPenalty = Math.Min(0.15 * patternLength, 1.0);
2020-08-18 17:50:16 +00:00
double longPatternPenalty = Math.Clamp(2.5 - 0.15 * patternLength, 0.0, 1.0);
2020-06-08 07:30:26 +00: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);
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;
2020-08-18 17:34:44 +00:00
if (hitobject.Rhythm.Difficulty == 0.0)
2020-06-08 07:30:26 +00:00
{
return 0.0;
}
double objectStrain = hitobject.Rhythm.Difficulty;
objectStrain *= repetitionPenalties(hitobject);
objectStrain *= patternLengthPenalty(notesSinceRhythmChange);
2020-08-12 15:59:22 +00:00
objectStrain *= speedPenalty(hitobject.DeltaTime);
2020-06-08 07:30:26 +00:00
notesSinceRhythmChange = 0;
currentStrain += objectStrain;
return currentStrain;
}
}
}