2019-01-24 16:43:03 +08: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 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
using System;
|
2019-05-12 19:00:43 +08:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2019-03-27 18:29:27 +08:00
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
2019-05-12 19:00:43 +08:00
|
|
|
|
using osu.Framework.Input.StateChanges;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
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>
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
public override string Name => "Autopilot";
|
2018-11-30 16:16:00 +08:00
|
|
|
|
public override string Acronym => "AP";
|
2019-03-27 18:29:27 +08:00
|
|
|
|
public override IconUsage Icon => OsuIcon.ModAutopilot;
|
2018-07-31 17:00:42 +08:00
|
|
|
|
public override ModType Type => ModType.Automation;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
public override string Description => @"Automatic cursor movement - just follow the rhythm.";
|
2018-05-31 11:36:37 +08:00
|
|
|
|
public override double ScoreMultiplier => 1;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
public override Type[] IncompatibleMods => new[] { typeof(OsuModSpunOut), typeof(ModRelax), typeof(ModSuddenDeath), typeof(ModNoFail), typeof(ModAutoplay) };
|
2019-05-12 19:00:43 +08:00
|
|
|
|
|
|
|
|
|
public bool AllowFail => false;
|
|
|
|
|
|
|
|
|
|
private OsuInputManager inputManager;
|
|
|
|
|
|
|
|
|
|
private List<OsuReplayFrame> replayFrames;
|
2019-05-12 20:00:59 +08:00
|
|
|
|
private int frameIndex;
|
2019-05-12 19:00:43 +08:00
|
|
|
|
|
|
|
|
|
public void Update(Playfield playfield)
|
|
|
|
|
{
|
|
|
|
|
// If we are on the last replay frame, no need to do anything
|
2019-05-16 04:48:37 +08:00
|
|
|
|
if (frameIndex == replayFrames.Count - 1) return;
|
2019-05-12 19:00:43 +08:00
|
|
|
|
|
|
|
|
|
// Check if we are closer to the next replay frame then the current one
|
|
|
|
|
if (Math.Abs(replayFrames[frameIndex].Time - playfield.Time.Current) >= Math.Abs(replayFrames[frameIndex + 1].Time - playfield.Time.Current))
|
|
|
|
|
{
|
|
|
|
|
// If we are, move to the next frame, and update the mouse position
|
|
|
|
|
frameIndex++;
|
2019-05-12 20:00:59 +08:00
|
|
|
|
new MousePositionAbsoluteInput { Position = playfield.ToScreenSpace(replayFrames[frameIndex].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)
|
|
|
|
|
{
|
|
|
|
|
// 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();
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|