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;
|
|
|
|
|
using osu.Game.Modes.Objects.Drawables;
|
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;
|
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-07 09:59:19 +08:00
|
|
|
|
public virtual Score GetScore() => new Score
|
2016-11-29 22:59:56 +08:00
|
|
|
|
{
|
|
|
|
|
TotalScore = TotalScore,
|
|
|
|
|
Combo = Combo,
|
|
|
|
|
MaxCombo = HighestCombo,
|
2017-01-10 16:01:53 +08:00
|
|
|
|
Accuracy = Accuracy,
|
|
|
|
|
Health = Health,
|
2016-11-29 22:59:56 +08:00
|
|
|
|
};
|
2016-11-29 20:28:43 +08:00
|
|
|
|
|
2016-11-29 21:02:37 +08:00
|
|
|
|
public readonly BindableDouble TotalScore = new BindableDouble { MinValue = 0 };
|
2016-11-29 20:28:43 +08:00
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
public readonly BindableDouble Health = new BindableDouble { MinValue = 0, MaxValue = 1 };
|
2016-11-29 20:28:43 +08:00
|
|
|
|
|
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>
|
|
|
|
|
/// Are we allowed to fail?
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected bool CanFail => true;
|
|
|
|
|
|
2017-01-24 18:04:42 +08:00
|
|
|
|
protected bool HasFailed { get; private set; }
|
2017-01-20 15:51:43 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Called when we reach a failing health of zero.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public event Action Failed;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Keeps track of the highest combo ever achieved in this play.
|
|
|
|
|
/// This is handled automatically by ScoreProcessor.
|
|
|
|
|
/// </summary>
|
2017-03-10 15:05:05 +08:00
|
|
|
|
public readonly BindableInt HighestCombo = new BindableInt();
|
2016-11-29 20:57:53 +08:00
|
|
|
|
|
2017-01-17 04:14:35 +08:00
|
|
|
|
public readonly List<JudgementInfo> Judgements;
|
2016-11-29 20:28:43 +08:00
|
|
|
|
|
2017-01-18 23:51:38 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Initializes a new instance of the <see cref="ScoreProcessor"/> class.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="hitObjectCount">Number of HitObjects. It is used for specifying Judgements collection Capacity</param>
|
2017-03-07 09:59:19 +08:00
|
|
|
|
protected ScoreProcessor(int hitObjectCount = 0)
|
2016-11-29 21:02:37 +08:00
|
|
|
|
{
|
2016-11-29 21:05:21 +08:00
|
|
|
|
Combo.ValueChanged += delegate { HighestCombo.Value = Math.Max(HighestCombo.Value, Combo.Value); };
|
2017-01-18 23:51:38 +08:00
|
|
|
|
Judgements = new List<JudgementInfo>(hitObjectCount);
|
2016-11-29 21:02:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void AddJudgement(JudgementInfo judgement)
|
2016-11-29 20:28:43 +08:00
|
|
|
|
{
|
|
|
|
|
Judgements.Add(judgement);
|
2016-11-29 20:46:30 +08:00
|
|
|
|
|
2016-11-29 21:02:37 +08:00
|
|
|
|
UpdateCalculations(judgement);
|
2016-11-29 20:57:53 +08:00
|
|
|
|
|
2016-11-29 21:02:37 +08:00
|
|
|
|
judgement.ComboAtHit = (ulong)Combo.Value;
|
2017-01-20 15:51:43 +08:00
|
|
|
|
if (Health.Value == Health.MinValue && !HasFailed)
|
|
|
|
|
{
|
|
|
|
|
HasFailed = true;
|
|
|
|
|
Failed?.Invoke();
|
|
|
|
|
}
|
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>
|
|
|
|
|
protected abstract void UpdateCalculations(JudgementInfo newJudgement);
|
2016-11-29 19:30:16 +08:00
|
|
|
|
}
|
|
|
|
|
}
|