2018-01-05 19:21:19 +08:00
|
|
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
2017-03-24 13:24:10 +08:00
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
2017-03-29 15:20:54 +08:00
|
|
|
using System;
|
2017-04-29 02:08:48 +08:00
|
|
|
using System.Collections.Generic;
|
2017-12-22 20:42:54 +08:00
|
|
|
using System.Linq;
|
2017-03-31 15:20:31 +08:00
|
|
|
using osu.Game.Beatmaps;
|
2017-04-18 15:05:58 +08:00
|
|
|
using osu.Game.Rulesets.Objects.Types;
|
|
|
|
using osu.Game.Rulesets.Taiko.Objects;
|
|
|
|
using osu.Game.Rulesets.Replays;
|
2017-05-03 10:22:09 +08:00
|
|
|
using osu.Game.Users;
|
2017-03-24 13:24:10 +08:00
|
|
|
|
2017-04-18 15:05:58 +08:00
|
|
|
namespace osu.Game.Rulesets.Taiko.Replays
|
2017-03-24 13:24:10 +08:00
|
|
|
{
|
2017-05-03 10:22:09 +08:00
|
|
|
public class TaikoAutoGenerator : AutoGenerator<TaikoHitObject>
|
2017-03-24 13:24:10 +08:00
|
|
|
{
|
2017-04-26 15:28:53 +08:00
|
|
|
private const double swell_hit_speed = 50;
|
|
|
|
|
2017-05-03 10:22:09 +08:00
|
|
|
public TaikoAutoGenerator(Beatmap<TaikoHitObject> beatmap)
|
2017-04-29 02:08:48 +08:00
|
|
|
: base(beatmap)
|
2017-03-24 13:24:10 +08:00
|
|
|
{
|
2017-05-03 10:22:09 +08:00
|
|
|
Replay = new Replay
|
|
|
|
{
|
|
|
|
User = new User
|
|
|
|
{
|
|
|
|
Username = @"Autoplay",
|
|
|
|
}
|
|
|
|
};
|
2017-03-24 13:24:10 +08:00
|
|
|
}
|
|
|
|
|
2017-04-29 02:08:48 +08:00
|
|
|
protected Replay Replay;
|
|
|
|
protected List<ReplayFrame> Frames => Replay.Frames;
|
|
|
|
|
|
|
|
public override Replay Generate()
|
2017-03-24 13:24:10 +08:00
|
|
|
{
|
|
|
|
bool hitButton = true;
|
|
|
|
|
2018-01-25 20:37:38 +08:00
|
|
|
Frames.Add(new TaikoReplayFrame(-100000, ReplayButtonState.None));
|
|
|
|
Frames.Add(new TaikoReplayFrame(Beatmap.HitObjects[0].StartTime - 1000, ReplayButtonState.None));
|
2017-03-24 13:24:10 +08:00
|
|
|
|
2017-04-29 02:08:48 +08:00
|
|
|
for (int i = 0; i < Beatmap.HitObjects.Count; i++)
|
2017-03-24 13:24:10 +08:00
|
|
|
{
|
2017-04-29 02:08:48 +08:00
|
|
|
TaikoHitObject h = Beatmap.HitObjects[i];
|
2017-03-24 13:24:10 +08:00
|
|
|
|
2017-03-31 15:20:31 +08:00
|
|
|
ReplayButtonState button;
|
2017-03-24 13:24:10 +08:00
|
|
|
|
|
|
|
IHasEndTime endTimeData = h as IHasEndTime;
|
|
|
|
double endTime = endTimeData?.EndTime ?? h.StartTime;
|
|
|
|
|
2017-03-29 15:20:54 +08:00
|
|
|
Swell swell = h as Swell;
|
|
|
|
DrumRoll drumRoll = h as DrumRoll;
|
|
|
|
Hit hit = h as Hit;
|
|
|
|
|
|
|
|
if (swell != null)
|
2017-03-24 13:24:10 +08:00
|
|
|
{
|
|
|
|
int d = 0;
|
|
|
|
int count = 0;
|
2017-03-29 15:20:54 +08:00
|
|
|
int req = swell.RequiredHits;
|
2017-04-26 15:28:53 +08:00
|
|
|
double hitRate = Math.Min(swell_hit_speed, swell.Duration / req);
|
2017-03-24 13:24:10 +08:00
|
|
|
for (double j = h.StartTime; j < endTime; j += hitRate)
|
|
|
|
{
|
|
|
|
switch (d)
|
|
|
|
{
|
|
|
|
default:
|
2017-04-26 15:28:53 +08:00
|
|
|
case 0:
|
2018-02-23 13:40:25 +08:00
|
|
|
button = ReplayButtonState.Left1;
|
2017-03-24 13:24:10 +08:00
|
|
|
break;
|
|
|
|
case 1:
|
2018-02-23 13:40:25 +08:00
|
|
|
button = ReplayButtonState.Right1;
|
2017-03-24 13:24:10 +08:00
|
|
|
break;
|
|
|
|
case 2:
|
2018-02-23 13:40:25 +08:00
|
|
|
button = ReplayButtonState.Left2;
|
2017-03-24 13:24:10 +08:00
|
|
|
break;
|
|
|
|
case 3:
|
2018-02-23 13:40:25 +08:00
|
|
|
button = ReplayButtonState.Right2;
|
2017-03-24 13:24:10 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-01-25 20:37:38 +08:00
|
|
|
Frames.Add(new TaikoReplayFrame(j, button));
|
2017-03-24 13:24:10 +08:00
|
|
|
d = (d + 1) % 4;
|
2017-04-26 15:28:53 +08:00
|
|
|
if (++count == req)
|
2017-03-24 13:24:10 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2017-03-29 15:20:54 +08:00
|
|
|
else if (drumRoll != null)
|
2017-03-24 13:24:10 +08:00
|
|
|
{
|
2017-12-22 20:42:54 +08:00
|
|
|
foreach (var tick in drumRoll.NestedHitObjects.OfType<DrumRollTick>())
|
2017-03-24 13:24:10 +08:00
|
|
|
{
|
2018-02-21 22:05:51 +08:00
|
|
|
Frames.Add(new TaikoReplayFrame(tick.StartTime, hitButton ? ReplayButtonState.Left1 : ReplayButtonState.Left2));
|
2017-03-24 13:24:10 +08:00
|
|
|
hitButton = !hitButton;
|
|
|
|
}
|
|
|
|
}
|
2017-03-29 15:20:54 +08:00
|
|
|
else if (hit != null)
|
2017-03-24 13:24:10 +08:00
|
|
|
{
|
2017-03-30 14:51:16 +08:00
|
|
|
if (hit is CentreHit)
|
2017-03-24 13:24:10 +08:00
|
|
|
{
|
2017-03-29 09:59:35 +08:00
|
|
|
if (h.IsStrong)
|
2018-02-21 22:05:51 +08:00
|
|
|
button = ReplayButtonState.Left1 | ReplayButtonState.Left2;
|
2017-03-24 13:24:10 +08:00
|
|
|
else
|
2018-02-21 22:05:51 +08:00
|
|
|
button = hitButton ? ReplayButtonState.Left1 : ReplayButtonState.Left2;
|
2017-03-24 13:24:10 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-03-29 09:59:35 +08:00
|
|
|
if (h.IsStrong)
|
2018-02-21 22:05:51 +08:00
|
|
|
button = ReplayButtonState.Right1 | ReplayButtonState.Right2;
|
2017-03-24 13:24:10 +08:00
|
|
|
else
|
2018-02-21 22:05:51 +08:00
|
|
|
button = hitButton ? ReplayButtonState.Right1 : ReplayButtonState.Right2;
|
2017-03-24 13:24:10 +08:00
|
|
|
}
|
|
|
|
|
2018-01-25 20:37:38 +08:00
|
|
|
Frames.Add(new TaikoReplayFrame(h.StartTime, button));
|
2017-03-24 13:24:10 +08:00
|
|
|
}
|
2017-03-29 15:20:54 +08:00
|
|
|
else
|
2017-05-07 00:38:17 +08:00
|
|
|
throw new InvalidOperationException("Unknown hit object type.");
|
2017-03-24 13:24:10 +08:00
|
|
|
|
2018-01-25 20:37:38 +08:00
|
|
|
Frames.Add(new TaikoReplayFrame(endTime + KEY_UP_DELAY, ReplayButtonState.None));
|
2017-03-24 13:24:10 +08:00
|
|
|
|
2017-04-29 02:08:48 +08:00
|
|
|
if (i < Beatmap.HitObjects.Count - 1)
|
2017-03-24 13:24:10 +08:00
|
|
|
{
|
2017-04-29 02:08:48 +08:00
|
|
|
double waitTime = Beatmap.HitObjects[i + 1].StartTime - 1000;
|
2017-03-24 13:24:10 +08:00
|
|
|
if (waitTime > endTime)
|
2018-01-25 20:37:38 +08:00
|
|
|
Frames.Add(new TaikoReplayFrame(waitTime, ReplayButtonState.None));
|
2017-03-24 13:24:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
hitButton = !hitButton;
|
|
|
|
}
|
2017-04-29 02:08:48 +08:00
|
|
|
|
|
|
|
return Replay;
|
2017-03-24 13:24:10 +08:00
|
|
|
}
|
|
|
|
}
|
2017-04-18 21:31:52 +08:00
|
|
|
}
|