2019-01-24 08:43:03 +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.
2018-06-14 06:32:07 +00:00
2022-06-27 06:06:42 +00:00
using System ;
2021-11-15 07:06:46 +00:00
using System.Collections.Generic ;
2021-11-15 07:06:29 +00:00
using Newtonsoft.Json ;
2022-06-27 06:05:49 +00:00
using osu.Game.Beatmaps ;
2018-06-14 06:32:07 +00:00
using osu.Game.Rulesets.Mods ;
2023-06-12 14:00:29 +00:00
using osu.Game.Rulesets.Scoring ;
2018-06-14 06:32:07 +00:00
namespace osu.Game.Rulesets.Difficulty
{
2021-11-17 11:20:54 +00:00
/// <summary>
/// Describes the difficulty of a beatmap, as output by a <see cref="DifficultyCalculator"/>.
/// </summary>
2021-11-15 10:54:35 +00:00
[JsonObject(MemberSerialization.OptIn)]
2018-06-14 06:32:07 +00:00
public class DifficultyAttributes
{
2021-11-17 11:47:52 +00:00
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 ;
2021-12-17 20:39:03 +00:00
protected const int ATTRIB_ID_DIFFICULTY = 11 ;
2021-11-17 11:47:52 +00:00
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 ;
2022-06-21 10:31:44 +00:00
protected const int ATTRIB_ID_SPEED_NOTE_COUNT = 21 ;
2023-06-19 12:38:13 +00:00
protected const int ATTRIB_ID_LEGACY_ACCURACY_SCORE = 23 ;
2023-06-12 14:00:29 +00:00
protected const int ATTRIB_ID_LEGACY_COMBO_SCORE = 25 ;
2023-06-19 12:38:13 +00:00
protected const int ATTRIB_ID_LEGACY_BONUS_SCORE_RATIO = 27 ;
2021-11-17 11:47:52 +00:00
2021-11-17 11:20:54 +00:00
/// <summary>
/// The mods which were applied to the beatmap.
/// </summary>
2022-06-27 06:06:42 +00:00
public Mod [ ] Mods { get ; set ; } = Array . Empty < Mod > ( ) ;
2021-11-15 07:06:29 +00:00
2021-11-17 11:20:54 +00:00
/// <summary>
2022-02-16 05:09:19 +00:00
/// The combined star rating of all skills.
2021-11-17 11:20:54 +00:00
/// </summary>
2023-06-28 07:14:44 +00:00
[JsonProperty("star_rating", Order = -3)]
2021-06-08 09:43:59 +00:00
public double StarRating { get ; set ; }
2021-11-15 07:06:29 +00:00
2021-11-17 11:20:54 +00:00
/// <summary>
/// The maximum achievable combo.
/// </summary>
2023-06-28 07:14:44 +00:00
[JsonProperty("max_combo", Order = -2)]
2021-06-08 09:43:59 +00:00
public int MaxCombo { get ; set ; }
2019-02-12 07:01:25 +00:00
2023-06-01 04:22:37 +00:00
/// <summary>
2023-06-19 12:38:13 +00:00
/// The accuracy portion of the legacy (ScoreV1) total score.
2023-06-01 04:22:37 +00:00
/// </summary>
2023-06-19 12:38:13 +00:00
public int LegacyAccuracyScore { get ; set ; }
2023-06-01 04:22:37 +00:00
2023-06-12 14:00:29 +00:00
/// <summary>
2023-06-19 12:38:13 +00:00
/// The combo-multiplied portion of the legacy (ScoreV1) total score.
2023-06-12 14:00:29 +00:00
/// </summary>
public int LegacyComboScore { get ; set ; }
/// <summary>
2023-06-19 12:38:13 +00:00
/// A ratio of <c>new_bonus_score / old_bonus_score</c> for converting the bonus score of legacy scores to the new scoring.
/// This is made up of all judgements that would be <see cref="HitResult.SmallBonus"/> or <see cref="HitResult.LargeBonus"/>.
2023-06-12 14:00:29 +00:00
/// </summary>
2023-06-19 12:38:13 +00:00
public double LegacyBonusScoreRatio { get ; set ; }
2023-06-12 14:00:29 +00:00
2021-11-17 11:20:54 +00:00
/// <summary>
/// Creates new <see cref="DifficultyAttributes"/>.
/// </summary>
2019-02-19 04:40:39 +00:00
public DifficultyAttributes ( )
2019-02-12 07:01:25 +00:00
{
}
2018-06-14 06:32:07 +00:00
2021-11-17 11:20:54 +00:00
/// <summary>
/// Creates new <see cref="DifficultyAttributes"/>.
/// </summary>
/// <param name="mods">The mods which were applied to the beatmap.</param>
/// <param name="starRating">The combined star rating of all skills.</param>
2021-11-21 03:12:24 +00:00
public DifficultyAttributes ( Mod [ ] mods , double starRating )
2018-06-14 06:32:07 +00:00
{
Mods = mods ;
StarRating = starRating ;
}
2021-11-15 07:06:46 +00:00
2021-11-17 11:20:54 +00:00
/// <summary>
/// Converts this <see cref="DifficultyAttributes"/> to osu-web compatible database attribute mappings.
/// </summary>
/// <remarks>
/// See: osu_difficulty_attribs table.
/// </remarks>
2023-06-01 04:22:37 +00:00
public virtual IEnumerable < ( int attributeId , object value ) > ToDatabaseAttributes ( )
{
2023-06-02 12:53:25 +00:00
yield return ( ATTRIB_ID_MAX_COMBO , MaxCombo ) ;
2023-06-19 12:38:13 +00:00
yield return ( ATTRIB_ID_LEGACY_ACCURACY_SCORE , LegacyAccuracyScore ) ;
2023-06-12 14:00:29 +00:00
yield return ( ATTRIB_ID_LEGACY_COMBO_SCORE , LegacyComboScore ) ;
2023-06-19 12:38:13 +00:00
yield return ( ATTRIB_ID_LEGACY_BONUS_SCORE_RATIO , LegacyBonusScoreRatio ) ;
2023-06-01 04:22:37 +00:00
}
2021-11-15 07:06:46 +00:00
2021-11-17 11:20:54 +00:00
/// <summary>
/// Reads osu-web database attribute mappings into this <see cref="DifficultyAttributes"/> object.
/// </summary>
/// <param name="values">The attribute mappings.</param>
2022-06-27 06:05:49 +00:00
/// <param name="onlineInfo">The <see cref="IBeatmapOnlineInfo"/> where more information about the beatmap may be extracted from (such as AR/CS/OD/etc).</param>
public virtual void FromDatabaseAttributes ( IReadOnlyDictionary < int , double > values , IBeatmapOnlineInfo onlineInfo )
2021-11-15 07:06:46 +00:00
{
2023-06-02 12:53:25 +00:00
MaxCombo = ( int ) values [ ATTRIB_ID_MAX_COMBO ] ;
2023-08-14 07:59:01 +00:00
// 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 ) ;
2023-08-14 15:58:13 +00:00
LegacyBonusScoreRatio = values . GetValueOrDefault ( ATTRIB_ID_LEGACY_BONUS_SCORE_RATIO ) ;
2021-11-15 07:06:46 +00:00
}
2018-06-14 06:32:07 +00:00
}
}