From c77e6074f647574b09403131874ba9566ea1e807 Mon Sep 17 00:00:00 2001 From: iiSaLMaN Date: Wed, 7 Aug 2019 19:58:26 +0300 Subject: [PATCH 1/7] Disallow adding to score after the player has failed --- osu.Game/Rulesets/Scoring/ScoreProcessor.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/osu.Game/Rulesets/Scoring/ScoreProcessor.cs b/osu.Game/Rulesets/Scoring/ScoreProcessor.cs index 2e863f7edb..fd851f2cbb 100644 --- a/osu.Game/Rulesets/Scoring/ScoreProcessor.cs +++ b/osu.Game/Rulesets/Scoring/ScoreProcessor.cs @@ -316,6 +316,9 @@ namespace osu.Game.Rulesets.Scoring /// The to apply. protected virtual void ApplyResult(JudgementResult result) { + if (HasFailed) + return; + result.ComboAtJudgement = Combo.Value; result.HighestComboAtJudgement = HighestCombo.Value; result.HealthAtJudgement = Health.Value; From 566d874641922a3b680b648542aecc7702a0236b Mon Sep 17 00:00:00 2001 From: iiSaLMaN Date: Thu, 8 Aug 2019 15:25:07 +0300 Subject: [PATCH 2/7] Prevent failing when reverting to a hasFailedAtJudgement --- osu.Game/Rulesets/Scoring/ScoreProcessor.cs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/osu.Game/Rulesets/Scoring/ScoreProcessor.cs b/osu.Game/Rulesets/Scoring/ScoreProcessor.cs index fd851f2cbb..5ca33ff0bc 100644 --- a/osu.Game/Rulesets/Scoring/ScoreProcessor.cs +++ b/osu.Game/Rulesets/Scoring/ScoreProcessor.cs @@ -95,7 +95,7 @@ namespace osu.Game.Rulesets.Scoring /// /// Whether this ScoreProcessor has already triggered the failed state. /// - public virtual bool HasFailed { get; private set; } + public virtual bool HasFailed { get; protected set; } /// /// The default conditions for failing. @@ -309,6 +309,7 @@ namespace osu.Game.Rulesets.Scoring } private readonly Dictionary scoreResultCounts = new Dictionary(); + private Judgement hasFailedAtJudgement; /// /// Applies the score change of a to this . @@ -317,7 +318,12 @@ namespace osu.Game.Rulesets.Scoring protected virtual void ApplyResult(JudgementResult result) { if (HasFailed) + { + if (hasFailedAtJudgement == null) + hasFailedAtJudgement = result.Judgement; + return; + } result.ComboAtJudgement = Combo.Value; result.HighestComboAtJudgement = HighestCombo.Value; @@ -365,6 +371,17 @@ namespace osu.Game.Rulesets.Scoring /// The judgement scoring result. protected virtual void RevertResult(JudgementResult result) { + if (HasFailed) + { + if (hasFailedAtJudgement == result.Judgement) + { + hasFailedAtJudgement = null; + HasFailed = false; + } + + return; + } + Combo.Value = result.ComboAtJudgement; HighestCombo.Value = result.HighestComboAtJudgement; Health.Value = result.HealthAtJudgement; From 88fa06efbadc23501209021ad4df1436bd4acb7f Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Fri, 9 Aug 2019 12:29:58 +0900 Subject: [PATCH 3/7] Refactor as proposed --- .../Rulesets/Judgements/JudgementResult.cs | 5 ++++ osu.Game/Rulesets/Scoring/ScoreProcessor.cs | 29 ++++++------------- 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/osu.Game/Rulesets/Judgements/JudgementResult.cs b/osu.Game/Rulesets/Judgements/JudgementResult.cs index 195fe316ac..0b3c3943c3 100644 --- a/osu.Game/Rulesets/Judgements/JudgementResult.cs +++ b/osu.Game/Rulesets/Judgements/JudgementResult.cs @@ -42,6 +42,11 @@ namespace osu.Game.Rulesets.Judgements /// public double HealthAtJudgement { get; internal set; } + /// + /// Whether the user was in a failed state prior to this occurring. + /// + public bool FailedAtJudgement { get; internal set; } + /// /// Whether a miss or hit occurred. /// diff --git a/osu.Game/Rulesets/Scoring/ScoreProcessor.cs b/osu.Game/Rulesets/Scoring/ScoreProcessor.cs index 5ca33ff0bc..dd8aae27d8 100644 --- a/osu.Game/Rulesets/Scoring/ScoreProcessor.cs +++ b/osu.Game/Rulesets/Scoring/ScoreProcessor.cs @@ -309,7 +309,6 @@ namespace osu.Game.Rulesets.Scoring } private readonly Dictionary scoreResultCounts = new Dictionary(); - private Judgement hasFailedAtJudgement; /// /// Applies the score change of a to this . @@ -317,17 +316,13 @@ namespace osu.Game.Rulesets.Scoring /// The to apply. protected virtual void ApplyResult(JudgementResult result) { - if (HasFailed) - { - if (hasFailedAtJudgement == null) - hasFailedAtJudgement = result.Judgement; - - return; - } - result.ComboAtJudgement = Combo.Value; result.HighestComboAtJudgement = HighestCombo.Value; result.HealthAtJudgement = Health.Value; + result.FailedAtJudgement = HasFailed; + + if (HasFailed) + return; JudgedHits++; @@ -371,21 +366,15 @@ namespace osu.Game.Rulesets.Scoring /// The judgement scoring result. protected virtual void RevertResult(JudgementResult result) { - if (HasFailed) - { - if (hasFailedAtJudgement == result.Judgement) - { - hasFailedAtJudgement = null; - HasFailed = false; - } - - return; - } - Combo.Value = result.ComboAtJudgement; HighestCombo.Value = result.HighestComboAtJudgement; Health.Value = result.HealthAtJudgement; + // Todo: Revert HasFailed state with proper player support + + if (result.FailedAtJudgement) + return; + JudgedHits--; if (result.Type != HitResult.None) From 33f4b628a5fb5316f0be69d52f9856e8d3ccef4e Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Fri, 9 Aug 2019 13:42:02 +0900 Subject: [PATCH 4/7] Make HasFailed private set --- osu.Game/Rulesets/Scoring/ScoreProcessor.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Rulesets/Scoring/ScoreProcessor.cs b/osu.Game/Rulesets/Scoring/ScoreProcessor.cs index dd8aae27d8..a39b432e20 100644 --- a/osu.Game/Rulesets/Scoring/ScoreProcessor.cs +++ b/osu.Game/Rulesets/Scoring/ScoreProcessor.cs @@ -95,7 +95,7 @@ namespace osu.Game.Rulesets.Scoring /// /// Whether this ScoreProcessor has already triggered the failed state. /// - public virtual bool HasFailed { get; protected set; } + public virtual bool HasFailed { get; private set; } /// /// The default conditions for failing. From d47a8c0826c06af5595d01e8a946df9141065169 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Fri, 9 Aug 2019 14:04:51 +0900 Subject: [PATCH 5/7] Remove unused combo result count statistic --- .../Scoring/OsuScoreProcessor.cs | 20 ------------------- 1 file changed, 20 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Scoring/OsuScoreProcessor.cs b/osu.Game.Rulesets.Osu/Scoring/OsuScoreProcessor.cs index cf0565c6da..dc4e59294b 100644 --- a/osu.Game.Rulesets.Osu/Scoring/OsuScoreProcessor.cs +++ b/osu.Game.Rulesets.Osu/Scoring/OsuScoreProcessor.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -using System.Collections.Generic; -using osu.Framework.Extensions; using osu.Game.Beatmaps; using osu.Game.Rulesets.Judgements; using osu.Game.Rulesets.Objects; @@ -22,8 +20,6 @@ namespace osu.Game.Rulesets.Osu.Scoring private float hpDrainRate; - private readonly Dictionary comboResultCounts = new Dictionary(); - protected override void ApplyBeatmap(Beatmap beatmap) { base.ApplyBeatmap(beatmap); @@ -31,22 +27,6 @@ namespace osu.Game.Rulesets.Osu.Scoring hpDrainRate = beatmap.BeatmapInfo.BaseDifficulty.DrainRate; } - protected override void Reset(bool storeResults) - { - base.Reset(storeResults); - comboResultCounts.Clear(); - } - - protected override void ApplyResult(JudgementResult result) - { - base.ApplyResult(result); - - var osuResult = (OsuJudgementResult)result; - - if (result.Type != HitResult.None) - comboResultCounts[osuResult.ComboType] = comboResultCounts.GetOrDefault(osuResult.ComboType) + 1; - } - protected override double HealthAdjustmentFactorFor(JudgementResult result) { switch (result.Type) From a9c4b5ac4e9c9c25527c4e71fb550809f7962d81 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Fri, 9 Aug 2019 14:04:56 +0900 Subject: [PATCH 6/7] Add tests --- .../Visual/Gameplay/TestSceneFailJudgement.cs | 60 +++++++++++++++++++ osu.Game/Rulesets/Scoring/ScoreProcessor.cs | 4 +- 2 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 osu.Game.Tests/Visual/Gameplay/TestSceneFailJudgement.cs diff --git a/osu.Game.Tests/Visual/Gameplay/TestSceneFailJudgement.cs b/osu.Game.Tests/Visual/Gameplay/TestSceneFailJudgement.cs new file mode 100644 index 0000000000..bb0901524f --- /dev/null +++ b/osu.Game.Tests/Visual/Gameplay/TestSceneFailJudgement.cs @@ -0,0 +1,60 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System; +using System.Linq; +using osu.Game.Rulesets; +using osu.Game.Rulesets.Mods; +using osu.Game.Rulesets.Scoring; +using osu.Game.Rulesets.UI; +using osu.Game.Scoring; +using osu.Game.Screens.Play; + +namespace osu.Game.Tests.Visual.Gameplay +{ + public class TestSceneFailJudgement : AllPlayersTestScene + { + protected override Player CreatePlayer(Ruleset ruleset) + { + Mods.Value = Array.Empty(); + + var beatmap = Beatmap.Value.GetPlayableBeatmap(ruleset.RulesetInfo, Array.Empty()); + return new FailPlayer(ruleset.GetAutoplayMod().CreateReplayScore(beatmap)); + } + + protected override void AddCheckSteps() + { + AddUntilStep("wait for fail", () => Player.HasFailed); + AddUntilStep("wait for multiple judged objects", () => ((FailPlayer)Player).DrawableRuleset.Playfield.AllHitObjects.Count(h => h.AllJudged) > 1); + AddAssert("total judgements == 1", () => + { + int count = 0; + + foreach (var stat in (HitResult[])Enum.GetValues(typeof(HitResult))) + count += ((FailPlayer)Player).ScoreProcessor.GetStatistic(stat); + + return count == 1; + }); + } + + private class FailPlayer : ReplayPlayer + { + public new DrawableRuleset DrawableRuleset => base.DrawableRuleset; + + public new ScoreProcessor ScoreProcessor => base.ScoreProcessor; + + protected override bool PauseOnFocusLost => false; + + public FailPlayer(Score score) + : base(score, false, false) + { + } + + protected override void LoadComplete() + { + base.LoadComplete(); + ScoreProcessor.FailConditions += (_, __) => true; + } + } + } +} diff --git a/osu.Game/Rulesets/Scoring/ScoreProcessor.cs b/osu.Game/Rulesets/Scoring/ScoreProcessor.cs index a39b432e20..1e7cd3810d 100644 --- a/osu.Game/Rulesets/Scoring/ScoreProcessor.cs +++ b/osu.Game/Rulesets/Scoring/ScoreProcessor.cs @@ -193,7 +193,7 @@ namespace osu.Game.Rulesets.Scoring score.Statistics[result] = GetStatistic(result); } - protected abstract int GetStatistic(HitResult result); + public abstract int GetStatistic(HitResult result); public abstract double GetStandardisedScore(); } @@ -421,7 +421,7 @@ namespace osu.Game.Rulesets.Scoring } } - protected override int GetStatistic(HitResult result) => scoreResultCounts.GetOrDefault(result); + public override int GetStatistic(HitResult result) => scoreResultCounts.GetOrDefault(result); public override double GetStandardisedScore() => getScore(ScoringMode.Standardised); From b89fb5cdf7ca5e5b1ac8932ed6b3e79fb7a8bedd Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 6 Sep 2019 16:51:30 +0900 Subject: [PATCH 7/7] Fix failing test --- .../Visual/Gameplay/TestSceneFailJudgement.cs | 10 +--------- osu.Game/Rulesets/Scoring/ScoreProcessor.cs | 9 +++++++-- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/osu.Game.Tests/Visual/Gameplay/TestSceneFailJudgement.cs b/osu.Game.Tests/Visual/Gameplay/TestSceneFailJudgement.cs index bb0901524f..d57ec44f39 100644 --- a/osu.Game.Tests/Visual/Gameplay/TestSceneFailJudgement.cs +++ b/osu.Game.Tests/Visual/Gameplay/TestSceneFailJudgement.cs @@ -26,15 +26,7 @@ namespace osu.Game.Tests.Visual.Gameplay { AddUntilStep("wait for fail", () => Player.HasFailed); AddUntilStep("wait for multiple judged objects", () => ((FailPlayer)Player).DrawableRuleset.Playfield.AllHitObjects.Count(h => h.AllJudged) > 1); - AddAssert("total judgements == 1", () => - { - int count = 0; - - foreach (var stat in (HitResult[])Enum.GetValues(typeof(HitResult))) - count += ((FailPlayer)Player).ScoreProcessor.GetStatistic(stat); - - return count == 1; - }); + AddAssert("total judgements == 1", () => ((FailPlayer)Player).ScoreProcessor.JudgedHits == 1); } private class FailPlayer : ReplayPlayer diff --git a/osu.Game/Rulesets/Scoring/ScoreProcessor.cs b/osu.Game/Rulesets/Scoring/ScoreProcessor.cs index 9f2c79df33..e4f20c27b4 100644 --- a/osu.Game/Rulesets/Scoring/ScoreProcessor.cs +++ b/osu.Game/Rulesets/Scoring/ScoreProcessor.cs @@ -92,6 +92,11 @@ namespace osu.Game.Rulesets.Scoring /// public virtual bool HasCompleted => false; + /// + /// The total number of judged s at the current point in time. + /// + public int JudgedHits { get; protected set; } + /// /// Whether this ScoreProcessor has already triggered the failed state. /// @@ -142,6 +147,8 @@ namespace osu.Game.Rulesets.Scoring Rank.Value = ScoreRank.X; HighestCombo.Value = 0; + JudgedHits = 0; + HasFailed = false; } @@ -208,7 +215,6 @@ namespace osu.Game.Rulesets.Scoring public sealed override bool HasCompleted => JudgedHits == MaxHits; protected int MaxHits { get; private set; } - protected int JudgedHits { get; private set; } private double maxHighestCombo; @@ -441,7 +447,6 @@ namespace osu.Game.Rulesets.Scoring base.Reset(storeResults); - JudgedHits = 0; baseScore = 0; rollingMaxBaseScore = 0; bonusScore = 0;