コード例 #1
0
ファイル: DialogueManager.cs プロジェクト: PeterDrake/quoke2
    public void BeginConversation()
    {
        dialogueUI.LoadNPC(GlobalControls.currentNpc);

        // Paste the path of the xml file you want to look at here
        TextAsset text = Resources.Load <TextAsset>(GlobalControls.currentNpc);

        convoFile.LoadXml(text.text);

        // looks through all the npc nodes instead of looking at just the <convoForest> tag
        foreach (XmlNode node in convoFile.LastChild)
        {
            if (!forest.ContainsKey(node.Name))
            {
                forest.Add(node.Name, new ConvoNode(node));
            }
        }

        // This is where the we let the NPC talk to the code. When we run into an NPC, tbey will start at the
        // appropriate starting node.
        Debug.Log(GlobalControls.npcList[GlobalControls.currentNpc].node);
        currentNode = forest[GlobalControls.npcList[GlobalControls.currentNpc].node];

        for (int c = 0; c < currentNode.playerArray.Count; c++)
        {
            buttons[c].gameObject.SetActive(true);
            //This displays the initial node's player text
            buttons[c].GetComponentInChildren <Text>().text = currentNode.playerArray[c];

            // Turns a button off if there is no text in the button
            if (buttons[c].GetComponentInChildren <Text>().text.Equals(""))
            {
                buttons[c].gameObject.SetActive(false);
            }
        }

        if (keyboardManager.leftTrading)
        {
            keyboardManager.leftTrading = false;

            // Angie was used for testing the dialogue system, and does *not* follow latest conventions for dialogue.
            // (that's why it's so long)
            if (GlobalControls.currentNpc.Contains("Angie"))
            {
                // If Angie is given the first aid kit and the epi pen at the same time, update
                // globalControlsProperties to say Angie has the first aid kit and the epi pen. Move to the appropriate
                // dialogue node
                if (!GlobalControls.globalControlsProperties.Contains("angieHasEpiPen") &&
                    !GlobalControls.globalControlsProperties.Contains("angieHasFirstAidKit") &&
                    GlobalItemList.ItemList["First Aid Kit"].containerName.Equals("Angie") &&
                    GlobalItemList.ItemList["Epi Pen"].containerName.Equals("Angie"))
                {
                    if (!GlobalControls.globalControlsProperties.Contains("angieSeriousDialogue"))
                    {
                        GlobalControls.SetCheckpoint("basic_angie_8.0");
                        currentNode = forest["leave_angie_0"];
                        GlobalControls.globalControlsProperties.Add("angieHasFirstAidKit");
                        GlobalControls.globalControlsProperties.Add("angieHasEpiPen");
                    }
                    else
                    {
                        GlobalControls.SetCheckpoint("basic_angie_9.0");
                        currentNode = forest["leave_angie_1"];
                        GlobalControls.globalControlsProperties.Add("angieHasFirstAidKit");
                        GlobalControls.globalControlsProperties.Add("angieHasEpiPen");
                    }
                }

                // If Angie is given the first aid kit, update globalControlsProperties to say Angie has the first
                // aid kit Move to the appropriate dialogue node
                else if (GlobalItemList.ItemList["First Aid Kit"].containerName.Equals("Angie") &&
                         !GlobalControls.globalControlsProperties.Contains("angieHasFirstAidKit"))
                {
                    if (!GlobalControls.globalControlsProperties.Contains("angieSeriousDialogue"))
                    {
                        GlobalControls.SetCheckpoint("basic_angie_4.0");
                        currentNode = forest["leave_angie_0.7"];
                        GlobalControls.globalControlsProperties.Add("angieHasFirstAidKit");
                    }
                    else
                    {
                        GlobalControls.SetCheckpoint("basic_angie_5.0");
                        currentNode = forest["leave_angie_1.4"];
                        GlobalControls.globalControlsProperties.Add("angieHasFirstAidKit");
                    }
                }
                // If Angie is given the epi pen (we assume that she already has the first aid kit),
                // update globalControlsProperties to say Angie has the epi pen. Move to the appropriate dialogue node
                else if (GlobalItemList.ItemList["Epi Pen"].containerName.Equals("Angie") &&
                         !GlobalControls.globalControlsProperties.Contains("angieHasEpiPen"))
                {
                    if (!GlobalControls.globalControlsProperties.Contains("angieSeriousDialogue"))
                    {
                        GlobalControls.SetCheckpoint("basic_angie_8.0");
                        currentNode = forest["leave_angie_0"];
                        GlobalControls.globalControlsProperties.Add("angieHasEpiPen");
                    }
                    else
                    {
                        GlobalControls.SetCheckpoint("basic_angie_9.0");
                        currentNode = forest["leave_angie_1"];
                        GlobalControls.globalControlsProperties.Add("angieHasEpiPen");
                    }
                }

                else if (!GlobalControls.globalControlsProperties.Contains("angieSeriousDialogue"))
                {
                    currentNode = forest["leave_angie_0"];
                }
                else if (GlobalControls.globalControlsProperties.Contains("angieSeriousDialogue"))
                {
                    currentNode = forest["leave_angie_1"];
                }
                else
                {
                    currentNode = forest["leave_error"];
                }
            }
            // Safi needs no items (only actions), so she requires only the following code
            else if (GlobalControls.currentNpc.Equals("Safi"))
            {
                currentNode = forest["leave_safi_0"];
            }
            // Everyone other than Safi needs more code
            else
            {
                // Current NPC is *not* Safi
                int    propertiesSet = 0;
                string checkpoint    = "basic_" + GlobalControls.currentNpc.ToLower() + "_";
                string leave         = "leave_" + GlobalControls.currentNpc.ToLower() + "_0";
                foreach (string need in GlobalControls.npcList[GlobalControls.currentNpc].needs)
                {
                    string property = GlobalControls.currentNpc.ToLower() + "Has" + RemoveWhitespace(need);
                    Debug.Log(property);
                    // If we just traded this needed item to the NPC and therefore the GlobalControls property for it
                    // has not yet been set
                    if (GlobalItemList.ItemList[need].containerName.Equals(GlobalControls.currentNpc) &&
                        !GlobalControls.globalControlsProperties.Contains(property))
                    {
                        propertiesSet++;
                        GlobalControls.SetCheckpoint(checkpoint + "3.0");
                        Debug.Log(checkpoint + "3.0");
                        GlobalControls.globalControlsProperties.Add(property);
                    }
                    else if (GlobalControls.globalControlsProperties.Contains(property))
                    {
                        propertiesSet++;
                    }
                }

                // If both properties are set now, set checkpoint to corresponding checkpoint
                if (propertiesSet == 2)
                {
                    GlobalControls.SetCheckpoint(checkpoint + "4.0");
                    Debug.Log(checkpoint + "4.0");
                }

                // Handles specific cases where dialogue should continue after trading with an NPC
                // In the case that the player just traded Annette some needed items in the 0 series of nodes
                if (currentNode.nodeName.Equals("basic_annette_1.0") &&
                    (GlobalControls.globalControlsProperties.Contains("annetteHasLeash") ||
                     GlobalControls.globalControlsProperties.Contains("annetteHasDogCrate")))
                {
                    currentNode = forest["basic_annette_0.6"];
                }
                else
                {
                    currentNode = forest[leave];
                }
            }

            npcInteractedCanvas.GetComponent <NPCInteracted>().UpdateNPCInteracted(GlobalControls.currentNpc);

            Debug.Log("Current Node A: " + currentNode.nodeName);
        }

        // Safi has specific actions do be done instead of trading, so handle that here
        if (GlobalControls.currentNpc.Equals("Safi"))
        {
            if (GlobalControls.globalControlsProperties.Contains("safiGasDone") &&
                !GlobalControls.globalControlsProperties.Contains("safiHeaterDone"))
            {
                currentNode = forest["basic_safi_3.0"];
            }

            if (GlobalControls.globalControlsProperties.Contains("safiHeaterDone"))
            {
                currentNode = forest["basic_safi_5.0"];
            }
        }

        // Go through all the buttons and put that node's text into the buttons.
        for (int i = 0; i < currentNode.playerArray.Count; i++)
        {
            buttons[i].gameObject.SetActive(true);
            buttons[i].GetComponentInChildren <Text>().text = currentNode.playerArray[i];

            // Turns a button off if there is no text in the button
            if (buttons[i].GetComponentInChildren <Text>().text.Equals(""))
            {
                buttons[i].gameObject.SetActive(false);
            }

            if (currentNode.nextNode[i].Contains("action"))
            {
                if (GlobalControls.npcList[GlobalControls.currentNpc]
                    .actionsComplete[Int32.Parse(currentNode.nextNode[i].Substring(6, 1))])
                {
                    Debug.Log("Action Complete");
                    buttons[i].gameObject.SetActive(false);
                }
            }
        }

        //This displays the initial node's npc text
        dialogueUI.AddDialogue(currentNode.npcText, GlobalControls.npcList[GlobalControls.currentNpc].name);

        if (cursorLocation > buttons.Length - 1)
        {
            cursorLocation = 0;
        }

        if (buttons[cursorLocation].gameObject.activeSelf)
        {
            cursorLocation = ChangeCursorLocations(cursorLocation);
        }
        else
        {
            while (!buttons[cursorLocation].gameObject.activeSelf)
            {
                cursorLocation++;
                if (cursorLocation > buttons.Length - 1)
                {
                    cursorLocation = 0;
                }
            }

            cursorLocation = ChangeCursorLocations(cursorLocation);
        }
    }