Tree("Root") {
    Composite(Sequence) {
        BTC.InitializeSpeechManager()
        BTC.SetSpeechRecognitionLanguage("it-IT")

        BTC.Wait(5)
        BTC.SetBool("startdialogue", false)
        BTC.AddPossbileSpeechIntent("Kueche.start_dialog.1")

        Decorator(Repeat) {
            Composite(Race) {
                Composite(Sequence) {
                    BTC.CompareBool("startdialogue", false)
                    //BTC.SynthesizeText("Gib mir Bescheid, sobald du bereit bist.")
                    BTC.SynthesizeText("Dimmi quando possiamo cominciare.")
                    BTC.SpeechOutputEnded()
                    BTC.StartSpeechIntentRecognition()

                    Composite(Race) {
                        Composite(Sequence) {
                            BTC.Wait(15)
                            BTC.CompareUserSpeechInputStarted(false)
                            BTC.AbortSpeechEventListener()
                            BTC.StopSpeechIntentRecognition()
                        }
                           
                        Composite(Sequence) {
                            BTC.UserStartedSpeechInput()
                            BTC.SpeechIntentRecognized()

                            // Intent erkannt
                            BTC.SetBool("startdialogue")
                        }   
                    }
                }

                Composite(Sequence) {
                    BTC.CompareBool("startdialogue")
                    BTC.ClearPossbileSpeechIntents()
                    //BTC.SynthesizeText("Wir beide werden jetzt ein feines Risotto nach dem Rezept meiner Nonna kochen. Kochst du denn gerne?")
                    BTC.SynthesizeText("Noi due adesso facciamo un buon risotto basato sulla ricetta di mia nonna. Ti piace cucinare?")
                    BTC.SpeechOutputEnded()

                    // Frage beantworten
                    BTC.AddPossbileSpeechIntent("Kueche.alles_gefunden.4")
                    BTC.AddPossbileSpeechIntent("Kueche.alles_gefunden.6")
                    BTC.StartSpeechIntentRecognition()

                    Composite(Race) {
                        // -- Race 1: User sagt etwas
                        Composite(Sequence) {
                            BTC.UserStartedSpeechInput()
                
                            Composite(Selector) {
                                // -- Selector 1: Intent erkannt
                                Composite(Sequence) {
                                    BTC.SpeechIntentRecognized()

                                    // Intent erkannt
                                    Composite(Race) {
                                        Composite(Sequence) {
                                            BTC.CompareIntentID("Kueche.alles_gefunden.4")
                                            BTC.ClearPossbileSpeechIntents()
                                            RunTree("32_Grotto_Kueche_Interesse_Kochen")
                                        }
                                        Composite(Sequence) {
                                            BTC.CompareIntentID("Kueche.alles_gefunden.6")
                                            BTC.ClearPossbileSpeechIntents()
                                            RunTree("32_Grotto_Kueche_Desinteresse_Kochen")
                                        }
                                    }
                                }

                                // -- Selector 2: Intent nicht erkannt
                                Composite(Sequence) {
                                    BTC.ClearPossbileSpeechIntents()

                                    // Fallback Button
                                    Composite(Marathon) {
                                        BTC.Set("TextMeshPro.HANDMENU.Option1Button", "text", "Sì")
                                        BTC.Show("GO.HANDMENU.Option1Button")
                                        BTC.Set("TextMeshPro.HANDMENU.Option2Button", "text", "No")
                                        BTC.Show("GO.HANDMENU.Option2Button")
                                    }

                                    Composite(Race) {
                                        Composite(Sequence) {
                                            // Ja
                                            BTC.Run("NamedEventTrigger.HANDMENU.Option1Button")
                                            BTC.AbortEventListener("NamedEventTrigger.HANDMENU.Option2Button")
                                            BTC.Hide("GO.HANDMENU.Option1Button")
                                            BTC.Hide("GO.HANDMENU.Option2Button")
                                            RunTree("32_Grotto_Kueche_Interesse_Kochen")
                                        }
                                        Composite(Sequence) {
                                            // Nein
                                            BTC.Run("NamedEventTrigger.HANDMENU.Option2Button")
                                            BTC.AbortEventListener("NamedEventTrigger.HANDMENU.Option1Button")
                                            BTC.Hide("GO.HANDMENU.Option1Button")
                                            BTC.Hide("GO.HANDMENU.Option2Button")
                                            RunTree("32_Grotto_Kueche_Desinteresse_Kochen")
                                        }
                                    }
                                }
                            }
                        }

                        // -- Race 2: User sagt nichts
                        Composite(Sequence) {
                            BTC.Wait(5)
                            BTC.CompareUserSpeechInputStarted(false)
                            BTC.AbortSpeechEventListener()
                            BTC.StopSpeechIntentRecognition()
                            BTC.ClearPossbileSpeechIntents()

                            // Fallback Button
                            Composite(Marathon) {
                                BTC.Set("TextMeshPro.HANDMENU.Option1Button", "text", "Sì")
                                BTC.Show("GO.HANDMENU.Option1Button")
                                BTC.Set("TextMeshPro.HANDMENU.Option2Button", "text", "No")
                                BTC.Show("GO.HANDMENU.Option2Button")
                            }

                            Composite(Race) {
                                Composite(Sequence) {
                                    // Ja
                                    BTC.Run("NamedEventTrigger.HANDMENU.Option1Button")
                                    BTC.AbortEventListener("NamedEventTrigger.HANDMENU.Option2Button")
                                    BTC.Hide("GO.HANDMENU.Option1Button")
                                    BTC.Hide("GO.HANDMENU.Option2Button")
                                    RunTree("32_Grotto_Kueche_Interesse_Kochen")
                                }
                                Composite(Sequence) {
                                    // Nein
                                    BTC.Run("NamedEventTrigger.HANDMENU.Option2Button")
                                    BTC.AbortEventListener("NamedEventTrigger.HANDMENU.Option1Button")
                                    BTC.Hide("GO.HANDMENU.Option1Button")
                                    BTC.Hide("GO.HANDMENU.Option2Button")
                                    RunTree("32_Grotto_Kueche_Desinteresse_Kochen")
                                }
                            }
                        }
                    }        
                }
            }
        }

        
    }
}

