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;
|
2022-08-12 22:57:49 +00:00
|
|
|
using System.Collections.Generic;
|
2021-05-15 00:07:24 +00:00
|
|
|
using System.Linq;
|
2022-09-18 21:43:14 +00:00
|
|
|
using osu.Framework.Bindables;
|
2022-08-10 20:09:11 +00:00
|
|
|
using osu.Framework.Localisation;
|
2021-04-27 20:19:04 +00:00
|
|
|
using osu.Framework.Utils;
|
2021-04-24 22:39:36 +00:00
|
|
|
using osu.Game.Beatmaps;
|
2022-09-18 21:43:14 +00:00
|
|
|
using osu.Game.Configuration;
|
|
|
|
using osu.Game.Overlays.Settings;
|
2021-04-24 22:39:36 +00:00
|
|
|
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;
|
2022-06-19 21:03:41 +00:00
|
|
|
using osu.Game.Rulesets.Osu.Objects;
|
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
|
|
|
{
|
2022-08-10 20:09:11 +00:00
|
|
|
public override LocalisableString Description => "It never gets boring!";
|
2021-04-24 23:34:39 +00:00
|
|
|
|
2022-11-01 10:47:20 +00:00
|
|
|
public override Type[] IncompatibleMods => base.IncompatibleMods.Append(typeof(OsuModTargetPractice)).ToArray();
|
2022-04-28 03:15:04 +00:00
|
|
|
|
2022-09-18 21:43:14 +00:00
|
|
|
[SettingSource("Angle sharpness", "How sharp angles should be", SettingControlType = typeof(SettingsSlider<float>))]
|
2022-09-25 19:49:22 +00:00
|
|
|
public BindableFloat AngleSharpness { get; } = new BindableFloat(7)
|
2022-09-18 21:43:14 +00:00
|
|
|
{
|
|
|
|
MinValue = 1,
|
|
|
|
MaxValue = 10,
|
|
|
|
Precision = 0.1f
|
|
|
|
};
|
|
|
|
|
2022-06-19 21:03:41 +00:00
|
|
|
private static readonly float playfield_diagonal = OsuPlayfield.BASE_SIZE.LengthFast;
|
|
|
|
|
2022-09-09 08:55:29 +00:00
|
|
|
private Random random = null!;
|
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
|
|
|
{
|
2022-08-12 22:57:49 +00:00
|
|
|
if (beatmap is not 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
|
|
|
|
2022-09-09 08:55:29 +00:00
|
|
|
random = 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
|
|
|
|
2022-08-12 22:57:49 +00: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 11:07:10 +00:00
|
|
|
bool flowDirection = false;
|
2022-03-08 03:50:30 +00:00
|
|
|
|
2022-06-19 11:07:10 +00:00
|
|
|
for (int i = 0; i < positionInfos.Count; i++)
|
2022-03-08 03:50:30 +00:00
|
|
|
{
|
2022-08-14 17:02:29 +00:00
|
|
|
if (shouldStartNewSection(osuBeatmap, positionInfos, i))
|
2022-03-08 03:50:30 +00:00
|
|
|
{
|
2022-09-18 21:43:14 +00:00
|
|
|
sectionOffset = getRandomOffset(0.0008f);
|
2022-07-26 17:07:25 +00:00
|
|
|
flowDirection = !flowDirection;
|
2022-06-19 11:07:10 +00:00
|
|
|
}
|
|
|
|
|
2022-12-06 23:40:18 +00:00
|
|
|
if (positionInfos[i].HitObject is Slider slider && random.NextDouble() < 0.5)
|
|
|
|
{
|
2022-12-07 21:09:53 +00:00
|
|
|
OsuHitObjectGenerationUtils.FlipSliderInPlaceHorizontally(slider);
|
2022-12-06 23:40:18 +00:00
|
|
|
}
|
|
|
|
|
2022-06-19 11:07:10 +00:00
|
|
|
if (i == 0)
|
|
|
|
{
|
2022-09-09 08:55:29 +00:00
|
|
|
positionInfos[i].DistanceFromPrevious = (float)(random.NextDouble() * OsuPlayfield.BASE_SIZE.Y / 2);
|
|
|
|
positionInfos[i].RelativeAngle = (float)(random.NextDouble() * 2 * Math.PI - Math.PI);
|
2022-03-08 03:50:30 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-08-12 22:57:49 +00:00
|
|
|
// Offsets only the angle of the current hit object if a flow change occurs.
|
2022-06-19 11:07:10 +00:00
|
|
|
float flowChangeOffset = 0;
|
2022-08-12 22:57:49 +00:00
|
|
|
|
|
|
|
// Offsets only the angle of the current hit object.
|
2022-09-18 21:43:14 +00:00
|
|
|
float oneTimeOffset = getRandomOffset(0.002f);
|
2022-06-19 11:07:10 +00:00
|
|
|
|
2022-08-14 17:02:29 +00:00
|
|
|
if (shouldApplyFlowChange(positionInfos, i))
|
2022-06-19 11:07:10 +00:00
|
|
|
{
|
2022-09-18 21:43:14 +00:00
|
|
|
flowChangeOffset = getRandomOffset(0.002f);
|
2022-06-19 21:03:41 +00:00
|
|
|
flowDirection = !flowDirection;
|
2022-07-26 17:07:25 +00:00
|
|
|
}
|
2022-06-19 11:07:10 +00:00
|
|
|
|
2022-08-12 22:57:49 +00: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 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
|
|
|
}
|
2022-06-19 21:03:41 +00:00
|
|
|
|
2022-09-18 21:43:14 +00:00
|
|
|
private float getRandomOffset(float stdDev)
|
|
|
|
{
|
2022-09-20 21:13:38 +00:00
|
|
|
// Range: [0.5, 2]
|
|
|
|
// Higher angle sharpness -> lower multiplier
|
2022-09-20 21:11:38 +00:00
|
|
|
float customMultiplier = (1.5f * AngleSharpness.MaxValue - AngleSharpness.Value) / (1.5f * AngleSharpness.MaxValue - AngleSharpness.Default);
|
|
|
|
|
2022-09-18 21:43:14 +00:00
|
|
|
return OsuHitObjectGenerationUtils.RandomGaussian(random, 0, stdDev * customMultiplier);
|
|
|
|
}
|
|
|
|
|
2022-06-19 21:03:41 +00: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>
|
2022-09-18 21:43:14 +00:00
|
|
|
private float getRelativeTargetAngle(float targetDistance, float offset, bool flowDirection)
|
2022-06-19 21:03:41 +00:00
|
|
|
{
|
2022-09-20 21:13:38 +00:00
|
|
|
// Range: [0.1, 1]
|
2022-09-18 21:43:14 +00:00
|
|
|
float angleSharpness = AngleSharpness.Value / AngleSharpness.MaxValue;
|
2022-09-20 21:13:38 +00:00
|
|
|
// Range: [0, 0.9]
|
2022-09-18 21:43:14 +00:00
|
|
|
float angleWideness = 1 - angleSharpness;
|
|
|
|
|
2022-09-20 21:13:38 +00:00
|
|
|
// Range: [-60, 30]
|
2022-09-18 21:43:14 +00:00
|
|
|
float customOffsetX = angleSharpness * 100 - 70;
|
2022-09-20 21:13:38 +00:00
|
|
|
// Range: [-0.075, 0.15]
|
2022-09-18 21:43:14 +00:00
|
|
|
float customOffsetY = angleWideness * 0.25f - 0.075f;
|
|
|
|
|
|
|
|
targetDistance += customOffsetX;
|
|
|
|
float angle = (float)(2.16 / (1 + 200 * Math.Exp(0.036 * (targetDistance - 310 + customOffsetX))) + 0.5);
|
|
|
|
angle += offset + customOffsetY;
|
|
|
|
|
2022-06-19 21:03:41 +00:00
|
|
|
float relativeAngle = (float)Math.PI - angle;
|
2022-09-18 21:43:14 +00:00
|
|
|
|
2022-06-19 21:03:41 +00:00
|
|
|
return flowDirection ? -relativeAngle : relativeAngle;
|
|
|
|
}
|
2022-08-12 22:57:49 +00:00
|
|
|
|
|
|
|
/// <returns>Whether a new section should be started at the current <see cref="OsuHitObject"/>.</returns>
|
2022-08-14 17:02:29 +00:00
|
|
|
private bool shouldStartNewSection(OsuBeatmap beatmap, IReadOnlyList<OsuHitObjectGenerationUtils.ObjectPositionInfo> positionInfos, int i)
|
|
|
|
{
|
|
|
|
if (i == 0)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// Exclude new-combo-spam and 1-2-combos.
|
|
|
|
bool previousObjectStartedCombo = positionInfos[Math.Max(0, i - 2)].HitObject.IndexInCurrentCombo > 1 &&
|
|
|
|
positionInfos[i - 1].HitObject.NewCombo;
|
|
|
|
bool previousObjectWasOnDownbeat = OsuHitObjectGenerationUtils.IsHitObjectOnBeat(beatmap, positionInfos[i - 1].HitObject, true);
|
|
|
|
bool previousObjectWasOnBeat = OsuHitObjectGenerationUtils.IsHitObjectOnBeat(beatmap, positionInfos[i - 1].HitObject);
|
|
|
|
|
2022-09-09 08:55:29 +00:00
|
|
|
return (previousObjectStartedCombo && random.NextDouble() < 0.6f) ||
|
2022-08-14 17:02:29 +00:00
|
|
|
previousObjectWasOnDownbeat ||
|
2022-09-09 08:55:29 +00:00
|
|
|
(previousObjectWasOnBeat && random.NextDouble() < 0.4f);
|
2022-08-14 17:02:29 +00:00
|
|
|
}
|
|
|
|
|
2022-08-12 22:57:49 +00:00
|
|
|
/// <returns>Whether a flow change should be applied at the current <see cref="OsuHitObject"/>.</returns>
|
2022-08-14 17:02:29 +00:00
|
|
|
private bool shouldApplyFlowChange(IReadOnlyList<OsuHitObjectGenerationUtils.ObjectPositionInfo> positionInfos, int i)
|
|
|
|
{
|
|
|
|
// Exclude new-combo-spam and 1-2-combos.
|
|
|
|
bool previousObjectStartedCombo = positionInfos[Math.Max(0, i - 2)].HitObject.IndexInCurrentCombo > 1 &&
|
|
|
|
positionInfos[i - 1].HitObject.NewCombo;
|
|
|
|
|
2022-09-09 08:55:29 +00:00
|
|
|
return previousObjectStartedCombo && random.NextDouble() < 0.6f;
|
2022-08-14 17:02:29 +00:00
|
|
|
}
|
2021-05-01 02:01:43 +00:00
|
|
|
}
|
2021-04-24 22:39:36 +00:00
|
|
|
}
|