osu/osu.Game.Rulesets.Osu/Objects/Spinner.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

102 lines
3.6 KiB
C#
Raw Normal View History

// 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
using System;
using System.Collections.Generic;
using System.Linq;
2020-09-17 08:05:24 +00:00
using System.Threading;
using osu.Game.Audio;
2017-07-26 04:22:46 +00:00
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Objects.Types;
using osu.Game.Rulesets.Osu.Judgements;
2019-09-06 06:24:00 +00:00
using osu.Game.Rulesets.Scoring;
using osuTK;
2018-04-13 09:19:50 +00:00
2017-04-18 07:05:58 +00:00
namespace osu.Game.Rulesets.Osu.Objects
{
2020-05-27 03:38:39 +00:00
public class Spinner : OsuHitObject, IHasDuration
{
public double EndTime
{
get => StartTime + Duration;
set => Duration = value - StartTime;
}
public double Duration { get; set; }
2018-04-13 09:19:50 +00:00
2017-05-14 03:45:35 +00:00
/// <summary>
/// Number of spins required to finish the spinner without miss.
/// </summary>
2017-05-14 06:36:09 +00:00
public int SpinsRequired { get; protected set; } = 1;
2018-04-13 09:19:50 +00:00
2023-09-12 11:51:22 +00:00
/// <summary>
/// The number of spins required to start receiving bonus score. The first bonus is awarded on this spin count.
/// </summary>
public int SpinsRequiredForBonus => SpinsRequired + bonus_spins_gap;
/// <summary>
/// The gap between spinner completion and the first bonus-awarding spin.
/// </summary>
private const int bonus_spins_gap = 2;
/// <summary>
/// Number of spins available to give bonus, beyond <see cref="SpinsRequired"/>.
/// </summary>
2020-07-24 12:03:55 +00:00
public int MaximumBonusSpins { get; protected set; } = 1;
2021-10-26 00:15:43 +00:00
public override Vector2 StackOffset => Vector2.Zero;
protected override void ApplyDefaultsToSelf(ControlPointInfo controlPointInfo, IBeatmapDifficultyInfo difficulty)
2017-05-14 03:45:35 +00:00
{
base.ApplyDefaultsToSelf(controlPointInfo, difficulty);
2018-04-13 09:19:50 +00:00
const double maximum_rotations_per_second = 477f / 60f;
double secondsDuration = Duration / 1000;
double minimumRotationsPerSecond = IBeatmapDifficultyInfo.DifficultyRange(difficulty.OverallDifficulty, 1.5, 2.5, 3.75);
2020-07-24 12:03:55 +00:00
SpinsRequired = (int)(secondsDuration * minimumRotationsPerSecond);
MaximumBonusSpins = (int)((maximum_rotations_per_second - minimumRotationsPerSecond) * secondsDuration) - bonus_spins_gap;
2017-05-14 03:45:35 +00:00
}
2020-09-17 08:05:24 +00:00
protected override void CreateNestedHitObjects(CancellationToken cancellationToken)
{
2020-09-17 08:05:24 +00:00
base.CreateNestedHitObjects(cancellationToken);
int totalSpins = MaximumBonusSpins + SpinsRequired + bonus_spins_gap;
for (int i = 0; i < totalSpins; i++)
{
2020-09-17 08:05:24 +00:00
cancellationToken.ThrowIfCancellationRequested();
double startTime = StartTime + (float)(i + 1) / totalSpins * Duration;
2023-09-12 11:51:22 +00:00
AddNested(i < SpinsRequiredForBonus
? new SpinnerTick { StartTime = startTime, SpinnerDuration = Duration }
: new SpinnerBonusTick { StartTime = startTime, SpinnerDuration = Duration, Samples = new[] { CreateHitSampleInfo("spinnerbonus") } });
}
}
2018-08-06 02:50:18 +00:00
public override Judgement CreateJudgement() => new OsuJudgement();
2019-10-09 10:08:31 +00:00
protected override HitWindows CreateHitWindows() => HitWindows.Empty;
public override IList<HitSampleInfo> AuxiliarySamples => CreateSpinningSamples();
public HitSampleInfo[] CreateSpinningSamples()
{
var referenceSample = Samples.FirstOrDefault();
if (referenceSample == null)
return Array.Empty<HitSampleInfo>();
return new[]
{
referenceSample.With("spinnerspin")
};
}
}
}