1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 09:27:34 +08:00
osu-lazer/osu.Game/Rulesets/Mods/ModAccuracyChallenge.cs

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

63 lines
2.5 KiB
C#
Raw Normal View History

2022-05-24 22:23:44 +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 System;
using System.Linq;
using osu.Framework.Bindables;
using osu.Framework.Graphics.Sprites;
using osu.Game.Configuration;
using osu.Game.Graphics.UserInterface;
using osu.Game.Overlays.Settings;
using osu.Game.Rulesets.Scoring;
using osu.Game.Rulesets.Judgements;
namespace osu.Game.Rulesets.Mods
{
public class ModAccuracyChallenge : ModFailCondition
{
public override string Name => "Accuracy Challenge";
public override string Acronym => "AC";
public override string Description => "Fail the map if you don't maintain a certain accuracy.";
public override IconUsage? Icon => FontAwesome.Solid.Calculator;
public override ModType Type => ModType.DifficultyIncrease;
public override double ScoreMultiplier => 1.0;
2022-05-25 08:04:57 +08:00
public override Type[] IncompatibleMods => base.IncompatibleMods.Concat(new[] { typeof(ModEasyWithExtraLives), typeof(ModPerfect) }).ToArray();
public override bool RequiresConfiguration => false;
2022-06-09 11:44:34 +08:00
public override string SettingDescription => base.SettingDescription.Replace(MinimumAccuracy.Value.ToString(), MinimumAccuracy.Value.ToString("##%"));
2022-05-24 22:23:44 +08:00
[SettingSource("Minimum accuracy", "Trigger a failure if your accuracy goes below this value.", SettingControlType = typeof(SettingsSlider<double, PercentSlider>))]
public BindableNumber<double> MinimumAccuracy { get; } = new BindableDouble
{
2022-05-25 08:04:57 +08:00
MinValue = 0.01,
2022-06-07 00:05:45 +08:00
MaxValue = 0.99,
2022-05-24 22:23:44 +08:00
Precision = 0.01,
Default = 0.9,
Value = 0.9,
};
private double baseScore;
private double maxBaseScore;
private double accuracy => maxBaseScore > 0 ? baseScore / maxBaseScore : 1;
protected override bool FailCondition(HealthProcessor healthProcessor, JudgementResult result)
{
2022-05-26 03:11:06 +08:00
// accuracy calculation logic taken from `ScoreProcessor`. should be updated here if the formula ever changes.
2022-05-24 22:23:44 +08:00
if (!result.Type.IsScorable() || result.Type.IsBonus())
return false;
baseScore += result.Type.IsHit() ? result.Judgement.NumericResultFor(result) : 0;
maxBaseScore += result.Judgement.MaxNumericResult;
return accuracy < MinimumAccuracy.Value;
}
}
public class PercentSlider : OsuSliderBar<double>
{
public PercentSlider()
{
DisplayAsPercentage = true;
}
}
}