mirror of
https://github.com/osukey/osukey.git
synced 2025-08-05 23:53:51 +09:00
Implement osu! autopilot mod (#4762)
Implement osu! autopilot mod Co-authored-by: Dean Herbert <pe@ppy.sh>
This commit is contained in:
@ -2,13 +2,19 @@
|
|||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using osu.Framework.Graphics.Sprites;
|
using osu.Framework.Graphics.Sprites;
|
||||||
|
using osu.Framework.Input.StateChanges;
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
using osu.Game.Rulesets.Mods;
|
using osu.Game.Rulesets.Mods;
|
||||||
|
using osu.Game.Rulesets.Osu.Objects;
|
||||||
|
using osu.Game.Rulesets.Osu.Replays;
|
||||||
|
using osu.Game.Rulesets.UI;
|
||||||
|
|
||||||
namespace osu.Game.Rulesets.Osu.Mods
|
namespace osu.Game.Rulesets.Osu.Mods
|
||||||
{
|
{
|
||||||
public class OsuModAutopilot : Mod
|
public class OsuModAutopilot : Mod, IApplicableFailOverride, IUpdatableByPlayfield, IApplicableToDrawableRuleset<OsuHitObject>
|
||||||
{
|
{
|
||||||
public override string Name => "Autopilot";
|
public override string Name => "Autopilot";
|
||||||
public override string Acronym => "AP";
|
public override string Acronym => "AP";
|
||||||
@ -17,5 +23,40 @@ namespace osu.Game.Rulesets.Osu.Mods
|
|||||||
public override string Description => @"Automatic cursor movement - just follow the rhythm.";
|
public override string Description => @"Automatic cursor movement - just follow the rhythm.";
|
||||||
public override double ScoreMultiplier => 1;
|
public override double ScoreMultiplier => 1;
|
||||||
public override Type[] IncompatibleMods => new[] { typeof(OsuModSpunOut), typeof(ModRelax), typeof(ModSuddenDeath), typeof(ModNoFail), typeof(ModAutoplay) };
|
public override Type[] IncompatibleMods => new[] { typeof(OsuModSpunOut), typeof(ModRelax), typeof(ModSuddenDeath), typeof(ModNoFail), typeof(ModAutoplay) };
|
||||||
|
|
||||||
|
public bool AllowFail => false;
|
||||||
|
|
||||||
|
private OsuInputManager inputManager;
|
||||||
|
|
||||||
|
private List<OsuReplayFrame> replayFrames;
|
||||||
|
|
||||||
|
private int currentFrame;
|
||||||
|
|
||||||
|
public void Update(Playfield playfield)
|
||||||
|
{
|
||||||
|
if (currentFrame == replayFrames.Count - 1) return;
|
||||||
|
|
||||||
|
double time = playfield.Time.Current;
|
||||||
|
|
||||||
|
// Very naive implementation of autopilot based on proximity to replay frames.
|
||||||
|
// TODO: this needs to be based on user interactions to better match stable (pausing until judgement is registered).
|
||||||
|
if (Math.Abs(replayFrames[currentFrame + 1].Time - time) <= Math.Abs(replayFrames[currentFrame].Time - time))
|
||||||
|
{
|
||||||
|
currentFrame++;
|
||||||
|
new MousePositionAbsoluteInput { Position = playfield.ToScreenSpace(replayFrames[currentFrame].Position) }.Apply(inputManager.CurrentState, inputManager);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Implement the functionality to automatically spin spinners
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ApplyToDrawableRuleset(DrawableRuleset<OsuHitObject> drawableRuleset)
|
||||||
|
{
|
||||||
|
// Grab the input manager to disable the user's cursor, and for future use
|
||||||
|
inputManager = (OsuInputManager)drawableRuleset.KeyBindingInputManager;
|
||||||
|
inputManager.AllowUserCursorMovement = false;
|
||||||
|
|
||||||
|
// Generate the replay frames the cursor should follow
|
||||||
|
replayFrames = new OsuAutoGenerator(drawableRuleset.Beatmap).Generate().Frames.Cast<OsuReplayFrame>().ToList();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,12 @@ namespace osu.Game.Rulesets.Osu
|
|||||||
set => ((OsuKeyBindingContainer)KeyBindingContainer).AllowUserPresses = value;
|
set => ((OsuKeyBindingContainer)KeyBindingContainer).AllowUserPresses = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Whether the user's cursor movement events should be accepted.
|
||||||
|
/// Can be used to block only movement while still accepting button input.
|
||||||
|
/// </summary>
|
||||||
|
public bool AllowUserCursorMovement { get; set; } = true;
|
||||||
|
|
||||||
protected override RulesetKeyBindingContainer CreateKeyBindingContainer(RulesetInfo ruleset, int variant, SimultaneousBindingMode unique)
|
protected override RulesetKeyBindingContainer CreateKeyBindingContainer(RulesetInfo ruleset, int variant, SimultaneousBindingMode unique)
|
||||||
=> new OsuKeyBindingContainer(ruleset, variant, unique);
|
=> new OsuKeyBindingContainer(ruleset, variant, unique);
|
||||||
|
|
||||||
@ -26,6 +32,13 @@ namespace osu.Game.Rulesets.Osu
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override bool Handle(UIEvent e)
|
||||||
|
{
|
||||||
|
if (e is MouseMoveEvent && !AllowUserCursorMovement) return false;
|
||||||
|
|
||||||
|
return base.Handle(e);
|
||||||
|
}
|
||||||
|
|
||||||
private class OsuKeyBindingContainer : RulesetKeyBindingContainer
|
private class OsuKeyBindingContainer : RulesetKeyBindingContainer
|
||||||
{
|
{
|
||||||
public bool AllowUserPresses = true;
|
public bool AllowUserPresses = true;
|
||||||
|
@ -82,14 +82,13 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
|
|
||||||
var easierMods = instance.GetModsFor(ModType.DifficultyReduction);
|
var easierMods = instance.GetModsFor(ModType.DifficultyReduction);
|
||||||
var harderMods = instance.GetModsFor(ModType.DifficultyIncrease);
|
var harderMods = instance.GetModsFor(ModType.DifficultyIncrease);
|
||||||
var assistMods = instance.GetModsFor(ModType.Automation);
|
|
||||||
|
|
||||||
var noFailMod = easierMods.FirstOrDefault(m => m is OsuModNoFail);
|
var noFailMod = easierMods.FirstOrDefault(m => m is OsuModNoFail);
|
||||||
var hiddenMod = harderMods.FirstOrDefault(m => m is OsuModHidden);
|
var hiddenMod = harderMods.FirstOrDefault(m => m is OsuModHidden);
|
||||||
|
|
||||||
var doubleTimeMod = harderMods.OfType<MultiMod>().FirstOrDefault(m => m.Mods.Any(a => a is OsuModDoubleTime));
|
var doubleTimeMod = harderMods.OfType<MultiMod>().FirstOrDefault(m => m.Mods.Any(a => a is OsuModDoubleTime));
|
||||||
|
|
||||||
var autoPilotMod = assistMods.FirstOrDefault(m => m is OsuModAutopilot);
|
var spunOutMod = easierMods.FirstOrDefault(m => m is OsuModSpunOut);
|
||||||
|
|
||||||
var easy = easierMods.FirstOrDefault(m => m is OsuModEasy);
|
var easy = easierMods.FirstOrDefault(m => m is OsuModEasy);
|
||||||
var hardRock = harderMods.FirstOrDefault(m => m is OsuModHardRock);
|
var hardRock = harderMods.FirstOrDefault(m => m is OsuModHardRock);
|
||||||
@ -101,7 +100,7 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
testMultiplierTextColour(noFailMod, modSelect.LowMultiplierColour);
|
testMultiplierTextColour(noFailMod, modSelect.LowMultiplierColour);
|
||||||
testMultiplierTextColour(hiddenMod, modSelect.HighMultiplierColour);
|
testMultiplierTextColour(hiddenMod, modSelect.HighMultiplierColour);
|
||||||
|
|
||||||
testUnimplementedMod(autoPilotMod);
|
testUnimplementedMod(spunOutMod);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
Reference in New Issue
Block a user