mirror of
https://github.com/ppy/osu.git
synced 2024-11-07 11:07:32 +08:00
allow modfailcondition to arbitrarily trigger fail
This commit is contained in:
parent
187086e4ec
commit
dc75d55f72
@ -19,12 +19,31 @@ namespace osu.Game.Rulesets.Mods
|
||||
public virtual bool PerformFail() => true;
|
||||
|
||||
public virtual bool RestartOnFail => Restart.Value;
|
||||
private HealthProcessor healthProcessorInternal;
|
||||
|
||||
public void ApplyToHealthProcessor(HealthProcessor healthProcessor)
|
||||
{
|
||||
healthProcessorInternal = healthProcessor;
|
||||
healthProcessor.FailConditions += FailCondition;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Immediately triggers a failure on the loaded <see cref="HealthProcessor"/>.
|
||||
/// </summary>
|
||||
protected void TriggerArbitraryFailure() => healthProcessorInternal.TriggerFailure();
|
||||
|
||||
/// <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="TriggerArbitraryFailure"/> instead.
|
||||
/// </remarks>
|
||||
protected abstract bool FailCondition(HealthProcessor healthProcessor, JudgementResult result);
|
||||
}
|
||||
}
|
||||
|
@ -33,6 +33,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;
|
||||
@ -44,10 +53,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