1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-24 23:42:54 +08:00

Use IHasFailCondition in HealthProcessor

This commit is contained in:
Peter-io 2024-07-11 20:21:23 +02:00
parent 0a8d90953d
commit 4a473f4011

View File

@ -2,9 +2,12 @@
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System; using System;
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Utils; using osu.Framework.Utils;
using osu.Game.Rulesets.Judgements; using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Mods;
namespace osu.Game.Rulesets.Scoring namespace osu.Game.Rulesets.Scoring
{ {
@ -19,7 +22,7 @@ namespace osu.Game.Rulesets.Scoring
/// <summary> /// <summary>
/// Additional conditions on top of <see cref="CheckDefaultFailCondition"/> that cause a failing state. /// Additional conditions on top of <see cref="CheckDefaultFailCondition"/> that cause a failing state.
/// </summary> /// </summary>
public event Func<HealthProcessor, JudgementResult, bool>? FailConditions; public List<IHasFailCondition> FailConditions = new List<IHasFailCondition>();
/// <summary> /// <summary>
/// The current health. /// The current health.
@ -34,12 +37,12 @@ namespace osu.Game.Rulesets.Scoring
/// <summary> /// <summary>
/// Object that triggered fail /// Object that triggered fail
/// </summary> /// </summary>
public object? FailTrigger; public List<IHasFailCondition> FailTriggers = new List<IHasFailCondition>();
/// <summary> /// <summary>
/// Immediately triggers a failure for this HealthProcessor. /// Immediately triggers a failure for this HealthProcessor.
/// </summary> /// </summary>
public void TriggerFailure(object? Trigger = null) public void TriggerFailure(IHasFailCondition? Trigger = null)
{ {
if (HasFailed) if (HasFailed)
return; return;
@ -48,7 +51,7 @@ namespace osu.Game.Rulesets.Scoring
HasFailed = true; HasFailed = true;
if (Trigger != null) if (Trigger != null)
FailTrigger = Trigger; FailTriggers.Add(Trigger);
} }
protected override void ApplyResultInternal(JudgementResult result) protected override void ApplyResultInternal(JudgementResult result)
@ -94,17 +97,16 @@ namespace osu.Game.Rulesets.Scoring
if (CheckDefaultFailCondition(result)) if (CheckDefaultFailCondition(result))
return true; return true;
if (FailConditions != null) if (FailConditions.Any())
{ {
foreach (var condition in FailConditions.GetInvocationList()) foreach (var condition in FailConditions)
{ {
bool conditionResult = (bool)condition.Method.Invoke(condition.Target, new object[] { this, result })!; if (condition.FailCondition(result))
if (conditionResult) FailTriggers.Add(condition);
{
FailTrigger = condition.Target;
return true;
}
} }
if (FailTriggers.Any())
return true;
} }
return false; return false;