2019-01-24 08:43:03 +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.
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2021-05-19 14:25:56 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2021-05-22 06:14:41 +00:00
|
|
|
|
using osu.Framework.Bindables;
|
2021-05-19 14:25:56 +00:00
|
|
|
|
using osu.Framework.Graphics;
|
2019-03-27 10:29:27 +00:00
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
2022-08-10 20:09:11 +00:00
|
|
|
|
using osu.Framework.Localisation;
|
2021-05-19 14:25:56 +00:00
|
|
|
|
using osu.Framework.Utils;
|
|
|
|
|
using osu.Game.Audio;
|
|
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
|
using osu.Game.Beatmaps.ControlPoints;
|
2021-06-24 02:07:29 +00:00
|
|
|
|
using osu.Game.Beatmaps.Timing;
|
2021-05-22 06:14:41 +00:00
|
|
|
|
using osu.Game.Configuration;
|
2018-01-09 04:41:57 +00:00
|
|
|
|
using osu.Game.Graphics;
|
2021-06-30 18:41:08 +00:00
|
|
|
|
using osu.Game.Overlays.Settings;
|
2018-01-09 04:41:57 +00:00
|
|
|
|
using osu.Game.Rulesets.Mods;
|
2021-06-24 01:34:39 +00:00
|
|
|
|
using osu.Game.Rulesets.Objects;
|
2021-05-19 14:25:56 +00:00
|
|
|
|
using osu.Game.Rulesets.Objects.Drawables;
|
2021-06-24 02:33:54 +00:00
|
|
|
|
using osu.Game.Rulesets.Objects.Types;
|
2021-05-19 14:25:56 +00:00
|
|
|
|
using osu.Game.Rulesets.Osu.Beatmaps;
|
|
|
|
|
using osu.Game.Rulesets.Osu.Objects;
|
|
|
|
|
using osu.Game.Rulesets.Osu.Objects.Drawables;
|
|
|
|
|
using osu.Game.Rulesets.Osu.UI;
|
2021-06-26 03:34:10 +00:00
|
|
|
|
using osu.Game.Rulesets.Osu.Utils;
|
2021-05-19 14:25:56 +00:00
|
|
|
|
using osu.Game.Rulesets.Scoring;
|
|
|
|
|
using osu.Game.Rulesets.UI;
|
|
|
|
|
using osuTK;
|
2021-07-13 11:26:05 +00:00
|
|
|
|
using osuTK.Graphics;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-01-09 04:41:57 +00:00
|
|
|
|
namespace osu.Game.Rulesets.Osu.Mods
|
|
|
|
|
{
|
2022-11-01 10:47:20 +00:00
|
|
|
|
public class OsuModTargetPractice : ModWithVisibilityAdjustment, IApplicableToDrawableRuleset<OsuHitObject>,
|
|
|
|
|
IApplicableToHealthProcessor, IApplicableToDifficulty, IApplicableFailOverride, IHasSeed, IHidesApproachCircles
|
2018-01-09 04:41:57 +00:00
|
|
|
|
{
|
2022-11-01 10:47:20 +00:00
|
|
|
|
public override string Name => "Target Practice";
|
2018-11-30 08:16:00 +00:00
|
|
|
|
public override string Acronym => "TP";
|
2018-07-31 09:00:42 +00:00
|
|
|
|
public override ModType Type => ModType.Conversion;
|
2020-01-14 13:22:00 +00:00
|
|
|
|
public override IconUsage? Icon => OsuIcon.ModTarget;
|
2022-08-10 20:09:11 +00:00
|
|
|
|
public override LocalisableString Description => @"Practice keeping up with the beat of the song.";
|
2022-11-01 08:57:20 +00:00
|
|
|
|
public override double ScoreMultiplier => 0.1;
|
2021-05-19 14:25:56 +00:00
|
|
|
|
|
2022-04-28 16:29:37 +00:00
|
|
|
|
public override Type[] IncompatibleMods => base.IncompatibleMods.Concat(new[]
|
2022-04-28 03:15:04 +00:00
|
|
|
|
{
|
|
|
|
|
typeof(IRequiresApproachCircles),
|
|
|
|
|
typeof(OsuModRandom),
|
|
|
|
|
typeof(OsuModSpunOut),
|
|
|
|
|
typeof(OsuModStrictTracking),
|
|
|
|
|
typeof(OsuModSuddenDeath)
|
2022-04-28 16:29:37 +00:00
|
|
|
|
}).ToArray();
|
2021-06-19 04:26:16 +00:00
|
|
|
|
|
2021-06-30 18:41:08 +00:00
|
|
|
|
[SettingSource("Seed", "Use a custom seed instead of a random one", SettingControlType = typeof(SettingsNumberBox))]
|
2022-09-25 19:49:22 +00:00
|
|
|
|
public Bindable<int?> Seed { get; } = new Bindable<int?>();
|
2021-05-22 06:14:41 +00:00
|
|
|
|
|
2022-08-29 08:12:09 +00:00
|
|
|
|
[SettingSource("Metronome ticks", "Whether a metronome beat should play in the background")]
|
2022-08-31 13:34:07 +00:00
|
|
|
|
public Bindable<bool> Metronome { get; } = new BindableBool(true);
|
2022-08-29 08:12:09 +00:00
|
|
|
|
|
2021-06-23 08:50:05 +00:00
|
|
|
|
#region Constants
|
2021-06-10 02:58:42 +00:00
|
|
|
|
|
2021-06-18 06:39:46 +00:00
|
|
|
|
/// <summary>
|
2021-06-18 08:05:09 +00:00
|
|
|
|
/// Jump distance for circles in the last combo
|
2021-06-18 06:39:46 +00:00
|
|
|
|
/// </summary>
|
2021-06-19 02:04:48 +00:00
|
|
|
|
private const float max_base_distance = 333f;
|
2021-06-18 06:39:46 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
2021-06-18 08:05:09 +00:00
|
|
|
|
/// The maximum allowed jump distance after multipliers are applied
|
2021-06-18 06:39:46 +00:00
|
|
|
|
/// </summary>
|
2021-06-19 02:04:48 +00:00
|
|
|
|
private const float distance_cap = 380f;
|
2021-06-17 14:01:58 +00:00
|
|
|
|
|
2021-06-18 06:39:46 +00:00
|
|
|
|
/// <summary>
|
2021-06-18 08:05:09 +00:00
|
|
|
|
/// The extent of rotation towards playfield centre when a circle is near the edge
|
|
|
|
|
/// </summary>
|
|
|
|
|
private const float edge_rotation_multiplier = 0.75f;
|
|
|
|
|
|
2021-06-19 02:04:48 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Number of recent circles to check for overlap
|
|
|
|
|
/// </summary>
|
|
|
|
|
private const int overlap_check_count = 5;
|
|
|
|
|
|
2021-06-18 08:05:09 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Duration of the undimming animation
|
2021-06-18 06:39:46 +00:00
|
|
|
|
/// </summary>
|
|
|
|
|
private const double undim_duration = 96;
|
|
|
|
|
|
2021-06-24 06:55:49 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Acceptable difference for timing comparisons
|
|
|
|
|
/// </summary>
|
|
|
|
|
private const double timing_precision = 1;
|
|
|
|
|
|
2021-06-23 08:50:05 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Private Fields
|
|
|
|
|
|
2022-07-31 13:43:16 +00:00
|
|
|
|
private ControlPointInfo controlPointInfo = null!;
|
2021-06-18 03:20:04 +00:00
|
|
|
|
|
2021-06-23 08:50:05 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Sudden Death (IApplicableFailOverride)
|
|
|
|
|
|
|
|
|
|
public bool PerformFail() => true;
|
|
|
|
|
|
|
|
|
|
public bool RestartOnFail => false;
|
2021-06-17 14:01:58 +00:00
|
|
|
|
|
2021-05-19 14:25:56 +00:00
|
|
|
|
public void ApplyToHealthProcessor(HealthProcessor healthProcessor)
|
|
|
|
|
{
|
|
|
|
|
// Sudden death
|
|
|
|
|
healthProcessor.FailConditions += (_, result)
|
|
|
|
|
=> result.Type.AffectsCombo()
|
2021-06-14 13:34:34 +00:00
|
|
|
|
&& !result.IsHit;
|
2021-05-19 14:25:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-06-23 08:50:05 +00:00
|
|
|
|
#endregion
|
2021-06-15 03:06:56 +00:00
|
|
|
|
|
2021-06-23 08:50:05 +00:00
|
|
|
|
#region Reduce AR (IApplicableToDifficulty)
|
2021-06-15 03:06:56 +00:00
|
|
|
|
|
2021-10-01 05:56:42 +00:00
|
|
|
|
public void ReadFromDifficulty(IBeatmapDifficultyInfo difficulty)
|
2021-06-17 14:01:58 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ApplyToDifficulty(BeatmapDifficulty difficulty)
|
|
|
|
|
{
|
|
|
|
|
// Decrease AR to increase preempt time
|
|
|
|
|
difficulty.ApproachRate *= 0.5f;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-23 08:50:05 +00:00
|
|
|
|
#endregion
|
2021-06-17 14:01:58 +00:00
|
|
|
|
|
2021-06-23 08:50:05 +00:00
|
|
|
|
#region Circle Transforms (ModWithVisibilityAdjustment)
|
2021-06-17 14:01:58 +00:00
|
|
|
|
|
|
|
|
|
protected override void ApplyIncreasedVisibilityState(DrawableHitObject drawable, ArmedState state)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void ApplyNormalVisibilityState(DrawableHitObject drawable, ArmedState state)
|
|
|
|
|
{
|
|
|
|
|
if (!(drawable is DrawableHitCircle circle)) return;
|
|
|
|
|
|
2021-07-13 11:26:05 +00:00
|
|
|
|
double startTime = circle.HitObject.StartTime;
|
|
|
|
|
double preempt = circle.HitObject.TimePreempt;
|
2021-06-17 14:01:58 +00:00
|
|
|
|
|
2021-07-18 13:34:28 +00:00
|
|
|
|
using (circle.BeginAbsoluteSequence(startTime - preempt))
|
2021-06-17 14:01:58 +00:00
|
|
|
|
{
|
2021-07-13 11:26:05 +00:00
|
|
|
|
// initial state
|
2021-07-18 13:34:28 +00:00
|
|
|
|
circle.ScaleTo(0.5f)
|
2021-07-18 14:01:26 +00:00
|
|
|
|
.FadeColour(OsuColour.Gray(0.5f));
|
2021-06-17 14:01:58 +00:00
|
|
|
|
|
2021-07-13 11:26:05 +00:00
|
|
|
|
// scale to final size
|
2021-07-18 13:34:28 +00:00
|
|
|
|
circle.ScaleTo(1f, preempt);
|
|
|
|
|
|
|
|
|
|
// Remove approach circles
|
|
|
|
|
circle.ApproachCircle.Hide();
|
2021-07-13 11:26:05 +00:00
|
|
|
|
}
|
2021-06-17 14:01:58 +00:00
|
|
|
|
|
2022-07-31 13:43:16 +00:00
|
|
|
|
using (circle.BeginAbsoluteSequence(startTime - controlPointInfo.TimingPointAt(startTime).BeatLength - undim_duration))
|
2021-07-18 13:34:28 +00:00
|
|
|
|
circle.FadeColour(Color4.White, undim_duration);
|
2021-06-17 14:01:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-06-23 08:50:05 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Beatmap Generation (IApplicableToBeatmap)
|
|
|
|
|
|
|
|
|
|
public override void ApplyToBeatmap(IBeatmap beatmap)
|
2021-06-17 14:01:58 +00:00
|
|
|
|
{
|
2021-06-23 08:50:05 +00:00
|
|
|
|
Seed.Value ??= RNG.Next();
|
2022-07-28 05:04:53 +00:00
|
|
|
|
|
2022-07-27 14:12:52 +00:00
|
|
|
|
var rng = new Random(Seed.Value.Value);
|
2021-06-23 08:50:05 +00:00
|
|
|
|
|
|
|
|
|
var osuBeatmap = (OsuBeatmap)beatmap;
|
|
|
|
|
|
|
|
|
|
if (osuBeatmap.HitObjects.Count == 0) return;
|
|
|
|
|
|
|
|
|
|
controlPointInfo = osuBeatmap.ControlPointInfo;
|
|
|
|
|
|
2022-07-27 14:12:52 +00:00
|
|
|
|
var originalHitObjects = osuBeatmap.HitObjects.OrderBy(x => x.StartTime).ToList();
|
|
|
|
|
var hitObjects = generateBeats(osuBeatmap, originalHitObjects)
|
2021-06-24 04:20:23 +00:00
|
|
|
|
.Select(beat =>
|
2021-06-23 08:50:05 +00:00
|
|
|
|
{
|
|
|
|
|
var newCircle = new HitCircle();
|
2021-10-02 03:34:29 +00:00
|
|
|
|
newCircle.ApplyDefaults(controlPointInfo, osuBeatmap.Difficulty);
|
2021-06-24 04:20:23 +00:00
|
|
|
|
newCircle.StartTime = beat;
|
2021-06-23 08:50:05 +00:00
|
|
|
|
return (OsuHitObject)newCircle;
|
|
|
|
|
}).ToList();
|
|
|
|
|
|
2022-07-28 05:04:53 +00:00
|
|
|
|
addHitSamples(hitObjects, originalHitObjects);
|
2021-06-23 08:50:05 +00:00
|
|
|
|
|
2022-07-28 05:04:53 +00:00
|
|
|
|
fixComboInfo(hitObjects, originalHitObjects);
|
2021-06-23 08:50:05 +00:00
|
|
|
|
|
2022-07-28 05:04:53 +00:00
|
|
|
|
randomizeCirclePos(hitObjects, rng);
|
2021-06-23 08:50:05 +00:00
|
|
|
|
|
|
|
|
|
osuBeatmap.HitObjects = hitObjects;
|
|
|
|
|
|
|
|
|
|
base.ApplyToBeatmap(beatmap);
|
2021-06-17 14:01:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-07-27 14:12:52 +00:00
|
|
|
|
private IEnumerable<double> generateBeats(IBeatmap beatmap, IReadOnlyCollection<OsuHitObject> originalHitObjects)
|
2021-06-15 03:06:56 +00:00
|
|
|
|
{
|
2021-10-27 04:04:41 +00:00
|
|
|
|
double startTime = originalHitObjects.First().StartTime;
|
|
|
|
|
double endTime = originalHitObjects.Last().GetEndTime();
|
2021-05-19 14:25:56 +00:00
|
|
|
|
|
2021-06-15 03:06:56 +00:00
|
|
|
|
var beats = beatmap.ControlPointInfo.TimingPoints
|
2021-06-24 04:20:23 +00:00
|
|
|
|
// Ignore timing points after endTime
|
2021-07-01 04:21:41 +00:00
|
|
|
|
.Where(timingPoint => !definitelyBigger(timingPoint.Time, endTime))
|
2021-06-24 04:20:23 +00:00
|
|
|
|
// Generate the beats
|
2021-06-24 01:51:45 +00:00
|
|
|
|
.SelectMany(timingPoint => getBeatsForTimingPoint(timingPoint, endTime))
|
2021-06-24 04:20:23 +00:00
|
|
|
|
// Remove beats before startTime
|
2021-06-24 06:55:49 +00:00
|
|
|
|
.Where(beat => almostBigger(beat, startTime))
|
2021-06-24 04:20:23 +00:00
|
|
|
|
// Remove beats during breaks
|
2022-07-27 14:12:52 +00:00
|
|
|
|
.Where(beat => !isInsideBreakPeriod(originalHitObjects, beatmap.Breaks, beat))
|
2021-06-15 03:06:56 +00:00
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
// Remove beats that are too close to the next one (e.g. due to timing point changes)
|
2021-10-27 04:04:41 +00:00
|
|
|
|
for (int i = beats.Count - 2; i >= 0; i--)
|
2021-06-15 03:06:56 +00:00
|
|
|
|
{
|
2021-10-27 04:04:41 +00:00
|
|
|
|
double beat = beats[i];
|
2021-06-14 13:34:34 +00:00
|
|
|
|
|
2021-07-01 04:21:41 +00:00
|
|
|
|
if (!definitelyBigger(beats[i + 1] - beat, beatmap.ControlPointInfo.TimingPointAt(beat).BeatLength / 2))
|
2021-06-24 02:56:14 +00:00
|
|
|
|
beats.RemoveAt(i);
|
2021-06-15 03:06:56 +00:00
|
|
|
|
}
|
2021-05-19 14:25:56 +00:00
|
|
|
|
|
2021-06-15 03:06:56 +00:00
|
|
|
|
return beats;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-28 05:04:53 +00:00
|
|
|
|
private void addHitSamples(IEnumerable<OsuHitObject> hitObjects, List<OsuHitObject> originalHitObjects)
|
2021-06-15 03:06:56 +00:00
|
|
|
|
{
|
2021-06-24 02:54:21 +00:00
|
|
|
|
foreach (var obj in hitObjects)
|
2021-05-20 03:57:13 +00:00
|
|
|
|
{
|
2021-07-01 03:57:57 +00:00
|
|
|
|
var samples = getSamplesAtTime(originalHitObjects, obj.StartTime);
|
2021-06-14 13:34:34 +00:00
|
|
|
|
|
2021-06-29 04:49:25 +00:00
|
|
|
|
// If samples aren't available at the exact start time of the object,
|
|
|
|
|
// use samples (without additions) in the closest original hit object instead
|
2021-07-01 03:57:57 +00:00
|
|
|
|
obj.Samples = samples ?? getClosestHitObject(originalHitObjects, obj.StartTime).Samples.Where(s => !HitSampleInfo.AllAdditions.Contains(s.Name)).ToList();
|
2021-05-20 03:57:13 +00:00
|
|
|
|
}
|
2021-06-15 03:06:56 +00:00
|
|
|
|
}
|
2021-05-19 14:25:56 +00:00
|
|
|
|
|
2022-07-28 05:04:53 +00:00
|
|
|
|
private void fixComboInfo(List<OsuHitObject> hitObjects, List<OsuHitObject> originalHitObjects)
|
2021-06-15 03:06:56 +00:00
|
|
|
|
{
|
2021-07-01 03:57:57 +00:00
|
|
|
|
// Copy combo indices from an original object at the same time or from the closest preceding object
|
|
|
|
|
// (Objects lying between two combos are assumed to belong to the preceding combo)
|
|
|
|
|
hitObjects.ForEach(newObj =>
|
2021-05-20 03:57:13 +00:00
|
|
|
|
{
|
2021-07-01 03:57:57 +00:00
|
|
|
|
var closestOrigObj = originalHitObjects.FindLast(y => almostBigger(newObj.StartTime, y.StartTime));
|
2021-06-24 03:21:43 +00:00
|
|
|
|
|
2021-06-24 05:39:50 +00:00
|
|
|
|
// It shouldn't be possible for closestOrigObj to be null
|
2021-06-24 03:21:43 +00:00
|
|
|
|
// But if it is, obj should be in the first combo
|
2021-07-01 03:57:57 +00:00
|
|
|
|
newObj.ComboIndex = closestOrigObj?.ComboIndex ?? 0;
|
2021-05-20 03:57:13 +00:00
|
|
|
|
});
|
2021-06-24 03:21:43 +00:00
|
|
|
|
|
|
|
|
|
// The copied combo indices may not be continuous if the original map starts and ends a combo in between beats
|
|
|
|
|
// e.g. A stream with each object starting a new combo
|
|
|
|
|
// So combo indices need to be reprocessed to ensure continuity
|
|
|
|
|
// Other kinds of combo info are also added in the process
|
2021-05-20 03:57:13 +00:00
|
|
|
|
var combos = hitObjects.GroupBy(x => x.ComboIndex).ToList();
|
2021-06-14 13:34:34 +00:00
|
|
|
|
|
2021-10-27 04:04:41 +00:00
|
|
|
|
for (int i = 0; i < combos.Count; i++)
|
2021-05-19 14:25:56 +00:00
|
|
|
|
{
|
2021-05-20 03:57:13 +00:00
|
|
|
|
var group = combos[i].ToList();
|
|
|
|
|
group.First().NewCombo = true;
|
|
|
|
|
group.Last().LastInCombo = true;
|
2021-05-19 14:25:56 +00:00
|
|
|
|
|
2021-10-27 04:04:41 +00:00
|
|
|
|
for (int j = 0; j < group.Count; j++)
|
2021-05-19 14:25:56 +00:00
|
|
|
|
{
|
2021-05-20 03:57:13 +00:00
|
|
|
|
var x = group[j];
|
|
|
|
|
x.ComboIndex = i;
|
|
|
|
|
x.IndexInCurrentCombo = j;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-06-15 03:06:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-07-28 05:04:53 +00:00
|
|
|
|
private void randomizeCirclePos(IReadOnlyList<OsuHitObject> hitObjects, Random rng)
|
2021-06-15 03:06:56 +00:00
|
|
|
|
{
|
2021-06-19 03:12:29 +00:00
|
|
|
|
if (hitObjects.Count == 0) return;
|
|
|
|
|
|
2022-08-01 04:22:58 +00:00
|
|
|
|
float nextSingle(float max = 1f) => (float)(rng.NextDouble() * max);
|
2021-05-19 14:25:56 +00:00
|
|
|
|
|
2021-06-24 03:37:00 +00:00
|
|
|
|
const float two_pi = MathF.PI * 2;
|
|
|
|
|
|
2021-10-27 04:04:41 +00:00
|
|
|
|
float direction = two_pi * nextSingle();
|
|
|
|
|
int maxComboIndex = hitObjects.Last().ComboIndex;
|
2021-06-14 13:34:34 +00:00
|
|
|
|
|
2021-10-27 04:04:41 +00:00
|
|
|
|
for (int i = 0; i < hitObjects.Count; i++)
|
2021-05-20 03:57:13 +00:00
|
|
|
|
{
|
2021-06-17 06:30:59 +00:00
|
|
|
|
var obj = hitObjects[i];
|
2021-06-17 14:01:58 +00:00
|
|
|
|
var lastPos = i == 0
|
|
|
|
|
? Vector2.Divide(OsuPlayfield.BASE_SIZE, 2)
|
|
|
|
|
: hitObjects[i - 1].Position;
|
|
|
|
|
|
2021-10-27 04:04:41 +00:00
|
|
|
|
float distance = maxComboIndex == 0
|
2021-06-19 03:12:29 +00:00
|
|
|
|
? (float)obj.Radius
|
2021-07-04 02:01:56 +00:00
|
|
|
|
: mapRange(obj.ComboIndex, 0, maxComboIndex, (float)obj.Radius, max_base_distance);
|
2021-06-17 14:01:58 +00:00
|
|
|
|
if (obj.NewCombo) distance *= 1.5f;
|
|
|
|
|
if (obj.Kiai) distance *= 1.2f;
|
2021-06-18 06:39:46 +00:00
|
|
|
|
distance = Math.Min(distance_cap, distance);
|
2021-06-17 14:01:58 +00:00
|
|
|
|
|
2021-06-19 02:04:48 +00:00
|
|
|
|
// Attempt to place the circle at a place that does not overlap with previous ones
|
|
|
|
|
|
2021-10-27 04:04:41 +00:00
|
|
|
|
int tryCount = 0;
|
2021-06-19 02:04:48 +00:00
|
|
|
|
|
2021-07-01 04:49:34 +00:00
|
|
|
|
// for checking overlap
|
|
|
|
|
var precedingObjects = hitObjects.SkipLast(hitObjects.Count - i).TakeLast(overlap_check_count).ToList();
|
|
|
|
|
|
2021-06-19 02:04:48 +00:00
|
|
|
|
do
|
|
|
|
|
{
|
2021-06-24 03:37:00 +00:00
|
|
|
|
if (tryCount > 0) direction = two_pi * nextSingle();
|
2021-06-19 02:04:48 +00:00
|
|
|
|
|
|
|
|
|
var relativePos = new Vector2(
|
2021-06-24 03:37:00 +00:00
|
|
|
|
distance * MathF.Cos(direction),
|
|
|
|
|
distance * MathF.Sin(direction)
|
2021-06-19 02:04:48 +00:00
|
|
|
|
);
|
2021-06-24 04:20:23 +00:00
|
|
|
|
// Rotate the new circle away from playfield border
|
2021-06-26 03:34:10 +00:00
|
|
|
|
relativePos = OsuHitObjectGenerationUtils.RotateAwayFromEdge(lastPos, relativePos, edge_rotation_multiplier);
|
2021-06-24 03:37:00 +00:00
|
|
|
|
direction = MathF.Atan2(relativePos.Y, relativePos.X);
|
2021-06-19 02:04:48 +00:00
|
|
|
|
|
|
|
|
|
var newPosition = Vector2.Add(lastPos, relativePos);
|
2021-06-14 13:34:34 +00:00
|
|
|
|
|
2021-06-19 02:04:48 +00:00
|
|
|
|
obj.Position = newPosition;
|
2021-06-17 14:01:58 +00:00
|
|
|
|
|
2021-06-19 04:26:16 +00:00
|
|
|
|
clampToPlayfield(obj);
|
|
|
|
|
|
2021-06-19 02:04:48 +00:00
|
|
|
|
tryCount++;
|
|
|
|
|
if (tryCount % 10 == 0) distance *= 0.9f;
|
2021-07-01 04:49:34 +00:00
|
|
|
|
} while (distance >= obj.Radius * 2 && checkForOverlap(precedingObjects, obj));
|
2021-06-17 14:01:58 +00:00
|
|
|
|
|
|
|
|
|
if (obj.LastInCombo)
|
2021-06-24 03:37:00 +00:00
|
|
|
|
direction = two_pi * nextSingle();
|
2021-05-20 03:57:13 +00:00
|
|
|
|
else
|
2021-06-24 03:37:00 +00:00
|
|
|
|
direction += distance / distance_cap * (nextSingle() * two_pi - MathF.PI);
|
2021-05-19 14:25:56 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-23 08:50:05 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Metronome (IApplicableToDrawableRuleset)
|
|
|
|
|
|
|
|
|
|
public void ApplyToDrawableRuleset(DrawableRuleset<OsuHitObject> drawableRuleset)
|
|
|
|
|
{
|
2022-08-29 08:12:09 +00:00
|
|
|
|
if (Metronome.Value)
|
|
|
|
|
drawableRuleset.Overlays.Add(new MetronomeBeat(drawableRuleset.Beatmap.HitObjects.First().StartTime));
|
2021-06-23 08:50:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Helper Subroutines
|
|
|
|
|
|
2021-06-24 02:07:29 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Check if a given time is inside a <see cref="BreakPeriod"/>.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <remarks>
|
|
|
|
|
/// The given time is also considered to be inside a break if it is earlier than the
|
|
|
|
|
/// start time of the first original hit object after the break.
|
|
|
|
|
/// </remarks>
|
2022-07-27 14:12:52 +00:00
|
|
|
|
/// <param name="originalHitObjects">Hit objects order by time.</param>
|
2021-06-24 02:07:29 +00:00
|
|
|
|
/// <param name="breaks">The breaks of the beatmap.</param>
|
|
|
|
|
/// <param name="time">The time to be checked.</param>=
|
2022-07-27 14:12:52 +00:00
|
|
|
|
private bool isInsideBreakPeriod(IReadOnlyCollection<OsuHitObject> originalHitObjects, IEnumerable<BreakPeriod> breaks, double time)
|
2021-06-24 02:07:29 +00:00
|
|
|
|
{
|
2021-06-24 02:56:14 +00:00
|
|
|
|
return breaks.Any(breakPeriod =>
|
2021-06-24 02:07:29 +00:00
|
|
|
|
{
|
2022-09-07 08:45:15 +00:00
|
|
|
|
OsuHitObject? firstObjAfterBreak = originalHitObjects.FirstOrDefault(obj => almostBigger(obj.StartTime, breakPeriod.EndTime));
|
2021-06-24 02:07:29 +00:00
|
|
|
|
|
2021-06-24 06:55:49 +00:00
|
|
|
|
return almostBigger(time, breakPeriod.StartTime)
|
2022-09-07 08:45:15 +00:00
|
|
|
|
// There should never really be a break section with no objects after it, but we've seen crashes from users with malformed beatmaps,
|
|
|
|
|
// so it's best to guard against this.
|
|
|
|
|
&& (firstObjAfterBreak == null || definitelyBigger(firstObjAfterBreak.StartTime, time));
|
2021-06-24 02:07:29 +00:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-24 01:51:45 +00:00
|
|
|
|
private IEnumerable<double> getBeatsForTimingPoint(TimingControlPoint timingPoint, double mapEndTime)
|
|
|
|
|
{
|
|
|
|
|
var beats = new List<double>();
|
|
|
|
|
int i = 0;
|
2021-10-27 04:04:41 +00:00
|
|
|
|
double currentTime = timingPoint.Time;
|
2021-06-24 01:51:45 +00:00
|
|
|
|
|
2022-06-20 07:53:03 +00:00
|
|
|
|
while (!definitelyBigger(currentTime, mapEndTime) && ReferenceEquals(controlPointInfo.TimingPointAt(currentTime), timingPoint))
|
2021-06-24 01:51:45 +00:00
|
|
|
|
{
|
|
|
|
|
beats.Add(Math.Floor(currentTime));
|
|
|
|
|
i++;
|
|
|
|
|
currentTime = timingPoint.Time + i * timingPoint.BeatLength;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return beats;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-29 04:49:25 +00:00
|
|
|
|
private OsuHitObject getClosestHitObject(List<OsuHitObject> hitObjects, double time)
|
|
|
|
|
{
|
2021-10-27 04:04:41 +00:00
|
|
|
|
int precedingIndex = hitObjects.FindLastIndex(h => h.StartTime < time);
|
2021-06-29 04:49:25 +00:00
|
|
|
|
|
2021-07-01 03:57:57 +00:00
|
|
|
|
if (precedingIndex == hitObjects.Count - 1) return hitObjects[precedingIndex];
|
2021-06-29 04:49:25 +00:00
|
|
|
|
|
|
|
|
|
// return the closest preceding/succeeding hit object, whoever is closer in time
|
2021-07-01 03:57:57 +00:00
|
|
|
|
return hitObjects[precedingIndex + 1].StartTime - time < time - hitObjects[precedingIndex].StartTime
|
|
|
|
|
? hitObjects[precedingIndex + 1]
|
|
|
|
|
: hitObjects[precedingIndex];
|
2021-06-29 04:49:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-05-19 14:25:56 +00:00
|
|
|
|
/// <summary>
|
2021-06-18 08:05:09 +00:00
|
|
|
|
/// Get samples (if any) for a specific point in time.
|
2021-05-19 14:25:56 +00:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <remarks>
|
2021-06-18 08:05:09 +00:00
|
|
|
|
/// Samples will be returned if a hit circle or a slider node exists at that point of time.
|
2021-05-19 14:25:56 +00:00
|
|
|
|
/// </remarks>
|
|
|
|
|
/// <param name="hitObjects">The list of hit objects in a beatmap, ordered by StartTime</param>
|
|
|
|
|
/// <param name="time">The point in time to get samples for</param>
|
|
|
|
|
/// <returns>Hit samples</returns>
|
2022-07-10 15:49:38 +00:00
|
|
|
|
private IList<HitSampleInfo>? getSamplesAtTime(IEnumerable<OsuHitObject> hitObjects, double time)
|
2021-05-19 14:25:56 +00:00
|
|
|
|
{
|
2021-06-24 04:20:23 +00:00
|
|
|
|
// Get a hit object that
|
|
|
|
|
// either has StartTime equal to the target time
|
|
|
|
|
// or has a repeat node at the target time
|
2021-06-24 02:33:54 +00:00
|
|
|
|
var sampleObj = hitObjects.FirstOrDefault(hitObject =>
|
2021-05-19 14:25:56 +00:00
|
|
|
|
{
|
2021-06-24 06:55:49 +00:00
|
|
|
|
if (almostEquals(time, hitObject.StartTime))
|
2021-06-24 02:33:54 +00:00
|
|
|
|
return true;
|
2021-06-14 13:34:34 +00:00
|
|
|
|
|
2021-06-28 03:33:19 +00:00
|
|
|
|
if (!(hitObject is IHasRepeats s))
|
2021-06-14 13:34:34 +00:00
|
|
|
|
return false;
|
2021-07-01 04:21:41 +00:00
|
|
|
|
// If time is outside the duration of the IHasRepeats,
|
|
|
|
|
// then this hitObject isn't the one we want
|
2021-06-24 06:55:49 +00:00
|
|
|
|
if (!almostBigger(time, hitObject.StartTime)
|
|
|
|
|
|| !almostBigger(s.EndTime, time))
|
2021-06-14 13:34:34 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
2021-06-24 02:33:54 +00:00
|
|
|
|
return nodeIndexFromTime(s, time - hitObject.StartTime) != -1;
|
2021-05-19 14:25:56 +00:00
|
|
|
|
});
|
|
|
|
|
if (sampleObj == null) return null;
|
|
|
|
|
|
2021-06-14 13:34:34 +00:00
|
|
|
|
IList<HitSampleInfo> samples;
|
|
|
|
|
|
2021-06-28 03:33:19 +00:00
|
|
|
|
if (sampleObj is IHasRepeats slider)
|
2021-06-24 02:38:21 +00:00
|
|
|
|
samples = slider.NodeSamples[nodeIndexFromTime(slider, time - sampleObj.StartTime)];
|
2021-05-19 14:25:56 +00:00
|
|
|
|
else
|
|
|
|
|
samples = sampleObj.Samples;
|
2021-06-14 13:34:34 +00:00
|
|
|
|
|
2021-05-19 14:25:56 +00:00
|
|
|
|
return samples;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-24 02:33:54 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Get the repeat node at a point in time.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="curve">The slider.</param>
|
|
|
|
|
/// <param name="timeSinceStart">The time since the start time of the slider.</param>
|
|
|
|
|
/// <returns>Index of the node. -1 if there isn't a node at the specific time.</returns>
|
2021-06-28 03:33:19 +00:00
|
|
|
|
private int nodeIndexFromTime(IHasRepeats curve, double timeSinceStart)
|
2021-06-24 02:33:54 +00:00
|
|
|
|
{
|
|
|
|
|
double spanDuration = curve.Duration / curve.SpanCount();
|
|
|
|
|
double nodeIndex = timeSinceStart / spanDuration;
|
|
|
|
|
|
2021-07-01 03:57:57 +00:00
|
|
|
|
if (almostEquals(nodeIndex, Math.Round(nodeIndex)))
|
2021-06-24 02:33:54 +00:00
|
|
|
|
return (int)Math.Round(nodeIndex);
|
|
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-24 04:02:48 +00:00
|
|
|
|
private bool checkForOverlap(IEnumerable<OsuHitObject> objectsToCheck, OsuHitObject target)
|
2021-06-19 02:04:48 +00:00
|
|
|
|
{
|
2021-06-24 04:02:48 +00:00
|
|
|
|
return objectsToCheck.Any(h => Vector2.Distance(h.Position, target.Position) < target.Radius * 2);
|
2021-06-19 02:04:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-06-24 04:20:23 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Move the hit object into playfield, taking its radius into account.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="obj">The hit object to be clamped.</param>
|
2021-06-19 04:26:16 +00:00
|
|
|
|
private void clampToPlayfield(OsuHitObject obj)
|
|
|
|
|
{
|
|
|
|
|
var position = obj.Position;
|
2021-10-27 04:04:41 +00:00
|
|
|
|
float radius = (float)obj.Radius;
|
2021-06-19 04:26:16 +00:00
|
|
|
|
|
|
|
|
|
if (position.Y < radius)
|
|
|
|
|
position.Y = radius;
|
|
|
|
|
else if (position.Y > OsuPlayfield.BASE_SIZE.Y - radius)
|
|
|
|
|
position.Y = OsuPlayfield.BASE_SIZE.Y - radius;
|
|
|
|
|
|
|
|
|
|
if (position.X < radius)
|
|
|
|
|
position.X = radius;
|
|
|
|
|
else if (position.X > OsuPlayfield.BASE_SIZE.X - radius)
|
|
|
|
|
position.X = OsuPlayfield.BASE_SIZE.X - radius;
|
|
|
|
|
|
|
|
|
|
obj.Position = position;
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-01 03:57:57 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Re-maps a number from one range to another.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="value">The number to be re-mapped.</param>
|
|
|
|
|
/// <param name="fromLow">Beginning of the original range.</param>
|
|
|
|
|
/// <param name="fromHigh">End of the original range.</param>
|
|
|
|
|
/// <param name="toLow">Beginning of the new range.</param>
|
|
|
|
|
/// <param name="toHigh">End of the new range.</param>
|
|
|
|
|
/// <returns>The re-mapped number.</returns>
|
2021-07-04 02:01:56 +00:00
|
|
|
|
private static float mapRange(float value, float fromLow, float fromHigh, float toLow, float toHigh)
|
2021-05-19 14:25:56 +00:00
|
|
|
|
{
|
2021-06-23 08:50:05 +00:00
|
|
|
|
return (value - fromLow) * (toHigh - toLow) / (fromHigh - fromLow) + toLow;
|
2021-05-19 14:25:56 +00:00
|
|
|
|
}
|
2021-06-23 08:50:05 +00:00
|
|
|
|
|
2021-06-24 06:55:49 +00:00
|
|
|
|
private static bool almostBigger(double value1, double value2)
|
|
|
|
|
{
|
|
|
|
|
return Precision.AlmostBigger(value1, value2, timing_precision);
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-01 04:21:41 +00:00
|
|
|
|
private static bool definitelyBigger(double value1, double value2)
|
|
|
|
|
{
|
|
|
|
|
return Precision.DefinitelyBigger(value1, value2, timing_precision);
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-24 06:55:49 +00:00
|
|
|
|
private static bool almostEquals(double value1, double value2)
|
|
|
|
|
{
|
|
|
|
|
return Precision.AlmostEquals(value1, value2, timing_precision);
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-23 08:50:05 +00:00
|
|
|
|
#endregion
|
2018-01-09 04:41:57 +00:00
|
|
|
|
}
|
|
|
|
|
}
|