2017-02-07 12:59:30 +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
|
2016-11-29 19:30:16 +08:00
|
|
|
|
|
2016-11-29 20:28:43 +08:00
|
|
|
|
using osu.Framework.Configuration;
|
2017-03-10 11:55:10 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2017-03-15 15:07:40 +08:00
|
|
|
|
using osu.Game.Modes.Judgements;
|
2017-03-16 11:40:35 +08:00
|
|
|
|
using osu.Game.Modes.UI;
|
|
|
|
|
using osu.Game.Modes.Objects;
|
2017-03-16 13:54:39 +08:00
|
|
|
|
using osu.Game.Beatmaps;
|
2016-11-29 19:30:16 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Modes
|
|
|
|
|
{
|
2016-11-29 21:02:37 +08:00
|
|
|
|
public abstract class ScoreProcessor
|
2016-11-29 19:30:16 +08:00
|
|
|
|
{
|
2017-03-16 12:39:57 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Invoked when the score is in a failing state.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public event Action Failed;
|
2016-11-29 20:28:43 +08:00
|
|
|
|
|
2017-03-16 12:39:57 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The current total score.
|
|
|
|
|
/// </summary>
|
2016-11-29 21:02:37 +08:00
|
|
|
|
public readonly BindableDouble TotalScore = new BindableDouble { MinValue = 0 };
|
2016-11-29 20:28:43 +08:00
|
|
|
|
|
2017-03-16 12:39:57 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The current accuracy.
|
|
|
|
|
/// </summary>
|
2016-11-29 21:02:37 +08:00
|
|
|
|
public readonly BindableDouble Accuracy = new BindableDouble { MinValue = 0, MaxValue = 1 };
|
2017-01-10 16:01:53 +08:00
|
|
|
|
|
2017-03-16 12:39:57 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The current health.
|
|
|
|
|
/// </summary>
|
2017-01-10 16:01:53 +08:00
|
|
|
|
public readonly BindableDouble Health = new BindableDouble { MinValue = 0, MaxValue = 1 };
|
2016-11-29 20:28:43 +08:00
|
|
|
|
|
2017-03-16 12:39:57 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The current combo.
|
|
|
|
|
/// </summary>
|
2017-03-10 15:05:05 +08:00
|
|
|
|
public readonly BindableInt Combo = new BindableInt();
|
2016-11-29 20:28:43 +08:00
|
|
|
|
|
2017-01-20 15:51:43 +08:00
|
|
|
|
/// <summary>
|
2017-03-16 12:39:57 +08:00
|
|
|
|
/// THe highest combo achieved by this score.
|
2017-01-20 15:51:43 +08:00
|
|
|
|
/// </summary>
|
2017-03-16 11:40:35 +08:00
|
|
|
|
public readonly BindableInt HighestCombo = new BindableInt();
|
2017-01-20 15:51:43 +08:00
|
|
|
|
|
2017-03-16 13:54:39 +08:00
|
|
|
|
protected ScoreProcessor()
|
|
|
|
|
{
|
|
|
|
|
Combo.ValueChanged += delegate { HighestCombo.Value = Math.Max(HighestCombo.Value, Combo.Value); };
|
|
|
|
|
|
|
|
|
|
Reset();
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-16 12:39:57 +08:00
|
|
|
|
public virtual Score GetScore() => new Score
|
|
|
|
|
{
|
|
|
|
|
TotalScore = TotalScore,
|
|
|
|
|
Combo = Combo,
|
|
|
|
|
MaxCombo = HighestCombo,
|
|
|
|
|
Accuracy = Accuracy,
|
|
|
|
|
Health = Health,
|
|
|
|
|
};
|
|
|
|
|
|
2017-01-20 15:51:43 +08:00
|
|
|
|
/// <summary>
|
2017-03-16 13:54:39 +08:00
|
|
|
|
/// Resets this ScoreProcessor to a stale state.
|
2017-01-20 15:51:43 +08:00
|
|
|
|
/// </summary>
|
2017-03-16 13:54:39 +08:00
|
|
|
|
protected virtual void Reset()
|
|
|
|
|
{
|
|
|
|
|
TotalScore.Value = 0;
|
|
|
|
|
Accuracy.Value = 0;
|
|
|
|
|
Health.Value = 0;
|
|
|
|
|
Combo.Value = 0;
|
|
|
|
|
HighestCombo.Value = 0;
|
|
|
|
|
}
|
2017-01-20 15:51:43 +08:00
|
|
|
|
|
2017-03-16 11:57:50 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Notifies subscribers that the score is in a failed state.
|
|
|
|
|
/// </summary>
|
2017-03-16 11:40:35 +08:00
|
|
|
|
protected void TriggerFailed()
|
|
|
|
|
{
|
|
|
|
|
Failed?.Invoke();
|
|
|
|
|
}
|
2017-03-16 13:54:39 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Checks if the score is in a failing state.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>Whether the score is in a failing state.</returns>
|
|
|
|
|
public abstract bool CheckFailed();
|
2017-03-16 11:40:35 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public abstract class ScoreProcessor<TObject, TJudgement> : ScoreProcessor
|
|
|
|
|
where TObject : HitObject
|
|
|
|
|
where TJudgement : JudgementInfo
|
|
|
|
|
{
|
2017-01-20 15:51:43 +08:00
|
|
|
|
/// <summary>
|
2017-03-16 11:40:35 +08:00
|
|
|
|
/// All judgements held by this ScoreProcessor.
|
2017-01-20 15:51:43 +08:00
|
|
|
|
/// </summary>
|
2017-03-16 12:49:16 +08:00
|
|
|
|
protected readonly List<TJudgement> Judgements = new List<TJudgement>();
|
2016-11-29 20:57:53 +08:00
|
|
|
|
|
2017-03-16 11:40:35 +08:00
|
|
|
|
/// <summary>
|
2017-03-16 12:39:57 +08:00
|
|
|
|
/// Whether the score is in a failable state.
|
2017-03-16 11:40:35 +08:00
|
|
|
|
/// </summary>
|
2017-03-16 12:39:57 +08:00
|
|
|
|
protected virtual bool IsFailable => Health.Value == Health.MinValue;
|
2016-11-29 20:28:43 +08:00
|
|
|
|
|
2017-01-18 23:51:38 +08:00
|
|
|
|
/// <summary>
|
2017-03-16 12:39:57 +08:00
|
|
|
|
/// Whether this ScoreProcessor has already failed.
|
2017-01-18 23:51:38 +08:00
|
|
|
|
/// </summary>
|
2017-03-16 12:39:57 +08:00
|
|
|
|
private bool hasFailed;
|
2017-03-16 11:40:35 +08:00
|
|
|
|
|
2017-03-16 12:13:45 +08:00
|
|
|
|
protected ScoreProcessor()
|
2016-11-29 21:02:37 +08:00
|
|
|
|
{
|
2017-03-16 12:13:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected ScoreProcessor(HitRenderer<TObject, TJudgement> hitRenderer)
|
|
|
|
|
{
|
2017-03-16 12:49:16 +08:00
|
|
|
|
Judgements.Capacity = hitRenderer.Beatmap.HitObjects.Count;
|
2017-03-16 11:40:35 +08:00
|
|
|
|
hitRenderer.OnJudgement += addJudgement;
|
2016-11-29 21:02:37 +08:00
|
|
|
|
|
2017-03-16 13:54:39 +08:00
|
|
|
|
ComputeTargets(hitRenderer.Beatmap);
|
2017-03-16 12:39:57 +08:00
|
|
|
|
|
2017-03-16 13:54:39 +08:00
|
|
|
|
Reset();
|
2017-03-16 12:39:57 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override bool CheckFailed()
|
|
|
|
|
{
|
|
|
|
|
if (!hasFailed && IsFailable)
|
2017-01-20 15:51:43 +08:00
|
|
|
|
{
|
2017-03-16 12:39:57 +08:00
|
|
|
|
hasFailed = true;
|
2017-03-16 11:40:35 +08:00
|
|
|
|
TriggerFailed();
|
2017-01-20 15:51:43 +08:00
|
|
|
|
}
|
2017-03-16 12:39:57 +08:00
|
|
|
|
|
|
|
|
|
return hasFailed;
|
2016-11-29 20:28:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-16 12:13:45 +08:00
|
|
|
|
/// <summary>
|
2017-03-16 13:54:39 +08:00
|
|
|
|
/// Computes target scoring values for this ScoreProcessor. This is equivalent to performing an auto-play of the score to find the values.
|
2017-03-16 12:13:45 +08:00
|
|
|
|
/// </summary>
|
2017-03-16 13:54:39 +08:00
|
|
|
|
/// <param name="beatmap">The Beatmap containing the objects that will be judged by this ScoreProcessor.</param>
|
|
|
|
|
protected virtual void ComputeTargets(Beatmap<TObject> beatmap) { }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Adds a judgement to this ScoreProcessor.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="judgement">The judgement to add.</param>
|
|
|
|
|
private void addJudgement(TJudgement judgement)
|
|
|
|
|
{
|
|
|
|
|
Judgements.Add(judgement);
|
|
|
|
|
|
|
|
|
|
UpdateCalculations(judgement);
|
|
|
|
|
|
|
|
|
|
judgement.ComboAtHit = (ulong)Combo.Value;
|
|
|
|
|
|
|
|
|
|
CheckFailed();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Reset()
|
2017-03-16 12:39:57 +08:00
|
|
|
|
{
|
|
|
|
|
Judgements.Clear();
|
|
|
|
|
|
|
|
|
|
hasFailed = false;
|
|
|
|
|
}
|
2017-03-16 12:13:45 +08:00
|
|
|
|
|
2016-11-29 20:28:43 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Update any values that potentially need post-processing on a judgement change.
|
|
|
|
|
/// </summary>
|
2016-11-29 21:02:37 +08:00
|
|
|
|
/// <param name="newJudgement">A new JudgementInfo that triggered this calculation. May be null.</param>
|
2017-03-16 11:40:35 +08:00
|
|
|
|
protected abstract void UpdateCalculations(TJudgement newJudgement);
|
2016-11-29 19:30:16 +08:00
|
|
|
|
}
|
2017-03-16 13:54:39 +08:00
|
|
|
|
}
|