Esempio n. 1
0
    private void OnNodeEntered(Node newNode)
    {
        if (dataToPass == null)
        {
            return;
        }

        Debug.Log("Entering node: " + newNode.title);
        txtNodeDisplay.text = newNode.text;

        KillAllChildren(parentOfResponses);
        for (int i = newNode.responses.Count - 1; i >= 0; i--)
        {
            int currentChoiceIndex = i;
            var response           = newNode.responses[i];
            var responceButton     = Instantiate(prefab_btnResponse, parentOfResponses);
            responceButton.GetComponentInChildren <UnityEngine.UI.Text>().text = response.displayText;
            responceButton.onClick.AddListener(delegate { OnNodeSelected(currentChoiceIndex); });
        }

        //TODO: Use member variable for current npc and update only when needed
        var npcObject = GameObject.Find(dataToPass.currentActiveNpc);

        if (npcObject == null)
        {
            return;
        }
        NpcData npc = npcObject.GetComponent <NpcData>();

        if (newNode.tags.Contains("END"))
        {
            Debug.Log("End!");
            dialogueCanvas.SetActive(false);
        }
        else if (newNode.tags.Contains("ACCEPT_QUEST"))
        {
            npc.ActivateQuest();
        }
        else if (newNode.tags.Contains("CHECK_QUEST"))
        {
            // If the function returns false, the textNodeDisplay prints "you are not done, and the option to
            // go back appears with a button
            if (!npc.CheckIfQuestIsDone())
            {
                txtNodeDisplay.text = "You are not done...";
            }
        }
        else if (newNode.tags.Contains("QUEST_DONE"))
        {
            // Give reward to the player accordingly to the current active quests reward
            // If there is a item like a sword as reward it is given to the player by
            // entering it into players inventory

            txtNodeDisplay.text = "You received:\n\n";
            if (npc.currentNpcQuest.MoneyReward > 0)
            {
                txtNodeDisplay.text += npc.currentNpcQuest.MoneyReward + "gold\n";
            }
            if (npc.currentNpcQuest.GameObjectReward != null)
            {
                txtNodeDisplay.text += npc.currentNpcQuest.GameObjectReward.name;
            }

            // Load the last conversation that COMPLETELY ends the quest, and makes the npc just say something along
            // the lines of "You did a good job before, thanks"
            npc.EndQuest();
        }
    }