2017-02-20 00:41:51 +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
|
|
|
|
|
|
2017-04-18 15:05:58 +08:00
|
|
|
|
using osu.Game.Rulesets.Objects;
|
2017-02-20 00:41:51 +08:00
|
|
|
|
using System.Collections.Generic;
|
2017-11-16 19:06:32 +08:00
|
|
|
|
using osu.Game.Rulesets.Mods;
|
|
|
|
|
using osu.Framework.Timing;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using osu.Framework.Extensions.IEnumerableExtensions;
|
2017-02-20 00:41:51 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Beatmaps
|
|
|
|
|
{
|
|
|
|
|
public abstract class DifficultyCalculator
|
|
|
|
|
{
|
|
|
|
|
protected double TimeRate = 1;
|
|
|
|
|
|
2017-11-16 19:06:32 +08:00
|
|
|
|
public abstract double Calculate(Dictionary<string, string> categoryDifficulty = null);
|
2017-02-20 00:41:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public abstract class DifficultyCalculator<T> : DifficultyCalculator where T : HitObject
|
|
|
|
|
{
|
2017-11-17 13:23:52 +08:00
|
|
|
|
protected readonly Beatmap<T> Beatmap;
|
2017-11-16 19:06:32 +08:00
|
|
|
|
protected readonly Mod[] Mods;
|
2017-08-22 12:34:58 +08:00
|
|
|
|
|
2017-11-17 13:26:33 +08:00
|
|
|
|
protected DifficultyCalculator(Beatmap beatmap, Mod[] mods = null)
|
2017-02-20 00:41:51 +08:00
|
|
|
|
{
|
2017-11-17 13:37:06 +08:00
|
|
|
|
Beatmap = CreateBeatmapConverter(beatmap).Convert(beatmap);
|
2017-11-16 19:06:32 +08:00
|
|
|
|
Mods = mods ?? new Mod[0];
|
2017-08-22 12:34:58 +08:00
|
|
|
|
|
2017-04-26 14:50:08 +08:00
|
|
|
|
|
2017-11-17 11:35:03 +08:00
|
|
|
|
ApplyMods(Mods);
|
2017-11-16 19:06:32 +08:00
|
|
|
|
|
2017-02-20 00:41:51 +08:00
|
|
|
|
PreprocessHitObjects();
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-16 19:06:32 +08:00
|
|
|
|
protected virtual void ApplyMods(Mod[] mods)
|
|
|
|
|
{
|
|
|
|
|
var clock = new StopwatchClock();
|
|
|
|
|
mods.OfType<IApplicableToClock>().ForEach(m => m.ApplyToClock(clock));
|
2017-11-16 19:41:26 +08:00
|
|
|
|
TimeRate = clock.Rate;
|
2017-11-16 19:06:32 +08:00
|
|
|
|
|
2017-11-17 13:23:52 +08:00
|
|
|
|
foreach (var mod in Mods.OfType<IApplicableToDifficulty>())
|
|
|
|
|
mod.ApplyToDifficulty(Beatmap.BeatmapInfo.BaseDifficulty);
|
|
|
|
|
|
2017-11-16 19:35:57 +08:00
|
|
|
|
foreach (var mod in mods.OfType<IApplicableToHitObject<T>>())
|
2017-11-17 13:23:52 +08:00
|
|
|
|
foreach (var obj in Beatmap.HitObjects)
|
2017-11-16 19:35:57 +08:00
|
|
|
|
mod.ApplyToHitObject(obj);
|
2017-11-17 13:23:52 +08:00
|
|
|
|
|
|
|
|
|
foreach (var h in Beatmap.HitObjects)
|
|
|
|
|
h.ApplyDefaults(Beatmap.ControlPointInfo, Beatmap.BeatmapInfo.BaseDifficulty);
|
2017-11-16 19:06:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-02-20 00:41:51 +08:00
|
|
|
|
protected virtual void PreprocessHitObjects()
|
|
|
|
|
{
|
|
|
|
|
}
|
2017-03-12 13:32:50 +08:00
|
|
|
|
|
2017-11-17 13:37:06 +08:00
|
|
|
|
protected abstract BeatmapConverter<T> CreateBeatmapConverter(Beatmap beatmap);
|
2017-02-20 00:41:51 +08:00
|
|
|
|
}
|
|
|
|
|
}
|