From 2cd40324a775eae5e005f96ed5f44235e3063768 Mon Sep 17 00:00:00 2001
From: Falampe <falampe@uni-potsdam.de>
Date: Thu, 9 Jan 2025 14:29:19 +0100
Subject: [PATCH] removed disaternode code in ImpulseController

added SolveSpecificDisturbance in Classcontroller and added it to the BranchPredictionInStructureTree in the impulsecontroller "int" case
---
 .../Runtime/Scripts/ImpulseController.cs      | 31 ++++++++-----------
 .../WholeClass/Scripts/ClassController.cs     | 26 +++++++++++-----
 2 files changed, 32 insertions(+), 25 deletions(-)

diff --git a/Packages/vr.teachr.structuretree/Runtime/Scripts/ImpulseController.cs b/Packages/vr.teachr.structuretree/Runtime/Scripts/ImpulseController.cs
index 925271b3b..ba213fc43 100644
--- a/Packages/vr.teachr.structuretree/Runtime/Scripts/ImpulseController.cs
+++ b/Packages/vr.teachr.structuretree/Runtime/Scripts/ImpulseController.cs
@@ -44,7 +44,8 @@ namespace TeachR.StructureTree
         private ConfigLoader config;
 
         #region utility vars
-        private static readonly HashSet<string> StudentreeKeywords = new HashSet<string> { "Stö", "StöEx", "Int", "anim", "KM", null }; // this exists to check if a node is an audiofile
+        //TODO: make code behave as predicted for global knowledge as well as parallel trees (which require different handeling)
+        private static readonly HashSet<string> StudentreeKeywords = new HashSet<string> {"randstö", "randint",  "stö", "stöex", "int", "anim", "KM", null }; // this exists to check if a node is an audiofile
 
         private static readonly string followedByAudioNode = "followedByAudioNode";
         private static readonly string InitialAudioChainNode = "initialAudioChainNode";
