2021-04-24 22:39:36 +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.
|
|
|
|
|
|
|
|
using System;
|
2021-05-15 00:07:24 +00:00
|
|
|
using System.Linq;
|
2021-04-27 20:19:04 +00:00
|
|
|
using osu.Framework.Utils;
|
2021-04-24 22:39:36 +00:00
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
using osu.Game.Rulesets.Mods;
|
2021-04-24 23:34:39 +00:00
|
|
|
using osu.Game.Rulesets.Objects;
|
2021-05-01 02:01:43 +00:00
|
|
|
using osu.Game.Rulesets.Osu.Beatmaps;
|
2021-04-24 22:39:36 +00:00
|
|
|
using osu.Game.Rulesets.Osu.UI;
|
2022-03-09 13:52:15 +00:00
|
|
|
using osu.Game.Rulesets.Osu.Utils;
|
2021-04-24 22:39:36 +00:00
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Osu.Mods
|
|
|
|
{
|
2021-04-24 23:34:39 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Mod that randomises the positions of the <see cref="HitObject"/>s
|
|
|
|
/// </summary>
|
2021-04-27 17:39:58 +00:00
|
|
|
public class OsuModRandom : ModRandom, IApplicableToBeatmap
|
2021-04-24 22:39:36 +00:00
|
|
|
{
|
2021-04-24 23:43:32 +00:00
|
|
|
public override string Description => "It never gets boring!";
|
2021-04-24 23:34:39 +00:00
|
|
|
|
2022-04-28 16:29:37 +00:00
|
|
|
public override Type[] IncompatibleMods => base.IncompatibleMods.Append(typeof(OsuModTarget)).ToArray();
|
2022-04-28 03:15:04 +00:00
|
|
|
|
2021-05-24 05:24:56 +00:00
|
|
|
private static readonly float playfield_diagonal = OsuPlayfield.BASE_SIZE.LengthFast;
|
2021-06-29 04:33:40 +00:00
|
|
|
|
2022-03-09 07:58:36 +00:00
|
|
|
private Random? rng;
|
2021-05-26 07:37:30 +00:00
|
|
|
|
2021-05-12 16:11:50 +00:00
|
|
|
public void ApplyToBeatmap(IBeatmap beatmap)
|
2021-04-24 22:39:36 +00:00
|
|
|
{
|
2021-05-12 16:11:50 +00:00
|
|
|
if (!(beatmap is OsuBeatmap osuBeatmap))
|
2021-05-01 02:01:43 +00:00
|
|
|
return;
|
|
|
|
|
2021-05-13 23:50:11 +00:00
|
|
|
Seed.Value ??= RNG.Next();
|
2021-04-27 18:44:36 +00:00
|
|
|
|
2021-05-26 07:37:30 +00:00
|
|
|
rng = new Random((int)Seed.Value);
|
2021-04-25 21:57:01 +00:00
|
|
|
|
2022-03-10 03:53:03 +00:00
|
|
|
var positionInfos = OsuHitObjectGenerationUtils.GeneratePositionInfos(osuBeatmap.HitObjects);
|
2022-03-08 03:50:30 +00:00
|
|
|
|
|
|
|
float rateOfChangeMultiplier = 0;
|
|
|
|
|
2022-03-10 03:53:03 +00:00
|
|
|
foreach (var positionInfo in positionInfos)
|
2022-03-08 03:50:30 +00:00
|
|
|
{
|
|
|
|
// rateOfChangeMultiplier only changes every 5 iterations in a combo
|
|
|
|
// to prevent shaky-line-shaped streams
|
2022-03-09 12:36:31 +00:00
|
|
|
if (positionInfo.HitObject.IndexInCurrentCombo % 5 == 0)
|
2022-03-08 03:50:30 +00:00
|
|
|
rateOfChangeMultiplier = (float)rng.NextDouble() * 2 - 1;
|
|
|
|
|
2022-03-10 03:53:03 +00:00
|
|
|
if (positionInfo == positionInfos.First())
|
2022-03-08 03:50:30 +00:00
|
|
|
{
|
2022-04-01 03:57:45 +00:00
|
|
|
positionInfo.DistanceFromPrevious = (float)(rng.NextDouble() * OsuPlayfield.BASE_SIZE.Y / 2);
|
2022-03-09 12:36:31 +00:00
|
|
|
positionInfo.RelativeAngle = (float)(rng.NextDouble() * 2 * Math.PI - Math.PI);
|
2022-03-08 03:50:30 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-03-25 07:13:25 +00:00
|
|
|
positionInfo.RelativeAngle = rateOfChangeMultiplier * 2 * (float)Math.PI * Math.Min(1f, positionInfo.DistanceFromPrevious / (playfield_diagonal * 0.5f));
|
2022-03-08 03:50:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-10 03:53:03 +00:00
|
|
|
osuBeatmap.HitObjects = OsuHitObjectGenerationUtils.RepositionHitObjects(positionInfos);
|
2021-05-24 05:19:10 +00:00
|
|
|
}
|
2021-05-01 02:01:43 +00:00
|
|
|
}
|
2021-04-24 22:39:36 +00:00
|
|
|
}
|