// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using System.Collections.Generic; using System.Linq; using JetBrains.Annotations; using Newtonsoft.Json; using osu.Game.Beatmaps; using osu.Game.Rulesets.Difficulty; using osu.Game.Rulesets.Mods; namespace osu.Game.Rulesets.Osu.Difficulty { public class OsuDifficultyAttributes : DifficultyAttributes { /// /// The difficulty corresponding to the aim skill. /// [JsonProperty("aim_difficulty")] public double AimDifficulty { get; set; } /// /// The difficulty corresponding to the speed skill. /// [JsonProperty("speed_difficulty")] public double SpeedDifficulty { get; set; } /// /// The number of clickable objects weighted by difficulty. /// Related to /// [JsonProperty("speed_note_count")] public double SpeedNoteCount { get; set; } /// /// The difficulty corresponding to the flashlight skill. /// [JsonProperty("flashlight_difficulty")] public double FlashlightDifficulty { get; set; } /// /// Describes how much of is contributed to by hitcircles or sliders. /// A value closer to 1.0 indicates most of is contributed by hitcircles. /// A value closer to 0.0 indicates most of is contributed by sliders. /// [JsonProperty("slider_factor")] public double SliderFactor { get; set; } /// /// The perceived approach rate inclusive of rate-adjusting mods (DT/HT/etc). /// /// /// Rate-adjusting mods don't directly affect the approach rate difficulty value, but have a perceived effect as a result of adjusting audio timing. /// [JsonProperty("approach_rate")] public double ApproachRate { get; set; } /// /// The perceived overall difficulty inclusive of rate-adjusting mods (DT/HT/etc). /// /// /// Rate-adjusting mods don't directly affect the overall difficulty value, but have a perceived effect as a result of adjusting audio timing. /// [JsonProperty("overall_difficulty")] public double OverallDifficulty { get; set; } /// /// The beatmap's drain rate. This doesn't scale with rate-adjusting mods. /// public double DrainRate { get; set; } /// /// The number of hitcircles in the beatmap. /// public int HitCircleCount { get; set; } /// /// The number of sliders in the beatmap. /// public int SliderCount { get; set; } /// /// The number of spinners in the beatmap. /// public int SpinnerCount { get; set; } public override IEnumerable<(int attributeId, object value)> ToDatabaseAttributes() { foreach (var v in base.ToDatabaseAttributes()) yield return v; yield return (ATTRIB_ID_AIM, AimDifficulty); yield return (ATTRIB_ID_SPEED, SpeedDifficulty); yield return (ATTRIB_ID_OVERALL_DIFFICULTY, OverallDifficulty); yield return (ATTRIB_ID_APPROACH_RATE, ApproachRate); yield return (ATTRIB_ID_DIFFICULTY, StarRating); if (ShouldSerializeFlashlightDifficulty()) yield return (ATTRIB_ID_FLASHLIGHT, FlashlightDifficulty); yield return (ATTRIB_ID_SLIDER_FACTOR, SliderFactor); yield return (ATTRIB_ID_SPEED_NOTE_COUNT, SpeedNoteCount); } public override void FromDatabaseAttributes(IReadOnlyDictionary values, IBeatmapOnlineInfo onlineInfo) { base.FromDatabaseAttributes(values, onlineInfo); AimDifficulty = values[ATTRIB_ID_AIM]; SpeedDifficulty = values[ATTRIB_ID_SPEED]; OverallDifficulty = values[ATTRIB_ID_OVERALL_DIFFICULTY]; ApproachRate = values[ATTRIB_ID_APPROACH_RATE]; StarRating = values[ATTRIB_ID_DIFFICULTY]; FlashlightDifficulty = values.GetValueOrDefault(ATTRIB_ID_FLASHLIGHT); SliderFactor = values[ATTRIB_ID_SLIDER_FACTOR]; SpeedNoteCount = values[ATTRIB_ID_SPEED_NOTE_COUNT]; DrainRate = onlineInfo.DrainRate; HitCircleCount = onlineInfo.CircleCount; SliderCount = onlineInfo.SliderCount; SpinnerCount = onlineInfo.SpinnerCount; } #region Newtonsoft.Json implicit ShouldSerialize() methods // The properties in this region are used implicitly by Newtonsoft.Json to not serialise certain fields in some cases. // They rely on being named exactly the same as the corresponding fields (casing included) and as such should NOT be renamed // unless the fields are also renamed. [UsedImplicitly] public bool ShouldSerializeFlashlightDifficulty() => Mods.Any(m => m is ModFlashlight); #endregion } }