osu/osu.Game.Rulesets.Mania/ManiaRuleset.cs

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

446 lines
16 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
2018-01-15 08:43:45 +00:00
using System;
using System.Collections.Generic;
2018-01-15 08:43:45 +00:00
using System.Linq;
2021-02-25 06:38:56 +00:00
using osu.Framework.Extensions.EnumExtensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites;
2017-08-23 03:49:50 +00:00
using osu.Framework.Input.Bindings;
2022-08-14 18:54:02 +00:00
using osu.Framework.Localisation;
using osu.Game.Beatmaps;
2018-04-13 13:41:35 +00:00
using osu.Game.Beatmaps.Legacy;
using osu.Game.Configuration;
using osu.Game.Graphics;
2018-06-11 05:36:19 +00:00
using osu.Game.Overlays.Settings;
using osu.Game.Rulesets.Configuration;
using osu.Game.Rulesets.Difficulty;
using osu.Game.Rulesets.Edit;
using osu.Game.Rulesets.Filter;
using osu.Game.Rulesets.Mania.Beatmaps;
using osu.Game.Rulesets.Mania.Configuration;
using osu.Game.Rulesets.Mania.Difficulty;
using osu.Game.Rulesets.Mania.Edit;
using osu.Game.Rulesets.Mania.Edit.Setup;
using osu.Game.Rulesets.Mania.Mods;
using osu.Game.Rulesets.Mania.Replays;
2019-12-17 11:08:13 +00:00
using osu.Game.Rulesets.Mania.Scoring;
using osu.Game.Rulesets.Mania.Skinning.Argon;
using osu.Game.Rulesets.Mania.Skinning.Default;
2020-12-07 03:32:52 +00:00
using osu.Game.Rulesets.Mania.Skinning.Legacy;
using osu.Game.Rulesets.Mania.UI;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Replays.Types;
2019-12-17 11:08:13 +00:00
using osu.Game.Rulesets.Scoring;
using osu.Game.Rulesets.Scoring.Legacy;
using osu.Game.Rulesets.UI;
2018-11-28 07:12:57 +00:00
using osu.Game.Scoring;
using osu.Game.Screens.Edit.Setup;
using osu.Game.Screens.Ranking.Statistics;
using osu.Game.Skinning;
2018-04-13 09:19:50 +00:00
2017-04-18 07:05:58 +00:00
namespace osu.Game.Rulesets.Mania
{
2019-12-24 04:48:27 +00:00
public class ManiaRuleset : Ruleset, ILegacyRuleset
{
2020-04-21 01:56:04 +00:00
/// <summary>
/// The maximum number of supported keys in a single stage.
/// </summary>
public const int MAX_STAGE_KEYS = 10;
public override DrawableRuleset CreateDrawableRulesetWith(IBeatmap beatmap, IReadOnlyList<Mod>? mods = null) => new DrawableManiaRuleset(this, beatmap, mods);
2019-12-17 11:08:13 +00:00
public override ScoreProcessor CreateScoreProcessor() => new ManiaScoreProcessor();
2019-12-17 11:08:13 +00:00
2023-01-11 04:01:18 +00:00
public override HealthProcessor CreateHealthProcessor(double drainStartTime) => new ManiaHealthProcessor(drainStartTime);
2019-12-17 11:08:13 +00:00
public override IBeatmapConverter CreateBeatmapConverter(IBeatmap beatmap) => new ManiaBeatmapConverter(beatmap, this);
2019-12-17 11:08:13 +00:00
2022-03-15 03:37:39 +00:00
public override PerformanceCalculator CreatePerformanceCalculator() => new ManiaPerformanceCalculator();
public const string SHORT_NAME = "mania";
public override string RulesetAPIVersionSupported => CURRENT_RULESET_API_VERSION;
2022-08-22 07:10:55 +00:00
public override HitObjectComposer CreateHitObjectComposer() => new ManiaHitObjectComposer(this);
2018-04-13 09:19:50 +00:00
2024-03-20 18:52:16 +00:00
public override IBeatmapVerifier CreateBeatmapVerifier() => new ManiaBeatmapVerifier();
public override ISkin? CreateSkinTransformer(ISkin skin, IBeatmap beatmap)
{
switch (skin)
{
case TrianglesSkin:
return new ManiaTrianglesSkinTransformer(skin, beatmap);
case ArgonSkin:
return new ManiaArgonSkinTransformer(skin, beatmap);
case DefaultLegacySkin:
return new ManiaClassicSkinTransformer(skin, beatmap);
case LegacySkin:
return new ManiaLegacySkinTransformer(skin, beatmap);
}
return null;
}
public override IEnumerable<Mod> ConvertFromLegacyMods(LegacyMods mods)
2018-04-13 13:41:35 +00:00
{
2021-02-25 06:38:56 +00:00
if (mods.HasFlagFast(LegacyMods.Nightcore))
2018-04-13 13:41:35 +00:00
yield return new ManiaModNightcore();
2021-02-25 06:38:56 +00:00
else if (mods.HasFlagFast(LegacyMods.DoubleTime))
2018-04-13 13:41:35 +00:00
yield return new ManiaModDoubleTime();
2021-02-25 06:38:56 +00:00
if (mods.HasFlagFast(LegacyMods.Perfect))
yield return new ManiaModPerfect();
2021-02-25 06:38:56 +00:00
else if (mods.HasFlagFast(LegacyMods.SuddenDeath))
yield return new ManiaModSuddenDeath();
2021-02-25 06:38:56 +00:00
if (mods.HasFlagFast(LegacyMods.Cinema))
2019-11-23 17:32:16 +00:00
yield return new ManiaModCinema();
2021-02-25 06:38:56 +00:00
else if (mods.HasFlagFast(LegacyMods.Autoplay))
2018-04-13 13:41:35 +00:00
yield return new ManiaModAutoplay();
2021-02-25 06:38:56 +00:00
if (mods.HasFlagFast(LegacyMods.Easy))
2018-04-13 13:41:35 +00:00
yield return new ManiaModEasy();
2021-02-25 06:38:56 +00:00
if (mods.HasFlagFast(LegacyMods.FadeIn))
2018-04-13 13:41:35 +00:00
yield return new ManiaModFadeIn();
2021-02-25 06:38:56 +00:00
if (mods.HasFlagFast(LegacyMods.Flashlight))
2018-04-13 13:41:35 +00:00
yield return new ManiaModFlashlight();
2021-02-25 06:38:56 +00:00
if (mods.HasFlagFast(LegacyMods.HalfTime))
2018-04-13 13:41:35 +00:00
yield return new ManiaModHalfTime();
2021-02-25 06:38:56 +00:00
if (mods.HasFlagFast(LegacyMods.HardRock))
2018-04-13 13:41:35 +00:00
yield return new ManiaModHardRock();
2021-02-25 06:38:56 +00:00
if (mods.HasFlagFast(LegacyMods.Hidden))
2018-04-13 13:41:35 +00:00
yield return new ManiaModHidden();
2021-02-25 06:38:56 +00:00
if (mods.HasFlagFast(LegacyMods.Key1))
2018-04-13 13:41:35 +00:00
yield return new ManiaModKey1();
2021-02-25 06:38:56 +00:00
if (mods.HasFlagFast(LegacyMods.Key2))
2018-04-13 13:41:35 +00:00
yield return new ManiaModKey2();
2021-02-25 06:38:56 +00:00
if (mods.HasFlagFast(LegacyMods.Key3))
2018-04-13 13:41:35 +00:00
yield return new ManiaModKey3();
2021-02-25 06:38:56 +00:00
if (mods.HasFlagFast(LegacyMods.Key4))
2018-04-13 13:41:35 +00:00
yield return new ManiaModKey4();
2021-02-25 06:38:56 +00:00
if (mods.HasFlagFast(LegacyMods.Key5))
2018-04-13 13:41:35 +00:00
yield return new ManiaModKey5();
2021-02-25 06:38:56 +00:00
if (mods.HasFlagFast(LegacyMods.Key6))
2018-04-13 13:41:35 +00:00
yield return new ManiaModKey6();
2021-02-25 06:38:56 +00:00
if (mods.HasFlagFast(LegacyMods.Key7))
2018-04-13 13:41:35 +00:00
yield return new ManiaModKey7();
2021-02-25 06:38:56 +00:00
if (mods.HasFlagFast(LegacyMods.Key8))
2018-04-13 13:41:35 +00:00
yield return new ManiaModKey8();
2021-02-25 06:38:56 +00:00
if (mods.HasFlagFast(LegacyMods.Key9))
2018-04-13 13:41:35 +00:00
yield return new ManiaModKey9();
2021-02-25 06:38:56 +00:00
if (mods.HasFlagFast(LegacyMods.KeyCoop))
2020-11-15 14:38:12 +00:00
yield return new ManiaModDualStages();
2021-02-25 06:38:56 +00:00
if (mods.HasFlagFast(LegacyMods.NoFail))
2018-04-13 13:41:35 +00:00
yield return new ManiaModNoFail();
2021-02-25 06:38:56 +00:00
if (mods.HasFlagFast(LegacyMods.Random))
2018-04-13 13:41:35 +00:00
yield return new ManiaModRandom();
2021-02-25 06:38:56 +00:00
if (mods.HasFlagFast(LegacyMods.Mirror))
yield return new ManiaModMirror();
if (mods.HasFlagFast(LegacyMods.ScoreV2))
yield return new ModScoreV2();
2018-04-13 13:41:35 +00:00
}
public override LegacyMods ConvertToLegacyMods(Mod[] mods)
{
var value = base.ConvertToLegacyMods(mods);
foreach (var mod in mods)
{
switch (mod)
{
2022-06-24 12:25:23 +00:00
case ManiaModKey1:
value |= LegacyMods.Key1;
break;
2022-06-24 12:25:23 +00:00
case ManiaModKey2:
value |= LegacyMods.Key2;
break;
2022-06-24 12:25:23 +00:00
case ManiaModKey3:
value |= LegacyMods.Key3;
break;
2022-06-24 12:25:23 +00:00
case ManiaModKey4:
value |= LegacyMods.Key4;
break;
2022-06-24 12:25:23 +00:00
case ManiaModKey5:
value |= LegacyMods.Key5;
break;
2022-06-24 12:25:23 +00:00
case ManiaModKey6:
value |= LegacyMods.Key6;
break;
2022-06-24 12:25:23 +00:00
case ManiaModKey7:
value |= LegacyMods.Key7;
break;
2022-06-24 12:25:23 +00:00
case ManiaModKey8:
value |= LegacyMods.Key8;
break;
2022-06-24 12:25:23 +00:00
case ManiaModKey9:
value |= LegacyMods.Key9;
break;
2022-06-24 12:25:23 +00:00
case ManiaModDualStages:
2020-11-15 14:38:12 +00:00
value |= LegacyMods.KeyCoop;
break;
2022-06-24 12:25:23 +00:00
case ManiaModFadeIn:
value |= LegacyMods.FadeIn;
2020-11-16 05:52:18 +00:00
value &= ~LegacyMods.Hidden; // this is toggled on in the base call due to inheritance, but we don't want that.
break;
2022-06-24 12:25:23 +00:00
case ManiaModMirror:
value |= LegacyMods.Mirror;
break;
2020-11-15 14:38:12 +00:00
2022-06-24 12:25:23 +00:00
case ManiaModRandom:
2020-11-15 14:38:12 +00:00
value |= LegacyMods.Random;
break;
}
}
return value;
}
public override IEnumerable<Mod> GetModsFor(ModType type)
{
switch (type)
{
case ModType.DifficultyReduction:
return new Mod[]
{
new ManiaModEasy(),
new ManiaModNoFail(),
2018-06-06 05:07:50 +00:00
new MultiMod(new ManiaModHalfTime(), new ManiaModDaycore()),
};
2019-04-01 03:16:05 +00:00
case ModType.DifficultyIncrease:
return new Mod[]
{
new ManiaModHardRock(),
2018-06-06 05:07:50 +00:00
new MultiMod(new ManiaModSuddenDeath(), new ManiaModPerfect()),
new MultiMod(new ManiaModDoubleTime(), new ManiaModNightcore()),
new MultiMod(new ManiaModFadeIn(), new ManiaModHidden(), new ManiaModCover()),
new ManiaModFlashlight(),
2022-05-24 14:56:31 +00:00
new ModAccuracyChallenge(),
};
2019-04-01 03:16:05 +00:00
case ModType.Conversion:
return new Mod[]
{
new ManiaModRandom(),
2018-01-22 06:11:15 +00:00
new ManiaModDualStages(),
new ManiaModMirror(),
2019-12-20 10:30:23 +00:00
new ManiaModDifficultyAdjust(),
new ManiaModClassic(),
2020-08-17 16:40:55 +00:00
new ManiaModInvert(),
2022-01-27 11:35:31 +00:00
new ManiaModConstantSpeed(),
new ManiaModHoldOff(),
new MultiMod(
new ManiaModKey1(),
new ManiaModKey2(),
new ManiaModKey3(),
new ManiaModKey4(),
new ManiaModKey5(),
new ManiaModKey6(),
new ManiaModKey7(),
new ManiaModKey8(),
new ManiaModKey9(),
new ManiaModKey10()
),
};
2019-04-01 03:16:05 +00:00
case ModType.Automation:
return new Mod[]
{
2019-11-23 17:32:16 +00:00
new MultiMod(new ManiaModAutoplay(), new ManiaModCinema()),
};
2019-04-01 03:16:05 +00:00
2019-01-26 04:15:45 +00:00
case ModType.Fun:
return new Mod[]
{
2021-07-28 10:21:08 +00:00
new MultiMod(new ModWindUp(), new ModWindDown()),
new ManiaModMuted(),
2022-03-01 13:12:06 +00:00
new ModAdaptiveSpeed()
2019-01-26 04:15:45 +00:00
};
2019-04-01 03:16:05 +00:00
case ModType.System:
return new Mod[]
{
new ModScoreV2(),
};
default:
2019-11-28 13:41:29 +00:00
return Array.Empty<Mod>();
}
}
2018-04-13 09:19:50 +00:00
public override string Description => "osu!mania";
2018-04-13 09:19:50 +00:00
public override string ShortName => SHORT_NAME;
2018-04-13 09:19:50 +00:00
public override string PlayingVerb => "Smashing keys";
public override Drawable CreateIcon() => new SpriteIcon { Icon = OsuIcon.RulesetMania };
2018-04-13 09:19:50 +00:00
public override DifficultyCalculator CreateDifficultyCalculator(IWorkingBeatmap beatmap) => new ManiaDifficultyCalculator(RulesetInfo, beatmap);
2018-04-13 09:19:50 +00:00
2019-12-24 04:48:27 +00:00
public int LegacyID => 3;
2018-04-13 09:19:50 +00:00
public ILegacyScoreSimulator CreateLegacyScoreSimulator() => new ManiaLegacyScoreSimulator();
public override IConvertibleReplayFrame CreateConvertibleReplayFrame() => new ManiaReplayFrame();
2018-04-13 09:19:50 +00:00
public override IRulesetConfigManager CreateConfig(SettingsStore? settings) => new ManiaRulesetConfigManager(settings, RulesetInfo);
2018-06-11 05:36:19 +00:00
public override RulesetSettingsSubsection CreateSettings() => new ManiaSettingsSubsection(this);
2018-01-15 08:43:45 +00:00
public override IEnumerable<int> AvailableVariants
{
get
{
2020-04-21 01:56:04 +00:00
for (int i = 1; i <= MAX_STAGE_KEYS; i++)
yield return (int)PlayfieldType.Single + i;
2020-04-21 01:56:04 +00:00
for (int i = 2; i <= MAX_STAGE_KEYS * 2; i += 2)
yield return (int)PlayfieldType.Dual + i;
2018-01-15 08:43:45 +00:00
}
}
2018-04-13 09:19:50 +00:00
2017-08-23 03:49:50 +00:00
public override IEnumerable<KeyBinding> GetDefaultKeyBindings(int variant = 0)
{
2018-01-22 06:18:11 +00:00
switch (getPlayfieldType(variant))
2018-01-15 08:43:45 +00:00
{
case PlayfieldType.Single:
return new SingleStageVariantGenerator(variant).GenerateMappings();
2019-04-01 03:16:05 +00:00
case PlayfieldType.Dual:
return new DualStageVariantGenerator(getDualStageKeyCount(variant)).GenerateMappings();
2018-01-15 08:43:45 +00:00
}
2018-04-13 09:19:50 +00:00
2019-11-28 13:41:29 +00:00
return Array.Empty<KeyBinding>();
2018-01-15 08:43:45 +00:00
}
2018-04-13 09:19:50 +00:00
public override LocalisableString GetVariantName(int variant)
2018-01-15 08:43:45 +00:00
{
2018-01-22 06:18:11 +00:00
switch (getPlayfieldType(variant))
2017-08-23 03:49:50 +00:00
{
2018-01-15 08:43:45 +00:00
default:
return $"{variant}K";
2019-04-01 03:16:05 +00:00
case PlayfieldType.Dual:
2018-01-15 08:43:45 +00:00
{
int keys = getDualStageKeyCount(variant);
return $"{keys}K + {keys}K";
2018-01-15 08:43:45 +00:00
}
}
}
2018-04-13 09:19:50 +00:00
2018-01-15 08:43:45 +00:00
/// <summary>
/// Finds the number of keys for each stage in a <see cref="PlayfieldType.Dual"/> variant.
2018-01-15 08:43:45 +00:00
/// </summary>
/// <param name="variant">The variant.</param>
private int getDualStageKeyCount(int variant) => (variant - (int)PlayfieldType.Dual) / 2;
2018-04-13 09:19:50 +00:00
2018-01-15 08:43:45 +00:00
/// <summary>
/// Finds the <see cref="PlayfieldType"/> that corresponds to a variant value.
2018-01-15 08:43:45 +00:00
/// </summary>
/// <param name="variant">The variant value.</param>
/// <returns>The <see cref="PlayfieldType"/> that corresponds to <paramref name="variant"/>.</returns>
2018-01-22 06:18:11 +00:00
private PlayfieldType getPlayfieldType(int variant)
2018-01-15 08:43:45 +00:00
{
return (PlayfieldType)Enum.GetValues(typeof(PlayfieldType)).Cast<int>().OrderDescending().First(v => variant >= v);
2018-01-15 08:43:45 +00:00
}
protected override IEnumerable<HitResult> GetValidHitResults()
{
return new[]
{
HitResult.Perfect,
HitResult.Great,
HitResult.Good,
HitResult.Ok,
HitResult.Meh,
// HitResult.SmallBonus is used for awarding perfect bonus score but is not included here as
// it would be a bit redundant to show this to the user.
};
}
public override StatisticItem[] CreateStatisticsForScore(ScoreInfo score, IBeatmap playableBeatmap) => new[]
{
new StatisticItem("Performance Breakdown", () => new PerformanceBreakdownChart(score, playableBeatmap)
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y
}),
new StatisticItem("Timing Distribution", () => new HitEventTimingDistributionGraph(score.HitEvents)
2020-08-27 18:46:49 +00:00
{
RelativeSizeAxes = Axes.X,
Height = 250
}, true),
new StatisticItem("Statistics", () => new SimpleStatisticTable(2, new SimpleStatisticItem[]
2022-02-05 13:30:35 +00:00
{
new AverageHitError(score.HitEvents),
new UnstableRate(score.HitEvents)
}), true)
};
public override IRulesetFilterCriteria CreateRulesetFilterCriteria()
{
return new ManiaFilterCriteria();
}
public override RulesetSetupSection CreateEditorSetupSection() => new ManiaSetupSection();
public override SetupSection CreateEditorDifficultySection() => new ManiaDifficultySection();
public int GetKeyCount(IBeatmapInfo beatmapInfo, IReadOnlyList<Mod>? mods = null)
=> ManiaBeatmapConverter.GetColumnCount(LegacyBeatmapConversionDifficultyInfo.FromBeatmapInfo(beatmapInfo), mods);
2018-01-15 08:43:45 +00:00
}
2018-04-13 09:19:50 +00:00
public enum PlayfieldType
2018-01-15 08:43:45 +00:00
{
/// <summary>
/// Columns are grouped into a single stage.
2018-01-22 05:57:25 +00:00
/// Number of columns in this stage lies at (item - Single).
2018-01-15 08:43:45 +00:00
/// </summary>
2018-01-22 05:57:25 +00:00
Single = 0,
2018-01-15 08:43:45 +00:00
/// <summary>
/// Columns are grouped into two stages.
2018-01-22 05:57:25 +00:00
/// Overall number of columns lies at (item - Dual), further computation is required for
/// number of columns in each individual stage.
2018-01-15 08:43:45 +00:00
/// </summary>
2018-01-22 05:57:25 +00:00
Dual = 1000,
}
}