2018-01-05 19:21:19 +08:00
|
|
|
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
2017-05-17 19:47:02 +08:00
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
|
|
|
|
using System;
|
2017-05-18 13:17:23 +08:00
|
|
|
|
using System.Linq;
|
2017-05-18 14:05:45 +08:00
|
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
|
using osu.Game.Rulesets.Mania.MathUtils;
|
2017-05-18 13:17:23 +08:00
|
|
|
|
using osu.Game.Rulesets.Objects;
|
2017-05-18 14:05:45 +08:00
|
|
|
|
using OpenTK;
|
2017-05-17 19:47:02 +08:00
|
|
|
|
|
2017-05-18 14:05:45 +08:00
|
|
|
|
namespace osu.Game.Rulesets.Mania.Beatmaps.Patterns.Legacy
|
2017-05-17 19:47:02 +08:00
|
|
|
|
{
|
2017-05-18 14:05:45 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// A pattern generator for legacy hit objects.
|
|
|
|
|
/// </summary>
|
|
|
|
|
internal abstract class PatternGenerator : Patterns.PatternGenerator
|
2017-05-17 19:47:02 +08:00
|
|
|
|
{
|
2017-05-18 14:05:45 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The column index at which to start generating random notes.
|
|
|
|
|
/// </summary>
|
2017-05-17 19:47:02 +08:00
|
|
|
|
protected readonly int RandomStart;
|
|
|
|
|
|
2017-05-18 14:05:45 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The random number generator to use.
|
|
|
|
|
/// </summary>
|
2017-05-17 19:47:02 +08:00
|
|
|
|
protected readonly FastRandom Random;
|
|
|
|
|
|
2018-01-03 17:44:25 +08:00
|
|
|
|
protected PatternGenerator(FastRandom random, HitObject hitObject, ManiaBeatmap beatmap, Pattern previousPattern)
|
|
|
|
|
: base(hitObject, beatmap, previousPattern)
|
2017-05-17 19:47:02 +08:00
|
|
|
|
{
|
2017-08-22 15:46:12 +08:00
|
|
|
|
if (random == null) throw new ArgumentNullException(nameof(random));
|
|
|
|
|
if (beatmap == null) throw new ArgumentNullException(nameof(beatmap));
|
|
|
|
|
if (previousPattern == null) throw new ArgumentNullException(nameof(previousPattern));
|
2017-05-17 19:47:02 +08:00
|
|
|
|
|
2017-08-22 15:46:12 +08:00
|
|
|
|
Random = random;
|
2018-01-03 17:44:25 +08:00
|
|
|
|
RandomStart = TotalColumns == 8 ? 1 : 0;
|
2017-05-17 19:47:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Converts an x-position into a column.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="position">The x-position.</param>
|
|
|
|
|
/// <param name="allowSpecial">Whether to treat as 7K + 1.</param>
|
|
|
|
|
/// <returns>The column.</returns>
|
|
|
|
|
protected int GetColumn(float position, bool allowSpecial = false)
|
|
|
|
|
{
|
2018-01-03 17:44:25 +08:00
|
|
|
|
if (allowSpecial && TotalColumns == 8)
|
2017-05-17 19:47:02 +08:00
|
|
|
|
{
|
|
|
|
|
const float local_x_divisor = 512f / 7;
|
|
|
|
|
return MathHelper.Clamp((int)Math.Floor(position / local_x_divisor), 0, 6) + 1;
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-03 17:44:25 +08:00
|
|
|
|
float localXDivisor = 512f / TotalColumns;
|
|
|
|
|
return MathHelper.Clamp((int)Math.Floor(position / localXDivisor), 0, TotalColumns - 1);
|
2017-05-17 19:47:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Generates a count of notes to be generated from probabilities.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="p2">Probability for 2 notes to be generated.</param>
|
|
|
|
|
/// <param name="p3">Probability for 3 notes to be generated.</param>
|
|
|
|
|
/// <param name="p4">Probability for 4 notes to be generated.</param>
|
|
|
|
|
/// <param name="p5">Probability for 5 notes to be generated.</param>
|
|
|
|
|
/// <param name="p6">Probability for 6 notes to be generated.</param>
|
|
|
|
|
/// <returns>The amount of notes to be generated.</returns>
|
2017-05-18 11:39:51 +08:00
|
|
|
|
protected int GetRandomNoteCount(double p2, double p3, double p4 = 0, double p5 = 0, double p6 = 0)
|
2017-05-17 19:47:02 +08:00
|
|
|
|
{
|
2017-08-22 15:46:12 +08:00
|
|
|
|
if (p2 < 0 || p2 > 1) throw new ArgumentOutOfRangeException(nameof(p2));
|
|
|
|
|
if (p3 < 0 || p3 > 1) throw new ArgumentOutOfRangeException(nameof(p3));
|
|
|
|
|
if (p4 < 0 || p4 > 1) throw new ArgumentOutOfRangeException(nameof(p4));
|
|
|
|
|
if (p5 < 0 || p5 > 1) throw new ArgumentOutOfRangeException(nameof(p5));
|
|
|
|
|
if (p6 < 0 || p6 > 1) throw new ArgumentOutOfRangeException(nameof(p6));
|
|
|
|
|
|
2017-05-17 19:47:02 +08:00
|
|
|
|
double val = Random.NextDouble();
|
|
|
|
|
if (val >= 1 - p6)
|
|
|
|
|
return 6;
|
|
|
|
|
if (val >= 1 - p5)
|
|
|
|
|
return 5;
|
|
|
|
|
if (val >= 1 - p4)
|
|
|
|
|
return 4;
|
|
|
|
|
if (val >= 1 - p3)
|
|
|
|
|
return 3;
|
|
|
|
|
return val >= 1 - p2 ? 2 : 1;
|
|
|
|
|
}
|
2017-05-18 13:17:23 +08:00
|
|
|
|
|
|
|
|
|
private double? conversionDifficulty;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// A difficulty factor used for various conversion methods from osu!stable.
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected double ConversionDifficulty
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (conversionDifficulty != null)
|
|
|
|
|
return conversionDifficulty.Value;
|
|
|
|
|
|
|
|
|
|
HitObject lastObject = Beatmap.HitObjects.LastOrDefault();
|
|
|
|
|
HitObject firstObject = Beatmap.HitObjects.FirstOrDefault();
|
|
|
|
|
|
|
|
|
|
double drainTime = (lastObject?.StartTime ?? 0) - (firstObject?.StartTime ?? 0);
|
2017-05-22 09:12:33 +08:00
|
|
|
|
drainTime -= Beatmap.TotalBreakTime;
|
2017-05-18 13:17:23 +08:00
|
|
|
|
|
|
|
|
|
if (drainTime == 0)
|
|
|
|
|
drainTime = 10000;
|
|
|
|
|
|
2017-10-19 13:05:11 +08:00
|
|
|
|
BeatmapDifficulty difficulty = Beatmap.BeatmapInfo.BaseDifficulty;
|
2017-05-18 13:17:23 +08:00
|
|
|
|
conversionDifficulty = ((difficulty.DrainRate + MathHelper.Clamp(difficulty.ApproachRate, 4, 7)) / 1.5 + Beatmap.HitObjects.Count / drainTime * 9f) / 38f * 5f / 1.15;
|
|
|
|
|
conversionDifficulty = Math.Min(conversionDifficulty.Value, 12);
|
|
|
|
|
|
|
|
|
|
return conversionDifficulty.Value;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-05-17 19:47:02 +08:00
|
|
|
|
}
|
|
|
|
|
}
|