osu/osu.Game/Modes/ScoreProcesssor.cs

81 lines
2.8 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
2016-11-29 11:30:16 +00:00
using System;
using System.Collections.Generic;
using osu.Framework.Configuration;
using osu.Game.Modes.Objects.Drawables;
2016-11-29 11:30:16 +00:00
namespace osu.Game.Modes
{
public abstract class ScoreProcessor
2016-11-29 11:30:16 +00:00
{
2016-11-29 14:59:56 +00:00
public virtual Score GetScore() => new Score()
{
TotalScore = TotalScore,
Combo = Combo,
MaxCombo = HighestCombo,
2017-01-10 08:01:53 +00:00
Accuracy = Accuracy,
Health = Health,
2016-11-29 14:59:56 +00:00
};
public readonly BindableDouble TotalScore = new BindableDouble { MinValue = 0 };
public readonly BindableDouble Accuracy = new BindableDouble { MinValue = 0, MaxValue = 1 };
2017-01-10 08:01:53 +00:00
public readonly BindableDouble Health = new BindableDouble { MinValue = 0, MaxValue = 1 };
public readonly BindableInt Combo = new BindableInt();
2017-01-20 07:51:43 +00:00
/// <summary>
/// Are we allowed to fail?
/// </summary>
protected bool CanFail => true;
2017-01-24 10:04:42 +00:00
protected bool HasFailed { get; private set; }
2017-01-20 07:51:43 +00: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>
2016-11-29 13:05:21 +00:00
public readonly BindableInt HighestCombo = new BindableInt();
2016-11-29 12:57:53 +00:00
public readonly List<JudgementInfo> Judgements;
2017-01-18 15:51:38 +00: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>
public ScoreProcessor(int hitObjectCount = 0)
{
2016-11-29 13:05:21 +00:00
Combo.ValueChanged += delegate { HighestCombo.Value = Math.Max(HighestCombo.Value, Combo.Value); };
2017-01-18 15:51:38 +00:00
Judgements = new List<JudgementInfo>(hitObjectCount);
}
public void AddJudgement(JudgementInfo judgement)
{
Judgements.Add(judgement);
2016-11-29 12:46:30 +00:00
UpdateCalculations(judgement);
2016-11-29 12:57:53 +00:00
judgement.ComboAtHit = (ulong)Combo.Value;
2017-01-20 07:51:43 +00:00
if (Health.Value == Health.MinValue && !HasFailed)
{
HasFailed = true;
Failed?.Invoke();
}
}
/// <summary>
/// Update any values that potentially need post-processing on a judgement change.
/// </summary>
/// <param name="newJudgement">A new JudgementInfo that triggered this calculation. May be null.</param>
protected abstract void UpdateCalculations(JudgementInfo newJudgement);
2016-11-29 11:30:16 +00:00
}
}