1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-16 10:17:36 +08:00
osu-lazer/osu.Game/Rulesets/Difficulty/DifficultyAttributes.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

116 lines
4.8 KiB
C#
Raw Normal View History

// 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 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
{
2021-11-17 19:20:54 +08:00
/// <summary>
/// Describes the difficulty of a beatmap, as output by a <see cref="DifficultyCalculator"/>.
/// </summary>
[JsonObject(MemberSerialization.OptIn)]
public class DifficultyAttributes
{
2021-11-17 19:47:52 +08: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;
protected const int ATTRIB_ID_DIFFICULTY = 11;
2021-11-17 19:47:52 +08: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 18:31:44 +08:00
protected const int ATTRIB_ID_SPEED_NOTE_COUNT = 21;
2023-06-19 20:38:13 +08:00
protected const int ATTRIB_ID_LEGACY_ACCURACY_SCORE = 23;
protected const int ATTRIB_ID_LEGACY_COMBO_SCORE = 25;
2023-06-19 20:38:13 +08:00
protected const int ATTRIB_ID_LEGACY_BONUS_SCORE_RATIO = 27;
2021-11-17 19:47:52 +08:00
2021-11-17 19:20:54 +08:00
/// <summary>
/// The mods which were applied to the beatmap.
/// </summary>
public Mod[] Mods { get; set; } = Array.Empty<Mod>();
2021-11-17 19:20:54 +08:00
/// <summary>
/// The combined star rating of all skills.
2021-11-17 19:20:54 +08:00
/// </summary>
[JsonProperty("star_rating", Order = -7)]
public double StarRating { get; set; }
2021-11-17 19:20:54 +08:00
/// <summary>
/// The maximum achievable combo.
/// </summary>
[JsonProperty("max_combo", Order = -6)]
public int MaxCombo { get; set; }
/// <summary>
2023-06-19 20:38:13 +08:00
/// The accuracy portion of the legacy (ScoreV1) total score.
/// </summary>
2023-06-19 20:38:13 +08:00
[JsonProperty("legacy_accuracy_score", Order = -5)]
public int LegacyAccuracyScore { get; set; }
/// <summary>
2023-06-19 20:38:13 +08:00
/// The combo-multiplied portion of the legacy (ScoreV1) total score.
/// </summary>
[JsonProperty("legacy_combo_score", Order = -4)]
public int LegacyComboScore { get; set; }
/// <summary>
2023-06-19 20:38:13 +08: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"/>.
/// </summary>
2023-06-19 20:38:13 +08:00
[JsonProperty("legacy_bonus_score_ratio", Order = -3)]
public double LegacyBonusScoreRatio { get; set; }
2021-11-17 19:20:54 +08:00
/// <summary>
/// Creates new <see cref="DifficultyAttributes"/>.
/// </summary>
2019-02-19 12:40:39 +08:00
public DifficultyAttributes()
{
}
2021-11-17 19:20:54 +08: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>
public DifficultyAttributes(Mod[] mods, double starRating)
{
Mods = mods;
StarRating = starRating;
}
2021-11-17 19:20:54 +08:00
/// <summary>
/// Converts this <see cref="DifficultyAttributes"/> to osu-web compatible database attribute mappings.
/// </summary>
/// <remarks>
/// See: osu_difficulty_attribs table.
/// </remarks>
public virtual IEnumerable<(int attributeId, object value)> ToDatabaseAttributes()
{
yield return (ATTRIB_ID_MAX_COMBO, MaxCombo);
2023-06-19 20:38:13 +08:00
yield return (ATTRIB_ID_LEGACY_ACCURACY_SCORE, LegacyAccuracyScore);
yield return (ATTRIB_ID_LEGACY_COMBO_SCORE, LegacyComboScore);
2023-06-19 20:38:13 +08:00
yield return (ATTRIB_ID_LEGACY_BONUS_SCORE_RATIO, LegacyBonusScoreRatio);
}
2021-11-17 19:20:54 +08:00
/// <summary>
/// Reads osu-web database attribute mappings into this <see cref="DifficultyAttributes"/> object.
/// </summary>
/// <param name="values">The attribute mappings.</param>
/// <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)
{
MaxCombo = (int)values[ATTRIB_ID_MAX_COMBO];
2023-06-19 20:38:13 +08:00
LegacyAccuracyScore = (int)values[ATTRIB_ID_LEGACY_ACCURACY_SCORE];
LegacyComboScore = (int)values[ATTRIB_ID_LEGACY_COMBO_SCORE];
2023-06-19 20:38:13 +08:00
LegacyBonusScoreRatio = (int)values[ATTRIB_ID_LEGACY_BONUS_SCORE_RATIO];
}
}
}