diff --git a/osu.Game.Rulesets.Catch.Tests/TestSceneCatcher.cs b/osu.Game.Rulesets.Catch.Tests/TestSceneCatcher.cs index 194a12a9b7..cf6011d721 100644 --- a/osu.Game.Rulesets.Catch.Tests/TestSceneCatcher.cs +++ b/osu.Game.Rulesets.Catch.Tests/TestSceneCatcher.cs @@ -1,6 +1,7 @@ // 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.Collections.Generic; using System.Linq; using NUnit.Framework; @@ -12,8 +13,11 @@ using osu.Framework.Testing; using osu.Game.Beatmaps; using osu.Game.Beatmaps.ControlPoints; using osu.Game.Configuration; +using osu.Game.Rulesets.Catch.Judgements; using osu.Game.Rulesets.Catch.Objects; using osu.Game.Rulesets.Catch.Objects.Drawables; +using osu.Game.Rulesets.Judgements; +using osu.Game.Rulesets.Scoring; using osu.Game.Tests.Visual; namespace osu.Game.Rulesets.Catch.Tests @@ -52,6 +56,53 @@ namespace osu.Game.Rulesets.Catch.Tests }; }); + [Test] + public void TestCatcherHyperStateReverted() + { + DrawableCatchHitObject drawableObject1 = null; + DrawableCatchHitObject drawableObject2 = null; + JudgementResult result1 = null; + JudgementResult result2 = null; + AddStep("catch hyper fruit", () => + { + drawableObject1 = createDrawableObject(new Fruit { HyperDashTarget = new Fruit { X = 100 } }); + result1 = attemptCatch(drawableObject1); + }); + AddStep("catch normal fruit", () => + { + drawableObject2 = createDrawableObject(new Fruit()); + result2 = attemptCatch(drawableObject2); + }); + AddStep("revert second result", () => + { + catcher.OnRevertResult(drawableObject2, result2); + }); + checkHyperDash(true); + AddStep("revert first result", () => + { + catcher.OnRevertResult(drawableObject1, result1); + }); + checkHyperDash(false); + } + + [Test] + public void TestCatcherAnimationStateReverted() + { + DrawableCatchHitObject drawableObject = null; + JudgementResult result = null; + AddStep("catch kiai fruit", () => + { + drawableObject = createDrawableObject(new TestKiaiFruit()); + result = attemptCatch(drawableObject); + }); + checkState(CatcherAnimationState.Kiai); + AddStep("revert result", () => + { + catcher.OnRevertResult(drawableObject, result); + }); + checkState(CatcherAnimationState.Idle); + } + [Test] public void TestCatcherCatchWidth() { @@ -166,10 +217,37 @@ namespace osu.Game.Rulesets.Catch.Tests private void attemptCatch(CatchHitObject hitObject, int count = 1) { - hitObject.ApplyDefaults(new ControlPointInfo(), new BeatmapDifficulty()); - for (var i = 0; i < count; i++) - catcher.AttemptCatch(hitObject); + attemptCatch(createDrawableObject(hitObject)); + } + + private JudgementResult attemptCatch(DrawableCatchHitObject drawableObject) + { + drawableObject.HitObject.ApplyDefaults(new ControlPointInfo(), new BeatmapDifficulty()); + var result = new CatchJudgementResult(drawableObject.HitObject, drawableObject.HitObject.CreateJudgement()) + { + Type = catcher.CanCatch(drawableObject.HitObject) ? HitResult.Great : HitResult.Miss + }; + catcher.OnNewResult(drawableObject, result); + return result; + } + + private DrawableCatchHitObject createDrawableObject(CatchHitObject hitObject) + { + switch (hitObject) + { + case Banana banana: + return new DrawableBanana(banana); + + case Droplet droplet: + return new DrawableDroplet(droplet); + + case Fruit fruit: + return new DrawableFruit(fruit); + + default: + throw new ArgumentOutOfRangeException(nameof(hitObject)); + } } public class TestCatcher : Catcher diff --git a/osu.Game.Rulesets.Catch.Tests/TestSceneCatcherArea.cs b/osu.Game.Rulesets.Catch.Tests/TestSceneCatcherArea.cs index 281ddc7eaa..8602c7aad1 100644 --- a/osu.Game.Rulesets.Catch.Tests/TestSceneCatcherArea.cs +++ b/osu.Game.Rulesets.Catch.Tests/TestSceneCatcherArea.cs @@ -15,7 +15,6 @@ using osu.Game.Rulesets.Catch.Judgements; using osu.Game.Rulesets.Catch.Objects; using osu.Game.Rulesets.Catch.Objects.Drawables; using osu.Game.Rulesets.Catch.UI; -using osu.Game.Rulesets.Judgements; using osu.Game.Rulesets.Scoring; namespace osu.Game.Rulesets.Catch.Tests @@ -58,10 +57,9 @@ namespace osu.Game.Rulesets.Catch.Tests Schedule(() => { - bool caught = area.AttemptCatch(fruit); - area.OnNewResult(drawable, new JudgementResult(fruit, new CatchJudgement()) + area.OnNewResult(drawable, new CatchJudgementResult(fruit, new CatchJudgement()) { - Type = caught ? HitResult.Great : HitResult.Miss + Type = area.MovableCatcher.CanCatch(fruit) ? HitResult.Great : HitResult.Miss }); drawable.Expire(); diff --git a/osu.Game.Rulesets.Catch/Judgements/CatchJudgementResult.cs b/osu.Game.Rulesets.Catch/Judgements/CatchJudgementResult.cs new file mode 100644 index 0000000000..c09355d59c --- /dev/null +++ b/osu.Game.Rulesets.Catch/Judgements/CatchJudgementResult.cs @@ -0,0 +1,28 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using JetBrains.Annotations; +using osu.Game.Rulesets.Catch.UI; +using osu.Game.Rulesets.Judgements; +using osu.Game.Rulesets.Objects; + +namespace osu.Game.Rulesets.Catch.Judgements +{ + public class CatchJudgementResult : JudgementResult + { + /// + /// The catcher animation state prior to this judgement. + /// + public CatcherAnimationState CatcherAnimationState; + + /// + /// Whether the catcher was hyper dashing prior to this judgement. + /// + public bool CatcherHyperDash; + + public CatchJudgementResult([NotNull] HitObject hitObject, [NotNull] Judgement judgement) + : base(hitObject, judgement) + { + } + } +} diff --git a/osu.Game.Rulesets.Catch/Objects/Drawables/DrawableCatchHitObject.cs b/osu.Game.Rulesets.Catch/Objects/Drawables/DrawableCatchHitObject.cs index 6aa8ff439e..70efe9cf29 100644 --- a/osu.Game.Rulesets.Catch/Objects/Drawables/DrawableCatchHitObject.cs +++ b/osu.Game.Rulesets.Catch/Objects/Drawables/DrawableCatchHitObject.cs @@ -5,7 +5,9 @@ using System; using JetBrains.Annotations; using osu.Framework.Bindables; using osu.Framework.Graphics; +using osu.Game.Rulesets.Catch.Judgements; using osu.Game.Rulesets.Catch.UI; +using osu.Game.Rulesets.Judgements; using osu.Game.Rulesets.Objects.Drawables; using osu.Game.Utils; @@ -52,6 +54,8 @@ namespace osu.Game.Rulesets.Catch.Objects.Drawables public override bool RemoveWhenNotAlive => IsOnPlate; + protected override JudgementResult CreateResult(Judgement judgement) => new CatchJudgementResult(HitObject, judgement); + protected override void CheckForResult(bool userTriggered, double timeOffset) { if (CheckPosition == null) return; diff --git a/osu.Game.Rulesets.Catch/UI/CatchPlayfield.cs b/osu.Game.Rulesets.Catch/UI/CatchPlayfield.cs index df87359ed6..fdc12bf088 100644 --- a/osu.Game.Rulesets.Catch/UI/CatchPlayfield.cs +++ b/osu.Game.Rulesets.Catch/UI/CatchPlayfield.cs @@ -81,7 +81,7 @@ namespace osu.Game.Rulesets.Catch.UI ((DrawableCatchHitObject)d).CheckPosition = checkIfWeCanCatch; } - private bool checkIfWeCanCatch(CatchHitObject obj) => CatcherArea.AttemptCatch(obj); + private bool checkIfWeCanCatch(CatchHitObject obj) => CatcherArea.MovableCatcher.CanCatch(obj); private void onNewResult(DrawableHitObject judgedObject, JudgementResult result) => CatcherArea.OnNewResult((DrawableCatchHitObject)judgedObject, result); diff --git a/osu.Game.Rulesets.Catch/UI/Catcher.cs b/osu.Game.Rulesets.Catch/UI/Catcher.cs index 2a3447c80a..a806e623af 100644 --- a/osu.Game.Rulesets.Catch/UI/Catcher.cs +++ b/osu.Game.Rulesets.Catch/UI/Catcher.cs @@ -14,9 +14,11 @@ using osu.Framework.Input.Bindings; using osu.Framework.Utils; using osu.Game.Beatmaps; using osu.Game.Configuration; +using osu.Game.Rulesets.Catch.Judgements; using osu.Game.Rulesets.Catch.Objects; using osu.Game.Rulesets.Catch.Objects.Drawables; using osu.Game.Rulesets.Catch.Skinning; +using osu.Game.Rulesets.Judgements; using osu.Game.Skinning; using osuTK; using osuTK.Graphics; @@ -190,11 +192,9 @@ namespace osu.Game.Rulesets.Catch.UI internal static float CalculateCatchWidth(BeatmapDifficulty difficulty) => CalculateCatchWidth(calculateScale(difficulty)); /// - /// Let the catcher attempt to catch a fruit. + /// Determine if this catcher can catch a in the current position. /// - /// The fruit to catch. - /// Whether the catch is possible. - public bool AttemptCatch(CatchHitObject hitObject) + public bool CanCatch(CatchHitObject hitObject) { if (!(hitObject is PalpableCatchHitObject fruit)) return false; @@ -205,21 +205,29 @@ namespace osu.Game.Rulesets.Catch.UI var catchObjectPosition = fruit.X; var catcherPosition = Position.X; - var validCatch = - catchObjectPosition >= catcherPosition - halfCatchWidth && - catchObjectPosition <= catcherPosition + halfCatchWidth; + return catchObjectPosition >= catcherPosition - halfCatchWidth && + catchObjectPosition <= catcherPosition + halfCatchWidth; + } - if (validCatch) - placeCaughtObject(fruit); + public void OnNewResult(DrawableCatchHitObject drawableObject, JudgementResult result) + { + var catchResult = (CatchJudgementResult)result; + catchResult.CatcherAnimationState = CurrentState; + catchResult.CatcherHyperDash = HyperDashing; + + if (!(drawableObject.HitObject is PalpableCatchHitObject hitObject)) return; + + if (result.IsHit) + placeCaughtObject(hitObject); // droplet doesn't affect the catcher state - if (fruit is TinyDroplet) return validCatch; + if (hitObject is TinyDroplet) return; - if (validCatch && fruit.HyperDash) + if (result.IsHit && hitObject.HyperDash) { - var target = fruit.HyperDashTarget; - var timeDifference = target.StartTime - fruit.StartTime; - double positionDifference = target.X - catcherPosition; + var target = hitObject.HyperDashTarget; + var timeDifference = target.StartTime - hitObject.StartTime; + double positionDifference = target.X - X; var velocity = positionDifference / Math.Max(1.0, timeDifference - 1000.0 / 60.0); SetHyperDashState(Math.Abs(velocity), target.X); @@ -227,12 +235,30 @@ namespace osu.Game.Rulesets.Catch.UI else SetHyperDashState(); - if (validCatch) - updateState(fruit.Kiai ? CatcherAnimationState.Kiai : CatcherAnimationState.Idle); - else if (!(fruit is Banana)) + if (result.IsHit) + updateState(hitObject.Kiai ? CatcherAnimationState.Kiai : CatcherAnimationState.Idle); + else if (!(hitObject is Banana)) updateState(CatcherAnimationState.Fail); + } - return validCatch; + public void OnRevertResult(DrawableCatchHitObject drawableObject, JudgementResult result) + { + var catchResult = (CatchJudgementResult)result; + + if (CurrentState != catchResult.CatcherAnimationState) + updateState(catchResult.CatcherAnimationState); + + if (HyperDashing != catchResult.CatcherHyperDash) + { + if (catchResult.CatcherHyperDash) + SetHyperDashState(2); + else + SetHyperDashState(); + } + + caughtFruitContainer.RemoveAll(d => d.HitObject == drawableObject.HitObject); + droppedObjectTarget.RemoveAll(d => (d as DrawableCatchHitObject)?.HitObject == drawableObject.HitObject); + hitExplosionContainer.RemoveAll(d => d.HitObject == drawableObject.HitObject); } /// @@ -464,6 +490,7 @@ namespace osu.Game.Rulesets.Catch.UI if (!hitLighting.Value) return; HitExplosion hitExplosion = hitExplosionPool.Get(); + hitExplosion.HitObject = caughtObject.HitObject; hitExplosion.X = caughtObject.X; hitExplosion.Scale = new Vector2(caughtObject.HitObject.Scale); hitExplosion.ObjectColour = caughtObject.AccentColour.Value; diff --git a/osu.Game.Rulesets.Catch/UI/CatcherArea.cs b/osu.Game.Rulesets.Catch/UI/CatcherArea.cs index 539776354c..857d9141c9 100644 --- a/osu.Game.Rulesets.Catch/UI/CatcherArea.cs +++ b/osu.Game.Rulesets.Catch/UI/CatcherArea.cs @@ -5,7 +5,6 @@ using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Game.Beatmaps; using osu.Game.Rulesets.Catch.Judgements; -using osu.Game.Rulesets.Catch.Objects; using osu.Game.Rulesets.Catch.Objects.Drawables; using osu.Game.Rulesets.Catch.Replays; using osu.Game.Rulesets.Judgements; @@ -42,6 +41,8 @@ namespace osu.Game.Rulesets.Catch.UI public void OnNewResult(DrawableCatchHitObject hitObject, JudgementResult result) { + MovableCatcher.OnNewResult(hitObject, result); + if (!result.Type.IsScorable()) return; @@ -56,12 +57,10 @@ namespace osu.Game.Rulesets.Catch.UI comboDisplay.OnNewResult(hitObject, result); } - public void OnRevertResult(DrawableCatchHitObject fruit, JudgementResult result) - => comboDisplay.OnRevertResult(fruit, result); - - public bool AttemptCatch(CatchHitObject obj) + public void OnRevertResult(DrawableCatchHitObject hitObject, JudgementResult result) { - return MovableCatcher.AttemptCatch(obj); + comboDisplay.OnRevertResult(hitObject, result); + MovableCatcher.OnRevertResult(hitObject, result); } protected override void UpdateAfterChildren() diff --git a/osu.Game.Rulesets.Catch/UI/HitExplosion.cs b/osu.Game.Rulesets.Catch/UI/HitExplosion.cs index 24ca778248..26627422e1 100644 --- a/osu.Game.Rulesets.Catch/UI/HitExplosion.cs +++ b/osu.Game.Rulesets.Catch/UI/HitExplosion.cs @@ -7,6 +7,7 @@ using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Effects; using osu.Framework.Graphics.Pooling; using osu.Framework.Utils; +using osu.Game.Rulesets.Catch.Objects; using osuTK; using osuTK.Graphics; @@ -15,6 +16,7 @@ namespace osu.Game.Rulesets.Catch.UI public class HitExplosion : PoolableDrawable { private Color4 objectColour; + public CatchHitObject HitObject; public Color4 ObjectColour {