1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-08 08:37:40 +08:00
osu-lazer/osu.Game.Rulesets.Osu/Mods/OsuModAimAssist.cs

73 lines
2.9 KiB
C#
Raw Normal View History

2019-08-20 04:54:07 +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.
using System;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Osu.Objects.Drawables;
using osu.Game.Rulesets.UI;
2019-08-20 23:23:50 +08:00
using osu.Game.Rulesets.Osu.UI;
2019-08-22 03:37:56 +08:00
using osuTK;
using System.Linq;
2022-01-05 20:05:22 +08:00
using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Configuration;
using osu.Framework.Bindables;
2019-08-20 04:54:07 +08:00
namespace osu.Game.Rulesets.Osu.Mods
{
2022-01-05 20:05:22 +08:00
internal class OsuModAimAssist : Mod, IUpdatableByPlayfield, IApplicableToDrawableRuleset<OsuHitObject>
2019-08-20 04:54:07 +08:00
{
2019-08-20 22:33:56 +08:00
public override string Name => "Aim Assist";
2019-08-20 04:54:07 +08:00
public override string Acronym => "AA";
public override IconUsage? Icon => FontAwesome.Solid.MousePointer;
2019-08-20 04:54:07 +08:00
public override ModType Type => ModType.Fun;
public override string Description => "No need to chase the circle, the circle chases you";
public override double ScoreMultiplier => 1;
2019-08-22 03:37:56 +08:00
public override Type[] IncompatibleMods => new[] { typeof(OsuModAutopilot), typeof(OsuModWiggle), typeof(OsuModTransform), typeof(ModAutoplay) };
2019-08-20 04:54:07 +08:00
[SettingSource("Assist strength", "Change the distance notes should travel towards you.", 0)]
public BindableFloat AssistStrength { get; } = new BindableFloat(0.3f)
{
Precision = 0.05f,
MinValue = 0.0f,
MaxValue = 1.0f,
};
2022-01-05 20:05:22 +08:00
2022-01-06 23:04:38 +08:00
private DateTime? lastUpdate;
2022-01-05 20:05:22 +08:00
public void ApplyToDrawableRuleset(DrawableRuleset<OsuHitObject> drawableRuleset)
{
2022-01-06 17:38:30 +08:00
// Hide judgment displays and follow points
drawableRuleset.Playfield.DisplayJudgements.Value = false;
(drawableRuleset.Playfield as OsuPlayfield)?.FollowPoints.Hide();
2022-01-05 20:05:22 +08:00
}
2019-08-20 04:54:07 +08:00
public void Update(Playfield playfield)
{
2022-01-06 23:04:38 +08:00
if (DateTime.Now - (lastUpdate ?? DateTime.MinValue) < TimeSpan.FromMilliseconds(100))
return;
Vector2 cursorPos = playfield.Cursor.ActiveCursor.DrawPosition;
double currentTime = playfield.Clock.CurrentTime;
2019-08-20 22:33:56 +08:00
foreach (var drawable in playfield.HitObjectContainer.AliveObjects.OfType<DrawableOsuHitObject>())
2019-08-20 04:54:07 +08:00
{
var h = drawable.HitObject;
2019-08-22 03:37:56 +08:00
if (currentTime < h.StartTime && (drawable is DrawableHitCircle || drawable is DrawableSlider))
2019-08-20 04:54:07 +08:00
{
double timeMoving = currentTime - (h.StartTime - h.TimePreempt);
float percentDoneMoving = (float)(timeMoving / h.TimePreempt);
float percentDistLeft = Math.Clamp(AssistStrength.Value - percentDoneMoving + 0.1f, 0, 1);
2019-08-20 04:54:07 +08:00
Vector2 targetPos = drawable.Position + percentDistLeft * (cursorPos - drawable.Position);
drawable.MoveTo(targetPos, h.StartTime - currentTime);
2019-08-22 03:37:56 +08:00
}
}
2022-01-06 23:04:38 +08:00
lastUpdate = DateTime.Now;
2019-08-20 04:54:07 +08:00
}
}
}