示例#1
0
    /// <summary>
    /// An interface to pass the chosen question to the DialogSystem.
    /// It will react by telling the GUI to display the answer.
    /// </summary>
    /// <param name="questionIndex">
    /// The index of the chosen question.
    /// </param>
    public void NextAnswer(int questionIndex)
    {
        //The question chosen by the player
        Question chosen = QuestionSets.Dequeue().Questions[questionIndex];

        Debug.Log(chosen.Text);
        Debug.Log(chosen.GetAnswer(ReactionType.Annoying).Text);
        Debug.Log(chosen.GetAnswer(ReactionType.Okay).Text);
        Debug.Log(chosen.GetAnswer(ReactionType.Comforting).Text);

        //The reaction the question would provoke
        ReactionType reaction = chosen.GetReactionFor(NPC.Character);

        Debug.Log(reaction);

        //The answer that our npc would give to the chosen question.
        Snippet answer = chosen.GetAnswer(reaction);

        Debug.Log(answer.Text);

        //If the answer contains a special need, add it to the NPC.
        if (answer.Need != Need.None)
        {
            NPC.AddSpecialNeed(answer.Need);
            if (answer.Need == Need.Tired)
            {
                NPC.StayDuration = Random.Range(0, GameClock.MaxStayDuration);
            }
        }

        //Make the NPC react to the question:
        switch (reaction)
        {
        case ReactionType.Annoying:
            NPC.ComfortLevel -= 1f;
            break;

        case ReactionType.Okay:
            NPC.ComfortLevel -= 0.5f;
            break;

        case ReactionType.Comforting:
            NPC.ComfortLevel += 0.5f;
            break;
        }

        if (NPC.ComfortLevel <= 0 || QuestionSets.Count == 0)
        {
            //Only show the answer. The dialog will end when "..." is pressed and Next ist executed.
            DialogDisplayer.DisplaySnippet(answer.Text);
        }
        else
        {
            //Take the matching reponse to the chosen question and discard the question. Also display the next questions.
            DialogDisplayer.DisplayAnswer(answer.Text, QuestionSets.Peek().ToStringList());
        }
    }