1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-16 13:17:26 +08:00
osu-lazer/osu.Game/Rulesets/Mods/ModDifficultyAdjust.cs

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

100 lines
3.6 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.
2021-07-08 13:28:13 +08:00
using System;
using System.Linq;
2019-12-11 19:43:16 +08:00
using osu.Framework.Bindables;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Localisation;
2021-07-08 13:28:13 +08:00
using osu.Game.Beatmaps;
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 LocalisableString 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;
2020-01-14 21:22:00 +08:00
public override IconUsage? Icon => FontAwesome.Solid.Hammer;
2019-12-11 19:43:16 +08:00
2022-08-12 21:32:27 +08:00
public override double ScoreMultiplier => 0.5;
2019-12-11 19:43:16 +08:00
public override bool RequiresConfiguration => true;
2019-12-11 19:43:16 +08:00
public override Type[] IncompatibleMods => new[] { typeof(ModEasy), typeof(ModHardRock) };
protected const int FIRST_SETTING_ORDER = 1;
protected const int LAST_SETTING_ORDER = 2;
[SettingSource("HP Drain", "Override a beatmap's set HP.", FIRST_SETTING_ORDER, SettingControlType = typeof(DifficultyAdjustSettingsControl))]
2021-07-08 15:40:32 +08:00
public DifficultyBindable DrainRate { get; } = new DifficultyBindable
{
Precision = 0.1f,
MinValue = 0,
MaxValue = 10,
2021-07-08 15:40:32 +08:00
ExtendedMaxValue = 11,
2021-07-09 12:24:26 +08:00
ReadCurrentFromDifficulty = diff => diff.DrainRate,
};
[SettingSource("Accuracy", "Override a beatmap's set OD.", LAST_SETTING_ORDER, SettingControlType = typeof(DifficultyAdjustSettingsControl))]
2021-07-08 15:40:32 +08:00
public DifficultyBindable OverallDifficulty { get; } = new DifficultyBindable
{
Precision = 0.1f,
MinValue = 0,
MaxValue = 10,
2021-07-08 15:40:32 +08:00
ExtendedMaxValue = 11,
2021-07-09 12:24:26 +08:00
ReadCurrentFromDifficulty = diff => diff.OverallDifficulty,
};
2019-12-11 19:43:16 +08:00
[SettingSource("Extended Limits", "Adjust difficulty beyond sane limits.")]
public BindableBool ExtendedLimits { get; } = new BindableBool();
protected ModDifficultyAdjust()
{
foreach (var (_, property) in this.GetOrderedSettingsSourceProperties())
{
if (property.GetValue(this) is DifficultyBindable diffAdjustBindable)
diffAdjustBindable.ExtendedLimits.BindTo(ExtendedLimits);
}
}
public override string SettingDescription
{
get
{
2020-03-23 10:54:21 +08:00
string drainRate = DrainRate.IsDefault ? string.Empty : $"HP {DrainRate.Value:N1}";
string overallDifficulty = OverallDifficulty.IsDefault ? string.Empty : $"OD {OverallDifficulty.Value:N1}";
return string.Join(", ", new[]
{
drainRate,
overallDifficulty
}.Where(s => !string.IsNullOrEmpty(s)));
}
}
public void ReadFromDifficulty(IBeatmapDifficultyInfo difficulty)
2019-12-11 19:43:16 +08:00
{
}
public void ApplyToDifficulty(BeatmapDifficulty difficulty) => ApplySettings(difficulty);
/// <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)
{
2021-07-08 13:28:13 +08:00
if (DrainRate.Value != null) difficulty.DrainRate = DrainRate.Value.Value;
if (OverallDifficulty.Value != null) difficulty.OverallDifficulty = OverallDifficulty.Value.Value;
2019-12-11 19:43:16 +08:00
}
}
2019-12-11 20:12:29 +08:00
}