diff --git a/Packages/vr.teachr.structuretree/Runtime/Scripts/ImpulseController.cs b/Packages/vr.teachr.structuretree/Runtime/Scripts/ImpulseController.cs index a967117ca694e35065628e7769eb6f792c475d27..3f8d3339e18d5aef6a27249eb17e09fb0751367a 100644 --- a/Packages/vr.teachr.structuretree/Runtime/Scripts/ImpulseController.cs +++ b/Packages/vr.teachr.structuretree/Runtime/Scripts/ImpulseController.cs @@ -330,22 +330,40 @@ namespace TeachR.StructureTree string keyword = StructureTreeHandler.stc[nextNode.nodeId].soundFileName.ToLower(); switch (keyword) { - case "stö": + case "stö": // a specific disturbance should be triggered - for all if global knowledge is true GoToNextNode(bcs); - ClassController.SetRandomDisturbance(bc.gameObject, _levelOfDistortion); + if (StructureTreeHandler.classHasGlobalKnowledge) + ClassController.SetGlobalRandomDisturbance(_levelOfDistortion); + else + ClassController.SetRandomDisturbance(bc.gameObject, _levelOfDistortion); _levelOfDistortion++; break; - case "stöex": + case "stöex": // a specific disturbance should be triggered, but more extreme! GoToNextNode(bcs); _levelOfDistortion++; + if (StructureTreeHandler.classHasGlobalKnowledge) + ClassController.SetGlobalRandomDisturbance(_levelOfDistortion); + else + ClassController.SetRandomDisturbance(bc.gameObject, _levelOfDistortion); + _levelOfDistortion++; + break; + case "randStö": // a random disturbance should be triggered + GoToNextNode(bcs); ClassController.SetRandomDisturbance(bc.gameObject, _levelOfDistortion); _levelOfDistortion++; break; - case "int": + case "int": // All disturbances should be stopped + GoToNextNode(bcs); + if (StructureTreeHandler.classHasGlobalKnowledge) + ClassController.SolveGlobalRandomDisturbance(); + else + ClassController.SolveRandomDisturbance(); + break; + case "randInt": // some random Disturbance should bes stopped GoToNextNode(bcs); ClassController.SolveRandomDisturbance(); break; - case "anim": + case "anim": // animation based on the structuretree is triggered GoToNextNode(bcs); float maximumDelay = !isInitiationInTree ? maxDelayInAction : maxInitialDelay; HandleAnimations(bcs, chanceToMisbehave, nextNode, maximumDelay); diff --git a/Packages/vr.teachr.students/Runtime/WholeClass/Scripts/ClassController.cs b/Packages/vr.teachr.students/Runtime/WholeClass/Scripts/ClassController.cs index fb632d846f47977551ae35f3b543d5f755ecd13c..fe414541636bff961a8a49c342c9c20137b28663 100644 --- a/Packages/vr.teachr.students/Runtime/WholeClass/Scripts/ClassController.cs +++ b/Packages/vr.teachr.students/Runtime/WholeClass/Scripts/ClassController.cs @@ -95,6 +95,27 @@ namespace TeachR.Student { DisruptStudent(student.GetComponent<BehaviourController>(), behaviour); } + /// <summary> + /// Will trigger a Disruption random Disturbance from <class>SpecialBehaviours</class> for each Student in the Classroom. + /// </summary> + /// <param name="level">provides level of distortion, defaults to zero</param> + public static void SetGlobalRandomDisturbance(int level = 0) + { + List<string> possibleDistortions = level switch + { + 0 => SpecialBehaviours._level0Distortion.ToList(), + 1 => SpecialBehaviours._level1Distortion.ToList(), + 2 => SpecialBehaviours._level2Distortion.ToList(), + _ => SpecialBehaviours._level0Distortion.ToList() + .Concat(SpecialBehaviours._level1Distortion) + .Concat(SpecialBehaviours._level2Distortion).ToList() + }; + + AllStudentAttributes.StudentSlots + .ToList() + .ForEach(slot => DisruptStudent(slot, possibleDistortions[Random.Range(0, possibleDistortions.Count)])); + } + public static GameObject GetRandomStudent() { int randomStudentSlot = Random.Range(0, AllStudentAttributes.StudentSlots.Length); @@ -131,5 +152,14 @@ namespace TeachR.Student { int rndDisturbance = Random.Range(0, countOfActiveDisturbances - 1); DisruptStudent(Behaviours[rndDisturbance], Behaviours[rndDisturbance].LastGoodBehaviour); } + + /// <summary> + /// Will reset all Students to their last good behaviour. + /// </summary> + public static void SolveGlobalRandomDisturbance() + => AllStudentAttributes.BehaviourControllers + .Where(bc => bc.IsDistorting) + .ToList() + .ForEach(bc => DisruptStudent(bc, bc.LastGoodBehaviour)); } } \ No newline at end of file