mirror of
https://github.com/ppy/osu.git
synced 2025-03-19 09:07:18 +08:00
Merge pull request #11123 from ekrctb/catcher-on-result
Move catcher state changing logic to OnNewResult and OnRevertResult
This commit is contained in:
commit
67e0f02665
@ -1,6 +1,7 @@
|
||||
// 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.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
|
||||
|
@ -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();
|
||||
|
28
osu.Game.Rulesets.Catch/Judgements/CatchJudgementResult.cs
Normal file
28
osu.Game.Rulesets.Catch/Judgements/CatchJudgementResult.cs
Normal file
@ -0,0 +1,28 @@
|
||||
// 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 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
|
||||
{
|
||||
/// <summary>
|
||||
/// The catcher animation state prior to this judgement.
|
||||
/// </summary>
|
||||
public CatcherAnimationState CatcherAnimationState;
|
||||
|
||||
/// <summary>
|
||||
/// Whether the catcher was hyper dashing prior to this judgement.
|
||||
/// </summary>
|
||||
public bool CatcherHyperDash;
|
||||
|
||||
public CatchJudgementResult([NotNull] HitObject hitObject, [NotNull] Judgement judgement)
|
||||
: base(hitObject, judgement)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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));
|
||||
|
||||
/// <summary>
|
||||
/// Let the catcher attempt to catch a fruit.
|
||||
/// Determine if this catcher can catch a <see cref="CatchHitObject"/> in the current position.
|
||||
/// </summary>
|
||||
/// <param name="hitObject">The fruit to catch.</param>
|
||||
/// <returns>Whether the catch is possible.</returns>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -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;
|
||||
|
@ -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()
|
||||
|
@ -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
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user