// 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 Newtonsoft.Json; using osu.Game.Beatmaps; using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Scoring; namespace osu.Game.Rulesets.Difficulty { /// /// Describes the difficulty of a beatmap, as output by a . /// [JsonObject(MemberSerialization.OptIn)] public class DifficultyAttributes { protected const int ATTRIB_ID_AIM = 1; protected const int ATTRIB_ID_SPEED = 3; protected const int ATTRIB_ID_OVERALL_DIFFICULTY = 5; protected const int ATTRIB_ID_APPROACH_RATE = 7; protected const int ATTRIB_ID_MAX_COMBO = 9; protected const int ATTRIB_ID_DIFFICULTY = 11; protected const int ATTRIB_ID_GREAT_HIT_WINDOW = 13; protected const int ATTRIB_ID_SCORE_MULTIPLIER = 15; protected const int ATTRIB_ID_FLASHLIGHT = 17; protected const int ATTRIB_ID_SLIDER_FACTOR = 19; protected const int ATTRIB_ID_SPEED_NOTE_COUNT = 21; protected const int ATTRIB_ID_LEGACY_ACCURACY_SCORE = 23; protected const int ATTRIB_ID_LEGACY_COMBO_SCORE = 25; protected const int ATTRIB_ID_LEGACY_BONUS_SCORE_RATIO = 27; /// /// The mods which were applied to the beatmap. /// public Mod[] Mods { get; set; } = Array.Empty(); /// /// The combined star rating of all skills. /// [JsonProperty("star_rating", Order = -3)] public double StarRating { get; set; } /// /// The maximum achievable combo. /// [JsonProperty("max_combo", Order = -2)] public int MaxCombo { get; set; } /// /// The accuracy portion of the legacy (ScoreV1) total score. /// public int LegacyAccuracyScore { get; set; } /// /// The combo-multiplied portion of the legacy (ScoreV1) total score. /// public int LegacyComboScore { get; set; } /// /// A ratio of new_bonus_score / old_bonus_score for converting the bonus score of legacy scores to the new scoring. /// This is made up of all judgements that would be or . /// public double LegacyBonusScoreRatio { get; set; } /// /// Creates new . /// public DifficultyAttributes() { } /// /// Creates new . /// /// The mods which were applied to the beatmap. /// The combined star rating of all skills. public DifficultyAttributes(Mod[] mods, double starRating) { Mods = mods; StarRating = starRating; } /// /// Converts this to osu-web compatible database attribute mappings. /// /// /// See: osu_difficulty_attribs table. /// public virtual IEnumerable<(int attributeId, object value)> ToDatabaseAttributes() { yield return (ATTRIB_ID_MAX_COMBO, MaxCombo); yield return (ATTRIB_ID_LEGACY_ACCURACY_SCORE, LegacyAccuracyScore); yield return (ATTRIB_ID_LEGACY_COMBO_SCORE, LegacyComboScore); yield return (ATTRIB_ID_LEGACY_BONUS_SCORE_RATIO, LegacyBonusScoreRatio); } /// /// Reads osu-web database attribute mappings into this object. /// /// The attribute mappings. /// The where more information about the beatmap may be extracted from (such as AR/CS/OD/etc). public virtual void FromDatabaseAttributes(IReadOnlyDictionary values, IBeatmapOnlineInfo onlineInfo) { MaxCombo = (int)values[ATTRIB_ID_MAX_COMBO]; // Temporarily allow these attributes to not exist so as to not block releases of server-side components while these attributes aren't populated/used yet. LegacyAccuracyScore = (int)values.GetValueOrDefault(ATTRIB_ID_LEGACY_ACCURACY_SCORE); LegacyComboScore = (int)values.GetValueOrDefault(ATTRIB_ID_LEGACY_COMBO_SCORE); LegacyBonusScoreRatio = values.GetValueOrDefault(ATTRIB_ID_LEGACY_BONUS_SCORE_RATIO); } } }