Exemplo n.º 1
0
    private void Analyze(string response)
    {
        var jsonResponse = JSON.Parse(response);

        if (jsonResponse == null)
        {
            return;
        }
        foreach (var result in jsonResponse["results"].Children)
        {
            var newTurn = new HandleTurn {
                Type = "Hero"
            };

            foreach (var alternative in result["alternatives"].Children)
            {
                var transcripts = alternative["transcript"].ToString();

                var toAnalyze = transcripts.Split('"')[1].Split(' ');

                BaseHero  hsm = null;
                BaseEnemy esm = null;
                foreach (var word in toAnalyze)
                {
                    GameObject hero, enemy;
                    BaseAttack attack;
                    if (_bsm.heroesToManage.HeroExists(word, out hero, ref hsm))
                    {
                        newTurn.AttackerGO = hero;
                        newTurn.Attacker   = hsm.Name;
                    }
                    else if (_bsm.enemiesInBattle.EnemyExists(word, out enemy, ref esm))
                    {
                        newTurn.AttackerTarget = enemy;
                    }
                    else if (hsm != null && hsm.Attacks.AttackExists(word, out attack))
                    {
                        newTurn.Attack = attack;
                    }
//                    else
//                    {
//                        switch (word)
//                        {
//                            case "attack":
//                            case "item":
//                            case "pokemon":
//                                break;
//                        }
//                    }
                    if (newTurn.IsConsistent())
                    {
                        break;
                    }
                }
                if (newTurn.IsConsistent())
                {
                    _bsm.VoiceInput(newTurn);
                    _buttonText.text = "Enregistrer";
                }
                else
                {
                    if (!newTurn.AttackerTarget)
                    {
                        newTurn.AttackerTarget = _bsm.enemiesInBattle[0];
                        if (newTurn.IsConsistent())
                        {
                            _bsm.VoiceInput(newTurn);
                            _buttonText.text = "Enregistrer";
                            return;
                        }
                    }

                    _buttonText.text = "Erreur, réessayez";
                }
            }
        }
    }