mirror of
https://github.com/ppy/osu
synced 2024-12-28 09:52:56 +00:00
Merge pull request #18626 from ggliv/decouple-mod-fails
Allow ModFailCondition to arbitrarily trigger failures
This commit is contained in:
commit
61b62b35f5
@ -20,11 +20,31 @@ namespace osu.Game.Rulesets.Mods
|
||||
|
||||
public virtual bool RestartOnFail => Restart.Value;
|
||||
|
||||
private Action? triggerFailureDelegate;
|
||||
|
||||
public void ApplyToHealthProcessor(HealthProcessor healthProcessor)
|
||||
{
|
||||
triggerFailureDelegate = healthProcessor.TriggerFailure;
|
||||
healthProcessor.FailConditions += FailCondition;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Immediately triggers a failure on the loaded <see cref="HealthProcessor"/>.
|
||||
/// </summary>
|
||||
protected void TriggerFailure() => triggerFailureDelegate?.Invoke();
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether <paramref name="result"/> should trigger a failure. Called every time a
|
||||
/// judgement is applied to <paramref name="healthProcessor"/>.
|
||||
/// </summary>
|
||||
/// <param name="healthProcessor">The loaded <see cref="HealthProcessor"/>.</param>
|
||||
/// <param name="result">The latest <see cref="JudgementResult"/>.</param>
|
||||
/// <returns>Whether the fail condition has been met.</returns>
|
||||
/// <remarks>
|
||||
/// This method should only be used to trigger failures based on <paramref name="result"/>.
|
||||
/// Using outside values to evaluate failure may introduce event ordering discrepancies, use
|
||||
/// an <see cref="IApplicableMod"/> with <see cref="TriggerFailure"/> instead.
|
||||
/// </remarks>
|
||||
protected abstract bool FailCondition(HealthProcessor healthProcessor, JudgementResult result);
|
||||
}
|
||||
}
|
||||
|
@ -31,6 +31,15 @@ namespace osu.Game.Rulesets.Scoring
|
||||
/// </summary>
|
||||
public bool HasFailed { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Immediately triggers a failure for this HealthProcessor.
|
||||
/// </summary>
|
||||
public void TriggerFailure()
|
||||
{
|
||||
if (Failed?.Invoke() != false)
|
||||
HasFailed = true;
|
||||
}
|
||||
|
||||
protected override void ApplyResultInternal(JudgementResult result)
|
||||
{
|
||||
result.HealthAtJudgement = Health.Value;
|
||||
@ -42,10 +51,7 @@ namespace osu.Game.Rulesets.Scoring
|
||||
Health.Value += GetHealthIncreaseFor(result);
|
||||
|
||||
if (meetsAnyFailCondition(result))
|
||||
{
|
||||
if (Failed?.Invoke() != false)
|
||||
HasFailed = true;
|
||||
}
|
||||
TriggerFailure();
|
||||
}
|
||||
|
||||
protected override void RevertResultInternal(JudgementResult result)
|
||||
|
Loading…
Reference in New Issue
Block a user