2018-09-06 02:30:03 +08:00
|
|
|
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
|
using osu.Game.Rulesets.Mods;
|
|
|
|
|
using osu.Game.Rulesets.Objects.Drawables;
|
2018-09-14 17:18:40 +08:00
|
|
|
|
using osu.Game.Rulesets.Objects.Types;
|
2018-09-06 02:30:03 +08:00
|
|
|
|
using osu.Game.Rulesets.Osu.Objects;
|
|
|
|
|
using OpenTK;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Osu.Mods
|
|
|
|
|
{
|
|
|
|
|
internal class OsuModWiggle : Mod, IApplicableToDrawableHitObjects
|
|
|
|
|
{
|
|
|
|
|
public override string Name => "Wiggle";
|
|
|
|
|
public override string ShortenedName => "WG";
|
2018-09-14 16:57:27 +08:00
|
|
|
|
public override FontAwesome Icon => FontAwesome.fa_certificate;
|
2018-09-06 02:30:03 +08:00
|
|
|
|
public override ModType Type => ModType.Fun;
|
|
|
|
|
public override string Description => "They just won't stay still...";
|
|
|
|
|
public override double ScoreMultiplier => 1;
|
2018-09-15 20:55:29 +08:00
|
|
|
|
public override Type[] IncompatibleMods => new[] { typeof(OsuModTransform) };
|
2018-09-06 02:30:03 +08:00
|
|
|
|
|
2018-09-14 17:18:40 +08:00
|
|
|
|
private const int wiggle_duration = 90; // (ms) Higher = fewer wiggles
|
2018-09-14 16:38:47 +08:00
|
|
|
|
private const int wiggle_strength = 10; // Higher = stronger wiggles
|
|
|
|
|
|
2018-09-06 02:30:03 +08:00
|
|
|
|
public void ApplyToDrawableHitObjects(IEnumerable<DrawableHitObject> drawables)
|
|
|
|
|
{
|
2018-09-14 16:38:47 +08:00
|
|
|
|
foreach (var drawable in drawables)
|
2018-09-06 02:30:03 +08:00
|
|
|
|
drawable.ApplyCustomUpdateState += drawableOnApplyCustomUpdateState;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void drawableOnApplyCustomUpdateState(DrawableHitObject drawable, ArmedState state)
|
|
|
|
|
{
|
2018-09-14 17:18:40 +08:00
|
|
|
|
var osuObject = (OsuHitObject)drawable.HitObject;
|
|
|
|
|
Vector2 origin = drawable.Position;
|
2018-09-14 16:38:47 +08:00
|
|
|
|
|
2018-09-16 06:16:37 +08:00
|
|
|
|
// Wiggle the repeat points with the slider instead of independently.
|
|
|
|
|
// Also fixes an issue with repeat points being positioned incorrectly.
|
|
|
|
|
if (osuObject is RepeatPoint)
|
|
|
|
|
return;
|
|
|
|
|
|
2018-09-14 17:20:19 +08:00
|
|
|
|
Random objRand = new Random((int)osuObject.StartTime);
|
2018-09-06 02:30:03 +08:00
|
|
|
|
|
|
|
|
|
// Wiggle all objects during TimePreempt
|
2018-09-14 17:18:40 +08:00
|
|
|
|
int amountWiggles = (int)osuObject.TimePreempt / wiggle_duration;
|
2018-09-06 02:30:03 +08:00
|
|
|
|
|
2018-09-14 17:18:40 +08:00
|
|
|
|
void wiggle()
|
2018-09-06 02:30:03 +08:00
|
|
|
|
{
|
2018-09-14 17:20:19 +08:00
|
|
|
|
float nextAngle = (float)(objRand.NextDouble() * 2 * Math.PI);
|
|
|
|
|
float nextDist = (float)(objRand.NextDouble() * wiggle_strength);
|
2018-09-14 17:18:40 +08:00
|
|
|
|
drawable.MoveTo(new Vector2((float)(nextDist * Math.Cos(nextAngle) + origin.X), (float)(nextDist * Math.Sin(nextAngle) + origin.Y)), wiggle_duration);
|
2018-09-06 02:30:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-09-14 17:18:40 +08:00
|
|
|
|
for (int i = 0; i < amountWiggles; i++)
|
|
|
|
|
using (drawable.BeginAbsoluteSequence(osuObject.StartTime - osuObject.TimePreempt + i * wiggle_duration, true))
|
|
|
|
|
wiggle();
|
|
|
|
|
|
2018-09-06 02:30:03 +08:00
|
|
|
|
// Keep wiggling sliders and spinners for their duration
|
2018-09-14 17:18:40 +08:00
|
|
|
|
if (!(osuObject is IHasEndTime endTime))
|
2018-09-06 02:30:03 +08:00
|
|
|
|
return;
|
|
|
|
|
|
2018-09-14 17:18:40 +08:00
|
|
|
|
amountWiggles = (int)(endTime.Duration / wiggle_duration);
|
2018-09-06 02:30:03 +08:00
|
|
|
|
|
|
|
|
|
for (int i = 0; i < amountWiggles; i++)
|
2018-09-14 17:18:40 +08:00
|
|
|
|
using (drawable.BeginAbsoluteSequence(osuObject.StartTime + i * wiggle_duration, true))
|
|
|
|
|
wiggle();
|
2018-09-06 02:30:03 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|