1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-07 23:47:32 +08:00
osu-lazer/osu.Game.Rulesets.Osu/Mods/OsuModRandom.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

103 lines
4.3 KiB
C#
Raw Normal View History

2021-04-25 06:39:36 +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;
using System.Linq;
2021-04-28 04:19:04 +08:00
using osu.Framework.Utils;
2021-04-25 06:39:36 +08:00
using osu.Game.Beatmaps;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Osu.Beatmaps;
2022-06-20 05:03:41 +08:00
using osu.Game.Rulesets.Osu.Objects;
2021-04-25 06:39:36 +08:00
using osu.Game.Rulesets.Osu.UI;
using osu.Game.Rulesets.Osu.Utils;
2021-04-25 06:39:36 +08:00
namespace osu.Game.Rulesets.Osu.Mods
{
/// <summary>
/// Mod that randomises the positions of the <see cref="HitObject"/>s
/// </summary>
public class OsuModRandom : ModRandom, IApplicableToBeatmap
2021-04-25 06:39:36 +08:00
{
2021-04-25 07:43:32 +08:00
public override string Description => "It never gets boring!";
public override Type[] IncompatibleMods => base.IncompatibleMods.Append(typeof(OsuModTarget)).ToArray();
2022-04-28 11:15:04 +08:00
2022-06-20 05:03:41 +08:00
private static readonly float playfield_diagonal = OsuPlayfield.BASE_SIZE.LengthFast;
private Random? rng;
public void ApplyToBeatmap(IBeatmap beatmap)
2021-04-25 06:39:36 +08:00
{
if (!(beatmap is OsuBeatmap osuBeatmap))
return;
Seed.Value ??= RNG.Next();
rng = new Random((int)Seed.Value);
var positionInfos = OsuHitObjectGenerationUtils.GeneratePositionInfos(osuBeatmap.HitObjects);
2022-06-19 19:07:10 +08:00
float sequenceOffset = 0;
bool flowDirection = false;
2022-06-19 19:07:10 +08:00
for (int i = 0; i < positionInfos.Count; i++)
{
2022-06-19 19:07:10 +08:00
bool invertFlow = false;
2022-06-19 19:07:10 +08:00
if (i == 0 ||
2022-06-20 05:03:41 +08:00
(positionInfos[Math.Max(0, i - 2)].HitObject.IndexInCurrentCombo > 1 && positionInfos[i - 1].HitObject.NewCombo && rng.NextDouble() < 0.6) ||
2022-06-19 19:07:10 +08:00
OsuHitObjectGenerationUtils.IsHitObjectOnBeat(osuBeatmap, positionInfos[i - 1].HitObject, true) ||
(OsuHitObjectGenerationUtils.IsHitObjectOnBeat(osuBeatmap, positionInfos[i - 1].HitObject) && rng.NextDouble() < 0.25))
{
2022-06-19 19:07:10 +08:00
sequenceOffset = OsuHitObjectGenerationUtils.RandomGaussian(rng, 0, 0.02f);
if (rng.NextDouble() < 0.6)
invertFlow = true;
}
if (i == 0)
{
positionInfos[i].DistanceFromPrevious = (float)(rng.NextDouble() * OsuPlayfield.BASE_SIZE.Y / 2);
positionInfos[i].RelativeAngle = (float)(rng.NextDouble() * 2 * Math.PI - Math.PI);
}
else
{
2022-06-19 19:07:10 +08:00
float flowChangeOffset = 0;
float oneTimeOffset = OsuHitObjectGenerationUtils.RandomGaussian(rng, 0, 0.03f);
2022-06-20 05:03:41 +08:00
if (positionInfos[Math.Max(0, i - 2)].HitObject.IndexInCurrentCombo > 1 && positionInfos[i - 1].HitObject.NewCombo && rng.NextDouble() < 0.6)
2022-06-19 19:07:10 +08:00
{
flowChangeOffset = OsuHitObjectGenerationUtils.RandomGaussian(rng, 0, 0.05f);
if (rng.NextDouble() < 0.8)
invertFlow = true;
}
if (invertFlow)
2022-06-20 05:03:41 +08:00
flowDirection = !flowDirection;
2022-06-19 19:07:10 +08:00
2022-06-20 05:03:41 +08:00
positionInfos[i].RelativeAngle = getRelativeTargetAngle(
2022-06-19 19:07:10 +08:00
positionInfos[i].DistanceFromPrevious,
(sequenceOffset + oneTimeOffset) * (float)Math.Sqrt(positionInfos[i].DistanceFromPrevious) +
2022-06-20 05:03:41 +08:00
flowChangeOffset * (float)Math.Sqrt(playfield_diagonal - positionInfos[i].DistanceFromPrevious),
2022-06-19 19:07:10 +08:00
flowDirection
);
}
}
osuBeatmap.HitObjects = OsuHitObjectGenerationUtils.RepositionHitObjects(positionInfos);
}
2022-06-20 05:03:41 +08:00
/// <param name="targetDistance">The target distance between the previous and the current <see cref="OsuHitObject"/>.</param>
/// <param name="offset">The angle (in rad) by which the target angle should be offset.</param>
/// <param name="flowDirection">Whether the relative angle should be positive or negative.</param>
private static float getRelativeTargetAngle(float targetDistance, float offset, bool flowDirection)
{
float angle = (float)(3 / (1 + 200 * Math.Exp(0.016 * (targetDistance - 466))) + 0.45 + offset);
float relativeAngle = (float)Math.PI - angle;
return flowDirection ? -relativeAngle : relativeAngle;
}
}
2021-04-25 06:39:36 +08:00
}