2020-03-13 11:59:30 +08: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;
|
2023-01-15 15:26:11 +08:00
|
|
|
using System.Diagnostics;
|
2020-03-13 11:59:30 +08:00
|
|
|
using System.Linq;
|
|
|
|
using osu.Framework.Allocation;
|
2020-07-14 11:52:34 +08:00
|
|
|
using osu.Framework.Bindables;
|
2020-03-13 11:59:30 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2020-12-01 10:32:20 +08:00
|
|
|
using osu.Framework.Graphics.Pooling;
|
2020-03-13 11:59:30 +08:00
|
|
|
using osu.Framework.Utils;
|
|
|
|
using osu.Game.Beatmaps;
|
2020-07-14 11:35:01 +08:00
|
|
|
using osu.Game.Configuration;
|
2020-12-08 14:02:55 +08:00
|
|
|
using osu.Game.Rulesets.Catch.Judgements;
|
2020-03-13 11:59:30 +08:00
|
|
|
using osu.Game.Rulesets.Catch.Objects;
|
|
|
|
using osu.Game.Rulesets.Catch.Objects.Drawables;
|
2020-03-26 14:11:59 +08:00
|
|
|
using osu.Game.Rulesets.Catch.Skinning;
|
2020-12-08 13:28:30 +08:00
|
|
|
using osu.Game.Rulesets.Judgements;
|
2023-10-20 17:57:14 +08:00
|
|
|
using osu.Game.Rulesets.Objects.Legacy;
|
2020-03-26 14:11:59 +08:00
|
|
|
using osu.Game.Skinning;
|
2020-03-13 11:59:30 +08:00
|
|
|
using osuTK;
|
|
|
|
using osuTK.Graphics;
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Catch.UI
|
|
|
|
{
|
2021-07-26 01:00:37 +08:00
|
|
|
[Cached]
|
2021-06-11 14:39:06 +08:00
|
|
|
public partial class Catcher : SkinReloadableDrawable
|
2020-03-13 11:59:30 +08:00
|
|
|
{
|
2021-07-21 15:43:24 +08:00
|
|
|
/// <summary>
|
|
|
|
/// The size of the catcher at 1x scale.
|
|
|
|
/// </summary>
|
2023-09-24 04:43:43 +08:00
|
|
|
/// <remarks>
|
|
|
|
/// This is mainly used to compute catching range, the actual catcher size may differ based on skin implementation and sprite textures.
|
|
|
|
/// This is also equivalent to the "catcherWidth" property in osu-stable when the game field and beatmap difficulty are set to default values.
|
|
|
|
/// </remarks>
|
|
|
|
/// <seealso cref="CatchPlayfield.WIDTH"/>
|
|
|
|
/// <seealso cref="CatchPlayfield.HEIGHT"/>
|
|
|
|
/// <seealso cref="IBeatmapDifficultyInfo.DEFAULT_DIFFICULTY"/>
|
2021-07-21 15:43:24 +08:00
|
|
|
public const float BASE_SIZE = 106.75f;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// The width of the catcher which can receive fruit. Equivalent to "catchMargin" in osu-stable.
|
|
|
|
/// </summary>
|
|
|
|
public const float ALLOWED_CATCH_RANGE = 0.8f;
|
|
|
|
|
2020-04-21 16:36:09 +08:00
|
|
|
/// <summary>
|
2021-07-28 18:02:24 +08:00
|
|
|
/// The default colour used to tint hyper-dash fruit, along with the moving catcher, its trail and after-image during a hyper-dash.
|
2020-04-21 16:36:09 +08:00
|
|
|
/// </summary>
|
2020-04-08 19:23:29 +08:00
|
|
|
public static readonly Color4 DEFAULT_HYPER_DASH_COLOUR = Color4.Red;
|
2020-03-26 10:37:26 +08:00
|
|
|
|
2020-04-22 10:12:29 +08:00
|
|
|
/// <summary>
|
|
|
|
/// The duration between transitioning to hyper-dash state.
|
|
|
|
/// </summary>
|
|
|
|
public const double HYPER_DASH_TRANSITION_DURATION = 180;
|
|
|
|
|
2020-03-13 11:59:30 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Whether we are hyper-dashing or not.
|
|
|
|
/// </summary>
|
|
|
|
public bool HyperDashing => hyperDashModifier != 1;
|
|
|
|
|
2021-03-30 13:33:55 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Whether <see cref="DrawablePalpableCatchHitObject"/> fruit should appear on the plate.
|
|
|
|
/// </summary>
|
|
|
|
public bool CatchFruitOnPlate { get; set; } = true;
|
|
|
|
|
2020-03-13 11:59:30 +08:00
|
|
|
/// <summary>
|
2021-10-26 19:09:48 +08:00
|
|
|
/// The speed of the catcher when the catcher is dashing.
|
2020-03-13 11:59:30 +08:00
|
|
|
/// </summary>
|
2021-10-26 19:09:48 +08:00
|
|
|
public const double BASE_DASH_SPEED = 1.0;
|
2020-03-13 11:59:30 +08:00
|
|
|
|
2021-06-11 14:39:06 +08:00
|
|
|
/// <summary>
|
2021-10-26 19:09:48 +08:00
|
|
|
/// The speed of the catcher when the catcher is not dashing.
|
2021-06-11 14:39:06 +08:00
|
|
|
/// </summary>
|
2021-10-26 19:09:48 +08:00
|
|
|
public const double BASE_WALK_SPEED = 0.5;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// The current speed of the catcher with the hyper-dash modifier applied.
|
|
|
|
/// </summary>
|
|
|
|
public double Speed => (Dashing ? BASE_DASH_SPEED : BASE_WALK_SPEED) * hyperDashModifier;
|
2021-06-11 14:39:06 +08:00
|
|
|
|
2021-04-22 16:06:08 +08:00
|
|
|
/// <summary>
|
|
|
|
/// The amount by which caught fruit should be scaled down to fit on the plate.
|
|
|
|
/// </summary>
|
|
|
|
private const float caught_fruit_scale_adjust = 0.5f;
|
|
|
|
|
2020-12-09 09:35:01 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Contains caught objects on the plate.
|
|
|
|
/// </summary>
|
2020-12-09 09:35:36 +08:00
|
|
|
private readonly Container<CaughtObject> caughtObjectContainer;
|
2020-12-02 20:23:34 +08:00
|
|
|
|
2020-12-09 09:35:01 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Contains objects dropped from the plate.
|
|
|
|
/// </summary>
|
2021-07-19 19:11:49 +08:00
|
|
|
private readonly DroppedObjectContainer droppedObjectTarget;
|
2020-12-09 09:35:01 +08:00
|
|
|
|
2021-06-14 18:41:51 +08:00
|
|
|
public CatcherAnimationState CurrentState
|
|
|
|
{
|
2021-07-26 16:50:52 +08:00
|
|
|
get => body.AnimationState.Value;
|
|
|
|
private set => body.AnimationState.Value = value;
|
2021-06-14 18:41:51 +08:00
|
|
|
}
|
2020-03-13 11:59:30 +08:00
|
|
|
|
2021-07-26 16:50:10 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Whether the catcher is currently dashing.
|
|
|
|
/// </summary>
|
2021-07-26 16:46:56 +08:00
|
|
|
public bool Dashing { get; set; }
|
2020-03-13 11:59:30 +08:00
|
|
|
|
2021-07-02 21:18:31 +08:00
|
|
|
/// <summary>
|
|
|
|
/// The currently facing direction.
|
|
|
|
/// </summary>
|
2021-07-02 21:00:41 +08:00
|
|
|
public Direction VisualDirection { get; set; } = Direction.Right;
|
2021-06-11 14:39:06 +08:00
|
|
|
|
2021-07-27 17:59:55 +08:00
|
|
|
public Vector2 BodyScale => Scale * body.Scale;
|
|
|
|
|
2020-04-22 12:27:15 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Width of the area that can be used to attempt catches during gameplay.
|
|
|
|
/// </summary>
|
2021-07-26 01:00:37 +08:00
|
|
|
public readonly float CatchWidth;
|
2020-04-22 12:27:15 +08:00
|
|
|
|
2021-07-26 16:50:52 +08:00
|
|
|
private readonly SkinnableCatcher body;
|
2020-03-14 16:06:23 +08:00
|
|
|
|
2020-04-21 10:58:56 +08:00
|
|
|
private Color4 hyperDashColour = DEFAULT_HYPER_DASH_COLOUR;
|
2020-03-26 14:11:31 +08:00
|
|
|
|
2023-12-04 16:30:18 +08:00
|
|
|
private double? lastHyperDashStartTime;
|
2020-03-13 11:59:30 +08:00
|
|
|
private double hyperDashModifier = 1;
|
|
|
|
private int hyperDashDirection;
|
|
|
|
private float hyperDashTargetPosition;
|
2023-01-15 15:26:11 +08:00
|
|
|
private Bindable<bool> hitLighting = null!;
|
2020-03-13 11:59:30 +08:00
|
|
|
|
2021-06-04 18:46:50 +08:00
|
|
|
private readonly HitExplosionContainer hitExplosionContainer;
|
2020-12-01 10:32:20 +08:00
|
|
|
|
2020-12-08 21:38:10 +08:00
|
|
|
private readonly DrawablePool<CaughtFruit> caughtFruitPool;
|
|
|
|
private readonly DrawablePool<CaughtBanana> caughtBananaPool;
|
|
|
|
private readonly DrawablePool<CaughtDroplet> caughtDropletPool;
|
|
|
|
|
2023-01-15 15:26:11 +08:00
|
|
|
public Catcher(DroppedObjectContainer droppedObjectTarget, IBeatmapDifficultyInfo? difficulty = null)
|
2020-03-13 11:59:30 +08:00
|
|
|
{
|
2021-07-19 19:11:49 +08:00
|
|
|
this.droppedObjectTarget = droppedObjectTarget;
|
2020-04-21 16:41:53 +08:00
|
|
|
|
2020-03-13 11:59:30 +08:00
|
|
|
Origin = Anchor.TopCentre;
|
|
|
|
|
2021-07-21 15:43:24 +08:00
|
|
|
Size = new Vector2(BASE_SIZE);
|
2023-03-29 17:03:21 +08:00
|
|
|
|
2020-03-13 11:59:30 +08:00
|
|
|
if (difficulty != null)
|
2023-10-18 22:56:15 +08:00
|
|
|
Scale = calculateScale(difficulty);
|
2020-04-22 12:27:15 +08:00
|
|
|
|
2021-07-26 01:00:37 +08:00
|
|
|
CatchWidth = CalculateCatchWidth(Scale);
|
2020-07-14 11:35:01 +08:00
|
|
|
|
2020-03-26 14:11:59 +08:00
|
|
|
InternalChildren = new Drawable[]
|
2020-03-13 11:59:30 +08:00
|
|
|
{
|
2020-12-08 21:38:10 +08:00
|
|
|
caughtFruitPool = new DrawablePool<CaughtFruit>(50),
|
|
|
|
caughtBananaPool = new DrawablePool<CaughtBanana>(100),
|
|
|
|
// less capacity is needed compared to fruit because droplet is not stacked
|
|
|
|
caughtDropletPool = new DrawablePool<CaughtDroplet>(25),
|
2020-12-09 09:35:36 +08:00
|
|
|
caughtObjectContainer = new Container<CaughtObject>
|
2020-12-02 18:28:47 +08:00
|
|
|
{
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
Origin = Anchor.BottomCentre,
|
2021-06-21 18:08:43 +08:00
|
|
|
// offset fruit vertically to better place "above" the plate.
|
|
|
|
Y = -5
|
2020-12-02 18:28:47 +08:00
|
|
|
},
|
2021-07-26 16:50:52 +08:00
|
|
|
body = new SkinnableCatcher(),
|
2021-06-04 18:46:50 +08:00
|
|
|
hitExplosionContainer = new HitExplosionContainer
|
2020-12-01 10:32:20 +08:00
|
|
|
{
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
Origin = Anchor.BottomCentre,
|
|
|
|
},
|
2020-03-13 11:59:30 +08:00
|
|
|
};
|
2020-12-02 18:28:47 +08:00
|
|
|
}
|
2020-03-13 11:59:30 +08:00
|
|
|
|
2020-12-02 18:28:47 +08:00
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(OsuConfigManager config)
|
|
|
|
{
|
|
|
|
hitLighting = config.GetBindable<bool>(OsuSetting.HitLighting);
|
2020-10-19 16:41:21 +08:00
|
|
|
}
|
|
|
|
|
2020-07-16 14:35:19 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Creates proxied content to be displayed beneath hitobjects.
|
|
|
|
/// </summary>
|
2020-12-09 09:35:36 +08:00
|
|
|
public Drawable CreateProxiedContent() => caughtObjectContainer.CreateProxy();
|
2020-07-16 14:35:19 +08:00
|
|
|
|
2020-04-22 12:27:15 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Calculates the width of the area used for attempting catches in gameplay.
|
|
|
|
/// </summary>
|
2020-04-22 12:36:59 +08:00
|
|
|
/// <param name="scale">The scale of the catcher.</param>
|
2021-07-21 15:43:24 +08:00
|
|
|
public static float CalculateCatchWidth(Vector2 scale) => BASE_SIZE * Math.Abs(scale.X) * ALLOWED_CATCH_RANGE;
|
2020-04-22 12:27:15 +08:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Calculates the width of the area used for attempting catches in gameplay.
|
|
|
|
/// </summary>
|
2020-04-22 12:36:59 +08:00
|
|
|
/// <param name="difficulty">The beatmap difficulty.</param>
|
2023-10-18 22:56:15 +08:00
|
|
|
public static float CalculateCatchWidth(IBeatmapDifficultyInfo difficulty) => CalculateCatchWidth(calculateScale(difficulty));
|
2020-03-13 11:59:30 +08:00
|
|
|
|
|
|
|
/// <summary>
|
2020-12-08 13:28:30 +08:00
|
|
|
/// Determine if this catcher can catch a <see cref="CatchHitObject"/> in the current position.
|
2020-03-13 11:59:30 +08:00
|
|
|
/// </summary>
|
2020-12-08 13:28:30 +08:00
|
|
|
public bool CanCatch(CatchHitObject hitObject)
|
2020-03-13 11:59:30 +08:00
|
|
|
{
|
2020-11-24 18:57:37 +08:00
|
|
|
if (!(hitObject is PalpableCatchHitObject fruit))
|
2020-08-21 00:58:07 +08:00
|
|
|
return false;
|
|
|
|
|
2021-07-26 01:00:37 +08:00
|
|
|
float halfCatchWidth = CatchWidth * 0.5f;
|
2021-07-26 17:18:24 +08:00
|
|
|
return fruit.EffectiveX >= X - halfCatchWidth &&
|
|
|
|
fruit.EffectiveX <= X + halfCatchWidth;
|
2020-12-08 13:28:30 +08:00
|
|
|
}
|
|
|
|
|
2021-03-30 13:33:55 +08:00
|
|
|
public void OnNewResult(DrawableCatchHitObject drawableObject, JudgementResult result)
|
2020-12-08 13:28:30 +08:00
|
|
|
{
|
2020-12-08 14:02:55 +08:00
|
|
|
var catchResult = (CatchJudgementResult)result;
|
|
|
|
catchResult.CatcherAnimationState = CurrentState;
|
2020-12-08 14:21:47 +08:00
|
|
|
catchResult.CatcherHyperDash = HyperDashing;
|
2020-12-08 14:02:55 +08:00
|
|
|
|
2021-11-19 03:03:41 +08:00
|
|
|
// Ignore JuiceStreams and BananaShowers
|
2020-12-09 09:25:35 +08:00
|
|
|
if (!(drawableObject is DrawablePalpableCatchHitObject palpableObject)) return;
|
2020-12-08 19:41:26 +08:00
|
|
|
|
|
|
|
var hitObject = palpableObject.HitObject;
|
2020-03-13 11:59:30 +08:00
|
|
|
|
2020-12-08 13:28:30 +08:00
|
|
|
if (result.IsHit)
|
2020-12-08 19:41:26 +08:00
|
|
|
{
|
2021-04-22 16:06:08 +08:00
|
|
|
var positionInStack = computePositionInStack(new Vector2(palpableObject.X - X, 0), palpableObject.DisplaySize.X);
|
2020-12-08 19:41:26 +08:00
|
|
|
|
2021-03-30 13:33:55 +08:00
|
|
|
if (CatchFruitOnPlate)
|
2021-03-25 16:04:35 +08:00
|
|
|
placeCaughtObject(palpableObject, positionInStack);
|
2020-12-08 19:41:26 +08:00
|
|
|
|
|
|
|
if (hitLighting.Value)
|
2021-07-25 23:19:51 +08:00
|
|
|
addLighting(result, drawableObject.AccentColour.Value, positionInStack.X);
|
2020-12-08 19:41:26 +08:00
|
|
|
}
|
2020-12-04 09:24:25 +08:00
|
|
|
|
2020-12-03 13:44:35 +08:00
|
|
|
// droplet doesn't affect the catcher state
|
2020-12-08 13:28:30 +08:00
|
|
|
if (hitObject is TinyDroplet) return;
|
2020-12-04 09:24:25 +08:00
|
|
|
|
2023-12-04 16:30:18 +08:00
|
|
|
// if a hyper fruit was already handled this frame, just go where it says to go.
|
|
|
|
// this special-cases some aspire maps that have doubled-up objects (one hyper, one not) at the same time instant.
|
|
|
|
// handling this "properly" elsewhere is impossible as there is no feasible way to ensure
|
|
|
|
// that the hyperfruit gets judged second (especially if it coincides with a last fruit in a juice stream).
|
|
|
|
if (lastHyperDashStartTime != Time.Current)
|
2020-03-13 11:59:30 +08:00
|
|
|
{
|
2023-12-04 16:30:18 +08:00
|
|
|
if (result.IsHit && hitObject.HyperDashTarget is CatchHitObject target)
|
|
|
|
{
|
|
|
|
double timeDifference = target.StartTime - hitObject.StartTime;
|
|
|
|
double positionDifference = target.EffectiveX - X;
|
|
|
|
double velocity = positionDifference / Math.Max(1.0, timeDifference - 1000.0 / 60.0);
|
2020-12-04 09:24:25 +08:00
|
|
|
|
2023-12-04 16:30:18 +08:00
|
|
|
SetHyperDashState(Math.Abs(velocity) / BASE_DASH_SPEED, target.EffectiveX);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
SetHyperDashState();
|
2020-03-13 11:59:30 +08:00
|
|
|
}
|
|
|
|
|
2020-12-08 13:28:30 +08:00
|
|
|
if (result.IsHit)
|
2021-06-14 18:41:51 +08:00
|
|
|
CurrentState = hitObject.Kiai ? CatcherAnimationState.Kiai : CatcherAnimationState.Idle;
|
2020-12-08 13:28:30 +08:00
|
|
|
else if (!(hitObject is Banana))
|
2021-06-14 18:41:51 +08:00
|
|
|
CurrentState = CatcherAnimationState.Fail;
|
2021-11-19 03:24:40 +08:00
|
|
|
|
|
|
|
if (palpableObject.HitObject.LastInCombo)
|
|
|
|
{
|
|
|
|
if (result.Judgement is CatchJudgement catchJudgement && catchJudgement.ShouldExplodeFor(result))
|
|
|
|
Explode();
|
|
|
|
else
|
|
|
|
Drop();
|
|
|
|
}
|
2020-12-08 13:28:30 +08:00
|
|
|
}
|
2020-03-13 11:59:30 +08:00
|
|
|
|
2023-01-19 18:43:23 +08:00
|
|
|
public void OnRevertResult(JudgementResult result)
|
2020-12-08 13:28:30 +08:00
|
|
|
{
|
2020-12-08 14:02:55 +08:00
|
|
|
var catchResult = (CatchJudgementResult)result;
|
2020-12-08 14:21:47 +08:00
|
|
|
|
2021-06-14 18:41:51 +08:00
|
|
|
CurrentState = catchResult.CatcherAnimationState;
|
2020-12-08 14:21:47 +08:00
|
|
|
|
|
|
|
if (HyperDashing != catchResult.CatcherHyperDash)
|
|
|
|
{
|
|
|
|
if (catchResult.CatcherHyperDash)
|
|
|
|
SetHyperDashState(2);
|
|
|
|
else
|
|
|
|
SetHyperDashState();
|
|
|
|
}
|
2020-12-08 14:24:39 +08:00
|
|
|
|
2023-01-19 18:43:23 +08:00
|
|
|
caughtObjectContainer.RemoveAll(d => d.HitObject == result.HitObject, false);
|
|
|
|
droppedObjectTarget.RemoveAll(d => d.HitObject == result.HitObject, false);
|
2020-03-13 11:59:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Set hyper-dash state.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="modifier">The speed multiplier. If this is less or equals to 1, this catcher will be non-hyper-dashing state.</param>
|
|
|
|
/// <param name="targetPosition">When this catcher crosses this position, this catcher ends hyper-dashing.</param>
|
|
|
|
public void SetHyperDashState(double modifier = 1, float targetPosition = -1)
|
|
|
|
{
|
2021-10-27 12:04:41 +08:00
|
|
|
bool wasHyperDashing = HyperDashing;
|
2020-03-13 11:59:30 +08:00
|
|
|
|
|
|
|
if (modifier <= 1 || X == targetPosition)
|
|
|
|
{
|
|
|
|
hyperDashModifier = 1;
|
|
|
|
hyperDashDirection = 0;
|
|
|
|
|
|
|
|
if (wasHyperDashing)
|
2020-05-10 23:05:30 +08:00
|
|
|
runHyperDashStateTransition(false);
|
2023-12-04 16:30:18 +08:00
|
|
|
|
|
|
|
lastHyperDashStartTime = null;
|
2020-03-13 11:59:30 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
hyperDashModifier = modifier;
|
|
|
|
hyperDashDirection = Math.Sign(targetPosition - X);
|
|
|
|
hyperDashTargetPosition = targetPosition;
|
|
|
|
|
|
|
|
if (!wasHyperDashing)
|
2020-05-10 23:05:30 +08:00
|
|
|
runHyperDashStateTransition(true);
|
2023-12-04 16:30:18 +08:00
|
|
|
|
|
|
|
lastHyperDashStartTime = Time.Current;
|
2020-03-13 11:59:30 +08:00
|
|
|
}
|
2020-03-26 14:11:31 +08:00
|
|
|
}
|
|
|
|
|
2020-03-13 11:59:30 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Drop any fruit off the plate.
|
|
|
|
/// </summary>
|
2020-12-02 20:23:34 +08:00
|
|
|
public void Drop() => clearPlate(DroppedObjectAnimation.Drop);
|
2020-03-13 11:59:30 +08:00
|
|
|
|
|
|
|
/// <summary>
|
2020-12-04 13:35:56 +08:00
|
|
|
/// Explode all fruit off the plate.
|
2020-03-13 11:59:30 +08:00
|
|
|
/// </summary>
|
2020-12-02 20:23:34 +08:00
|
|
|
public void Explode() => clearPlate(DroppedObjectAnimation.Explode);
|
2020-03-13 11:59:30 +08:00
|
|
|
|
2020-12-04 13:36:40 +08:00
|
|
|
private void runHyperDashStateTransition(bool hyperDashing)
|
|
|
|
{
|
2021-04-20 17:18:50 +08:00
|
|
|
this.FadeColour(hyperDashing ? hyperDashColour : Color4.White, HYPER_DASH_TRANSITION_DURATION, Easing.OutQuint);
|
2020-12-04 13:36:40 +08:00
|
|
|
}
|
|
|
|
|
2021-05-27 13:50:42 +08:00
|
|
|
protected override void SkinChanged(ISkinSource skin)
|
2020-03-26 14:11:59 +08:00
|
|
|
{
|
2021-05-27 13:50:42 +08:00
|
|
|
base.SkinChanged(skin);
|
2020-03-26 14:11:59 +08:00
|
|
|
|
2020-04-21 10:58:56 +08:00
|
|
|
hyperDashColour =
|
|
|
|
skin.GetConfig<CatchSkinColour, Color4>(CatchSkinColour.HyperDash)?.Value ??
|
|
|
|
DEFAULT_HYPER_DASH_COLOUR;
|
|
|
|
|
2020-05-10 23:05:30 +08:00
|
|
|
runHyperDashStateTransition(HyperDashing);
|
2020-03-26 14:11:59 +08:00
|
|
|
}
|
|
|
|
|
2020-03-13 11:59:30 +08:00
|
|
|
protected override void Update()
|
|
|
|
{
|
|
|
|
base.Update();
|
|
|
|
|
2021-07-02 21:00:41 +08:00
|
|
|
var scaleFromDirection = new Vector2((int)VisualDirection, 1);
|
2023-03-29 17:03:21 +08:00
|
|
|
|
2021-07-26 16:50:52 +08:00
|
|
|
body.Scale = scaleFromDirection;
|
2023-03-29 17:03:21 +08:00
|
|
|
// Inverse of catcher scale is applied here, as catcher gets scaled by circle size and so do the incoming fruit.
|
2024-02-14 12:17:05 +08:00
|
|
|
caughtObjectContainer.Scale = new Vector2(1 / Scale.X);
|
2021-07-02 21:00:41 +08:00
|
|
|
|
2020-03-13 11:59:30 +08:00
|
|
|
// Correct overshooting.
|
2020-03-14 14:35:59 +08:00
|
|
|
if ((hyperDashDirection > 0 && hyperDashTargetPosition < X) ||
|
|
|
|
(hyperDashDirection < 0 && hyperDashTargetPosition > X))
|
2020-03-13 11:59:30 +08:00
|
|
|
{
|
|
|
|
X = hyperDashTargetPosition;
|
|
|
|
SetHyperDashState();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-09 09:25:35 +08:00
|
|
|
private void placeCaughtObject(DrawablePalpableCatchHitObject drawableObject, Vector2 position)
|
2020-12-03 13:44:35 +08:00
|
|
|
{
|
2020-12-08 21:38:10 +08:00
|
|
|
var caughtObject = getCaughtObject(drawableObject.HitObject);
|
2020-12-04 13:35:56 +08:00
|
|
|
|
2020-12-03 13:44:35 +08:00
|
|
|
if (caughtObject == null) return;
|
|
|
|
|
2020-12-08 22:35:24 +08:00
|
|
|
caughtObject.CopyStateFrom(drawableObject);
|
2020-12-08 21:38:10 +08:00
|
|
|
caughtObject.Anchor = Anchor.TopCentre;
|
2020-12-08 19:41:26 +08:00
|
|
|
caughtObject.Position = position;
|
2021-04-22 16:06:08 +08:00
|
|
|
caughtObject.Scale *= caught_fruit_scale_adjust;
|
2020-12-03 13:44:35 +08:00
|
|
|
|
2020-12-09 09:35:36 +08:00
|
|
|
caughtObjectContainer.Add(caughtObject);
|
2020-12-04 13:35:56 +08:00
|
|
|
|
2020-12-03 13:44:35 +08:00
|
|
|
if (!caughtObject.StaysOnPlate)
|
2020-12-04 13:35:56 +08:00
|
|
|
removeFromPlate(caughtObject, DroppedObjectAnimation.Explode);
|
|
|
|
}
|
|
|
|
|
2020-12-08 11:48:13 +08:00
|
|
|
private Vector2 computePositionInStack(Vector2 position, float displayRadius)
|
2020-12-04 13:35:56 +08:00
|
|
|
{
|
2021-04-22 16:06:08 +08:00
|
|
|
// this is taken from osu-stable (lenience should be 10 * 10 at standard scale).
|
|
|
|
const float lenience_adjust = 10 / CatchHitObject.OBJECT_RADIUS;
|
2020-12-04 13:35:56 +08:00
|
|
|
|
2021-04-22 16:06:08 +08:00
|
|
|
float adjustedRadius = displayRadius * lenience_adjust;
|
|
|
|
float checkDistance = MathF.Pow(adjustedRadius, 2);
|
2020-12-04 13:35:56 +08:00
|
|
|
|
2021-04-22 16:06:08 +08:00
|
|
|
while (caughtObjectContainer.Any(f => Vector2Extensions.DistanceSquared(f.Position, position) < checkDistance))
|
|
|
|
{
|
|
|
|
position.X += RNG.NextSingle(-adjustedRadius, adjustedRadius);
|
|
|
|
position.Y -= RNG.NextSingle(0, 5);
|
|
|
|
}
|
2020-12-08 11:48:13 +08:00
|
|
|
|
|
|
|
return position;
|
2020-12-04 13:35:56 +08:00
|
|
|
}
|
|
|
|
|
2021-07-25 23:19:51 +08:00
|
|
|
private void addLighting(JudgementResult judgementResult, Color4 colour, float x) =>
|
2021-08-13 03:14:46 +08:00
|
|
|
hitExplosionContainer.Add(new HitExplosionEntry(Time.Current, judgementResult, colour, x));
|
2020-12-03 13:44:35 +08:00
|
|
|
|
2023-01-15 15:26:11 +08:00
|
|
|
private CaughtObject? getCaughtObject(PalpableCatchHitObject source)
|
2020-12-03 13:44:35 +08:00
|
|
|
{
|
|
|
|
switch (source)
|
|
|
|
{
|
2022-06-24 20:25:23 +08:00
|
|
|
case Fruit:
|
2020-12-08 21:38:10 +08:00
|
|
|
return caughtFruitPool.Get();
|
2020-12-03 13:44:35 +08:00
|
|
|
|
2022-06-24 20:25:23 +08:00
|
|
|
case Banana:
|
2020-12-08 21:38:10 +08:00
|
|
|
return caughtBananaPool.Get();
|
2020-12-03 13:44:35 +08:00
|
|
|
|
2022-06-24 20:25:23 +08:00
|
|
|
case Droplet:
|
2020-12-08 21:38:10 +08:00
|
|
|
return caughtDropletPool.Get();
|
2020-12-03 13:44:35 +08:00
|
|
|
|
|
|
|
default:
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-08 21:38:10 +08:00
|
|
|
private CaughtObject getDroppedObject(CaughtObject caughtObject)
|
|
|
|
{
|
|
|
|
var droppedObject = getCaughtObject(caughtObject.HitObject);
|
2023-01-15 15:26:11 +08:00
|
|
|
Debug.Assert(droppedObject != null);
|
2020-12-08 21:38:10 +08:00
|
|
|
|
2020-12-08 22:35:24 +08:00
|
|
|
droppedObject.CopyStateFrom(caughtObject);
|
2020-12-08 21:38:10 +08:00
|
|
|
droppedObject.Anchor = Anchor.TopLeft;
|
2020-12-09 09:35:36 +08:00
|
|
|
droppedObject.Position = caughtObjectContainer.ToSpaceOfOtherDrawable(caughtObject.DrawPosition, droppedObjectTarget);
|
2020-12-08 21:38:10 +08:00
|
|
|
|
|
|
|
return droppedObject;
|
|
|
|
}
|
|
|
|
|
2020-12-02 20:23:34 +08:00
|
|
|
private void clearPlate(DroppedObjectAnimation animation)
|
2020-03-13 11:59:30 +08:00
|
|
|
{
|
2023-04-22 03:46:03 +08:00
|
|
|
var caughtObjects = caughtObjectContainer.Children.ToArray();
|
2020-12-08 21:38:10 +08:00
|
|
|
|
2020-12-09 09:35:36 +08:00
|
|
|
caughtObjectContainer.Clear(false);
|
2020-03-13 11:59:30 +08:00
|
|
|
|
2023-04-22 16:54:50 +08:00
|
|
|
// Use the already returned PoolableDrawables for new objects
|
2023-04-22 03:46:03 +08:00
|
|
|
var droppedObjects = caughtObjects.Select(getDroppedObject).ToArray();
|
|
|
|
|
2020-12-08 21:38:10 +08:00
|
|
|
droppedObjectTarget.AddRange(droppedObjects);
|
2020-03-13 11:59:30 +08:00
|
|
|
|
2020-12-08 21:38:10 +08:00
|
|
|
foreach (var droppedObject in droppedObjects)
|
|
|
|
applyDropAnimation(droppedObject, animation);
|
2020-12-02 20:23:34 +08:00
|
|
|
}
|
|
|
|
|
2020-12-08 19:34:08 +08:00
|
|
|
private void removeFromPlate(CaughtObject caughtObject, DroppedObjectAnimation animation)
|
2020-12-02 20:23:34 +08:00
|
|
|
{
|
2022-08-26 14:19:05 +08:00
|
|
|
caughtObjectContainer.Remove(caughtObject, false);
|
2020-12-02 20:23:34 +08:00
|
|
|
|
2023-04-22 16:54:50 +08:00
|
|
|
var droppedObject = getDroppedObject(caughtObject);
|
2020-12-02 20:23:34 +08:00
|
|
|
|
2023-04-22 16:54:50 +08:00
|
|
|
droppedObjectTarget.Add(droppedObject);
|
|
|
|
|
|
|
|
applyDropAnimation(droppedObject, animation);
|
2020-12-02 20:23:34 +08:00
|
|
|
}
|
|
|
|
|
2020-12-08 21:38:10 +08:00
|
|
|
private void applyDropAnimation(Drawable d, DroppedObjectAnimation animation)
|
2020-12-02 20:23:34 +08:00
|
|
|
{
|
2020-12-08 19:34:08 +08:00
|
|
|
switch (animation)
|
2020-12-02 20:23:34 +08:00
|
|
|
{
|
2020-12-08 19:34:08 +08:00
|
|
|
case DroppedObjectAnimation.Drop:
|
|
|
|
d.MoveToY(d.Y + 75, 750, Easing.InSine);
|
|
|
|
d.FadeOut(750);
|
|
|
|
break;
|
2020-03-13 11:59:30 +08:00
|
|
|
|
2020-12-08 19:34:08 +08:00
|
|
|
case DroppedObjectAnimation.Explode:
|
2021-07-02 21:00:41 +08:00
|
|
|
float originalX = droppedObjectTarget.ToSpaceOfOtherDrawable(d.DrawPosition, caughtObjectContainer).X * caughtObjectContainer.Scale.X;
|
2020-12-08 19:34:08 +08:00
|
|
|
d.MoveToY(d.Y - 50, 250, Easing.OutSine).Then().MoveToY(d.Y + 50, 500, Easing.InSine);
|
|
|
|
d.MoveToX(d.X + originalX * 6, 1000);
|
|
|
|
d.FadeOut(750);
|
|
|
|
break;
|
2020-03-13 11:59:30 +08:00
|
|
|
}
|
2020-12-08 19:34:08 +08:00
|
|
|
|
2023-04-22 16:54:50 +08:00
|
|
|
// Define lifetime start for dropped objects to be disposed correctly when rewinding replay
|
2023-04-22 03:46:03 +08:00
|
|
|
d.LifetimeStart = Clock.CurrentTime;
|
2020-12-08 19:34:08 +08:00
|
|
|
d.Expire();
|
2020-03-13 11:59:30 +08:00
|
|
|
}
|
2020-12-02 20:23:34 +08:00
|
|
|
|
2023-10-18 22:56:15 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Calculates the scale of the catcher based off the provided beatmap difficulty.
|
|
|
|
/// </summary>
|
2023-10-20 17:57:14 +08:00
|
|
|
private static Vector2 calculateScale(IBeatmapDifficultyInfo difficulty) => new Vector2(LegacyRulesetExtensions.CalculateScaleFromCircleSize(difficulty.CircleSize) * 2);
|
2023-10-18 22:56:15 +08:00
|
|
|
|
2020-12-03 17:45:38 +08:00
|
|
|
private enum DroppedObjectAnimation
|
|
|
|
{
|
|
|
|
Drop,
|
|
|
|
Explode
|
|
|
|
}
|
2020-12-02 20:23:34 +08:00
|
|
|
}
|
2020-03-13 11:59:30 +08:00
|
|
|
}
|