@@ -324,7 +325,7 @@ namespace TeachR.StructureTree
                 LogData($"{DateTime.Now.ToString(DateTimeFormat)};impulse:{impulse};nextNode:{nextNode.nodeId}");
                 if (bc.nextNode != null)
                 {
-                    if (nodeFlags[followedByAudioNode])
+                    if (nodeFlags[followedByAudioNode]) //TODO: take care of global knowledge vs parallel tree behaviour
                     {
                         if (nodeFlags[InitialAudioChainNode])
                         {//Start Student Node Chain
@@ -419,12 +420,6 @@ namespace TeachR.StructureTree
 
         private void BranchPredictionInStructureTree(BehaviourController bc, GraphToTreeConverter.StructureTreeNode nextNode, string impulse, bool isInitiationInTree)
         {
-            // Was it the last node and negative? Start desaster!
-            if (nextNode.nextNodes.Count == 0 && impulse == "negative")
-            {
-                MenuDataHolder.IsNonScripted = true;
-                return;
-            }
 
             bool nextImpulseIsDelayed = false;
 
@@ -435,7 +430,7 @@ namespace TeachR.StructureTree
             string keyword = StructureTreeHandler.stc[nextNode.nodeId].soundFileName.ToLower();
             switch (keyword)
             {
-                case "stö": // a specific disturbance should be triggered - for all if global knowledge is true
+                case "stö": // a disturbance should be triggered - for all students if global knowledge is true  else for a specific student 
                     GoToNextNode(bcs);
                     if (StructureTreeHandler.classHasGlobalKnowledge)
                         ClassController.SetGlobalRandomDisturbance(_levelOfDistortion, maxDelayInAction);
@@ -443,7 +438,7 @@ namespace TeachR.StructureTree
                         ClassController.SetRandomDisturbance(bc.gameObject, _levelOfDistortion);
                     _levelOfDistortion++;
                     break;
-                case "stöex": // a specific disturbance should be triggered, but more extreme!
+                case "stöex": // like stö, but more extreme!
                     GoToNextNode(bcs);
                     _levelOfDistortion++;
                     if (StructureTreeHandler.classHasGlobalKnowledge)
@@ -452,19 +447,19 @@ namespace TeachR.StructureTree
                         ClassController.SetRandomDisturbance(bc.gameObject, _levelOfDistortion);
                     _levelOfDistortion++;
                     break;
-                case "randStö": // a random disturbance should be triggered within the class
+                case "randstö": // multiple random disturbances should be triggered within the class
                     GoToNextNode(bcs);
                     ClassController.SetRandomDisturbance( _levelOfDistortion);
                     _levelOfDistortion++;
                     break;
-                case "int": // All disturbances should be stopped
+                case "int": // resolves all or a specific Disruption, based on global knowledge
                     GoToNextNode(bcs);
-                    //if (StructureTreeHandler.classHasGlobalKnowledge)
+                    if (StructureTreeHandler.classHasGlobalKnowledge)
                         ClassController.SolveGlobalDisturbances(maxDelayInAction);
-                    //else
-                    //    ClassController.SolveRandomDisturbance(); // 
+                    else
+                        ClassController.SolveSpecificDisturbance(bc);
                     break;
-                case "randInt": // some random Disturbance should bes stopped
+                case "randint": // some random Disturbance should bes stopped (to decrease the overall stress I guess)
                     GoToNextNode(bcs);
                     ClassController.SolveRandomDisturbance();
                     break;
@@ -475,8 +470,8 @@ namespace TeachR.StructureTree
                     nextImpulseIsDelayed = true;
                     break;
                 default:
-                        PrepareImpulse(bc);
-                        return;                  
+                    PrepareImpulse(bc);
+                    return;                  
             }
 
             // this code just happens, if impulse does not need to be prepared
diff --git a/Packages/vr.teachr.students/Runtime/WholeClass/Scripts/ClassController.cs b/Packages/vr.teachr.students/Runtime/WholeClass/Scripts/ClassController.cs
index 5e1a030a0..9cf572e1f 100644
--- a/Packages/vr.teachr.students/Runtime/WholeClass/Scripts/ClassController.cs
+++ b/Packages/vr.teachr.students/Runtime/WholeClass/Scripts/ClassController.cs
@@ -1,9 +1,8 @@
-using System.Collections;
-using System.Collections.Generic;
+using System.Collections.Generic;
 using System.Linq;
+using UnityEngine;
 using TeachR.ApplicationManager;
 using TeachR.WebCommunication;
-using UnityEngine;
 
 namespace TeachR.Student { 
     public static class ClassController
@@ -28,8 +27,8 @@ namespace TeachR.Student {
                 if (_behaviourControllers != null) return _behaviourControllers;
                 _behaviourControllers = new List<BehaviourController>();
 
-                foreach (GameObject s in AllStudentAttributes.FindStudentSlots())
-                    _behaviourControllers.Add(s.GetComponent<BehaviourController>());
+                foreach (GameObject slot in AllStudentAttributes.FindStudentSlots())
+                    _behaviourControllers.Add(slot.GetComponent<BehaviourController>());
 
                 return _behaviourControllers;
             }
@@ -103,7 +102,7 @@ namespace TeachR.Student {
         public static void SetGlobalRandomDisturbance(int level = 0, float delay = 0)
         {
             List<string> possibleDistortions = level switch
-            {
+            {//DISCUSS: [FL] Should this switchstatement be a Methon in SpecialBehaviours? 
                 0 => SpecialBehaviours._level0Distortion.ToList(),
                 1 => SpecialBehaviours._level1Distortion.ToList(),
                 2 => SpecialBehaviours._level2Distortion.ToList(),
@@ -112,9 +111,12 @@ namespace TeachR.Student {
                     .Concat(SpecialBehaviours._level2Distortion).ToList()
             };
 
+            float rndDelay = Random.value * delay;
+            string rndDistortion = possibleDistortions[Random.Range(0, possibleDistortions.Count)];
+
             AllStudentAttributes.BehaviourControllers
                 .ToList()
-                .ForEach(bc => bc.DelayedDisrupt(possibleDistortions[Random.Range(0, possibleDistortions.Count)], Random.value*delay));
+                .ForEach(bc => bc.DelayedDisrupt(rndDistortion, rndDelay));
         }
 
         public static GameObject GetRandomStudent()
@@ -154,6 +156,16 @@ namespace TeachR.Student {
             DisruptStudent(Behaviours[rndDisturbance], Behaviours[rndDisturbance].LastGoodBehaviour);
         }
 
+
+        /// <summary>
+        /// Will resolve Disturbance of a specific Student, if the Student is disturbing.
+        /// </summary>
+        /// <param name="bc"></param>
+        public static void SolveSpecificDisturbance(BehaviourController bc)
+        {
+            if (bc.IsDistorting) bc.Disrupt(bc.LastGoodBehaviour);
+        }
+
         /// <summary>
         /// Will reset all Students to their last good behaviour.
         /// </summary>
-- 
GitLab