1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-06 18:30:34 +08:00
osu-lazer/osu.Game.Rulesets.Taiko/Difficulty/Skills/Colour.cs

142 lines
5.1 KiB
C#
Raw Normal View History

2020-05-11 13:50:02 +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;
using osu.Game.Rulesets.Mods;
2020-05-11 13:50:02 +08:00
using osu.Game.Rulesets.Taiko.Difficulty.Preprocessing;
using osu.Game.Rulesets.Taiko.Objects;
namespace osu.Game.Rulesets.Taiko.Difficulty.Skills
{
/// <summary>
/// Calculates the colour coefficient of taiko difficulty.
/// </summary>
public class Colour : StrainDecaySkill
2020-05-11 13:50:02 +08:00
{
protected override double SkillMultiplier => 1;
2020-05-22 19:50:21 +08:00
protected override double StrainDecayBase => 0.4;
2020-05-11 13:50:02 +08:00
/// <summary>
/// Maximum number of entries to keep in <see cref="monoHistory"/>.
/// </summary>
2020-08-22 23:51:35 +08:00
private const int mono_history_max_length = 5;
2020-05-11 13:50:02 +08:00
2020-08-13 12:47:35 +08:00
/// <summary>
/// Queue with the lengths of the last <see cref="mono_history_max_length"/> most recent mono (single-colour) patterns,
/// with the most recent value at the end of the queue.
2020-08-13 12:47:35 +08:00
/// </summary>
2020-08-22 23:51:35 +08:00
private readonly LimitedCapacityQueue<int> monoHistory = new LimitedCapacityQueue<int>(mono_history_max_length);
/// <summary>
/// The <see cref="HitType"/> of the last object hit before the one being considered.
/// </summary>
2020-08-22 23:51:35 +08:00
private HitType? previousHitType;
2020-08-13 12:47:35 +08:00
/// <summary>
2020-08-22 23:51:35 +08:00
/// Length of the current mono pattern.
2020-08-13 12:47:35 +08:00
/// </summary>
private int currentMonoLength;
2020-05-11 13:53:42 +08:00
public Colour(Mod[] mods)
: base(mods)
{
}
2020-08-13 00:35:56 +08:00
protected override double StrainValueOf(DifficultyHitObject current)
2020-05-22 19:50:21 +08:00
{
// changing from/to a drum roll or a swell does not constitute a colour change.
// hits spaced more than a second apart are also exempt from colour strain.
2020-08-13 00:35:56 +08:00
if (!(current.LastObject is Hit && current.BaseObject is Hit && current.DeltaTime < 1000))
{
monoHistory.Clear();
var currentHit = current.BaseObject as Hit;
currentMonoLength = currentHit != null ? 1 : 0;
previousHitType = currentHit?.Type;
2020-08-13 00:35:56 +08:00
return 0.0;
}
var taikoCurrent = (TaikoDifficultyHitObject)current;
double objectStrain = 0.0;
2020-08-19 01:39:03 +08:00
if (previousHitType != null && taikoCurrent.HitType != previousHitType)
2020-08-13 00:35:56 +08:00
{
2020-08-13 12:47:35 +08:00
// The colour has changed.
2020-08-13 00:35:56 +08:00
objectStrain = 1.0;
if (monoHistory.Count < 2)
2020-08-13 12:47:35 +08:00
{
// There needs to be at least two streaks to determine a strain.
2020-08-13 00:35:56 +08:00
objectStrain = 0.0;
2020-08-13 12:47:35 +08:00
}
2020-08-13 00:35:56 +08:00
else if ((monoHistory[^1] + currentMonoLength) % 2 == 0)
2020-08-13 12:47:35 +08:00
{
// The last streak in the history is guaranteed to be a different type to the current streak.
2020-08-22 23:15:08 +08:00
// If the total number of notes in the two streaks is even, nullify this object's strain.
objectStrain = 0.0;
2020-08-13 12:47:35 +08:00
}
2020-08-13 00:35:56 +08:00
objectStrain *= repetitionPenalties();
currentMonoLength = 1;
}
else
{
currentMonoLength += 1;
}
previousHitType = taikoCurrent.HitType;
return objectStrain;
2020-05-22 19:50:21 +08:00
}
2020-05-11 13:53:42 +08:00
2020-08-13 12:47:35 +08:00
/// <summary>
/// The penalty to apply due to the length of repetition in colour streaks.
/// </summary>
2020-06-08 15:30:26 +08:00
private double repetitionPenalties()
2020-05-11 13:50:02 +08:00
{
const int most_recent_patterns_to_compare = 2;
2020-06-08 15:30:26 +08:00
double penalty = 1.0;
2020-05-11 13:50:02 +08:00
2020-08-19 01:13:18 +08:00
monoHistory.Enqueue(currentMonoLength);
2020-05-11 13:50:02 +08:00
for (int start = monoHistory.Count - most_recent_patterns_to_compare - 1; start >= 0; start--)
2020-06-08 15:30:26 +08:00
{
if (!isSamePattern(start, most_recent_patterns_to_compare))
continue;
2020-05-22 19:50:21 +08:00
int notesSince = 0;
for (int i = start; i < monoHistory.Count; i++) notesSince += monoHistory[i];
penalty *= repetitionPenalty(notesSince);
break;
2020-06-08 15:30:26 +08:00
}
2020-05-11 13:50:02 +08:00
2020-06-08 15:30:26 +08:00
return penalty;
}
2020-05-11 13:50:02 +08:00
/// <summary>
/// Determines whether the last <paramref name="mostRecentPatternsToCompare"/> patterns have repeated in the history
/// of single-colour note sequences, starting from <paramref name="start"/>.
/// </summary>
private bool isSamePattern(int start, int mostRecentPatternsToCompare)
{
for (int i = 0; i < mostRecentPatternsToCompare; i++)
{
if (monoHistory[start + i] != monoHistory[monoHistory.Count - mostRecentPatternsToCompare + i])
return false;
}
return true;
}
/// <summary>
/// Calculates the strain penalty for a colour pattern repetition.
/// </summary>
/// <param name="notesSince">The number of notes since the last repetition of the pattern.</param>
2020-08-13 12:47:35 +08:00
private double repetitionPenalty(int notesSince) => Math.Min(1.0, 0.032 * notesSince);
2020-05-11 13:50:02 +08:00
}
}