2019-01-24 08:43:03 +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.
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
|
using osu.Game.Rulesets.Catch.Objects;
|
|
|
|
|
using osu.Game.Rulesets.Catch.UI;
|
|
|
|
|
using osu.Game.Rulesets.Objects.Types;
|
2018-05-25 10:11:29 +00:00
|
|
|
|
using osu.Game.Rulesets.Catch.MathUtils;
|
2019-07-31 09:44:01 +00:00
|
|
|
|
using osu.Game.Rulesets.Mods;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Catch.Beatmaps
|
|
|
|
|
{
|
2018-04-19 13:04:12 +00:00
|
|
|
|
public class CatchBeatmapProcessor : BeatmapProcessor
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2018-06-29 03:45:48 +00:00
|
|
|
|
public const int RNG_SEED = 1337;
|
|
|
|
|
|
2018-04-19 13:04:12 +00:00
|
|
|
|
public CatchBeatmapProcessor(IBeatmap beatmap)
|
|
|
|
|
: base(beatmap)
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2018-04-19 13:04:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-06-29 03:45:48 +00:00
|
|
|
|
public override void PostProcess()
|
|
|
|
|
{
|
2018-04-19 13:04:12 +00:00
|
|
|
|
base.PostProcess();
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2019-07-31 09:44:01 +00:00
|
|
|
|
ApplyPositionOffsets(Beatmap);
|
2018-06-29 03:45:48 +00:00
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
|
int index = 0;
|
2019-04-01 03:16:05 +00:00
|
|
|
|
|
2018-04-19 13:04:12 +00:00
|
|
|
|
foreach (var obj in Beatmap.HitObjects.OfType<CatchHitObject>())
|
2018-06-26 11:13:55 +00:00
|
|
|
|
{
|
2020-02-19 06:37:12 +00:00
|
|
|
|
obj.IndexInBeatmap = index;
|
|
|
|
|
foreach (var nested in obj.NestedHitObjects.OfType<CatchHitObject>())
|
|
|
|
|
nested.IndexInBeatmap = index;
|
|
|
|
|
|
2018-06-26 11:13:55 +00:00
|
|
|
|
if (obj.LastInCombo && obj.NestedHitObjects.LastOrDefault() is IHasComboInformation lastNested)
|
|
|
|
|
lastNested.LastInCombo = true;
|
2020-02-19 06:37:12 +00:00
|
|
|
|
|
|
|
|
|
index++;
|
2018-06-26 11:13:55 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-31 09:44:01 +00:00
|
|
|
|
public static void ApplyPositionOffsets(IBeatmap beatmap, params Mod[] mods)
|
2018-05-25 10:11:29 +00:00
|
|
|
|
{
|
|
|
|
|
var rng = new FastRandom(RNG_SEED);
|
|
|
|
|
|
2019-07-31 09:44:01 +00:00
|
|
|
|
bool shouldApplyHardRockOffset = mods.Any(m => m is ModHardRock);
|
|
|
|
|
float? lastPosition = null;
|
|
|
|
|
double lastStartTime = 0;
|
|
|
|
|
|
2019-08-01 04:33:00 +00:00
|
|
|
|
foreach (var obj in beatmap.HitObjects.OfType<CatchHitObject>())
|
2018-05-25 10:11:29 +00:00
|
|
|
|
{
|
2019-08-01 04:33:00 +00:00
|
|
|
|
obj.XOffset = 0;
|
|
|
|
|
|
2018-05-25 10:11:29 +00:00
|
|
|
|
switch (obj)
|
|
|
|
|
{
|
2019-07-31 09:44:01 +00:00
|
|
|
|
case Fruit fruit:
|
|
|
|
|
if (shouldApplyHardRockOffset)
|
|
|
|
|
applyHardRockOffset(fruit, ref lastPosition, ref lastStartTime, rng);
|
|
|
|
|
break;
|
|
|
|
|
|
2018-05-25 10:11:29 +00:00
|
|
|
|
case BananaShower bananaShower:
|
2018-06-29 06:01:33 +00:00
|
|
|
|
foreach (var banana in bananaShower.NestedHitObjects.OfType<Banana>())
|
2018-05-25 10:11:29 +00:00
|
|
|
|
{
|
2020-07-01 15:21:45 +00:00
|
|
|
|
banana.XOffset = (float)(rng.NextDouble() * CatchPlayfield.WIDTH);
|
2018-06-13 09:39:26 +00:00
|
|
|
|
rng.Next(); // osu!stable retrieved a random banana type
|
|
|
|
|
rng.Next(); // osu!stable retrieved a random banana rotation
|
2018-06-13 12:10:54 +00:00
|
|
|
|
rng.Next(); // osu!stable retrieved a random banana colour
|
2018-05-25 10:11:29 +00:00
|
|
|
|
}
|
2019-02-28 04:31:40 +00:00
|
|
|
|
|
2018-05-25 10:11:29 +00:00
|
|
|
|
break;
|
2019-04-01 03:16:05 +00:00
|
|
|
|
|
2018-05-25 10:11:29 +00:00
|
|
|
|
case JuiceStream juiceStream:
|
2020-03-11 09:37:58 +00:00
|
|
|
|
// Todo: BUG!! Stable used the last control point as the final position of the path, but it should use the computed path instead.
|
2020-07-01 15:21:45 +00:00
|
|
|
|
lastPosition = juiceStream.X + juiceStream.Path.ControlPoints[^1].Position.Value.X;
|
2020-03-11 09:37:58 +00:00
|
|
|
|
|
|
|
|
|
// Todo: BUG!! Stable attempted to use the end time of the stream, but referenced it too early in execution and used the start time instead.
|
|
|
|
|
lastStartTime = juiceStream.StartTime;
|
|
|
|
|
|
2018-05-25 10:11:29 +00:00
|
|
|
|
foreach (var nested in juiceStream.NestedHitObjects)
|
|
|
|
|
{
|
2019-08-01 05:57:17 +00:00
|
|
|
|
var catchObject = (CatchHitObject)nested;
|
|
|
|
|
catchObject.XOffset = 0;
|
|
|
|
|
|
|
|
|
|
if (catchObject is TinyDroplet)
|
2020-07-01 15:21:45 +00:00
|
|
|
|
catchObject.XOffset = Math.Clamp(rng.Next(-20, 20), -catchObject.X, CatchPlayfield.WIDTH - catchObject.X);
|
2019-08-01 05:57:17 +00:00
|
|
|
|
else if (catchObject is Droplet)
|
2018-06-13 10:52:04 +00:00
|
|
|
|
rng.Next(); // osu!stable retrieved a random droplet rotation
|
2018-05-25 10:11:29 +00:00
|
|
|
|
}
|
2019-02-28 04:31:40 +00:00
|
|
|
|
|
2018-05-25 10:11:29 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-03-11 09:36:37 +00:00
|
|
|
|
|
|
|
|
|
initialiseHyperDash(beatmap);
|
2018-05-25 10:11:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-08-01 04:33:00 +00:00
|
|
|
|
private static void applyHardRockOffset(CatchHitObject hitObject, ref float? lastPosition, ref double lastStartTime, FastRandom rng)
|
2019-07-31 09:44:01 +00:00
|
|
|
|
{
|
2019-08-01 04:33:00 +00:00
|
|
|
|
float offsetPosition = hitObject.X;
|
2019-07-31 09:44:01 +00:00
|
|
|
|
double startTime = hitObject.StartTime;
|
|
|
|
|
|
|
|
|
|
if (lastPosition == null)
|
|
|
|
|
{
|
2019-08-01 04:33:00 +00:00
|
|
|
|
lastPosition = offsetPosition;
|
2019-07-31 09:44:01 +00:00
|
|
|
|
lastStartTime = startTime;
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-01 04:33:00 +00:00
|
|
|
|
float positionDiff = offsetPosition - lastPosition.Value;
|
2020-03-11 09:43:08 +00:00
|
|
|
|
|
|
|
|
|
// Todo: BUG!! Stable calculated time deltas as ints, which affects randomisation. This should be changed to a double.
|
|
|
|
|
int timeDiff = (int)(startTime - lastStartTime);
|
2019-07-31 09:44:01 +00:00
|
|
|
|
|
|
|
|
|
if (timeDiff > 1000)
|
|
|
|
|
{
|
2019-08-01 04:33:00 +00:00
|
|
|
|
lastPosition = offsetPosition;
|
2019-07-31 09:44:01 +00:00
|
|
|
|
lastStartTime = startTime;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (positionDiff == 0)
|
|
|
|
|
{
|
2019-08-01 04:33:00 +00:00
|
|
|
|
applyRandomOffset(ref offsetPosition, timeDiff / 4d, rng);
|
2019-08-01 05:57:07 +00:00
|
|
|
|
hitObject.XOffset = offsetPosition - hitObject.X;
|
2019-07-31 09:44:01 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-11 09:43:08 +00:00
|
|
|
|
// ReSharper disable once PossibleLossOfFraction
|
2020-07-01 15:21:45 +00:00
|
|
|
|
if (Math.Abs(positionDiff) < timeDiff / 3)
|
2019-08-01 04:33:00 +00:00
|
|
|
|
applyOffset(ref offsetPosition, positionDiff);
|
2019-07-31 09:44:01 +00:00
|
|
|
|
|
2019-08-01 05:57:07 +00:00
|
|
|
|
hitObject.XOffset = offsetPosition - hitObject.X;
|
2019-07-31 09:44:01 +00:00
|
|
|
|
|
2019-08-01 04:33:00 +00:00
|
|
|
|
lastPosition = offsetPosition;
|
2019-07-31 09:44:01 +00:00
|
|
|
|
lastStartTime = startTime;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Applies a random offset in a random direction to a position, ensuring that the final position remains within the boundary of the playfield.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="position">The position which the offset should be applied to.</param>
|
|
|
|
|
/// <param name="maxOffset">The maximum offset, cannot exceed 20px.</param>
|
|
|
|
|
/// <param name="rng">The random number generator.</param>
|
|
|
|
|
private static void applyRandomOffset(ref float position, double maxOffset, FastRandom rng)
|
|
|
|
|
{
|
|
|
|
|
bool right = rng.NextBool();
|
2020-07-01 15:21:45 +00:00
|
|
|
|
float rand = Math.Min(20, (float)rng.Next(0, Math.Max(0, maxOffset)));
|
2019-07-31 09:44:01 +00:00
|
|
|
|
|
|
|
|
|
if (right)
|
|
|
|
|
{
|
|
|
|
|
// Clamp to the right bound
|
2020-07-01 15:21:45 +00:00
|
|
|
|
if (position + rand <= CatchPlayfield.WIDTH)
|
2019-07-31 09:44:01 +00:00
|
|
|
|
position += rand;
|
|
|
|
|
else
|
|
|
|
|
position -= rand;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Clamp to the left bound
|
|
|
|
|
if (position - rand >= 0)
|
|
|
|
|
position -= rand;
|
|
|
|
|
else
|
|
|
|
|
position += rand;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Applies an offset to a position, ensuring that the final position remains within the boundary of the playfield.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="position">The position which the offset should be applied to.</param>
|
|
|
|
|
/// <param name="amount">The amount to offset by.</param>
|
|
|
|
|
private static void applyOffset(ref float position, float amount)
|
|
|
|
|
{
|
|
|
|
|
if (amount > 0)
|
|
|
|
|
{
|
|
|
|
|
// Clamp to the right bound
|
|
|
|
|
if (position + amount < 1)
|
|
|
|
|
position += amount;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Clamp to the left bound
|
|
|
|
|
if (position + amount > 0)
|
|
|
|
|
position += amount;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-11 09:36:37 +00:00
|
|
|
|
private static void initialiseHyperDash(IBeatmap beatmap)
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2018-09-12 17:48:35 +00:00
|
|
|
|
List<CatchHitObject> objectWithDroplets = new List<CatchHitObject>();
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2020-03-11 09:36:37 +00:00
|
|
|
|
foreach (var currentObject in beatmap.HitObjects)
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2020-03-11 09:36:37 +00:00
|
|
|
|
if (currentObject is Fruit fruitObject)
|
|
|
|
|
objectWithDroplets.Add(fruitObject);
|
2019-11-11 12:05:36 +00:00
|
|
|
|
|
2018-09-12 17:48:35 +00:00
|
|
|
|
if (currentObject is JuiceStream)
|
2019-11-11 11:53:22 +00:00
|
|
|
|
{
|
2018-09-12 17:48:35 +00:00
|
|
|
|
foreach (var currentJuiceElement in currentObject.NestedHitObjects)
|
2019-11-11 11:53:22 +00:00
|
|
|
|
{
|
2018-09-12 17:48:35 +00:00
|
|
|
|
if (!(currentJuiceElement is TinyDroplet))
|
|
|
|
|
objectWithDroplets.Add((CatchHitObject)currentJuiceElement);
|
2019-11-11 11:53:22 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-09-12 17:48:35 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-09-13 15:15:46 +00:00
|
|
|
|
objectWithDroplets.Sort((h1, h2) => h1.StartTime.CompareTo(h2.StartTime));
|
|
|
|
|
|
2020-07-01 15:21:45 +00:00
|
|
|
|
double halfCatcherWidth = Catcher.CalculateCatchWidth(beatmap.BeatmapInfo.BaseDifficulty) / 2;
|
2018-09-12 17:48:35 +00:00
|
|
|
|
int lastDirection = 0;
|
|
|
|
|
double lastExcess = halfCatcherWidth;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-09-12 17:48:35 +00:00
|
|
|
|
for (int i = 0; i < objectWithDroplets.Count - 1; i++)
|
|
|
|
|
{
|
|
|
|
|
CatchHitObject currentObject = objectWithDroplets[i];
|
|
|
|
|
CatchHitObject nextObject = objectWithDroplets[i + 1];
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2020-03-11 09:36:37 +00:00
|
|
|
|
// Reset variables in-case values have changed (e.g. after applying HR)
|
|
|
|
|
currentObject.HyperDashTarget = null;
|
|
|
|
|
currentObject.DistanceToHyperDash = 0;
|
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
|
int thisDirection = nextObject.X > currentObject.X ? 1 : -1;
|
2019-03-03 11:21:39 +00:00
|
|
|
|
double timeToNext = nextObject.StartTime - currentObject.StartTime - 1000f / 60f / 4; // 1/4th of a frame of grace time, taken from osu-stable
|
2018-04-13 09:19:50 +00:00
|
|
|
|
double distanceToNext = Math.Abs(nextObject.X - currentObject.X) - (lastDirection == thisDirection ? lastExcess : halfCatcherWidth);
|
2020-03-13 03:59:30 +00:00
|
|
|
|
float distanceToHyper = (float)(timeToNext * Catcher.BASE_SPEED - distanceToNext);
|
2019-04-01 03:16:05 +00:00
|
|
|
|
|
2018-09-12 17:48:35 +00:00
|
|
|
|
if (distanceToHyper < 0)
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
|
|
|
|
currentObject.HyperDashTarget = nextObject;
|
|
|
|
|
lastExcess = halfCatcherWidth;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2018-09-12 17:48:35 +00:00
|
|
|
|
currentObject.DistanceToHyperDash = distanceToHyper;
|
2019-11-20 12:19:49 +00:00
|
|
|
|
lastExcess = Math.Clamp(distanceToHyper, 0, halfCatcherWidth);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lastDirection = thisDirection;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|