public static bool Prefix(ref GameEnergyCounter __instance, float energyChange) { if (!(GMPUI.EndlessMode && Config.EndlessContinueOnFail)) { return(true); } GameObject endlessObj = GameObject.Find("GMP Endless Behavior"); if (endlessObj == null) { return(true); } if (energyChange > 0) { return(true); } EndlessBehavior endlessBehavior = endlessObj.GetComponent <EndlessBehavior>(); if (endlessBehavior.nextSong != null) { bool willFail = (__instance.energy + energyChange) <= 0; if (willFail && BS_Utils.Plugin.LevelData.IsSet && !BS_Utils.Plugin.LevelData.GameplayCoreSceneSetupData.gameplayModifiers.noFailOn0Energy) { __instance.ProcessEnergyChange(0.5f); endlessBehavior.SongEnd(); return(false); } } return(true); }
public IEnumerator ActivateOnlyAfterOnePass() { // Given a behaviors sequence, EndlessBehavior endlessBehavior = new EndlessBehavior(); BehaviorSequence sequence = new BehaviorSequence(true, new List <IBehavior> { endlessBehavior }); // When we activate it, sequence.LifeCycle.Activate(); yield return(null); sequence.Update(); // Then it is activated only after one pass. endlessBehavior.LifeCycle.MarkToFastForward(); yield return(null); sequence.Update(); yield return(null); sequence.Update(); Assert.AreEqual(Stage.Active, sequence.LifeCycle.Stage); // Cleanup. sequence.LifeCycle.Deactivate(); }
public IEnumerator NonBlockingBehaviorDoesNotBlock() { // Given a chapter with a step with no conditions but a transition to the end, and a non-blocking endless behavior, EndlessBehavior nonBlockingBehavior = new EndlessBehavior(false); ITransition transition = new Transition(); transition.Data.TargetStep = null; IStep step = new Step("NonBlockingStep"); step.Data.Transitions.Data.Transitions.Add(transition); step.Data.Behaviors.Data.Behaviors.Add(nonBlockingBehavior); IChapter chapter = new Chapter("NonBlockingChapter", step); chapter.Configure(RuntimeConfigurator.Configuration.GetCurrentMode()); // When we activate the chapter, chapter.LifeCycle.Activate(); // Then it will finish activation immediately after a few update cycles. while (chapter.LifeCycle.Stage != Stage.Active) { yield return(null); chapter.Update(); } Assert.AreEqual(Stage.Active, chapter.LifeCycle.Stage); }
public IEnumerator NonBlockingBehaviorLoop() { // Given a chapter with a step with a loop transition, and a non-blocking endless behavior, EndlessBehavior nonBlockingBehavior = new EndlessBehavior(false); ITransition transition = new Transition(); IStep step = new Step("NonBlockingStep"); transition.Data.TargetStep = step; step.Data.Transitions.Data.Transitions.Add(transition); step.Data.Behaviors.Data.Behaviors.Add(nonBlockingBehavior); IChapter chapter = new Chapter("NonBlockingChapter", step); chapter.Configure(RuntimeConfigurator.Configuration.GetCurrentMode()); // When we activate the chapter, chapter.LifeCycle.Activate(); // Then it will loop without any problems. int loops = 3; while (loops > 0) { while (step.LifeCycle.Stage != Stage.Activating) { yield return(null); chapter.Update(); } while (step.LifeCycle.Stage != Stage.Active) { yield return(null); chapter.Update(); } while (step.LifeCycle.Stage != Stage.Deactivating) { yield return(null); chapter.Update(); } while (step.LifeCycle.Stage != Stage.Inactive) { yield return(null); chapter.Update(); } Assert.AreEqual(Stage.Activating, chapter.LifeCycle.Stage); loops--; } Assert.AreEqual(Stage.Inactive, step.LifeCycle.Stage); }
public IEnumerator BlockingBehaviorDoesBlock() { // Given a chapter with a step with no conditions but a transition to the end, and a blocking endless behavior, EndlessBehavior blockingBehavior = new EndlessBehavior(true); ITransition transition = new Transition(); transition.Data.TargetStep = null; IStep step = new Step("BlockingStep"); step.Data.Transitions.Data.Transitions.Add(transition); step.Data.Behaviors.Data.Behaviors.Add(blockingBehavior); IChapter chapter = new Chapter("BlockingChapter", step); chapter.Configure(RuntimeConfigurator.Configuration.GetCurrentMode()); // When we activate the chapter, chapter.LifeCycle.Activate(); while (blockingBehavior.LifeCycle.Stage != Stage.Activating) { yield return(null); chapter.Update(); } // When endless behavior stays activating even after a few frames, int waitingFrames = 10; while (waitingFrames > 0) { yield return(null); chapter.Update(); Assert.AreEqual(Stage.Activating, blockingBehavior.LifeCycle.Stage); Assert.AreEqual(Stage.Activating, chapter.LifeCycle.Stage); waitingFrames--; } // Then the chapter will not be activated until the behavior finishes. blockingBehavior.LifeCycle.MarkToFastForward(); Assert.AreEqual(Stage.Activating, chapter.LifeCycle.Stage); while (chapter.LifeCycle.Stage != Stage.Active) { yield return(null); chapter.Update(); } Assert.AreEqual(Stage.Active, chapter.LifeCycle.Stage); }
public IEnumerator FastForwardInactiveNonBlockingBehavior() { // Given a non-blocking behavior, EndlessBehavior behavior = new EndlessBehavior(false); behavior.Configure(RuntimeConfigurator.Configuration.GetCurrentMode()); // When we mark it to fast-forward, behavior.LifeCycle.MarkToFastForward(); // Then it doesn't autocomplete because it hasn't been activated yet. Assert.AreEqual(Stage.Inactive, behavior.LifeCycle.Stage); yield break; }
public IEnumerator BlockingBehaviorActivating() { // Given a blocking behavior, EndlessBehavior behavior = new EndlessBehavior(true); behavior.Configure(RuntimeConfigurator.Configuration.GetCurrentMode()); // When we activate it, behavior.LifeCycle.Activate(); // Then it is immediately activating. Assert.AreEqual(Stage.Activating, behavior.LifeCycle.Stage); yield break; }
public IEnumerator NonBlockingBehaviorActivating() { // Given a non-blocking behavior, EndlessBehavior behavior = new EndlessBehavior(false); behavior.Configure(RuntimeConfigurator.Configuration.GetCurrentMode()); // When we activate it, behavior.LifeCycle.Activate(); // Then behavior starts its activation. Assert.AreEqual(Stage.Activating, behavior.LifeCycle.Stage); yield break; }
public IEnumerator FastForwardInactiveNonBlockingBehaviorAndActivateIt() { // Given a non-blocking behavior, EndlessBehavior behavior = new EndlessBehavior(false); behavior.Configure(RuntimeConfigurator.Configuration.GetCurrentMode()); // When we mark it to fast-forward and activate it, behavior.LifeCycle.MarkToFastForward(); behavior.LifeCycle.Activate(); // Then the behavior should be activated immediately. Assert.AreEqual(Stage.Active, behavior.LifeCycle.Stage); yield break; }
public IEnumerator UnskipChild() { // Given an activating repeating behavior sequence of one not optional and one skipped optional behavior, OptionalEndlessBehavior optional = new OptionalEndlessBehavior(); EndlessBehavior notOptional = new EndlessBehavior(); BehaviorSequence sequence = new BehaviorSequence(true, new List <IBehavior> { notOptional, optional, }); sequence.Configure(RuntimeConfigurator.Configuration.GetCurrentMode()); sequence.LifeCycle.Activate(); yield return(null); sequence.Update(); notOptional.LifeCycle.MarkToFastForwardStage(Stage.Activating); notOptional.LifeCycle.MarkToFastForwardStage(Stage.Deactivating); sequence.Configure(new Mode("Test", new WhitelistTypeRule <IOptional>().Add <OptionalEndlessBehavior>())); yield return(null); sequence.Update(); //When you re-enable it, sequence.Configure(RuntimeConfigurator.Configuration.GetCurrentMode()); notOptional.LifeCycle.MarkToFastForwardStage(Stage.Activating); notOptional.LifeCycle.MarkToFastForwardStage(Stage.Deactivating); while (optional.LifeCycle.Stage != Stage.Activating) { yield return(null); sequence.Update(); } // Then it is not skipped when it's its turn. Assert.AreEqual(Stage.Activating, optional.LifeCycle.Stage); }
public IEnumerator SkipChildNotWhenItIsExecuted() { // Given an activating behavior sequence of one not optional and one optional behavior, OptionalEndlessBehavior optional = new OptionalEndlessBehavior(); EndlessBehavior notOptional = new EndlessBehavior(); BehaviorSequence sequence = new BehaviorSequence(false, new List <IBehavior> { notOptional, optional, }); sequence.Configure(RuntimeConfigurator.Configuration.GetCurrentMode()); sequence.LifeCycle.Activate(); yield return(null); sequence.Update(); // When the optional behavior is marked to be skipped before it was its turn, sequence.Configure(new Mode("Test", new WhitelistTypeRule <IOptional>().Add <OptionalEndlessBehavior>())); notOptional.LifeCycle.MarkToFastForwardStage(Stage.Activating); notOptional.LifeCycle.MarkToFastForwardStage(Stage.Deactivating); while (notOptional.LifeCycle.Stage != Stage.Inactive) { yield return(null); sequence.Update(); } while (sequence.LifeCycle.Stage != Stage.Active) { Assert.AreEqual(Stage.Inactive, optional.LifeCycle.Stage); yield return(null); sequence.Update(); } // Then it is skipped. Assert.AreEqual(Stage.Active, sequence.LifeCycle.Stage); yield break; }
public IEnumerator NonBlockingBehaviorActivated() { // Given a non-blocking behavior, EndlessBehavior behavior = new EndlessBehavior(false); behavior.Configure(RuntimeConfigurator.Configuration.GetCurrentMode()); // When we activate and finish activation, behavior.LifeCycle.Activate(); behavior.LifeCycle.MarkToFastForward(); yield return(null); behavior.Update(); yield return(null); behavior.Update(); // Then it is activated. Assert.AreEqual(Stage.Active, behavior.LifeCycle.Stage); }
public IEnumerator BehaviorActivated() { // Given non-blocking behavior which wraps a behavior that is not activated immediately, EndlessBehavior endlessBehavior = new EndlessBehavior(); NonblockingWrapperBehavior behavior = new NonblockingWrapperBehavior(endlessBehavior, false); behavior.Configure(RuntimeConfigurator.Configuration.GetCurrentMode()); // When we activate it, behavior.LifeCycle.Activate(); endlessBehavior.LifeCycle.MarkToFastForward(); yield return(null); behavior.Update(); yield return(null); behavior.Update(); // Then it is activated. Assert.AreEqual(Stage.Active, behavior.LifeCycle.Stage); }