1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-16 03:42:58 +08:00
osu-lazer/osu.Game.Rulesets.Taiko/Replays/TaikoAutoGenerator.cs

158 lines
5.5 KiB
C#
Raw Normal View History

// 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-04-13 17:19:50 +08:00
using System;
using System.Collections.Generic;
using System.Linq;
using osu.Game.Beatmaps;
2018-11-28 16:20:37 +08:00
using osu.Game.Replays;
2018-04-13 17:19:50 +08:00
using osu.Game.Rulesets.Objects.Types;
using osu.Game.Rulesets.Taiko.Objects;
using osu.Game.Rulesets.Replays;
2019-03-07 17:30:31 +08:00
using osu.Game.Rulesets.Taiko.Beatmaps;
2019-08-19 22:18:25 +08:00
using osu.Game.Rulesets.Objects;
2018-04-13 17:19:50 +08:00
namespace osu.Game.Rulesets.Taiko.Replays
{
2019-03-07 17:30:31 +08:00
public class TaikoAutoGenerator : AutoGenerator
2018-04-13 17:19:50 +08:00
{
2019-03-07 17:30:31 +08:00
public new TaikoBeatmap Beatmap => (TaikoBeatmap)base.Beatmap;
2018-04-13 17:19:50 +08:00
private const double swell_hit_speed = 50;
2019-03-07 17:30:31 +08:00
public TaikoAutoGenerator(IBeatmap beatmap)
2018-04-13 17:19:50 +08:00
: base(beatmap)
{
2018-11-29 12:22:45 +08:00
Replay = new Replay();
2018-04-13 17:19:50 +08:00
}
protected Replay Replay;
protected List<ReplayFrame> Frames => Replay.Frames;
public override Replay Generate()
{
bool hitButton = true;
Frames.Add(new TaikoReplayFrame(-100000));
Frames.Add(new TaikoReplayFrame(Beatmap.HitObjects[0].StartTime - 1000));
for (int i = 0; i < Beatmap.HitObjects.Count; i++)
{
TaikoHitObject h = Beatmap.HitObjects[i];
IHasEndTime endTimeData = h as IHasEndTime;
double endTime = endTimeData?.EndTime ?? h.StartTime;
Swell swell = h as Swell;
DrumRoll drumRoll = h as DrumRoll;
Hit hit = h as Hit;
if (swell != null)
{
int d = 0;
int count = 0;
int req = swell.RequiredHits;
double hitRate = Math.Min(swell_hit_speed, swell.Duration / req);
2019-04-01 11:16:05 +08:00
2018-04-13 17:19:50 +08:00
for (double j = h.StartTime; j < endTime; j += hitRate)
{
TaikoAction action;
switch (d)
{
default:
case 0:
action = TaikoAction.LeftCentre;
break;
2019-04-01 11:16:05 +08:00
2018-04-13 17:19:50 +08:00
case 1:
action = TaikoAction.LeftRim;
break;
2019-04-01 11:16:05 +08:00
2018-04-13 17:19:50 +08:00
case 2:
action = TaikoAction.RightCentre;
break;
2019-04-01 11:16:05 +08:00
2018-04-13 17:19:50 +08:00
case 3:
action = TaikoAction.RightRim;
break;
}
Frames.Add(new TaikoReplayFrame(j, action));
d = (d + 1) % 4;
if (++count == req)
break;
}
}
else if (drumRoll != null)
{
foreach (var tick in drumRoll.NestedHitObjects.OfType<DrumRollTick>())
{
Frames.Add(new TaikoReplayFrame(tick.StartTime, hitButton ? TaikoAction.LeftCentre : TaikoAction.RightCentre));
hitButton = !hitButton;
}
}
else if (hit != null)
{
TaikoAction[] actions;
if (hit is CentreHit)
{
actions = h.IsStrong
? new[] { TaikoAction.LeftCentre, TaikoAction.RightCentre }
: new[] { hitButton ? TaikoAction.LeftCentre : TaikoAction.RightCentre };
}
else
{
actions = h.IsStrong
? new[] { TaikoAction.LeftRim, TaikoAction.RightRim }
: new[] { hitButton ? TaikoAction.LeftRim : TaikoAction.RightRim };
}
Frames.Add(new TaikoReplayFrame(h.StartTime, actions));
}
else
throw new InvalidOperationException("Unknown hit object type.");
2019-08-20 02:45:23 +08:00
var nextHitObject = GetNextObject(i); // Get the next object that requires pressing the same button
bool canDelayKeyUp = nextHitObject == null || nextHitObject.StartTime > endTime + KEY_UP_DELAY;
2019-08-19 23:05:25 +08:00
double calculatedDelay = canDelayKeyUp ? KEY_UP_DELAY : (nextHitObject.StartTime - endTime) * 0.9;
2019-08-15 03:05:24 +08:00
2019-08-19 22:18:25 +08:00
Frames.Add(new TaikoReplayFrame(endTime + calculatedDelay));
if (i < Beatmap.HitObjects.Count - 1)
2019-08-15 03:05:24 +08:00
{
2019-08-19 22:18:25 +08:00
double waitTime = Beatmap.HitObjects[i + 1].StartTime - 1000;
2018-04-13 17:19:50 +08:00
if (waitTime > endTime)
Frames.Add(new TaikoReplayFrame(waitTime));
}
hitButton = !hitButton;
}
return Replay;
}
2019-08-19 22:18:25 +08:00
protected override HitObject GetNextObject(int currentIndex)
{
2019-08-26 16:45:12 +08:00
Type desiredType = Beatmap.HitObjects[currentIndex].GetType();
2019-08-19 22:18:25 +08:00
2019-08-26 16:45:12 +08:00
for (int i = currentIndex + 1; i < Beatmap.HitObjects.Count; i++)
2019-08-19 22:18:25 +08:00
{
2019-08-26 16:45:12 +08:00
var currentObj = Beatmap.HitObjects[i];
2019-08-20 02:45:23 +08:00
if (currentObj.GetType() == desiredType ||
2019-08-26 16:45:12 +08:00
// Un-press all keys before a DrumRoll or Swell
currentObj is DrumRoll || currentObj is Swell)
{
return Beatmap.HitObjects[i];
}
2019-08-19 22:18:25 +08:00
}
return null;
}
2018-04-13 17:19:50 +08:00
}
}