2022-05-26 12:08:00 +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.Bindables;
|
2022-06-10 06:52:10 +08:00
|
|
|
using osu.Framework.Utils;
|
2022-05-26 12:08:00 +08:00
|
|
|
using osu.Game.Configuration;
|
2022-06-10 06:52:10 +08:00
|
|
|
using osu.Game.Rulesets.Mods;
|
|
|
|
using osu.Game.Rulesets.Objects.Drawables;
|
2022-06-07 21:36:44 +08:00
|
|
|
using osu.Game.Rulesets.Osu.Objects;
|
2022-06-10 06:52:10 +08:00
|
|
|
using osu.Game.Rulesets.Osu.Objects.Drawables;
|
2022-06-07 21:36:44 +08:00
|
|
|
using osu.Game.Rulesets.Osu.UI;
|
2022-06-10 06:52:10 +08:00
|
|
|
using osu.Game.Rulesets.Osu.Utils;
|
|
|
|
using osu.Game.Rulesets.UI;
|
2022-05-26 12:08:00 +08:00
|
|
|
using osuTK;
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Osu.Mods
|
|
|
|
{
|
2022-06-10 06:52:10 +08:00
|
|
|
internal class OsuModRepel : Mod, IUpdatableByPlayfield, IApplicableToDrawableRuleset<OsuHitObject>
|
2022-05-26 12:08:00 +08:00
|
|
|
{
|
|
|
|
public override string Name => "Repel";
|
|
|
|
public override string Acronym => "RP";
|
2022-06-10 06:52:10 +08:00
|
|
|
public override ModType Type => ModType.Fun;
|
2022-07-01 17:19:31 +08:00
|
|
|
public override string Description => "Hit objects run away!";
|
2022-06-10 06:52:10 +08:00
|
|
|
public override double ScoreMultiplier => 1;
|
|
|
|
public override Type[] IncompatibleMods => new[] { typeof(OsuModAutopilot), typeof(OsuModWiggle), typeof(OsuModTransform), typeof(ModAutoplay), typeof(OsuModMagnetised) };
|
|
|
|
|
|
|
|
private IFrameStableClock gameplayClock;
|
2022-05-26 12:08:00 +08:00
|
|
|
|
|
|
|
[SettingSource("Repulsion strength", "How strong the repulsion is.", 0)]
|
2022-06-10 06:52:10 +08:00
|
|
|
public BindableFloat RepulsionStrength { get; } = new BindableFloat(0.6f)
|
2022-05-26 12:08:00 +08:00
|
|
|
{
|
|
|
|
Precision = 0.05f,
|
|
|
|
MinValue = 0.05f,
|
|
|
|
MaxValue = 1.0f,
|
|
|
|
};
|
|
|
|
|
2022-06-10 06:52:10 +08:00
|
|
|
public void ApplyToDrawableRuleset(DrawableRuleset<OsuHitObject> drawableRuleset)
|
|
|
|
{
|
|
|
|
gameplayClock = drawableRuleset.FrameStableClock;
|
2022-06-08 13:00:47 +08:00
|
|
|
|
2022-06-10 06:52:10 +08:00
|
|
|
// Hide judgment displays and follow points as they won't make any sense.
|
|
|
|
// Judgements can potentially be turned on in a future where they display at a position relative to their drawable counterpart.
|
|
|
|
drawableRuleset.Playfield.DisplayJudgements.Value = false;
|
|
|
|
(drawableRuleset.Playfield as OsuPlayfield)?.FollowPoints.Hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Update(Playfield playfield)
|
2022-05-26 12:08:00 +08:00
|
|
|
{
|
2022-06-10 06:52:10 +08:00
|
|
|
var cursorPos = playfield.Cursor.ActiveCursor.DrawPosition;
|
|
|
|
|
|
|
|
foreach (var drawable in playfield.HitObjectContainer.AliveObjects)
|
2022-06-07 21:36:44 +08:00
|
|
|
{
|
2022-07-07 03:58:25 +08:00
|
|
|
var destination = Vector2.Clamp(2 * drawable.Position - cursorPos, Vector2.Zero, OsuPlayfield.BASE_SIZE);
|
2022-06-07 21:36:44 +08:00
|
|
|
|
2022-06-10 06:52:10 +08:00
|
|
|
if (drawable.HitObject is Slider thisSlider)
|
2022-06-07 21:36:44 +08:00
|
|
|
{
|
2022-06-10 06:52:10 +08:00
|
|
|
var possibleMovementBounds = OsuHitObjectGenerationUtils.CalculatePossibleMovementBounds(thisSlider);
|
2022-06-07 21:36:44 +08:00
|
|
|
|
2022-07-07 03:58:25 +08:00
|
|
|
destination = Vector2.Clamp(
|
|
|
|
destination,
|
|
|
|
new Vector2(possibleMovementBounds.Left, possibleMovementBounds.Top),
|
|
|
|
new Vector2(possibleMovementBounds.Right, possibleMovementBounds.Bottom)
|
|
|
|
);
|
2022-06-07 21:36:44 +08:00
|
|
|
}
|
|
|
|
|
2022-06-10 06:52:10 +08:00
|
|
|
switch (drawable)
|
|
|
|
{
|
|
|
|
case DrawableHitCircle circle:
|
|
|
|
easeTo(circle, destination);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DrawableSlider slider:
|
|
|
|
|
|
|
|
if (!slider.HeadCircle.Result.HasResult)
|
|
|
|
easeTo(slider, destination);
|
|
|
|
else
|
|
|
|
easeTo(slider, destination - slider.Ball.DrawPosition);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2022-06-07 21:36:44 +08:00
|
|
|
}
|
2022-05-26 12:08:00 +08:00
|
|
|
}
|
2022-06-10 06:52:10 +08:00
|
|
|
|
|
|
|
private void easeTo(DrawableHitObject hitObject, Vector2 destination)
|
|
|
|
{
|
|
|
|
double dampLength = Interpolation.Lerp(3000, 40, 0.8 * RepulsionStrength.Value);
|
|
|
|
|
|
|
|
float x = (float)Interpolation.DampContinuously(hitObject.X, destination.X, dampLength, gameplayClock.ElapsedFrameTime);
|
|
|
|
float y = (float)Interpolation.DampContinuously(hitObject.Y, destination.Y, dampLength, gameplayClock.ElapsedFrameTime);
|
|
|
|
|
|
|
|
hitObject.Position = new Vector2(x, y);
|
|
|
|
}
|
2022-05-26 12:08:00 +08:00
|
|
|
}
|
|
|
|
}
|