1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-16 05:02:56 +08:00
osu-lazer/osu.Game.Rulesets.Catch/Mods/CatchModHardRock.cs

122 lines
3.8 KiB
C#
Raw Normal View History

// 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 17:19:50 +08:00
using osu.Framework.MathUtils;
using osu.Game.Rulesets.Catch.Objects;
using osu.Game.Rulesets.Catch.UI;
2018-04-13 17:19:50 +08:00
using osu.Game.Rulesets.Mods;
using System;
using osu.Game.Rulesets.Objects;
2018-04-13 17:19:50 +08:00
namespace osu.Game.Rulesets.Catch.Mods
{
public class CatchModHardRock : ModHardRock, IApplicableToHitObject
2018-04-13 17:19:50 +08:00
{
public override double ScoreMultiplier => 1.12;
public override bool Ranked => true;
2019-03-19 13:10:39 +08:00
private float? lastPosition;
private double lastStartTime;
public void ApplyToHitObject(HitObject hitObject)
{
if (hitObject is JuiceStream stream)
{
lastPosition = stream.EndX;
lastStartTime = stream.EndTime;
return;
}
if (!(hitObject is Fruit))
return;
var catchObject = (CatchHitObject)hitObject;
float position = catchObject.X;
2019-03-19 13:10:39 +08:00
double startTime = hitObject.StartTime;
2019-03-19 13:10:39 +08:00
if (lastPosition == null)
{
2019-03-19 13:10:39 +08:00
lastPosition = position;
lastStartTime = startTime;
2019-03-19 13:10:39 +08:00
return;
}
2019-03-19 13:12:10 +08:00
float positionDiff = position - lastPosition.Value;
2019-03-19 13:10:39 +08:00
double timeDiff = startTime - lastStartTime;
if (timeDiff > 1000)
{
2019-03-19 13:10:39 +08:00
lastPosition = position;
lastStartTime = startTime;
return;
}
2019-03-19 13:10:39 +08:00
if (positionDiff == 0)
{
2019-03-19 13:10:39 +08:00
applyRandomOffset(ref position, timeDiff / 4d);
catchObject.X = position;
return;
}
2019-03-19 13:10:39 +08:00
if (Math.Abs(positionDiff * CatchPlayfield.BASE_WIDTH) < timeDiff / 3d)
applyOffset(ref position, positionDiff);
2019-03-19 13:10:39 +08:00
catchObject.X = position;
2019-03-19 13:10:39 +08:00
lastPosition = position;
lastStartTime = startTime;
}
2019-03-19 13:10:39 +08:00
/// <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>
private void applyRandomOffset(ref float position, double maxOffset)
{
bool right = RNG.NextBool();
float rand = Math.Min(20, (float)RNG.NextDouble(0, Math.Max(0, maxOffset))) / CatchPlayfield.BASE_WIDTH;
2019-03-19 13:10:39 +08:00
if (right)
{
2019-03-19 13:10:39 +08:00
// Clamp to the right bound
if (position + rand <= 1)
position += rand;
else
2019-03-19 13:10:39 +08:00
position -= rand;
}
2019-03-19 13:10:39 +08:00
else
{
// Clamp to the left bound
if (position - rand >= 0)
position -= rand;
else
position += rand;
}
}
2019-03-19 13:10:39 +08:00
/// <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 void applyOffset(ref float position, float amount)
{
if (amount > 0)
{
2019-03-19 13:12:10 +08:00
// Clamp to the right bound
if (position + amount < 1)
position += amount;
2019-03-19 13:10:39 +08:00
}
else
{
2019-03-19 13:12:10 +08:00
// Clamp to the left bound
if (position + amount > 0)
position += amount;
2019-03-19 13:10:39 +08:00
}
}
2018-04-13 17:19:50 +08:00
}
}