2017-03-24 13:24:10 +08:00
|
|
|
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
2017-03-29 15:20:54 +08:00
|
|
|
|
using System;
|
2017-03-31 15:20:31 +08:00
|
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
|
using osu.Game.Modes.Objects.Types;
|
|
|
|
|
using osu.Game.Modes.Taiko.Objects;
|
|
|
|
|
using osu.Game.Modes.Replays;
|
2017-03-24 13:24:10 +08:00
|
|
|
|
|
2017-03-31 15:20:31 +08:00
|
|
|
|
namespace osu.Game.Modes.Taiko.Replays
|
2017-03-24 13:24:10 +08:00
|
|
|
|
{
|
2017-03-31 15:20:31 +08:00
|
|
|
|
public class TaikoAutoReplay : Replay
|
2017-03-24 13:24:10 +08:00
|
|
|
|
{
|
2017-03-29 10:04:16 +08:00
|
|
|
|
private readonly Beatmap<TaikoHitObject> beatmap;
|
2017-03-24 13:24:10 +08:00
|
|
|
|
|
2017-03-29 10:04:16 +08:00
|
|
|
|
public TaikoAutoReplay(Beatmap<TaikoHitObject> beatmap)
|
2017-03-24 13:24:10 +08:00
|
|
|
|
{
|
2017-03-29 10:04:16 +08:00
|
|
|
|
this.beatmap = beatmap;
|
2017-03-24 13:24:10 +08:00
|
|
|
|
|
|
|
|
|
createAutoReplay();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void createAutoReplay()
|
|
|
|
|
{
|
|
|
|
|
bool hitButton = true;
|
|
|
|
|
|
2017-03-31 15:20:31 +08:00
|
|
|
|
Frames.Add(new ReplayFrame(-100000, 320, 240, ReplayButtonState.None));
|
|
|
|
|
Frames.Add(new ReplayFrame(beatmap.HitObjects[0].StartTime - 1000, 320, 240, ReplayButtonState.None));
|
2017-03-24 13:24:10 +08:00
|
|
|
|
|
2017-03-29 10:04:16 +08:00
|
|
|
|
for (int i = 0; i < beatmap.HitObjects.Count; i++)
|
2017-03-24 13:24:10 +08:00
|
|
|
|
{
|
2017-03-29 10:04:16 +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;
|
|
|
|
|
double hitRate = swell.Duration / req;
|
2017-03-24 13:24:10 +08:00
|
|
|
|
for (double j = h.StartTime; j < endTime; j += hitRate)
|
|
|
|
|
{
|
|
|
|
|
switch (d)
|
|
|
|
|
{
|
|
|
|
|
default:
|
2017-03-31 15:20:31 +08:00
|
|
|
|
button = ReplayButtonState.Left1;
|
2017-03-24 13:24:10 +08:00
|
|
|
|
break;
|
|
|
|
|
case 1:
|
2017-03-31 15:20:31 +08:00
|
|
|
|
button = ReplayButtonState.Right1;
|
2017-03-24 13:24:10 +08:00
|
|
|
|
break;
|
|
|
|
|
case 2:
|
2017-03-31 15:20:31 +08:00
|
|
|
|
button = ReplayButtonState.Left2;
|
2017-03-24 13:24:10 +08:00
|
|
|
|
break;
|
|
|
|
|
case 3:
|
2017-03-31 15:20:31 +08:00
|
|
|
|
button = ReplayButtonState.Right2;
|
2017-03-24 13:24:10 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-31 15:20:31 +08:00
|
|
|
|
Frames.Add(new ReplayFrame(j, 0, 0, button));
|
2017-03-24 13:24:10 +08:00
|
|
|
|
d = (d + 1) % 4;
|
|
|
|
|
if (++count > req)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-03-29 15:20:54 +08:00
|
|
|
|
else if (drumRoll != null)
|
2017-03-24 13:24:10 +08:00
|
|
|
|
{
|
2017-04-03 14:32:38 +08:00
|
|
|
|
foreach (var tick in drumRoll.Ticks)
|
2017-03-24 13:24:10 +08:00
|
|
|
|
{
|
2017-04-03 14:32:38 +08:00
|
|
|
|
Frames.Add(new ReplayFrame(tick.StartTime, 0, 0, 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)
|
2017-03-31 15:20:31 +08:00
|
|
|
|
button = ReplayButtonState.Right1 | ReplayButtonState.Right2;
|
2017-03-24 13:24:10 +08:00
|
|
|
|
else
|
2017-03-31 15:20:31 +08:00
|
|
|
|
button = hitButton ? ReplayButtonState.Right1 : ReplayButtonState.Right2;
|
2017-03-24 13:24:10 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-03-29 09:59:35 +08:00
|
|
|
|
if (h.IsStrong)
|
2017-03-31 15:20:31 +08:00
|
|
|
|
button = ReplayButtonState.Left1 | ReplayButtonState.Left2;
|
2017-03-24 13:24:10 +08:00
|
|
|
|
else
|
2017-03-31 15:20:31 +08:00
|
|
|
|
button = hitButton ? ReplayButtonState.Left1 : ReplayButtonState.Left2;
|
2017-03-24 13:24:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-31 15:20:31 +08:00
|
|
|
|
Frames.Add(new ReplayFrame(h.StartTime, 0, 0, button));
|
2017-03-24 13:24:10 +08:00
|
|
|
|
}
|
2017-03-29 15:20:54 +08:00
|
|
|
|
else
|
|
|
|
|
throw new Exception("Unknown hit object type.");
|
2017-03-24 13:24:10 +08:00
|
|
|
|
|
2017-03-31 15:20:31 +08:00
|
|
|
|
Frames.Add(new ReplayFrame(endTime + 1, 0, 0, ReplayButtonState.None));
|
2017-03-24 13:24:10 +08:00
|
|
|
|
|
2017-03-29 10:04:16 +08:00
|
|
|
|
if (i < beatmap.HitObjects.Count - 1)
|
2017-03-24 13:24:10 +08:00
|
|
|
|
{
|
2017-03-29 10:04:16 +08:00
|
|
|
|
double waitTime = beatmap.HitObjects[i + 1].StartTime - 1000;
|
2017-03-24 13:24:10 +08:00
|
|
|
|
if (waitTime > endTime)
|
2017-03-31 15:20:31 +08:00
|
|
|
|
Frames.Add(new ReplayFrame(waitTime, 0, 0, ReplayButtonState.None));
|
2017-03-24 13:24:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hitButton = !hitButton;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|