1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 12:17:26 +08:00
osu-lazer/osu.Game.Modes.Taiko/Beatmaps/TaikoBeatmapConverter.cs

132 lines
5.1 KiB
C#
Raw Normal View History

2017-03-11 23:34:21 +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.Beatmaps.Legacy;
using osu.Game.Beatmaps.Samples;
using osu.Game.Modes.Objects;
using osu.Game.Modes.Objects.Types;
2017-03-11 23:34:21 +08:00
using osu.Game.Modes.Taiko.Objects;
using System;
2017-03-11 23:34:21 +08:00
using System.Collections.Generic;
using System.Linq;
using osu.Game.Database;
2017-03-11 23:34:21 +08:00
namespace osu.Game.Modes.Taiko.Beatmaps
{
2017-03-17 12:33:48 +08:00
internal class TaikoBeatmapConverter : IBeatmapConverter<TaikoHitObject>
2017-03-11 23:34:21 +08:00
{
2017-03-17 13:44:48 +08:00
private const float legacy_velocity_scale = 1.4f;
2017-03-17 18:52:24 +08:00
private const float bash_convert_factor = 1.65f;
2017-03-17 13:44:48 +08:00
2017-04-03 14:24:30 +08:00
/// <summary>
/// Drum roll distance that results in a duration of 1 speed-adjusted beat length.
/// </summary>
private const float base_distance = 100;
2017-03-17 12:33:48 +08:00
public Beatmap<TaikoHitObject> Convert(Beatmap original)
2017-03-11 23:34:21 +08:00
{
2017-03-18 17:34:45 +08:00
if (original is LegacyBeatmap)
2017-03-17 13:44:48 +08:00
original.TimingInfo.ControlPoints.ForEach(c => c.VelocityAdjustment /= legacy_velocity_scale);
2017-03-17 12:33:48 +08:00
return new Beatmap<TaikoHitObject>(original)
2017-03-11 23:34:21 +08:00
{
HitObjects = original.HitObjects.SelectMany(h => convertHitObject(h, original)).ToList()
};
}
private IEnumerable<TaikoHitObject> convertHitObject(HitObject obj, Beatmap beatmap)
{
// Check if this HitObject is already a TaikoHitObject, and return it if so
var originalTaiko = obj as TaikoHitObject;
if (originalTaiko != null)
yield return originalTaiko;
var distanceData = obj as IHasDistance;
var repeatsData = obj as IHasRepeats;
var endTimeData = obj as IHasEndTime;
2017-03-29 09:59:35 +08:00
// Old osu! used hit sounding to determine various hit type information
SampleType sample = obj.Sample?.Type ?? SampleType.None;
2017-03-29 09:59:35 +08:00
bool strong = (sample & SampleType.Finish) > 0;
if (distanceData != null)
{
2017-04-03 14:24:30 +08:00
double sv = base_distance * beatmap.BeatmapInfo.Difficulty.SliderMultiplier * beatmap.TimingInfo.BeatLengthAt(obj.StartTime) / 1000;
double l = distanceData.Distance * legacy_velocity_scale;
double v = sv * legacy_velocity_scale;
double bl = beatmap.TimingInfo.BeatLengthAt(obj.StartTime);
int repeats = repeatsData?.RepeatCount ?? 1;
double skipPeriod = Math.Min(bl / beatmap.BeatmapInfo.Difficulty.SliderTickRate, distanceData.Duration / repeats);
if (skipPeriod > 0 && l / v * 1000 < 2 * bl)
{
for (double j = obj.StartTime; j <= distanceData.EndTime + skipPeriod / 8; j += skipPeriod)
{
// Todo: This should generate different type of hits (including strongs)
// depending on hitobject sound additions (not implemented fully yet)
yield return new CentreHit
{
StartTime = obj.StartTime,
Sample = obj.Sample,
IsStrong = strong
};
}
}
else
{
yield return new DrumRoll
{
StartTime = obj.StartTime,
Sample = obj.Sample,
IsStrong = strong,
Distance = distanceData.Distance * (repeatsData?.RepeatCount ?? 1) * legacy_velocity_scale,
TickRate = beatmap.BeatmapInfo.Difficulty.SliderTickRate == 3 ? 3 : 4
};
}
}
else if (endTimeData != null)
{
double hitMultiplier = BeatmapDifficulty.DifficultyRange(beatmap.BeatmapInfo.Difficulty.OverallDifficulty, 3, 5, 7.5) * bash_convert_factor;
yield return new Swell
{
StartTime = obj.StartTime,
Sample = obj.Sample,
2017-03-28 09:02:41 +08:00
IsStrong = strong,
EndTime = endTimeData.EndTime,
RequiredHits = (int)Math.Max(1, endTimeData.Duration / 1000 * hitMultiplier)
};
}
else
2017-03-30 14:51:16 +08:00
{
bool isCentre = (sample & ~(SampleType.Finish | SampleType.Normal)) == 0;
if (isCentre)
2017-03-30 14:51:16 +08:00
{
yield return new CentreHit
{
StartTime = obj.StartTime,
Sample = obj.Sample,
IsStrong = strong
};
}
else
{
yield return new RimHit
{
StartTime = obj.StartTime,
Sample = obj.Sample,
IsStrong = strong,
};
}
2017-03-30 14:51:16 +08:00
}
2017-03-11 23:34:21 +08:00
}
}
}