2021-02-05 05:31:22 +00: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.
|
|
|
|
|
2023-07-18 03:31:21 +00:00
|
|
|
using System;
|
2023-07-19 18:28:04 +00:00
|
|
|
using System.Linq;
|
2021-02-05 05:31:22 +00:00
|
|
|
using osu.Game.Rulesets.Objects;
|
|
|
|
using osu.Game.Rulesets.Objects.Drawables;
|
|
|
|
using osu.Game.Rulesets.Osu.Objects.Drawables;
|
2023-08-23 11:37:39 +00:00
|
|
|
using osu.Game.Rulesets.Osu.Scoring;
|
2023-08-23 11:12:18 +00:00
|
|
|
using osu.Game.Rulesets.Scoring;
|
2021-02-08 11:12:33 +00:00
|
|
|
using osu.Game.Rulesets.UI;
|
2021-02-05 05:31:22 +00:00
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Osu.UI
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// Ensures that <see cref="HitObject"/>s are hit in order of appearance. The classic note lock.
|
|
|
|
/// <remarks>
|
|
|
|
/// Hits will be blocked until the previous <see cref="HitObject"/>s have been judged.
|
|
|
|
/// </remarks>
|
|
|
|
/// </summary>
|
2023-07-19 18:44:28 +00:00
|
|
|
public class LegacyHitPolicy : IHitPolicy
|
2021-02-05 05:31:22 +00:00
|
|
|
{
|
2023-09-01 07:54:35 +00:00
|
|
|
public IHitObjectContainer? HitObjectContainer { get; set; }
|
2021-02-05 05:31:22 +00:00
|
|
|
|
2023-08-23 11:37:39 +00:00
|
|
|
private readonly double hittableRange;
|
|
|
|
|
|
|
|
public LegacyHitPolicy(double hittableRange = OsuHitWindows.MISS_WINDOW)
|
|
|
|
{
|
|
|
|
this.hittableRange = hittableRange;
|
|
|
|
}
|
|
|
|
|
2021-02-05 05:31:22 +00:00
|
|
|
public void HandleHit(DrawableHitObject hitObject)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-08-23 11:12:18 +00:00
|
|
|
public virtual ClickAction CheckHittable(DrawableHitObject hitObject, double time, HitResult result)
|
2021-02-05 05:31:22 +00:00
|
|
|
{
|
2023-09-01 07:54:35 +00:00
|
|
|
if (HitObjectContainer == null)
|
|
|
|
throw new InvalidOperationException($"{nameof(HitObjectContainer)} should be set before {nameof(CheckHittable)} is called.");
|
|
|
|
|
2023-07-19 18:28:04 +00:00
|
|
|
var aliveObjects = HitObjectContainer.AliveObjects.ToList();
|
|
|
|
int index = aliveObjects.IndexOf(hitObject);
|
2023-07-18 03:31:21 +00:00
|
|
|
|
|
|
|
if (index > 0)
|
2021-02-05 05:31:22 +00:00
|
|
|
{
|
2023-07-19 18:28:04 +00:00
|
|
|
var previousHitObject = (DrawableOsuHitObject)aliveObjects[index - 1];
|
2023-07-18 03:31:21 +00:00
|
|
|
if (previousHitObject.HitObject.StackHeight > 0 && !previousHitObject.AllJudged)
|
|
|
|
return ClickAction.Ignore;
|
|
|
|
}
|
2021-02-05 05:31:22 +00:00
|
|
|
|
2023-08-23 11:12:18 +00:00
|
|
|
if (result == HitResult.None)
|
|
|
|
return ClickAction.Shake;
|
|
|
|
|
2023-07-19 18:28:04 +00:00
|
|
|
foreach (DrawableHitObject testObject in aliveObjects)
|
2023-07-18 03:31:21 +00:00
|
|
|
{
|
|
|
|
if (testObject.AllJudged)
|
|
|
|
continue;
|
2021-02-05 05:31:22 +00:00
|
|
|
|
2023-07-18 03:31:21 +00:00
|
|
|
// if we found the object being checked, we can move on to the final timing test.
|
|
|
|
if (testObject == hitObject)
|
|
|
|
break;
|
2021-02-05 05:31:22 +00:00
|
|
|
|
2023-07-18 03:31:21 +00:00
|
|
|
// for all other objects, we check for validity and block the hit if any are still valid.
|
|
|
|
// 3ms of extra leniency to account for slightly unsnapped objects.
|
|
|
|
if (testObject.HitObject.GetEndTime() + 3 < hitObject.HitObject.StartTime)
|
|
|
|
return ClickAction.Shake;
|
|
|
|
}
|
2021-02-05 05:31:22 +00:00
|
|
|
|
2023-08-23 11:37:39 +00:00
|
|
|
return Math.Abs(hitObject.HitObject.StartTime - time) < hittableRange ? ClickAction.Hit : ClickAction.Shake;
|
2021-02-05 05:31:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|