1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-24 14:47:24 +08:00
osu-lazer/osu.Game.Rulesets.Osu/Mods/OsuModAutopilot.cs

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

74 lines
3.1 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 17:19:50 +08:00
using System;
2019-05-12 19:00:43 +08:00
using System.Collections.Generic;
using System.Diagnostics;
2019-05-12 19:00:43 +08:00
using System.Linq;
using osu.Framework.Graphics.Sprites;
2019-05-12 19:00:43 +08:00
using osu.Framework.Input.StateChanges;
using osu.Game.Graphics;
using osu.Game.Rulesets.Mods;
2019-05-12 19:00:43 +08:00
using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Rulesets.Osu.Replays;
using osu.Game.Rulesets.UI;
2018-04-13 17:19:50 +08:00
namespace osu.Game.Rulesets.Osu.Mods
{
2019-05-12 19:00:43 +08:00
public class OsuModAutopilot : Mod, IApplicableFailOverride, IUpdatableByPlayfield, IApplicableToDrawableRuleset<OsuHitObject>
{
public override string Name => "Autopilot";
public override string Acronym => "AP";
2020-01-14 21:22:00 +08:00
public override IconUsage? Icon => OsuIcon.ModAutopilot;
public override ModType Type => ModType.Automation;
public override string Description => @"Automatic cursor movement - just follow the rhythm.";
public override double ScoreMultiplier => 1;
2022-07-12 05:23:32 +08:00
public override Type[] IncompatibleMods => new[] { typeof(OsuModSpunOut), typeof(ModRelax), typeof(ModFailCondition), typeof(ModNoFail), typeof(ModAutoplay), typeof(OsuModMagnetised), typeof(OsuModRepel) };
2019-05-12 19:00:43 +08:00
public bool PerformFail() => false;
2019-09-19 00:45:42 +08:00
public bool RestartOnFail => false;
2019-05-12 19:00:43 +08:00
private OsuInputManager? inputManager;
2019-05-12 19:00:43 +08:00
private IFrameStableClock? gameplayClock;
private List<OsuReplayFrame>? replayFrames;
private int currentFrame;
2019-05-12 19:00:43 +08:00
public void Update(Playfield playfield)
{
Debug.Assert(inputManager != null);
Debug.Assert(gameplayClock != null);
Debug.Assert(replayFrames != null);
if (currentFrame == replayFrames.Count - 1) return;
double time = gameplayClock.CurrentTime;
2019-05-12 19:00:43 +08:00
// 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))
2019-05-12 19:00:43 +08:00
{
currentFrame++;
new MousePositionAbsoluteInput { Position = playfield.ToScreenSpace(replayFrames[currentFrame].Position) }.Apply(inputManager.CurrentState, inputManager);
2019-05-12 19:00:43 +08:00
}
// TODO: Implement the functionality to automatically spin spinners
}
public void ApplyToDrawableRuleset(DrawableRuleset<OsuHitObject> drawableRuleset)
{
gameplayClock = drawableRuleset.FrameStableClock;
2019-05-12 19:00:43 +08:00
// 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, drawableRuleset.Mods).Generate().Frames.Cast<OsuReplayFrame>().ToList();
2019-05-12 19:00:43 +08:00
}
}
}