From 9dff5cea07089425821a19cb1a385186a150eb02 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Thu, 2 Aug 2018 20:37:07 +0900 Subject: [PATCH] Make Rulesets.Catch use the new judgement result structure --- .../Judgements/CatchBananaJudgement.cs | 5 +- .../Judgements/CatchJudgement.cs | 30 ++++++------ osu.Game.Rulesets.Catch/Objects/Banana.cs | 4 +- .../Objects/CatchHitObject.cs | 8 ---- .../Drawable/DrawableCatchHitObject.cs | 7 ++- osu.Game.Rulesets.Catch/Objects/Droplet.cs | 6 ++- osu.Game.Rulesets.Catch/Objects/Fruit.cs | 6 ++- .../Objects/ICatchObjectWithJudgement.cs | 12 ----- .../Objects/TinyDroplet.cs | 4 +- .../Scoring/CatchScoreProcessor.cs | 46 ++++--------------- osu.Game.Rulesets.Catch/UI/CatchPlayfield.cs | 3 +- osu.Game.Rulesets.Catch/UI/CatcherArea.cs | 6 +-- 12 files changed, 50 insertions(+), 87 deletions(-) delete mode 100644 osu.Game.Rulesets.Catch/Objects/ICatchObjectWithJudgement.cs diff --git a/osu.Game.Rulesets.Catch/Judgements/CatchBananaJudgement.cs b/osu.Game.Rulesets.Catch/Judgements/CatchBananaJudgement.cs index c39e663d75..f38009263f 100644 --- a/osu.Game.Rulesets.Catch/Judgements/CatchBananaJudgement.cs +++ b/osu.Game.Rulesets.Catch/Judgements/CatchBananaJudgement.cs @@ -1,6 +1,7 @@ // Copyright (c) 2007-2018 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using osu.Game.Rulesets.Judgements; using osu.Game.Rulesets.Scoring; namespace osu.Game.Rulesets.Catch.Judgements @@ -9,8 +10,6 @@ namespace osu.Game.Rulesets.Catch.Judgements { public override bool AffectsCombo => false; - public override bool ShouldExplode => true; - protected override int NumericResultFor(HitResult result) { switch (result) @@ -32,5 +31,7 @@ namespace osu.Game.Rulesets.Catch.Judgements return 8; } } + + public override bool ShouldExplodeFor(JudgementResult result) => true; } } diff --git a/osu.Game.Rulesets.Catch/Judgements/CatchJudgement.cs b/osu.Game.Rulesets.Catch/Judgements/CatchJudgement.cs index 51d7d3b5cd..8a51867899 100644 --- a/osu.Game.Rulesets.Catch/Judgements/CatchJudgement.cs +++ b/osu.Game.Rulesets.Catch/Judgements/CatchJudgement.cs @@ -23,21 +23,10 @@ namespace osu.Game.Rulesets.Catch.Judgements } /// - /// The base health increase for the result achieved. + /// Retrieves the numeric health increase of a . /// - public float HealthIncrease => HealthIncreaseFor(Result); - - /// - /// Whether fruit on the platter should explode or drop. - /// Note that this is only checked if the owning object is also - /// - public virtual bool ShouldExplode => IsHit; - - /// - /// Convert a to a base health increase. - /// - /// The value to convert. - /// The base health increase. + /// The to find the numeric health increase for. + /// The numeric health increase of . protected virtual float HealthIncreaseFor(HitResult result) { switch (result) @@ -48,5 +37,18 @@ namespace osu.Game.Rulesets.Catch.Judgements return 10.2f; } } + + /// + /// Retrieves the numeric health increase of a . + /// + /// The to find the numeric health increase for. + /// The numeric health increase of . + public float HealthIncreaseFor(JudgementResult result) => HealthIncreaseFor(result.Type); + + /// + /// Whether fruit on the platter should explode or drop. + /// Note that this is only checked if the owning object is also + /// + public virtual bool ShouldExplodeFor(JudgementResult result) => result.IsHit; } } diff --git a/osu.Game.Rulesets.Catch/Objects/Banana.cs b/osu.Game.Rulesets.Catch/Objects/Banana.cs index d0f4f6c5db..1b84869172 100644 --- a/osu.Game.Rulesets.Catch/Objects/Banana.cs +++ b/osu.Game.Rulesets.Catch/Objects/Banana.cs @@ -1,7 +1,9 @@ // Copyright (c) 2007-2018 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using System.Collections.Generic; using osu.Game.Rulesets.Catch.Judgements; +using osu.Game.Rulesets.Judgements; namespace osu.Game.Rulesets.Catch.Objects { @@ -9,6 +11,6 @@ namespace osu.Game.Rulesets.Catch.Objects { public override FruitVisualRepresentation VisualRepresentation => FruitVisualRepresentation.Banana; - public override CatchJudgement Judgement { get; } = new CatchBananaJudgement(); + protected override IEnumerable CreateJudgements() => new[] { new CatchBananaJudgement() }; } } diff --git a/osu.Game.Rulesets.Catch/Objects/CatchHitObject.cs b/osu.Game.Rulesets.Catch/Objects/CatchHitObject.cs index 7f2cff561e..d55cdac115 100644 --- a/osu.Game.Rulesets.Catch/Objects/CatchHitObject.cs +++ b/osu.Game.Rulesets.Catch/Objects/CatchHitObject.cs @@ -1,10 +1,8 @@ // Copyright (c) 2007-2018 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE -using System.Collections.Generic; using osu.Game.Beatmaps; using osu.Game.Beatmaps.ControlPoints; -using osu.Game.Rulesets.Judgements; using osu.Game.Rulesets.Objects; using osu.Game.Rulesets.Objects.Types; @@ -56,12 +54,6 @@ namespace osu.Game.Rulesets.Catch.Objects } protected override HitWindows CreateHitWindows() => null; - - protected override IEnumerable CreateJudgements() - { - if (this is ICatchObjectWithJudgement judgeable) - yield return judgeable.Judgement; - } } public enum FruitVisualRepresentation diff --git a/osu.Game.Rulesets.Catch/Objects/Drawable/DrawableCatchHitObject.cs b/osu.Game.Rulesets.Catch/Objects/Drawable/DrawableCatchHitObject.cs index 126977ecb2..019a4779ac 100644 --- a/osu.Game.Rulesets.Catch/Objects/Drawable/DrawableCatchHitObject.cs +++ b/osu.Game.Rulesets.Catch/Objects/Drawable/DrawableCatchHitObject.cs @@ -2,6 +2,7 @@ // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using System; +using System.Linq; using OpenTK; using OpenTK.Graphics; using osu.Framework.Graphics; @@ -56,10 +57,8 @@ namespace osu.Game.Rulesets.Catch.Objects.Drawable { if (CheckPosition == null) return; - if (timeOffset >= 0 && HitObject is ICatchObjectWithJudgement judgeable) - { - ApplyJudgement(judgeable.Judgement, j => j.Result = CheckPosition.Invoke(HitObject) ? HitResult.Perfect : HitResult.Miss); - } + if (timeOffset >= 0 && Results.Count > 0) + ApplyResult(Results.Single(), r => r.Type = CheckPosition.Invoke(HitObject) ? HitResult.Perfect : HitResult.Miss); } protected override void SkinChanged(ISkinSource skin, bool allowFallback) diff --git a/osu.Game.Rulesets.Catch/Objects/Droplet.cs b/osu.Game.Rulesets.Catch/Objects/Droplet.cs index e92b06d0d1..a6e7d29305 100644 --- a/osu.Game.Rulesets.Catch/Objects/Droplet.cs +++ b/osu.Game.Rulesets.Catch/Objects/Droplet.cs @@ -1,12 +1,14 @@ // Copyright (c) 2007-2018 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using System.Collections.Generic; using osu.Game.Rulesets.Catch.Judgements; +using osu.Game.Rulesets.Judgements; namespace osu.Game.Rulesets.Catch.Objects { - public class Droplet : CatchHitObject, ICatchObjectWithJudgement + public class Droplet : CatchHitObject { - public virtual CatchJudgement Judgement { get; } = new CatchDropletJudgement(); + protected override IEnumerable CreateJudgements() => new[] { new CatchDropletJudgement() }; } } diff --git a/osu.Game.Rulesets.Catch/Objects/Fruit.cs b/osu.Game.Rulesets.Catch/Objects/Fruit.cs index 4bcb1a400f..fd9cd13beb 100644 --- a/osu.Game.Rulesets.Catch/Objects/Fruit.cs +++ b/osu.Game.Rulesets.Catch/Objects/Fruit.cs @@ -1,12 +1,14 @@ // Copyright (c) 2007-2018 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using System.Collections.Generic; using osu.Game.Rulesets.Catch.Judgements; +using osu.Game.Rulesets.Judgements; namespace osu.Game.Rulesets.Catch.Objects { - public class Fruit : CatchHitObject, ICatchObjectWithJudgement + public class Fruit : CatchHitObject { - public virtual CatchJudgement Judgement { get; } = new CatchJudgement(); + protected override IEnumerable CreateJudgements() => new[] { new CatchJudgement() }; } } diff --git a/osu.Game.Rulesets.Catch/Objects/ICatchObjectWithJudgement.cs b/osu.Game.Rulesets.Catch/Objects/ICatchObjectWithJudgement.cs deleted file mode 100644 index 2aa5a5c83a..0000000000 --- a/osu.Game.Rulesets.Catch/Objects/ICatchObjectWithJudgement.cs +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright (c) 2007-2018 ppy Pty Ltd . -// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE - -using osu.Game.Rulesets.Catch.Judgements; - -namespace osu.Game.Rulesets.Catch.Objects -{ - public interface ICatchObjectWithJudgement - { - CatchJudgement Judgement { get; } - } -} diff --git a/osu.Game.Rulesets.Catch/Objects/TinyDroplet.cs b/osu.Game.Rulesets.Catch/Objects/TinyDroplet.cs index d7cc002dfc..069d3be5c0 100644 --- a/osu.Game.Rulesets.Catch/Objects/TinyDroplet.cs +++ b/osu.Game.Rulesets.Catch/Objects/TinyDroplet.cs @@ -1,12 +1,14 @@ // Copyright (c) 2007-2018 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using System.Collections.Generic; using osu.Game.Rulesets.Catch.Judgements; +using osu.Game.Rulesets.Judgements; namespace osu.Game.Rulesets.Catch.Objects { public class TinyDroplet : Droplet { - public override CatchJudgement Judgement { get; } = new CatchTinyDropletJudgement(); + protected override IEnumerable CreateJudgements() => new[] { new CatchTinyDropletJudgement() }; } } diff --git a/osu.Game.Rulesets.Catch/Scoring/CatchScoreProcessor.cs b/osu.Game.Rulesets.Catch/Scoring/CatchScoreProcessor.cs index 5b69d836a3..183c6f0f12 100644 --- a/osu.Game.Rulesets.Catch/Scoring/CatchScoreProcessor.cs +++ b/osu.Game.Rulesets.Catch/Scoring/CatchScoreProcessor.cs @@ -2,7 +2,6 @@ // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using System; -using System.Linq; using osu.Game.Beatmaps; using osu.Game.Rulesets.Catch.Judgements; using osu.Game.Rulesets.Catch.Objects; @@ -21,55 +20,28 @@ namespace osu.Game.Rulesets.Catch.Scoring private float hpDrainRate; - protected override void SimulateAutoplay(Beatmap beatmap) + protected override void ApplyBeatmap(Beatmap beatmap) { - hpDrainRate = beatmap.BeatmapInfo.BaseDifficulty.DrainRate; + base.ApplyBeatmap(beatmap); - foreach (var obj in beatmap.HitObjects) - { - switch (obj) - { - case JuiceStream stream: - foreach (var nestedObject in stream.NestedHitObjects) - switch (nestedObject) - { - case TinyDroplet _: - AddJudgement(new CatchTinyDropletJudgement { Result = HitResult.Perfect }); - break; - case Droplet _: - AddJudgement(new CatchDropletJudgement { Result = HitResult.Perfect }); - break; - case Fruit _: - AddJudgement(new CatchJudgement { Result = HitResult.Perfect }); - break; - } - break; - case BananaShower shower: - foreach (var _ in shower.NestedHitObjects.Cast()) - AddJudgement(new CatchBananaJudgement { Result = HitResult.Perfect }); - break; - case Fruit _: - AddJudgement(new CatchJudgement { Result = HitResult.Perfect }); - break; - } - } + hpDrainRate = beatmap.BeatmapInfo.BaseDifficulty.DrainRate; } private const double harshness = 0.01; - protected override void OnNewJudgement(Judgement judgement) + protected override void OnNewJudgement(JudgementResult result) { - base.OnNewJudgement(judgement); + base.OnNewJudgement(result); - if (judgement.Result == HitResult.Miss) + if (result.Type == HitResult.Miss) { - if (!judgement.IsBonus) + if (!result.Judgement.IsBonus) Health.Value -= hpDrainRate * (harshness * 2); return; } - if (judgement is CatchJudgement catchJudgement) - Health.Value += Math.Max(catchJudgement.HealthIncrease - hpDrainRate, 0) * harshness; + if (result.Judgement is CatchJudgement catchJudgement) + Health.Value += Math.Max(catchJudgement.HealthIncreaseFor(result) - hpDrainRate, 0) * harshness; } } } diff --git a/osu.Game.Rulesets.Catch/UI/CatchPlayfield.cs b/osu.Game.Rulesets.Catch/UI/CatchPlayfield.cs index ea3b6fb0e0..7b52066d15 100644 --- a/osu.Game.Rulesets.Catch/UI/CatchPlayfield.cs +++ b/osu.Game.Rulesets.Catch/UI/CatchPlayfield.cs @@ -67,6 +67,7 @@ namespace osu.Game.Rulesets.Catch.UI fruit.CheckPosition = CheckIfWeCanCatch; } - private void onJudgement(DrawableHitObject judgedObject, Judgement judgement) => catcherArea.OnJudgement((DrawableCatchHitObject)judgedObject, judgement); + private void onJudgement(DrawableHitObject judgedObject, JudgementResult result) + => catcherArea.OnJudgement((DrawableCatchHitObject)judgedObject, result); } } diff --git a/osu.Game.Rulesets.Catch/UI/CatcherArea.cs b/osu.Game.Rulesets.Catch/UI/CatcherArea.cs index 7b06426b07..ca9fa6f595 100644 --- a/osu.Game.Rulesets.Catch/UI/CatcherArea.cs +++ b/osu.Game.Rulesets.Catch/UI/CatcherArea.cs @@ -48,7 +48,7 @@ namespace osu.Game.Rulesets.Catch.UI private DrawableCatchHitObject lastPlateableFruit; - public void OnJudgement(DrawableCatchHitObject fruit, Judgement judgement) + public void OnJudgement(DrawableCatchHitObject fruit, JudgementResult result) { void runAfterLoaded(Action action) { @@ -63,7 +63,7 @@ namespace osu.Game.Rulesets.Catch.UI lastPlateableFruit.OnLoadComplete = _ => action(); } - if (judgement.IsHit && fruit.CanBePlated) + if (result.IsHit && fruit.CanBePlated) { var caughtFruit = (DrawableCatchHitObject)GetVisualRepresentation?.Invoke(fruit.HitObject); @@ -86,7 +86,7 @@ namespace osu.Game.Rulesets.Catch.UI if (fruit.HitObject.LastInCombo) { - if (((CatchJudgement)judgement).ShouldExplode) + if (((CatchJudgement)result.Judgement).ShouldExplodeFor(result)) runAfterLoaded(() => MovableCatcher.Explode()); else MovableCatcher.Drop();