Implement Score Processor Mod Interface

- Add a delegate whenever we want to register an additional fail condition
This commit is contained in:
Brayzure
2017-11-20 02:15:29 -05:00
parent de4d8eb196
commit da30d76f9b
6 changed files with 74 additions and 28 deletions

View File

@ -3,6 +3,7 @@
using System;
using System.Diagnostics;
using System.Collections.Generic;
using osu.Framework.Configuration;
using osu.Game.Beatmaps;
using osu.Game.Rulesets.Judgements;
@ -31,6 +32,11 @@ namespace osu.Game.Rulesets.Scoring
/// </summary>
public event Action<Judgement> NewJudgement;
/// <summary>
/// Invoked when we want to check if a failure condition has been fulfilled
/// </summary>
public event Func<ScoreProcessor, bool> FailChecker;
/// <summary>
/// The current total score.
/// </summary>
@ -66,8 +72,6 @@ namespace osu.Game.Rulesets.Scoring
/// </summary>
protected virtual bool HasCompleted => false;
public int strictFail = 0;
/// <summary>
/// Whether this ScoreProcessor has already triggered the failed state.
/// </summary>
@ -78,16 +82,6 @@ namespace osu.Game.Rulesets.Scoring
/// </summary>
protected virtual bool FailCondition => Health.Value == Health.MinValue;
/// <summary>
/// The conditions for failing if the Sudden Death mod is enabled.
/// </summary>
protected virtual bool SuddenDeathFailCondition => Combo.Value != HighestCombo.Value;
/// <summary>
/// The conditions for failing if the Perfect mod is enabled.
/// </summary>
protected virtual bool PerfectFailCondition => Accuracy.Value != 1;
protected ScoreProcessor()
{
Combo.ValueChanged += delegate { HighestCombo.Value = Math.Max(HighestCombo.Value, Combo.Value); };
@ -133,16 +127,11 @@ namespace osu.Game.Rulesets.Scoring
/// </summary>
protected void UpdateFailed()
{
if (HasFailed)
if (HasFailed || !FailCondition)
return;
if(FailCondition ||
(strictFail==1 && SuddenDeathFailCondition) ||
(strictFail==2 && PerfectFailCondition))
{
if (Failed?.Invoke() != false)
HasFailed = true;
}
if (Failed?.Invoke() != false)
HasFailed = true;
}
/// <summary>
@ -157,6 +146,18 @@ namespace osu.Game.Rulesets.Scoring
AllJudged?.Invoke();
}
protected void CheckAlternateFailConditions()
{
if (HasFailed)
return;
if (FailChecker?.Invoke(this) == true)
{
if (Failed?.Invoke() != false)
HasFailed = true;
}
}
/// <summary>
/// Retrieve a score populated with data for the current play this processor is responsible for.
/// </summary>
@ -233,6 +234,8 @@ namespace osu.Game.Rulesets.Scoring
OnNewJudgement(judgement);
updateScore();
CheckAlternateFailConditions();
NotifyNewJudgement(judgement);
UpdateFailed();
}