Skip to content

Commit 91903d2

Browse files
authored
Merge pull request #212 from WilliamQiufeng/mine-fixes
Fix mines not handled properly in autoplay
2 parents 073a57a + bb50e8e commit 91903d2

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

Quaver.API/Replays/Replay.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,10 @@ public static Replay GeneratePerfectReplayKeys(Replay replay, Qua map)
378378
replay.Frames.Add(new ReplayFrame(item.Key, state));
379379
}
380380

381+
// Add ending frame w/ no press state. (+10000 just to be on the safe side.)
382+
// This ensures that mines are handled at the end of the map.
383+
replay.Frames.Add(new ReplayFrame(map.Length + 10000, 0));
384+
381385
return replay;
382386
}
383387

Quaver.API/Replays/Virtual/VirtualReplayPlayer.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,15 @@ public void PlayNextFrame()
153153
{
154154
var obj = Map.GetHitObjectAtJudgementIndex(i);
155155

156-
var hitStat = new HitStat(HitStatType.Miss, KeyPressType.None, obj, obj.StartTime,
157-
Judgement.Miss, int.MinValue, ScoreProcessor.Accuracy, ScoreProcessor.Health);
156+
var hitStat = obj.Type switch
157+
{
158+
HitObjectType.Normal => new HitStat(HitStatType.Miss, KeyPressType.None, obj, obj.StartTime,
159+
Judgement.Miss, int.MinValue, ScoreProcessor.Accuracy, ScoreProcessor.Health),
160+
HitObjectType.Mine => new HitStat(HitStatType.Hit, KeyPressType.None, obj, obj.StartTime,
161+
Judgement.Marv, 0, ScoreProcessor.Accuracy, ScoreProcessor.Health),
162+
_ => throw new ArgumentOutOfRangeException(nameof(obj.Type), obj.Type,
163+
"Unhandled note type")
164+
};
158165

159166
ScoreProcessor.CalculateScore(hitStat);
160167

@@ -230,6 +237,8 @@ private void HandleKeyPressesInFrame()
230237
// Handle mines that were hit between frames.
231238
// The previous frame's pressed keys are held up until now, so [previousFrameTime..Time)
232239
// is the interval to check for mine hits.
240+
// This covers the last frame too! see ReplayCapturer.Capture: it adds a frame if judgement count
241+
// does not match expected, forcing another call into this.
233242
foreach (var lane in previousFramePressed)
234243
{
235244
foreach (var mine in ActiveMines)

0 commit comments

Comments
 (0)