osu/osu.Game.Rulesets.Mania/Scoring/ManiaScoreProcessor.cs

280 lines
9.4 KiB
C#
Raw Normal View History

// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
2017-05-26 10:56:50 +00:00
using System;
using System.Linq;
2017-05-26 10:56:50 +00:00
using osu.Game.Beatmaps;
using osu.Game.Rulesets.Judgements;
2017-04-18 07:05:58 +00:00
using osu.Game.Rulesets.Mania.Judgements;
using osu.Game.Rulesets.Mania.Objects;
2017-05-26 10:56:50 +00:00
using osu.Game.Rulesets.Objects.Drawables;
2017-04-18 07:05:58 +00:00
using osu.Game.Rulesets.Scoring;
using osu.Game.Rulesets.UI;
2017-04-18 07:05:58 +00:00
namespace osu.Game.Rulesets.Mania.Scoring
{
2017-05-03 03:44:19 +00:00
internal class ManiaScoreProcessor : ScoreProcessor<ManiaHitObject, ManiaJudgement>
{
2017-05-26 10:56:50 +00:00
/// <summary>
/// The maximum score achievable.
/// Does _not_ include bonus score - for bonus score see <see cref="bonusScore"/>.
/// </summary>
private const int max_score = 1000000;
/// <summary>
/// The amount of the score attributed to combo.
/// </summary>
private const double combo_portion_max = max_score * 0.2;
/// <summary>
/// The amount of the score attributed to accuracy.
/// </summary>
private const double accuracy_portion_max = max_score * 0.8;
2017-05-26 11:25:24 +00:00
/// <summary>
/// The factor used to determine relevance of combos.
/// </summary>
private const double combo_base = 4;
/// <summary>
/// The combo value at which hit objects result in the max score possible.
/// </summary>
private const int combo_relevance_cap = 400;
2017-05-26 11:42:03 +00:00
/// <summary>
/// The hit HP multiplier at OD = 0.
/// </summary>
private const double hp_multiplier_min = 0.75;
/// <summary>
/// The hit HP multiplier at OD = 0.
/// </summary>
private const double hp_multiplier_mid = 0.85;
/// <summary>
/// The hit HP multiplier at OD = 0.
/// </summary>
private const double hp_multiplier_max = 1;
/// <summary>
/// The default BAD hit HP increase.
/// </summary>
private const double hp_increase_bad = 0.005;
/// <summary>
/// The default OK hit HP increase.
/// </summary>
private const double hp_increase_ok = 0.010;
/// <summary>
/// The default GOOD hit HP increase.
/// </summary>
private const double hp_increase_good = 0.035;
/// <summary>
/// The default tick hit HP increase.
/// </summary>
private const double hp_increase_tick = 0.040;
/// <summary>
/// The default GREAT hit HP increase.
/// </summary>
private const double hp_increase_great = 0.055;
/// <summary>
/// The default PERFECT hit HP increase.
/// </summary>
private const double hp_increase_perfect = 0.065;
/// <summary>
/// The MISS HP multiplier at OD = 0.
/// </summary>
private const double hp_multiplier_miss_min = 0.5;
/// <summary>
/// The MISS HP multiplier at OD = 5.
/// </summary>
private const double hp_multiplier_miss_mid = 0.75;
/// <summary>
/// The MISS HP multiplier at OD = 10.
/// </summary>
private const double hp_multiplier_miss_max = 1;
/// <summary>
/// The default MISS HP increase.
/// </summary>
private const double hp_increase_miss = -0.125;
2017-05-29 02:42:43 +00:00
/// <summary>
/// The MISS HP multiplier. This is multiplied to the miss hp increase.
/// </summary>
private double hpMissMultiplier = 1;
/// <summary>
/// The HIT HP multiplier. This is multiplied to hit hp increases.
/// </summary>
private double hpMultiplier = 1;
2017-05-26 10:56:50 +00:00
/// <summary>
/// The cumulative combo portion of the score.
/// </summary>
private double comboScore => combo_portion_max * comboPortion / maxComboPortion;
/// <summary>
/// The cumulative accuracy portion of the score.
/// </summary>
private double accuracyScore => accuracy_portion_max * Math.Pow(Accuracy, 4) * totalHits / maxTotalHits;
/// <summary>
/// The cumulative bonus score.
/// This is added on top of <see cref="max_score"/>, thus the total score can exceed <see cref="max_score"/>.
/// </summary>
private double bonusScore;
2017-05-26 11:42:03 +00:00
/// <summary>
/// The <see cref="comboPortion"/> achieved by a perfect playthrough.
/// </summary>
2017-05-26 10:56:50 +00:00
private double maxComboPortion;
2017-05-26 11:42:03 +00:00
/// <summary>
/// The portion of the score dedicated to combo.
/// </summary>
2017-05-26 10:56:50 +00:00
private double comboPortion;
2017-05-26 11:42:03 +00:00
/// <summary>
/// The <see cref="totalHits"/> achieved by a perfect playthrough.
/// </summary>
2017-05-26 10:56:50 +00:00
private int maxTotalHits;
2017-05-26 11:42:03 +00:00
/// <summary>
/// The total hits.
/// </summary>
private int totalHits;
2017-05-26 11:26:26 +00:00
public ManiaScoreProcessor()
{
}
2017-08-09 04:28:29 +00:00
public ManiaScoreProcessor(RulesetContainer<ManiaHitObject, ManiaJudgement> rulesetContainer)
: base(rulesetContainer)
{
}
2017-05-26 10:56:50 +00:00
protected override void ComputeTargets(Beatmap<ManiaHitObject> beatmap)
{
2017-05-26 11:42:03 +00:00
BeatmapDifficulty difficulty = beatmap.BeatmapInfo.Difficulty;
hpMultiplier = BeatmapDifficulty.DifficultyRange(difficulty.DrainRate, hp_multiplier_min, hp_multiplier_mid, hp_multiplier_max);
hpMissMultiplier = BeatmapDifficulty.DifficultyRange(difficulty.DrainRate, hp_multiplier_miss_min, hp_multiplier_miss_mid, hp_multiplier_miss_max);
2017-05-26 11:26:26 +00:00
while (true)
2017-05-26 10:56:50 +00:00
{
2017-05-26 11:26:26 +00:00
foreach (var obj in beatmap.HitObjects)
2017-05-26 10:56:50 +00:00
{
var holdNote = obj as HoldNote;
2017-05-26 11:26:26 +00:00
if (obj is Note)
2017-05-26 10:56:50 +00:00
{
2017-09-05 10:44:59 +00:00
AddJudgement(new ManiaJudgement { Result = HitResult.Perfect });
2017-05-26 11:26:26 +00:00
}
else if (holdNote != null)
2017-05-26 10:56:50 +00:00
{
2017-05-26 11:26:26 +00:00
// Head
2017-09-05 10:44:59 +00:00
AddJudgement(new ManiaJudgement { Result = HitResult.Perfect });
2017-05-26 10:56:50 +00:00
2017-05-26 11:26:26 +00:00
// Ticks
int tickCount = holdNote.Ticks.Count();
for (int i = 0; i < tickCount; i++)
2017-09-05 10:44:59 +00:00
AddJudgement(new HoldNoteTickJudgement { Result = HitResult.Perfect });
AddJudgement(new HoldNoteTailJudgement { Result = HitResult.Perfect });
2017-05-26 10:56:50 +00:00
}
}
2017-05-26 11:26:26 +00:00
if (!HasFailed)
break;
hpMultiplier *= 1.01;
hpMissMultiplier *= 0.98;
Reset();
2017-05-26 10:56:50 +00:00
}
maxTotalHits = totalHits;
maxComboPortion = comboPortion;
}
protected override void OnNewJudgement(Judgement judgement)
{
2017-05-26 10:56:50 +00:00
bool isTick = judgement is HoldNoteTickJudgement;
2017-09-05 10:44:59 +00:00
if (isTick)
{
if (judgement.IsHit)
{
Health.Value += hpMultiplier * hp_increase_tick;
bonusScore += judgement.NumericResult;
}
}
else
{
2017-05-26 10:56:50 +00:00
totalHits++;
2017-09-05 10:44:59 +00:00
switch (judgement.Result)
{
case HitResult.Miss:
Health.Value += hpMissMultiplier * hp_increase_miss;
break;
case HitResult.Meh:
Health.Value += hpMultiplier * hp_increase_bad;
break;
case HitResult.Ok:
Health.Value += hpMultiplier * hp_increase_ok;
break;
case HitResult.Good:
Health.Value += hpMultiplier * hp_increase_good;
break;
case HitResult.Great:
Health.Value += hpMultiplier * hp_increase_great;
break;
case HitResult.Perfect:
Health.Value += hpMultiplier * hp_increase_perfect;
break;
}
if (judgement.IsHit)
{
// A factor that is applied to make higher combos more relevant
double comboRelevance = Math.Min(Math.Max(0.5, Math.Log(Combo.Value, combo_base)), Math.Log(combo_relevance_cap, combo_base));
comboPortion += judgement.NumericResult * comboRelevance;
}
2017-05-26 10:56:50 +00:00
}
int scoreForAccuracy = 0;
int maxScoreForAccuracy = 0;
foreach (var j in Judgements)
{
var maniaJudgement = (ManiaJudgement)j;
scoreForAccuracy += maniaJudgement.NumericAccuracyResult;
maxScoreForAccuracy += maniaJudgement.MaxNumericAccuracyResult;
2017-05-26 10:56:50 +00:00
}
Accuracy.Value = (double)scoreForAccuracy / maxScoreForAccuracy;
TotalScore.Value = comboScore + accuracyScore + bonusScore;
}
2017-05-22 06:28:51 +00:00
protected override void Reset()
{
base.Reset();
Health.Value = 1;
2017-05-26 11:26:06 +00:00
bonusScore = 0;
comboPortion = 0;
totalHits = 0;
2017-05-22 06:28:51 +00:00
}
}
}