1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 10:52:53 +08:00
osu-lazer/osu.Game.Rulesets.Osu/Difficulty/OsuLegacyScoreSimulator.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

178 lines
6.5 KiB
C#
Raw Normal View History

2023-06-12 22:05:09 +08:00
// 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.
using System;
using System.Collections.Generic;
using System.Linq;
using osu.Game.Beatmaps;
2023-06-19 20:38:13 +08:00
using osu.Game.Rulesets.Judgements;
2023-06-12 22:05:09 +08:00
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Types;
using osu.Game.Rulesets.Osu.Objects;
2023-06-19 20:38:13 +08:00
using osu.Game.Rulesets.Scoring;
2023-06-12 22:05:09 +08:00
namespace osu.Game.Rulesets.Osu.Difficulty
{
internal class OsuLegacyScoreSimulator : ILegacyScoreSimulator
2023-06-12 22:05:09 +08:00
{
2023-06-19 20:38:13 +08:00
public int AccuracyScore { get; private set; }
2023-06-12 22:05:09 +08:00
2023-06-19 20:38:13 +08:00
public int ComboScore { get; private set; }
2023-06-12 22:05:09 +08:00
2023-06-19 20:38:13 +08:00
public double BonusScoreRatio => legacyBonusScore == 0 ? 0 : (double)modernBonusScore / legacyBonusScore;
2023-06-12 22:05:09 +08:00
2023-06-19 20:38:13 +08:00
private int legacyBonusScore;
private int modernBonusScore;
2023-06-12 22:05:09 +08:00
private int combo;
2023-06-26 21:19:01 +08:00
private double scoreMultiplier;
private IBeatmap playableBeatmap = null!;
2023-06-12 22:05:09 +08:00
2023-06-26 21:19:01 +08:00
public void Simulate(IWorkingBeatmap workingBeatmap, IBeatmap playableBeatmap, IReadOnlyList<Mod> mods)
2023-06-12 22:05:09 +08:00
{
this.playableBeatmap = playableBeatmap;
2023-06-26 21:19:01 +08:00
IBeatmap baseBeatmap = workingBeatmap.Beatmap;
2023-06-12 22:05:09 +08:00
int countNormal = 0;
int countSlider = 0;
int countSpinner = 0;
2023-06-26 21:19:01 +08:00
foreach (HitObject obj in workingBeatmap.Beatmap.HitObjects)
2023-06-12 22:05:09 +08:00
{
switch (obj)
{
case IHasPath:
countSlider++;
break;
case IHasDuration:
countSpinner++;
break;
default:
countNormal++;
break;
}
}
int objectCount = countNormal + countSlider + countSpinner;
int drainLength = 0;
if (baseBeatmap.HitObjects.Count > 0)
{
int breakLength = baseBeatmap.Breaks.Select(b => (int)Math.Round(b.EndTime) - (int)Math.Round(b.StartTime)).Sum();
drainLength = ((int)Math.Round(baseBeatmap.HitObjects[^1].StartTime) - (int)Math.Round(baseBeatmap.HitObjects[0].StartTime) - breakLength) / 1000;
}
2023-06-12 22:05:09 +08:00
int difficultyPeppyStars = (int)Math.Round(
(baseBeatmap.Difficulty.DrainRate
+ baseBeatmap.Difficulty.OverallDifficulty
+ baseBeatmap.Difficulty.CircleSize
+ Math.Clamp((float)objectCount / drainLength * 8, 0, 16)) / 38 * 5);
2023-06-12 22:05:09 +08:00
scoreMultiplier = difficultyPeppyStars * mods.Aggregate(1.0, (current, mod) => current * mod.ScoreMultiplier);
foreach (var obj in playableBeatmap.HitObjects)
simulateHit(obj);
}
private void simulateHit(HitObject hitObject)
{
bool increaseCombo = true;
bool addScoreComboMultiplier = false;
2023-06-19 20:38:13 +08:00
2023-06-12 22:05:09 +08:00
bool isBonus = false;
2023-06-19 20:38:13 +08:00
HitResult bonusResult = HitResult.None;
2023-06-12 22:05:09 +08:00
int scoreIncrease = 0;
switch (hitObject)
{
case SliderHeadCircle:
case SliderTailCircle:
case SliderRepeat:
scoreIncrease = 30;
break;
case SliderTick:
scoreIncrease = 10;
break;
case SpinnerBonusTick:
scoreIncrease = 1100;
increaseCombo = false;
isBonus = true;
2023-06-19 20:38:13 +08:00
bonusResult = HitResult.LargeBonus;
2023-06-12 22:05:09 +08:00
break;
case SpinnerTick:
scoreIncrease = 100;
increaseCombo = false;
isBonus = true;
2023-06-19 20:38:13 +08:00
bonusResult = HitResult.SmallBonus;
2023-06-12 22:05:09 +08:00
break;
case HitCircle:
scoreIncrease = 300;
addScoreComboMultiplier = true;
break;
case Slider:
foreach (var nested in hitObject.NestedHitObjects)
simulateHit(nested);
scoreIncrease = 300;
increaseCombo = false;
addScoreComboMultiplier = true;
break;
case Spinner spinner:
// The spinner object applies a lenience because gameplay mechanics differ from osu-stable.
// We'll redo the calculations to match osu-stable here...
const double maximum_rotations_per_second = 477.0 / 60;
double minimumRotationsPerSecond = IBeatmapDifficultyInfo.DifficultyRange(playableBeatmap.Difficulty.OverallDifficulty, 3, 5, 7.5);
double secondsDuration = spinner.Duration / 1000;
// The total amount of half spins possible for the entire spinner.
int totalHalfSpinsPossible = (int)(secondsDuration * maximum_rotations_per_second * 2);
// The amount of half spins that are required to successfully complete the spinner (i.e. get a 300).
int halfSpinsRequiredForCompletion = (int)(secondsDuration * minimumRotationsPerSecond);
// To be able to receive bonus points, the spinner must be rotated another 1.5 times.
int halfSpinsRequiredBeforeBonus = halfSpinsRequiredForCompletion + 3;
for (int i = 0; i <= totalHalfSpinsPossible; i++)
{
if (i > halfSpinsRequiredBeforeBonus && (i - halfSpinsRequiredBeforeBonus) % 2 == 0)
simulateHit(new SpinnerBonusTick());
else if (i > 1 && i % 2 == 0)
simulateHit(new SpinnerTick());
}
scoreIncrease = 300;
addScoreComboMultiplier = true;
break;
}
if (addScoreComboMultiplier)
{
// ReSharper disable once PossibleLossOfFraction (intentional to match osu-stable...)
ComboScore += (int)(Math.Max(0, combo - 1) * (scoreIncrease / 25 * scoreMultiplier));
}
if (isBonus)
2023-06-19 20:38:13 +08:00
{
legacyBonusScore += scoreIncrease;
modernBonusScore += Judgement.ToNumericResult(bonusResult);
}
2023-06-12 22:05:09 +08:00
else
2023-06-19 20:38:13 +08:00
AccuracyScore += scoreIncrease;
2023-06-12 22:05:09 +08:00
if (increaseCombo)
combo++;
}
}
}