<commit_before>﻿// Copyright (c) ppy Pty Ltd <<EMAIL>>. 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;
using osu.Game.Rulesets.Osu.UI;
using osuTK;
using System.Linq;
using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Configuration;
using osu.Framework.Bindables;

namespace osu.Game.Rulesets.Osu.Mods
{
    internal class OsuModAimAssist : Mod, IUpdatableByPlayfield, IApplicableToDrawableRuleset<OsuHitObject>
    {
        public override string Name => "Aim Assist";
        public override string Acronym => "AA";
        public override IconUsage? Icon => FontAwesome.Solid.MousePointer;
        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;
        public override Type[] IncompatibleMods => new[] { typeof(OsuModAutopilot), typeof(OsuModWiggle), typeof(OsuModTransform), typeof(ModAutoplay) };

        [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,
        };

        private DateTime? lastUpdate;

        public void ApplyToDrawableRuleset(DrawableRuleset<OsuHitObject> drawableRuleset)
        {
            // Hide judgment displays and follow points
            drawableRuleset.Playfield.DisplayJudgements.Value = false;
            (drawableRuleset.Playfield as OsuPlayfield)?.FollowPoints.Hide();
        }

        public void Update(Playfield playfield)
        {
            if (DateTime.Now - (lastUpdate ?? DateTime.MinValue) < TimeSpan.FromMilliseconds(100))
                return;

            Vector2 cursorPos = playfield.Cursor.ActiveCursor.DrawPosition;
            double currentTime = playfield.Clock.CurrentTime;

            foreach (var drawable in playfield.HitObjectContainer.AliveObjects.OfType<DrawableOsuHitObject>())
            {
                var h = drawable.HitObject;

                if (currentTime < h.StartTime && (drawable is DrawableHitCircle || drawable is DrawableSlider))
                {
                    double timeMoving = currentTime - (h.StartTime - h.TimePreempt);
                    float percentDoneMoving = (float)(timeMoving / h.TimePreempt);
                    float percentDistLeft = Math.Clamp(AssistStrength.Value - percentDoneMoving + 0.1f, 0, 1);

                    Vector2 targetPos = drawable.Position + percentDistLeft * (cursorPos - drawable.Position);
                    drawable.MoveTo(targetPos, h.StartTime - currentTime);
                }
            }

            lastUpdate = DateTime.Now;
        }
    }
}
<commit_msg>use playfield clock<commit_after>﻿// Copyright (c) ppy Pty Ltd <<EMAIL>>. 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;
using osu.Game.Rulesets.Osu.UI;
using osuTK;
using System.Linq;
using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Configuration;
using osu.Framework.Bindables;

namespace osu.Game.Rulesets.Osu.Mods
{
    internal class OsuModAimAssist : Mod, IUpdatableByPlayfield, IApplicableToDrawableRuleset<OsuHitObject>
    {
        public override string Name => "Aim Assist";
        public override string Acronym => "AA";
        public override IconUsage? Icon => FontAwesome.Solid.MousePointer;
        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;
        public override Type[] IncompatibleMods => new[] { typeof(OsuModAutopilot), typeof(OsuModWiggle), typeof(OsuModTransform), typeof(ModAutoplay) };

        [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,
        };

        private double? lastUpdate;

        public void ApplyToDrawableRuleset(DrawableRuleset<OsuHitObject> drawableRuleset)
        {
            // Hide judgment displays and follow points
            drawableRuleset.Playfield.DisplayJudgements.Value = false;
            (drawableRuleset.Playfield as OsuPlayfield)?.FollowPoints.Hide();
        }

        public void Update(Playfield playfield)
        {
            double currentTime = playfield.Clock.CurrentTime;

            if (currentTime - (lastUpdate ?? double.MinValue) < 100)
                return;

            Vector2 cursorPos = playfield.Cursor.ActiveCursor.DrawPosition;

            foreach (var drawable in playfield.HitObjectContainer.AliveObjects.OfType<DrawableOsuHitObject>())
            {
                var h = drawable.HitObject;

                if (currentTime < h.StartTime && (drawable is DrawableHitCircle || drawable is DrawableSlider))
                {
                    double timeMoving = currentTime - (h.StartTime - h.TimePreempt);
                    float percentDoneMoving = (float)(timeMoving / h.TimePreempt);
                    float percentDistLeft = Math.Clamp(AssistStrength.Value - percentDoneMoving + 0.1f, 0, 1);

                    Vector2 targetPos = drawable.Position + percentDistLeft * (cursorPos - drawable.Position);
                    drawable.MoveTo(targetPos, h.StartTime - currentTime);
                }
            }

            lastUpdate = currentTime;
        }
    }
}

{'fraction_non_alphanumeric': 0.08951025810721376, 'fraction_numerical': 0.0066181336863004635, 'mean_word_length': 2.5454545454545454, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4033557', 'n_tokens_mistral': 1755, 'n_tokens_neox': 1668, 'n_words': 414}