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
|
|
|
|
|
2018-01-09 04:41:57 +00:00
|
|
|
|
using System;
|
2019-05-12 11:00:43 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2019-03-27 10:29:27 +00:00
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
2019-05-12 11:00:43 +00:00
|
|
|
|
using osu.Framework.Input.StateChanges;
|
2022-08-10 20:09:11 +00:00
|
|
|
|
using osu.Framework.Localisation;
|
2018-01-09 04:41:57 +00:00
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
|
using osu.Game.Rulesets.Mods;
|
2019-05-12 11:00:43 +00:00
|
|
|
|
using osu.Game.Rulesets.Osu.Objects;
|
|
|
|
|
using osu.Game.Rulesets.Osu.Replays;
|
2023-02-14 08:35:41 +00:00
|
|
|
|
using osu.Game.Rulesets.Osu.UI;
|
2019-05-12 11:00:43 +00:00
|
|
|
|
using osu.Game.Rulesets.UI;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-01-09 04:41:57 +00:00
|
|
|
|
namespace osu.Game.Rulesets.Osu.Mods
|
|
|
|
|
{
|
2019-05-12 11:00:43 +00:00
|
|
|
|
public class OsuModAutopilot : Mod, IApplicableFailOverride, IUpdatableByPlayfield, IApplicableToDrawableRuleset<OsuHitObject>
|
2018-01-09 04:41:57 +00:00
|
|
|
|
{
|
|
|
|
|
public override string Name => "Autopilot";
|
2018-11-30 08:16:00 +00:00
|
|
|
|
public override string Acronym => "AP";
|
2020-01-14 13:22:00 +00:00
|
|
|
|
public override IconUsage? Icon => OsuIcon.ModAutopilot;
|
2018-07-31 09:00:42 +00:00
|
|
|
|
public override ModType Type => ModType.Automation;
|
2022-08-10 20:09:11 +00:00
|
|
|
|
public override LocalisableString Description => @"Automatic cursor movement - just follow the rhythm.";
|
2022-08-12 06:25:35 +00:00
|
|
|
|
public override double ScoreMultiplier => 0.1;
|
2023-05-30 06:18:22 +00:00
|
|
|
|
|
|
|
|
|
public override Type[] IncompatibleMods => new[]
|
|
|
|
|
{
|
|
|
|
|
typeof(OsuModSpunOut),
|
|
|
|
|
typeof(ModRelax),
|
|
|
|
|
typeof(ModFailCondition),
|
|
|
|
|
typeof(ModNoFail),
|
|
|
|
|
typeof(ModAutoplay),
|
|
|
|
|
typeof(OsuModMagnetised),
|
|
|
|
|
typeof(OsuModRepel)
|
|
|
|
|
};
|
2019-05-12 11:00:43 +00:00
|
|
|
|
|
2020-05-12 11:08:35 +00:00
|
|
|
|
public bool PerformFail() => false;
|
|
|
|
|
|
2019-09-18 16:45:42 +00:00
|
|
|
|
public bool RestartOnFail => false;
|
2019-05-12 11:00:43 +00:00
|
|
|
|
|
2022-07-31 13:43:16 +00:00
|
|
|
|
private OsuInputManager inputManager = null!;
|
2019-05-12 11:00:43 +00:00
|
|
|
|
|
2022-07-31 13:43:16 +00:00
|
|
|
|
private List<OsuReplayFrame> replayFrames = null!;
|
2019-08-12 06:05:27 +00:00
|
|
|
|
|
2023-05-30 06:18:22 +00:00
|
|
|
|
private int currentFrame = -1;
|
2019-05-12 11:00:43 +00:00
|
|
|
|
|
|
|
|
|
public void Update(Playfield playfield)
|
|
|
|
|
{
|
2019-08-12 06:05:27 +00:00
|
|
|
|
if (currentFrame == replayFrames.Count - 1) return;
|
|
|
|
|
|
2022-08-25 00:59:32 +00:00
|
|
|
|
double time = playfield.Clock.CurrentTime;
|
2019-05-12 11:00:43 +00:00
|
|
|
|
|
2019-08-12 06:05:27 +00:00
|
|
|
|
// Very naive implementation of autopilot based on proximity to replay frames.
|
2023-05-30 06:18:22 +00:00
|
|
|
|
// Special case for the first frame is required to ensure the mouse is in a sane position until the actual time of the first frame is hit.
|
2019-08-12 06:05:27 +00:00
|
|
|
|
// TODO: this needs to be based on user interactions to better match stable (pausing until judgement is registered).
|
2023-05-30 06:18:22 +00:00
|
|
|
|
if (currentFrame < 0 || Math.Abs(replayFrames[currentFrame + 1].Time - time) <= Math.Abs(replayFrames[currentFrame].Time - time))
|
2019-05-12 11:00:43 +00:00
|
|
|
|
{
|
2019-08-12 06:05:27 +00:00
|
|
|
|
currentFrame++;
|
|
|
|
|
new MousePositionAbsoluteInput { Position = playfield.ToScreenSpace(replayFrames[currentFrame].Position) }.Apply(inputManager.CurrentState, inputManager);
|
2019-05-12 11:00:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 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
|
2023-02-14 09:10:25 +00:00
|
|
|
|
inputManager = ((DrawableOsuRuleset)drawableRuleset).KeyBindingInputManager;
|
2019-05-12 11:00:43 +00:00
|
|
|
|
inputManager.AllowUserCursorMovement = false;
|
|
|
|
|
|
|
|
|
|
// Generate the replay frames the cursor should follow
|
2021-02-11 08:47:29 +00:00
|
|
|
|
replayFrames = new OsuAutoGenerator(drawableRuleset.Beatmap, drawableRuleset.Mods).Generate().Frames.Cast<OsuReplayFrame>().ToList();
|
2023-02-13 22:51:39 +00:00
|
|
|
|
|
|
|
|
|
drawableRuleset.UseResumeOverlay = false;
|
2019-05-12 11:00:43 +00:00
|
|
|
|
}
|
2018-01-09 04:41:57 +00:00
|
|
|
|
}
|
|
|
|
|
}
|