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;
|
2022-08-13 06:57:49 +08:00
|
|
|
using System.Collections.Generic;
|
2021-05-15 08:07:24 +08:00
|
|
|
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;
|
2021-04-25 07:34:39 +08:00
|
|
|
using osu.Game.Rulesets.Objects;
|
2021-05-01 10:01:43 +08:00
|
|
|
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;
|
2022-03-09 21:52:15 +08:00
|
|
|
using osu.Game.Rulesets.Osu.Utils;
|
2021-04-25 06:39:36 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Osu.Mods
|
|
|
|
{
|
2021-04-25 07:34:39 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Mod that randomises the positions of the <see cref="HitObject"/>s
|
|
|
|
/// </summary>
|
2021-04-28 01:39:58 +08:00
|
|
|
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!";
|
2021-04-25 07:34:39 +08:00
|
|
|
|
2022-04-29 00:29:37 +08:00
|
|
|
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;
|
|
|
|
|
2022-03-09 15:58:36 +08:00
|
|
|
private Random? rng;
|
2021-05-26 15:37:30 +08:00
|
|
|
|
2021-05-13 00:11:50 +08:00
|
|
|
public void ApplyToBeatmap(IBeatmap beatmap)
|
2021-04-25 06:39:36 +08:00
|
|
|
{
|
2022-08-13 06:57:49 +08:00
|
|
|
if (beatmap is not OsuBeatmap osuBeatmap)
|
2021-05-01 10:01:43 +08:00
|
|
|
return;
|
|
|
|
|
2021-05-14 07:50:11 +08:00
|
|
|
Seed.Value ??= RNG.Next();
|
2021-04-28 02:44:36 +08:00
|
|
|
|
2021-05-26 15:37:30 +08:00
|
|
|
rng = new Random((int)Seed.Value);
|
2021-04-26 05:57:01 +08:00
|
|
|
|
2022-03-10 11:53:03 +08:00
|
|
|
var positionInfos = OsuHitObjectGenerationUtils.GeneratePositionInfos(osuBeatmap.HitObjects);
|
2022-03-08 11:50:30 +08:00
|
|
|
|
2022-08-13 06:57:49 +08:00
|
|
|
// Offsets the angles of all hit objects in a "section" by the same amount.
|
|
|
|
float sectionOffset = 0;
|
|
|
|
|
|
|
|
// Whether the angles are positive or negative (clockwise or counter-clockwise flow).
|
2022-06-19 19:07:10 +08:00
|
|
|
bool flowDirection = false;
|
2022-03-08 11:50:30 +08:00
|
|
|
|
2022-06-19 19:07:10 +08:00
|
|
|
for (int i = 0; i < positionInfos.Count; i++)
|
2022-03-08 11:50:30 +08:00
|
|
|
{
|
2022-08-13 06:57:49 +08:00
|
|
|
if (shouldStartNewSection(osuBeatmap, positionInfos, i, 0.6f, 0.4f))
|
2022-03-08 11:50:30 +08:00
|
|
|
{
|
2022-08-13 09:11:58 +08:00
|
|
|
sectionOffset = OsuHitObjectGenerationUtils.RandomGaussian(rng, 0, 0.0008f);
|
2022-07-27 01:07:25 +08:00
|
|
|
flowDirection = !flowDirection;
|
2022-06-19 19:07:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2022-03-08 11:50:30 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-08-13 06:57:49 +08:00
|
|
|
// Offsets only the angle of the current hit object if a flow change occurs.
|
2022-06-19 19:07:10 +08:00
|
|
|
float flowChangeOffset = 0;
|
2022-08-13 06:57:49 +08:00
|
|
|
|
|
|
|
// Offsets only the angle of the current hit object.
|
2022-07-27 01:07:25 +08:00
|
|
|
float oneTimeOffset = OsuHitObjectGenerationUtils.RandomGaussian(rng, 0, 0.002f);
|
2022-06-19 19:07:10 +08:00
|
|
|
|
2022-08-13 06:57:49 +08:00
|
|
|
if (shouldApplyFlowChange(positionInfos, i, 0.6f))
|
2022-06-19 19:07:10 +08:00
|
|
|
{
|
2022-06-20 06:05:03 +08:00
|
|
|
flowChangeOffset = OsuHitObjectGenerationUtils.RandomGaussian(rng, 0, 0.002f);
|
2022-06-20 05:03:41 +08:00
|
|
|
flowDirection = !flowDirection;
|
2022-07-27 01:07:25 +08:00
|
|
|
}
|
2022-06-19 19:07:10 +08:00
|
|
|
|
2022-08-13 06:57:49 +08:00
|
|
|
float totalOffset =
|
|
|
|
// sectionOffset and oneTimeOffset should mainly affect patterns with large spacing.
|
|
|
|
(sectionOffset + oneTimeOffset) * positionInfos[i].DistanceFromPrevious +
|
|
|
|
// flowChangeOffset should mainly affect streams.
|
|
|
|
flowChangeOffset * (playfield_diagonal - positionInfos[i].DistanceFromPrevious);
|
|
|
|
|
|
|
|
positionInfos[i].RelativeAngle = getRelativeTargetAngle(positionInfos[i].DistanceFromPrevious, totalOffset, flowDirection);
|
2022-03-08 11:50:30 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-10 11:53:03 +08:00
|
|
|
osuBeatmap.HitObjects = OsuHitObjectGenerationUtils.RepositionHitObjects(positionInfos);
|
2021-05-24 13:19:10 +08:00
|
|
|
}
|
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)
|
|
|
|
{
|
2022-08-13 09:11:58 +08:00
|
|
|
float angle = (float)(2.16 / (1 + 200 * Math.Exp(0.036 * (targetDistance - 310))) + 0.5 + offset);
|
2022-06-20 05:03:41 +08:00
|
|
|
float relativeAngle = (float)Math.PI - angle;
|
|
|
|
return flowDirection ? -relativeAngle : relativeAngle;
|
|
|
|
}
|
2022-08-13 06:57:49 +08:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// A new section should be started...<br/>
|
|
|
|
/// ...at the beginning of the <see cref="OsuBeatmap"/>.<br/>
|
|
|
|
/// ...on every combo start with a probability of <paramref name="newComboProbability"/> (excluding new-combo-spam and 1-2-combos).<br/>
|
|
|
|
/// ...on every downbeat.<br/>
|
|
|
|
/// ...on every beat with a probability of <paramref name="beatProbability"/>.<br/>
|
|
|
|
/// </summary>
|
|
|
|
/// <returns>Whether a new section should be started at the current <see cref="OsuHitObject"/>.</returns>
|
|
|
|
private bool shouldStartNewSection(
|
|
|
|
OsuBeatmap beatmap,
|
|
|
|
IReadOnlyList<OsuHitObjectGenerationUtils.ObjectPositionInfo> positionInfos,
|
|
|
|
int i,
|
|
|
|
float newComboProbability,
|
|
|
|
float beatProbability
|
|
|
|
) =>
|
|
|
|
i == 0 ||
|
|
|
|
(positionInfos[Math.Max(0, i - 2)].HitObject.IndexInCurrentCombo > 1 && positionInfos[i - 1].HitObject.NewCombo && rng?.NextDouble() < newComboProbability) ||
|
|
|
|
OsuHitObjectGenerationUtils.IsHitObjectOnBeat(beatmap, positionInfos[i - 1].HitObject, true) ||
|
|
|
|
(OsuHitObjectGenerationUtils.IsHitObjectOnBeat(beatmap, positionInfos[i - 1].HitObject) && rng?.NextDouble() < beatProbability);
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// A flow change should occur on every combo start with a probability of <paramref name="probability"/> (excluding new-combo-spam and 1-2-combos).
|
|
|
|
/// </summary>
|
|
|
|
/// <returns>Whether a flow change should be applied at the current <see cref="OsuHitObject"/>.</returns>
|
|
|
|
private bool shouldApplyFlowChange(IReadOnlyList<OsuHitObjectGenerationUtils.ObjectPositionInfo> positionInfos, int i, float probability) =>
|
|
|
|
positionInfos[Math.Max(0, i - 2)].HitObject.IndexInCurrentCombo > 1 &&
|
|
|
|
positionInfos[i - 1].HitObject.NewCombo &&
|
|
|
|
rng?.NextDouble() < probability;
|
2021-05-01 10:01:43 +08:00
|
|
|
}
|
2021-04-25 06:39:36 +08:00
|
|
|
}
|