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-09-05 18:30:03 +00:00
|
|
|
|
|
|
|
|
|
using System;
|
2022-01-24 09:24:40 +00:00
|
|
|
|
using osu.Framework.Bindables;
|
2018-09-05 18:30:03 +00:00
|
|
|
|
using osu.Framework.Graphics;
|
2019-03-27 10:29:27 +00:00
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
2022-08-10 20:09:11 +00:00
|
|
|
|
using osu.Framework.Localisation;
|
2022-01-24 09:24:40 +00:00
|
|
|
|
using osu.Game.Configuration;
|
2018-09-05 18:30:03 +00:00
|
|
|
|
using osu.Game.Rulesets.Mods;
|
|
|
|
|
using osu.Game.Rulesets.Objects.Drawables;
|
2018-09-14 09:18:40 +00:00
|
|
|
|
using osu.Game.Rulesets.Objects.Types;
|
2018-09-05 18:30:03 +00:00
|
|
|
|
using osu.Game.Rulesets.Osu.Objects;
|
2018-11-20 07:51:59 +00:00
|
|
|
|
using osuTK;
|
2018-09-05 18:30:03 +00:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Osu.Mods
|
|
|
|
|
{
|
2020-11-05 07:04:42 +00:00
|
|
|
|
internal class OsuModWiggle : ModWithVisibilityAdjustment
|
2018-09-05 18:30:03 +00:00
|
|
|
|
{
|
|
|
|
|
public override string Name => "Wiggle";
|
2018-11-30 08:16:00 +00:00
|
|
|
|
public override string Acronym => "WG";
|
2020-01-14 13:22:00 +00:00
|
|
|
|
public override IconUsage? Icon => FontAwesome.Solid.Certificate;
|
2018-09-05 18:30:03 +00:00
|
|
|
|
public override ModType Type => ModType.Fun;
|
2022-08-10 20:09:11 +00:00
|
|
|
|
public override LocalisableString Description => "They just won't stay still...";
|
2018-09-05 18:30:03 +00:00
|
|
|
|
public override double ScoreMultiplier => 1;
|
2023-12-03 02:39:44 +00:00
|
|
|
|
public override Type[] IncompatibleMods => new[] { typeof(OsuModTransform), typeof(OsuModMagnetised), typeof(OsuModRepel), typeof(OsuModDepth) };
|
2018-09-05 18:30:03 +00:00
|
|
|
|
|
2022-07-25 03:36:21 +00:00
|
|
|
|
private const int wiggle_duration = 100; // (ms) Higher = fewer wiggles
|
2022-07-23 21:30:57 +00:00
|
|
|
|
|
|
|
|
|
[SettingSource("Strength", "Multiplier applied to the wiggling strength.")]
|
2022-08-01 14:30:00 +00:00
|
|
|
|
public BindableDouble Strength { get; } = new BindableDouble(1)
|
2022-01-24 09:24:40 +00:00
|
|
|
|
{
|
2022-01-26 23:10:15 +00:00
|
|
|
|
MinValue = 0.1f,
|
2022-01-24 11:16:29 +00:00
|
|
|
|
MaxValue = 2f,
|
2022-01-26 23:10:15 +00:00
|
|
|
|
Precision = 0.1f
|
2022-01-24 09:24:40 +00:00
|
|
|
|
};
|
2022-07-23 21:30:57 +00:00
|
|
|
|
|
2020-11-05 07:04:42 +00:00
|
|
|
|
protected override void ApplyIncreasedVisibilityState(DrawableHitObject hitObject, ArmedState state) => drawableOnApplyCustomUpdateState(hitObject, state);
|
|
|
|
|
|
|
|
|
|
protected override void ApplyNormalVisibilityState(DrawableHitObject hitObject, ArmedState state) => drawableOnApplyCustomUpdateState(hitObject, state);
|
2018-09-05 18:30:03 +00:00
|
|
|
|
|
|
|
|
|
private void drawableOnApplyCustomUpdateState(DrawableHitObject drawable, ArmedState state)
|
|
|
|
|
{
|
2018-09-14 09:18:40 +00:00
|
|
|
|
var osuObject = (OsuHitObject)drawable.HitObject;
|
|
|
|
|
Vector2 origin = drawable.Position;
|
2018-09-14 08:38:47 +00:00
|
|
|
|
|
2021-04-21 01:32:08 +00:00
|
|
|
|
// Wiggle the repeat points and the tail with the slider instead of independently.
|
2018-09-15 22:16:37 +00:00
|
|
|
|
// Also fixes an issue with repeat points being positioned incorrectly.
|
2021-04-21 01:29:18 +00:00
|
|
|
|
if (osuObject is SliderRepeat || osuObject is SliderTailCircle)
|
2018-09-15 22:16:37 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2018-09-14 09:20:19 +00:00
|
|
|
|
Random objRand = new Random((int)osuObject.StartTime);
|
2018-09-05 18:30:03 +00:00
|
|
|
|
|
|
|
|
|
// Wiggle all objects during TimePreempt
|
2022-07-23 21:30:57 +00:00
|
|
|
|
int amountWiggles = (int)osuObject.TimePreempt / wiggle_duration;
|
2018-09-05 18:30:03 +00:00
|
|
|
|
|
2018-09-14 09:18:40 +00:00
|
|
|
|
void wiggle()
|
2018-09-05 18:30:03 +00:00
|
|
|
|
{
|
2018-09-14 09:20:19 +00:00
|
|
|
|
float nextAngle = (float)(objRand.NextDouble() * 2 * Math.PI);
|
2022-08-01 14:30:00 +00:00
|
|
|
|
float nextDist = (float)(objRand.NextDouble() * Strength.Value * 7);
|
2022-07-23 21:30:57 +00:00
|
|
|
|
drawable.MoveTo(new Vector2((float)(nextDist * Math.Cos(nextAngle) + origin.X), (float)(nextDist * Math.Sin(nextAngle) + origin.Y)), wiggle_duration);
|
2018-09-05 18:30:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-09-14 09:18:40 +00:00
|
|
|
|
for (int i = 0; i < amountWiggles; i++)
|
2019-11-11 11:53:22 +00:00
|
|
|
|
{
|
2022-07-23 21:30:57 +00:00
|
|
|
|
using (drawable.BeginAbsoluteSequence(osuObject.StartTime - osuObject.TimePreempt + i * wiggle_duration))
|
2018-09-14 09:18:40 +00:00
|
|
|
|
wiggle();
|
2019-11-11 11:53:22 +00:00
|
|
|
|
}
|
2018-09-14 09:18:40 +00:00
|
|
|
|
|
2018-09-05 18:30:03 +00:00
|
|
|
|
// Keep wiggling sliders and spinners for their duration
|
2020-05-27 03:38:39 +00:00
|
|
|
|
if (!(osuObject is IHasDuration endTime))
|
2018-09-05 18:30:03 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2022-07-23 21:30:57 +00:00
|
|
|
|
amountWiggles = (int)(endTime.Duration / wiggle_duration);
|
2018-09-05 18:30:03 +00:00
|
|
|
|
|
|
|
|
|
for (int i = 0; i < amountWiggles; i++)
|
2019-11-11 11:53:22 +00:00
|
|
|
|
{
|
2022-07-23 21:30:57 +00:00
|
|
|
|
using (drawable.BeginAbsoluteSequence(osuObject.StartTime + i * wiggle_duration))
|
2018-09-14 09:18:40 +00:00
|
|
|
|
wiggle();
|
2019-11-11 11:53:22 +00:00
|
|
|
|
}
|
2018-09-05 18:30:03 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|