1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-19 01:12:56 +08:00
osu-lazer/osu.Game/Rulesets/Mods/ModDifficultyAdjust.cs

82 lines
2.7 KiB
C#
Raw Normal View History

2019-12-11 19:43:16 +08: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.
using osu.Game.Beatmaps;
using osu.Framework.Bindables;
using osu.Framework.Graphics.Sprites;
using System;
using osu.Game.Configuration;
2019-12-11 19:43:16 +08:00
namespace osu.Game.Rulesets.Mods
{
2019-12-20 18:30:23 +08:00
public abstract class ModDifficultyAdjust : Mod, IApplicableToDifficulty
2019-12-11 19:43:16 +08:00
{
public override string Name => @"Difficulty Adjust";
public override string Description => @"Override a beatmap's difficulty settings.";
2019-12-11 19:43:16 +08:00
public override string Acronym => "DA";
public override ModType Type => ModType.Conversion;
public override IconUsage Icon => FontAwesome.Solid.Hammer;
public override double ScoreMultiplier => 1.0;
public override Type[] IncompatibleMods => new[] { typeof(ModEasy), typeof(ModHardRock) };
[SettingSource("Drain Rate", "Override a beatmap's set HP.")]
2019-12-25 14:20:10 +08:00
public BindableNumber<float> DrainRate { get; } = new BindableFloat
{
Precision = 0.1f,
MinValue = 1,
MaxValue = 10,
Default = 5,
Value = 5,
};
[SettingSource("Overall Difficulty", "Override a beatmap's set OD.")]
2019-12-25 14:20:10 +08:00
public BindableNumber<float> OverallDifficulty { get; } = new BindableFloat
{
Precision = 0.1f,
MinValue = 1,
MaxValue = 10,
Default = 5,
Value = 5,
};
2019-12-11 19:43:16 +08:00
2019-12-13 15:22:07 +08:00
private BeatmapDifficulty difficulty;
public void ApplyToDifficulty(BeatmapDifficulty difficulty)
2019-12-11 19:43:16 +08:00
{
2019-12-13 15:22:07 +08:00
if (this.difficulty == null || this.difficulty.ID != difficulty.ID)
{
this.difficulty = difficulty;
TransferSettings(difficulty);
2019-12-13 15:46:58 +08:00
}
2019-12-13 15:27:34 +08:00
else
ApplySettings(difficulty);
}
/// <summary>
/// Transfer initial settings from the beatmap to settings.
/// </summary>
/// <param name="difficulty">The beatmap's initial values.</param>
protected virtual void TransferSettings(BeatmapDifficulty difficulty)
{
DrainRate.Value = DrainRate.Default = difficulty.DrainRate;
OverallDifficulty.Value = OverallDifficulty.Default = difficulty.OverallDifficulty;
}
/// <summary>
/// Apply all custom settings to the provided beatmap.
/// </summary>
/// <param name="difficulty">The beatmap to have settings applied.</param>
protected virtual void ApplySettings(BeatmapDifficulty difficulty)
{
difficulty.DrainRate = DrainRate.Value;
difficulty.OverallDifficulty = OverallDifficulty.Value;
2019-12-11 19:43:16 +08:00
}
}
2019-12-11 20:12:29 +08:00
}