// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using System; using System.Collections.Generic; using System.Linq; using osu.Game.Rulesets.Difficulty.Preprocessing; using osu.Game.Rulesets.Objects; using osu.Game.Rulesets.Taiko.Objects; using osu.Game.Rulesets.Taiko.Difficulty.Preprocessing.Colour; using osu.Game.Rulesets.Taiko.Difficulty.Preprocessing.Rhythm; namespace osu.Game.Rulesets.Taiko.Difficulty.Preprocessing { /// /// Represents a single hit object in taiko difficulty calculation. /// public class TaikoDifficultyHitObject : DifficultyHitObject { /// /// The list of all of the same colour as this in the beatmap. /// private readonly IReadOnlyList? monoDifficultyHitObjects; /// /// The index of this in . /// public readonly int MonoIndex; /// /// The list of all that is either a regular note or finisher in the beatmap /// private readonly IReadOnlyList noteDifficultyHitObjects; /// /// The index of this in . /// public readonly int NoteIndex; /// /// The rhythm required to hit this hit object. /// public readonly TaikoDifficultyHitObjectRhythm Rhythm; /// /// Colour data for this hit object. This is used by colour evaluator to calculate colour difficulty, but can be used /// by other skills in the future. /// public readonly TaikoDifficultyHitObjectColour Colour; /// /// Creates a new difficulty hit object. /// /// The gameplay associated with this difficulty object. /// The gameplay preceding . /// The gameplay preceding . /// The rate of the gameplay clock. Modified by speed-changing mods. /// The list of all s in the current beatmap. /// The list of centre (don) s in the current beatmap. /// The list of rim (kat) s in the current beatmap. /// The list of s that is a hit (i.e. not a drumroll or swell) in the current beatmap. /// The position of this in the list. public TaikoDifficultyHitObject(HitObject hitObject, HitObject lastObject, HitObject lastLastObject, double clockRate, List objects, List centreHitObjects, List rimHitObjects, List noteObjects, int index) : base(hitObject, lastObject, clockRate, objects, index) { noteDifficultyHitObjects = noteObjects; // Create the Colour object, its properties should be filled in by TaikoDifficultyPreprocessor Colour = new TaikoDifficultyHitObjectColour(); Rhythm = getClosestRhythm(lastObject, lastLastObject, clockRate); switch ((hitObject as Hit)?.Type) { case HitType.Centre: MonoIndex = centreHitObjects.Count; centreHitObjects.Add(this); monoDifficultyHitObjects = centreHitObjects; break; case HitType.Rim: MonoIndex = rimHitObjects.Count; rimHitObjects.Add(this); monoDifficultyHitObjects = rimHitObjects; break; } if (hitObject is Hit) { NoteIndex = noteObjects.Count; noteObjects.Add(this); } } /// /// List of most common rhythm changes in taiko maps. /// /// /// The general guidelines for the values are: /// /// rhythm changes with ratio closer to 1 (that are not 1) are harder to play, /// speeding up is generally harder than slowing down (with exceptions of rhythm changes requiring a hand switch). /// /// private static readonly TaikoDifficultyHitObjectRhythm[] common_rhythms = { new TaikoDifficultyHitObjectRhythm(1, 1, 0.0), new TaikoDifficultyHitObjectRhythm(2, 1, 0.3), new TaikoDifficultyHitObjectRhythm(1, 2, 0.5), new TaikoDifficultyHitObjectRhythm(3, 1, 0.3), new TaikoDifficultyHitObjectRhythm(1, 3, 0.35), new TaikoDifficultyHitObjectRhythm(3, 2, 0.6), // purposefully higher (requires hand switch in full alternating gameplay style) new TaikoDifficultyHitObjectRhythm(2, 3, 0.4), new TaikoDifficultyHitObjectRhythm(5, 4, 0.5), new TaikoDifficultyHitObjectRhythm(4, 5, 0.7) }; /// /// Returns the closest rhythm change from required to hit this object. /// /// The gameplay preceding this one. /// The gameplay preceding . /// The rate of the gameplay clock. private TaikoDifficultyHitObjectRhythm getClosestRhythm(HitObject lastObject, HitObject lastLastObject, double clockRate) { double prevLength = (lastObject.StartTime - lastLastObject.StartTime) / clockRate; double ratio = DeltaTime / prevLength; return common_rhythms.OrderBy(x => Math.Abs(x.Ratio - ratio)).First(); } public TaikoDifficultyHitObject? PreviousMono(int backwardsIndex) => monoDifficultyHitObjects?.ElementAtOrDefault(MonoIndex - (backwardsIndex + 1)); public TaikoDifficultyHitObject? NextMono(int forwardsIndex) => monoDifficultyHitObjects?.ElementAtOrDefault(MonoIndex + (forwardsIndex + 1)); public TaikoDifficultyHitObject? PreviousNote(int backwardsIndex) => noteDifficultyHitObjects.ElementAtOrDefault(NoteIndex - (backwardsIndex + 1)); public TaikoDifficultyHitObject? NextNote(int forwardsIndex) => noteDifficultyHitObjects.ElementAtOrDefault(NoteIndex + (forwardsIndex + 1)); } }