Tree("32_Grotto_Kueche_Interesse_Kochen") {
// --- Kueche - Interesse Kochen ---
    Composite(Sequence) {
        //BTC.SynthesizeText("Was kochst du denn manchmal so?")
        BTC.SynthesizeText("Cosa ti piace cucinare?")
        BTC.SpeechOutputEnded()

        // Frage beantworten
        BTC.AddPossbileSpeechIntent("Kueche.Interesse_Kochen.2")
        BTC.StartSpeechIntentRecognition()

        Composite(Race) {
            // -- Race 1: User sagt etwas
            Composite(Sequence) {
                BTC.UserStartedSpeechInput()
                
                Composite(Selector) {
                    // -- Selector 1: Intent erkannt
                    Composite(Sequence) {
                        BTC.SpeechIntentRecognized()
                        BTC.ClearPossbileSpeechIntents()
                    }

                    // -- Selector 2: Intent nicht erkannt
                    Composite(Sequence) {
                        BTC.ClearPossbileSpeechIntents()
                    }
                }
            }

            // -- Race 2: User sagt nichts
            Composite(Sequence) {
                BTC.Wait(10)
                BTC.CompareUserSpeechInputStarted(false)
                BTC.AbortSpeechEventListener()
                BTC.StopSpeechIntentRecognition()
                BTC.ClearPossbileSpeechIntents()
            }
        }

        RunTree("32_Grotto_Kueche_Kochen_Anzahl")
    }
}

