2022-05-24 10:23:44 -04: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 ;
2022-06-09 00:15:15 -04:00
using System.Globalization ;
2022-05-24 10:23:44 -04:00
using System.Linq ;
using osu.Framework.Bindables ;
2023-01-17 17:03:04 +09:00
using osu.Framework.Localisation ;
2022-05-24 10:23:44 -04:00
using osu.Game.Configuration ;
using osu.Game.Overlays.Settings ;
using osu.Game.Rulesets.Scoring ;
using osu.Game.Rulesets.Judgements ;
2023-01-17 17:03:04 +09:00
using osu.Game.Scoring ;
2022-05-24 10:23:44 -04:00
namespace osu.Game.Rulesets.Mods
{
2023-01-17 17:03:04 +09:00
public class ModAccuracyChallenge : ModFailCondition , IApplicableToScoreProcessor
2022-05-24 10:23:44 -04:00
{
public override string Name = > "Accuracy Challenge" ;
2023-01-17 17:03:04 +09:00
2022-05-24 10:23:44 -04:00
public override string Acronym = > "AC" ;
2023-01-17 17:03:04 +09:00
public override LocalisableString Description = > "Fail if your accuracy drops too low!" ;
2022-05-24 10:23:44 -04:00
public override ModType Type = > ModType . DifficultyIncrease ;
2023-01-17 17:03:04 +09:00
2022-05-24 10:23:44 -04:00
public override double ScoreMultiplier = > 1.0 ;
2023-01-17 17:03:04 +09:00
2022-05-24 20:04:57 -04:00
public override Type [ ] IncompatibleMods = > base . IncompatibleMods . Concat ( new [ ] { typeof ( ModEasyWithExtraLives ) , typeof ( ModPerfect ) } ) . ToArray ( ) ;
2023-01-17 17:03:04 +09:00
2022-05-24 20:04:57 -04:00
public override bool RequiresConfiguration = > false ;
2023-01-17 17:03:04 +09:00
2022-06-09 00:15:15 -04:00
public override string SettingDescription = > base . SettingDescription . Replace ( MinimumAccuracy . ToString ( ) , MinimumAccuracy . Value . ToString ( "##%" , NumberFormatInfo . InvariantInfo ) ) ;
2022-05-24 10:23:44 -04:00
2023-03-07 19:43:52 +01:00
[SettingSource("Minimum accuracy", "Trigger a failure if your accuracy goes below this value.", SettingControlType = typeof(SettingsPercentageSlider<double>))]
2022-05-24 10:23:44 -04:00
public BindableNumber < double > MinimumAccuracy { get ; } = new BindableDouble
{
2023-01-24 00:31:46 -05:00
MinValue = 0.60 ,
2022-06-06 12:05:45 -04:00
MaxValue = 0.99 ,
2022-05-24 10:23:44 -04:00
Precision = 0.01 ,
Default = 0.9 ,
Value = 0.9 ,
} ;
2023-01-17 17:03:04 +09:00
private ScoreProcessor scoreProcessor = null ! ;
2023-01-17 10:23:57 -05:00
public void ApplyToScoreProcessor ( ScoreProcessor scoreProcessor ) = > this . scoreProcessor = scoreProcessor ;
2023-01-17 17:03:04 +09:00
public ScoreRank AdjustRank ( ScoreRank rank , double accuracy ) = > rank ;
2022-05-24 10:23:44 -04:00
protected override bool FailCondition ( HealthProcessor healthProcessor , JudgementResult result )
{
2023-01-18 12:24:41 -05:00
if ( ! result . Type . AffectsAccuracy ( ) )
2022-05-24 10:23:44 -04:00
return false ;
2023-01-18 18:08:58 +09:00
return getAccuracyWithImminentResultAdded ( result ) < MinimumAccuracy . Value ;
}
private double getAccuracyWithImminentResultAdded ( JudgementResult result )
{
var score = new ScoreInfo { Ruleset = scoreProcessor . Ruleset . RulesetInfo } ;
// This is super ugly, but if we don't do it this way we will not have the most recent result added to the accuracy value.
// Hopefully we can improve this in the future.
scoreProcessor . PopulateScore ( score ) ;
score . Statistics [ result . Type ] + + ;
return scoreProcessor . ComputeAccuracy ( score ) ;
2022-05-24 10:23:44 -04:00
}
}
}