1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-06 06:57:39 +08:00
osu-lazer/osu.Game/Beatmaps/BeatmapDifficulty.cs

57 lines
3.0 KiB
C#
Raw Normal View History

2018-01-05 19:21:19 +08:00
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
2016-12-06 17:56:20 +08:00
2017-10-05 03:52:12 +08:00
using System.ComponentModel.DataAnnotations.Schema;
using Newtonsoft.Json;
2016-10-04 23:31:10 +08:00
2017-07-26 12:22:46 +08:00
namespace osu.Game.Beatmaps
{
public class BeatmapDifficulty
{
2017-05-15 11:54:56 +08:00
/// <summary>
/// The default value used for all difficulty settings except <see cref="SliderMultiplier"/> and <see cref="SliderTickRate"/>.
/// </summary>
public const float DEFAULT_DIFFICULTY = 5;
2017-10-06 05:23:26 +08:00
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
[JsonIgnore]
2017-10-14 13:28:25 +08:00
public int ID { get; set; }
2017-10-17 17:26:28 +08:00
2017-05-15 11:54:56 +08:00
public float DrainRate { get; set; } = DEFAULT_DIFFICULTY;
public float CircleSize { get; set; } = DEFAULT_DIFFICULTY;
public float OverallDifficulty { get; set; } = DEFAULT_DIFFICULTY;
public float ApproachRate { get; set; } = DEFAULT_DIFFICULTY;
public float SliderMultiplier { get; set; } = 1;
public float SliderTickRate { get; set; } = 1;
/// <summary>
/// Maps a difficulty value [0, 10] to a two-piece linear range of values.
/// </summary>
/// <param name="difficulty">The difficulty value to be mapped.</param>
/// <param name="min">Minimum of the resulting range which will be achieved by a difficulty value of 0.</param>
/// <param name="mid">Midpoint of the resulting range which will be achieved by a difficulty value of 5.</param>
/// <param name="max">Maximum of the resulting range which will be achieved by a difficulty value of 10.</param>
/// <returns>Value to which the difficulty value maps in the specified range.</returns>
public static double DifficultyRange(double difficulty, double min, double mid, double max)
{
if (difficulty > 5)
return mid + (max - mid) * (difficulty - 5) / 5;
if (difficulty < 5)
return mid - (mid - min) * (5 - difficulty) / 5;
return mid;
}
2018-02-02 18:35:44 +08:00
/// <summary>
/// Maps a difficulty value [0, 10] to a two-piece linear range of values.
/// </summary>
/// <param name="difficulty">The difficulty value to be mapped.</param>
/// <param name="range">The values that define the two linear ranges.</param>
/// <param name="range.min">Minimum of the resulting range which will be achieved by a difficulty value of 0.</param>
/// <param name="range.mid">Midpoint of the resulting range which will be achieved by a difficulty value of 5.</param>
/// <param name="range.max">Maximum of the resulting range which will be achieved by a difficulty value of 10.</param>
/// <returns>Value to which the difficulty value maps in the specified range.</returns>
public static double DifficultyRange(double difficulty, (double min, double mid, double max) range)
=> DifficultyRange(difficulty, range.min, range.mid, range.max);
}
}