Beispiel #1
0
 bool CheckQuest(NPCSpeechHolder.Dialogue dialogue)
 {
     if (QuestManagerScript.ins.GetExistingQuestFromID(dialogue.questID).HasCompletedCurrentObjective())
     {
         QuestManagerScript.ins.GetExistingQuestFromID(dialogue.questID).CompleteObjective();
         return(true);
     }
     return(false);
 }
Beispiel #2
0
 bool GiveQuest(NPCSpeechHolder.Dialogue dialogue)
 {
     if (dialogue.givesQuest && !QuestManagerScript.ins.DoesQuestExist(dialogue.questID))
     {
         GameManagerScript.ins.playerQuests.AddQuest(QuestManagerScript.ins.CreateQuestFromID(dialogue.questID));
         return(true);
     }
     return(false);
 }
Beispiel #3
0
 /// <summary>
 /// if we can open the shop from the current dialogue, open it
 /// </summary>
 /// <param name="dialogue"></param>
 /// <returns></returns>
 bool CheckShop(NPCSpeechHolder.Dialogue dialogue)
 {
     if (dialogue.openShop)
     {
         OpenShop(); //opens shop and sets values
         return(true);
     }
     return(false);
 }
Beispiel #4
0
 void DoDialogue(NPCSpeechHolder.Dialogue dialogue)
 {
     //check to see if the current dialogue will be normal dialogue or a choice
     if (dialogue.isChoice)   //if choice, then display the choices and set values
     {
         inChoice = true;
         DisplayChoices(dialogue);
     }
     else     //if normal speech, set values and being displaying the text
     {
         SetNameText(dialogue.speakerName);
         SetSpeechText(dialogue.text);
         EnterSpeech(nameText.text, speechText.text);
     }
 }
Beispiel #5
0
    /// <summary>
    /// displays the choices of the current dialogue
    /// </summary>
    /// <param name="dialogue"></param>
    void DisplayChoices(NPCSpeechHolder.Dialogue dialogue)
    {
        speechPanel.gameObject.SetActive(false); //set this inactive since we don't need it
        //destory old choices if there were any in the grid layout
        foreach (Transform child in choiceGridLayoutPanel.transform)
        {
            Destroy(child.gameObject);
        }

        //instantiate the new choices in the grid layout
        foreach (NPCSpeechHolder.Choice choice in dialogue.myChoices.choices)
        {
            Button choiceButton = (Button)Instantiate(choicePrefab, choiceGridLayoutPanel);
            choiceButton.GetComponentInChildren <TMPro.TextMeshProUGUI>().text = choice.choiceText;
            choiceButton.GetComponent <ChoiceScript>().choiceSet = choice.setToGoTo;
        }
        choicePanel.gameObject.SetActive(true); //set the choice panel and grid layout to be active
    }
Beispiel #6
0
    /// <summary>
    /// called when the player hits space (either to enter dialogue, skip text, or see next line)
    /// </summary>
    /// <param name="player"></param>
    /// <param name="npc"></param>
    public void Speak(GameObject player, GameObject npc)
    {
        this.player = player;                                      //set player

        this.npc = npc;                                            //set actor/npc
        if (npcSpeech == null || pInfo == null || npcInfo == null) //get components if they are null (meaning this is the first line)
        {
            npcSpeech = npc.GetComponent <NPCSpeechHolder>();
            pInfo     = player.GetComponent <PlayerInfo>();
            npcInfo   = npc.GetComponent <NPCInfo>();
        }

        //return if we are in the shop
        //useful for if we want to have the merchant talk after buying and selling
        if (inShop)
        {
            return;
        }
        //if not in shop, then we are either in a choice or we are in normal dialogue
        //either way, we need the speechOutline active
        speechOutline.gameObject.SetActive(true);

        //if we are in a choice, return so we don't mess anything up
        if (inChoice)
        {
            return;
        }
        //if in normal dialogue, that means we need the current line to push out
        NPCSpeechHolder.Dialogue dialogue = npcSpeech.Speak();

        //checks to see if the first line of dialogue has been spoken
        if (!hasStartedTalking)
        {
            hasStartedTalking = true;
            player.GetComponent <PlayerMovementScript>().CanPlayerMove = false; //disable player movement
            DoDialogue(dialogue);                                               //prints dialogue
        }
        else if (!hasFinishedTalking)                                           //we havent finished dialogue, so finish it
        {
            hasFinishedTalking = true;
            FinishSpeech(); //print full text
        }
        else                //this means that the current dialogue is done and we can move onto the next line
        {
            hasFinishedTalking = false;
            //checks to see if the current dialogue does not open a shop
            //if it does, this wont run and the shop will open from this line

            if (dialogue.checkQuestCondition)
            {
                changedQuestDialoguePath = true;
                if (CheckQuest(dialogue))
                {
                    npcSpeech.SetDialogueSetChoice(dialogue.setToGoToForComplete);
                }
                else
                {
                    npcSpeech.SetDialogueSetChoice(dialogue.setToGoToForInProgress);
                }
            }
            else
            {
                changedQuestDialoguePath = false;
            }

            GiveQuest(dialogue);
            if (!CheckShop(dialogue))
            {
                //check to see if we can continue talking (reached the last line) and move current dialogue to next one
                bool IsFinished = npcSpeech.UpdateCurrentLine();
                dialogue = npcSpeech.Speak();                //get next line
                if (!IsFinished || changedQuestDialoguePath) //if not finished, print next line
                {
                    DoDialogue(dialogue);
                }
                else     //if we are finished, end the dialogue
                {
                    EndSpeech();
                }
            }
        }
    }