Tree("32_Grotto_Kueche_Kochen_Anzahl") {
// --- Kueche - Kochen Anzahl ---
    Composite(Sequence) {
        //BTC.SynthesizeText("Ja, das mag ich auch gerne. Wie oft kochst du denn so?")
        BTC.SynthesizeText("Sì, questo piace anche a me. Cucini spesso?")
        BTC.SpeechOutputEnded()

        // Frage beantworten
        BTC.AddPossbileSpeechIntent("Kueche.Kochen_Anzahl.2")
        BTC.AddPossbileSpeechIntent("Kueche.Kochen_Anzahl.4")
        BTC.StartSpeechIntentRecognition()

        Composite(Race) {
            // -- Race 1: User sagt etwas
            Composite(Sequence) {
                BTC.UserStartedSpeechInput()
                
                Composite(Selector) {
                    // -- Selector 1: Intent erkannt
                    Composite(Sequence) {
                        BTC.SpeechIntentRecognized()
                        BTC.ClearPossbileSpeechIntents()
                    }

                    // -- Selector 2: Intent nicht erkannt
                    Composite(Sequence) {
                        BTC.ClearPossbileSpeechIntents()
                    }
                }
            }

            // -- Race 2: User sagt nichts
            Composite(Sequence) {
                BTC.Wait(10)
                BTC.CompareUserSpeechInputStarted(false)
                BTC.AbortSpeechEventListener()
                BTC.StopSpeechIntentRecognition()
                BTC.ClearPossbileSpeechIntents()
            }
        }

        RunTree("32_Grotto_Kueche_Interaktion")        
    }
}

Tree("32_Grotto_Kueche_Desinteresse_Kochen") {
// --- Kueche - Desinteresse Kochen ---
    Composite(Sequence) {
        //BTC.SynthesizeText("Okay, aber heute kochen wir gemeinsam und das Risotto ist auch nicht allzu schwer. Was ist denn dein Lieblingsgericht?")
        BTC.SynthesizeText("Okay, ma oggi cuciniamo insieme. Fare un risotto non è complicato. Qual è il tuo piatto preferito?")
        BTC.SpeechOutputEnded()

        // Lieblingsgericht beantworten
        BTC.AddPossbileSpeechIntent("Kueche.Desinteresse_Kochen.2")
        BTC.StartSpeechIntentRecognition()

        Composite(Race) {
            // -- Race 1: User sagt etwas
            Composite(Sequence) {
                BTC.UserStartedSpeechInput()
                
                Composite(Selector) {
                    // -- Selector 1: Intent erkannt
                    Composite(Sequence) {
                        BTC.SpeechIntentRecognized()
                        BTC.ClearPossbileSpeechIntents()
                    }

                    // -- Selector 2: Intent nicht erkannt
                    Composite(Sequence) {
                        BTC.ClearPossbileSpeechIntents()
                    }
                }
            }

            // -- Race 2: User sagt nichts
            Composite(Sequence) {
                BTC.Wait(10)
                BTC.CompareUserSpeechInputStarted(false)
                BTC.AbortSpeechEventListener()
                BTC.StopSpeechIntentRecognition()
                BTC.ClearPossbileSpeechIntents()
            }
        }

        //BTC.SynthesizeText("Ja, das mag ich auch gerne.")
        BTC.SynthesizeText("Sì, questo piace anche a me.")
        BTC.SpeechOutputEnded()

        RunTree("32_Grotto_Kueche_Interaktion") 
    }
}

Tree("32_Grotto_Kueche_Interaktion") {
    Composite(Sequence) {
        //BTC.SynthesizeText("Gut, dann fangen wir jetzt mit dem Risotto an. Gebe bitte die Pilze in den Topf.")
        BTC.SynthesizeText("Bene, allora cominciamo con il risotto. Metti i funghi nella pentola.")
        BTC.SpeechOutputEnded()

        BTC.Enable("NamedOutline.INTERACTABLES.Teller")
        BTC.Set("Collider.INTERACTABLES.Topf", "otherTag", "Steinpilze")
    
        Composite(Marathon) {
            Composite(Sequence) {
                BTC.Run("NamedGrabEvent.INTERACTABLES.Pilz01")
                BTC.Run("Collider.INTERACTABLES.Topf")
            }

            Composite(Sequence) {
                BTC.Run("NamedGrabEvent.INTERACTABLES.Pilz02")
                BTC.Run("Collider.INTERACTABLES.Topf")
            }

            Composite(Sequence) {
                BTC.Run("NamedGrabEvent.INTERACTABLES.Pilz03")
                BTC.Run("Collider.INTERACTABLES.Topf")
            }
        }

        BTC.Disable("NamedOutline.INTERACTABLES.Teller")
        BTC.Wait(300)
        BTC.SetBool("startdialogue", false)
        BTC.AddPossbileSpeechIntent("Kueche.start_dialog.1")
    }
}