2017-05-18 16:39:03 +08:00
|
|
|
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
|
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
|
using osu.Game.Rulesets.Mania.MathUtils;
|
|
|
|
|
using osu.Game.Rulesets.Objects;
|
|
|
|
|
using osu.Game.Rulesets.Objects.Types;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using osu.Game.Audio;
|
|
|
|
|
using osu.Game.Rulesets.Mania.Objects;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Mania.Beatmaps.Patterns.Legacy
|
|
|
|
|
{
|
|
|
|
|
internal class EndTimeObjectPatternGenerator : PatternGenerator
|
|
|
|
|
{
|
|
|
|
|
private readonly double endTime;
|
|
|
|
|
|
2017-08-22 15:22:40 +08:00
|
|
|
|
public EndTimeObjectPatternGenerator(FastRandom random, HitObject hitObject, Beatmap beatmap, int availableColumns)
|
|
|
|
|
: base(random, hitObject, beatmap, availableColumns, new Pattern())
|
2017-05-18 16:39:03 +08:00
|
|
|
|
{
|
|
|
|
|
var endtimeData = HitObject as IHasEndTime;
|
|
|
|
|
|
|
|
|
|
endTime = endtimeData?.EndTime ?? 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override Pattern Generate()
|
|
|
|
|
{
|
|
|
|
|
var pattern = new Pattern();
|
|
|
|
|
|
|
|
|
|
bool generateHold = endTime - HitObject.StartTime >= 100;
|
|
|
|
|
|
|
|
|
|
if (AvailableColumns == 8)
|
|
|
|
|
{
|
|
|
|
|
if (HitObject.Samples.Any(s => s.Name == SampleInfo.HIT_FINISH) && endTime - HitObject.StartTime < 1000)
|
|
|
|
|
addToPattern(pattern, 0, generateHold);
|
|
|
|
|
else
|
|
|
|
|
addToPattern(pattern, getNextRandomColumn(RandomStart), generateHold);
|
|
|
|
|
}
|
2017-05-22 09:23:08 +08:00
|
|
|
|
else if (AvailableColumns > 0)
|
2017-05-18 16:39:03 +08:00
|
|
|
|
addToPattern(pattern, getNextRandomColumn(0), generateHold);
|
|
|
|
|
|
|
|
|
|
return pattern;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Picks a random column after a column.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="start">The starting column.</param>
|
|
|
|
|
/// <returns>A random column after <paramref name="start"/>.</returns>
|
|
|
|
|
private int getNextRandomColumn(int start)
|
|
|
|
|
{
|
|
|
|
|
int nextColumn = Random.Next(start, AvailableColumns);
|
|
|
|
|
|
2017-05-22 09:20:42 +08:00
|
|
|
|
while (PreviousPattern.ColumnHasObject(nextColumn))
|
2017-05-18 16:39:03 +08:00
|
|
|
|
nextColumn = Random.Next(start, AvailableColumns);
|
|
|
|
|
|
|
|
|
|
return nextColumn;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Constructs and adds a note to a pattern.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="pattern">The pattern to add to.</param>
|
|
|
|
|
/// <param name="column">The column to add the note to.</param>
|
|
|
|
|
/// <param name="holdNote">Whether to add a hold note.</param>
|
|
|
|
|
private void addToPattern(Pattern pattern, int column, bool holdNote)
|
|
|
|
|
{
|
|
|
|
|
ManiaHitObject newObject;
|
|
|
|
|
|
|
|
|
|
if (holdNote)
|
|
|
|
|
{
|
2017-05-24 19:45:01 +08:00
|
|
|
|
var hold = new HoldNote
|
2017-05-18 16:39:03 +08:00
|
|
|
|
{
|
|
|
|
|
StartTime = HitObject.StartTime,
|
|
|
|
|
Column = column,
|
2017-05-22 08:57:03 +08:00
|
|
|
|
Duration = endTime - HitObject.StartTime
|
2017-05-18 16:39:03 +08:00
|
|
|
|
};
|
|
|
|
|
|
2017-12-23 18:17:05 +08:00
|
|
|
|
if (hold.Head.Samples == null)
|
|
|
|
|
hold.Head.Samples = new SampleInfoList();
|
|
|
|
|
|
|
|
|
|
hold.Head.Samples.Add(new SampleInfo { Name = SampleInfo.HIT_NORMAL });
|
2017-05-24 19:45:01 +08:00
|
|
|
|
|
2017-05-24 20:57:38 +08:00
|
|
|
|
hold.Tail.Samples = HitObject.Samples;
|
2017-05-24 19:45:01 +08:00
|
|
|
|
|
|
|
|
|
newObject = hold;
|
2017-05-18 16:39:03 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
newObject = new Note
|
|
|
|
|
{
|
|
|
|
|
StartTime = HitObject.StartTime,
|
|
|
|
|
Samples = HitObject.Samples,
|
2017-05-22 08:57:03 +08:00
|
|
|
|
Column = column
|
2017-05-18 16:39:03 +08:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pattern.Add(newObject);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|