// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using System; using osu.Framework.Bindables; using osu.Game.Configuration; using osu.Game.Rulesets.Judgements; using osu.Game.Rulesets.Scoring; namespace osu.Game.Rulesets.Mods { public abstract class ModFailCondition : Mod, IApplicableToHealthProcessor, IApplicableFailOverride { public override Type[] IncompatibleMods => new[] { typeof(ModNoFail), typeof(ModRelax), typeof(ModAutoplay) }; [SettingSource("Restart on fail", "Automatically restarts when failed.")] public BindableBool Restart { get; } = new BindableBool(); public virtual bool PerformFail() => true; public virtual bool RestartOnFail => Restart.Value; private event Action failureTriggered; public void ApplyToHealthProcessor(HealthProcessor healthProcessor) { failureTriggered = healthProcessor.TriggerFailure; healthProcessor.FailConditions += FailCondition; } /// /// Immediately triggers a failure on the loaded . /// protected void TriggerFailure() => failureTriggered?.Invoke(); /// /// Determines whether should trigger a failure. Called every time a /// judgement is applied to . /// /// The loaded . /// The latest . /// Whether the fail condition has been met. /// /// This method should only be used to trigger failures based on . /// Using outside values to evaluate failure may introduce event ordering discrepancies, use /// an with instead. /// protected abstract bool FailCondition(HealthProcessor healthProcessor, JudgementResult result); } }