Ejemplo n.º 1
0
 public DialogueWordsData(DialogueWords words, DialogueData parent)
 {
     model       = words;
     this.parent = parent;
     if (model.Options.Count > 0 && parent)
     {
         int index = parent.model.Words.IndexOf(words);
         for (int i = 0; i < model.Options.Count; i++)
         {
             int         indexBack = index;
             WordsOption option    = model.Options[i];
             if (words.NeedToChusCorrectOption)
             {
                 if (model.IndexOfCorrectOption == i)
                 {
                     indexBack++;
                 }
             }
             else
             {
                 indexBack = option.IndexToGoBack > 0 && option.OptionType != WordsOptionType.SubmitAndGet && option.OptionType != WordsOptionType.OnlyGet &&
                             parent.model.StoryDialogue && (option.OptionType == WordsOptionType.BranchDialogue || option.OptionType == WordsOptionType.BranchWords) && !option.GoBack
                     ? option.IndexToGoBack : indexBack;
             }
             WordsOptionData od = new WordsOptionData(option, this, indexBack);
             optionDatas.Add(od);
         }
     }
 }
Ejemplo n.º 2
0
    /// <summary>
    /// 生成分支对话选项
    /// </summary>
    private void MakeNormalOption()
    {
        if (wordsToSay.Count < 1 || wordsToSay.Peek().Options.Count < 1)
        {
            return;
        }
        DialogueWords currentWords = wordsToSay.Peek();

        dialogueDatas.TryGetValue(currentDialog.ID, out DialogueData dialogDataFound);
        if (CurrentType == DialogueType.Normal)
        {
            ClearOptions(OptionType.Quest, OptionType.Objective);
        }
        else
        {
            ClearOptions();
        }
        bool isLastWords = currentDialog.IndexOfWords(wordsToSay.Peek()) == currentDialog.Words.Count - 1;

        foreach (WordsOption option in currentWords.Options)
        {
            if (option.OptionType == WordsOptionType.Choice && dialogDataFound != null)
            {
                DialogueWordsData wordsDataFound = dialogDataFound.wordsDatas.Find(x => x.wordsIndex == currentDialog.IndexOfWords(currentWords));
                //这个选择型分支是否完成了
                if (isLastWords || wordsDataFound != null && wordsDataFound.IsOptionCmplt(currentWords.IndexOfOption(option)))
                {
                    continue;//是最后一句话或者选项完成则跳过创建
                }
            }
            if (option.IsValid)
            {
                if (option.OptionType == WordsOptionType.OnlyGet && (option.ShowOnlyWhenNotHave && BackpackManager.Instance.HasItemWithID(option.ItemCanGet.ItemID) ||
                                                                     option.OnlyForQuest && option.BindedQuest && !QuestManager.Instance.HasOngoingQuestWithID(option.BindedQuest.ID)))
                {
                    continue;//若已持有当前选项给的道具,或者需任务驱动但任务未接取,则跳过创建
                }
                else if (option.OptionType == WordsOptionType.SubmitAndGet && option.OnlyForQuest && option.BindedQuest &&
                         !QuestManager.Instance.HasOngoingQuestWithID(option.BindedQuest.ID))
                {
                    continue;//若需当前选项需任务驱动但任务未接取,则跳过创建
                }
                OptionAgent oa = ObjectPool.Get(UI.optionPrefab, UI.optionsParent, false).GetComponent <OptionAgent>();
                oa.Init(option.Title, option);
                optionAgents.Add(oa);
            }
        }
        //把第一页以外的选项隐藏
        for (int i = UI.lineAmount - (int)(UI.wordsText.preferredHeight / UI.textLineHeight); i < optionAgents.Count; i++)
        {
            ZetanUtility.SetActive(optionAgents[i].gameObject, false);
        }
        if (optionAgents.Count < 1)
        {
            MakeContinueOption();//如果所有选择型分支都完成了,则可以进行下一句对话
        }
        CheckPages();
        //Debug.Log("make");
        //Debug.Log(optionAgents.Count);
    }
Ejemplo n.º 3
0
 public void StartOneWords(DialogueWords words, Dialogue dialogToGoBack = null, int indexToGoBack = -1)
 {
     if (!UI || !words.IsValid)
     {
         Debug.Log(words.Words);
         Debug.Log(words.TalkerType);
         Debug.Log(words.TalkerInfo);
         return;
     }
     IsTalking = true;
     wordsToSay.Clear();
     wordsToSay.Enqueue(words);
     MakeContinueOption(true);
     ZetanUtility.SetActive(UI.wordsText.gameObject, true);
     SetPageArea(false, false, false);
     if (dialogToGoBack && indexToGoBack > -1)
     {
         if (waitToGoBackRoutine != null)
         {
             StopCoroutine(waitToGoBackRoutine);
         }
         currentDialog       = dialogToGoBack;
         this.indexToGoBack  = indexToGoBack;
         waitToGoBackRoutine = StartCoroutine(WaitToGoBack());
     }
 }
Ejemplo n.º 4
0
    public void showDalogueData(Dialogue dialogue)
    {
        DialogueWords words = dialogue.Words[currentDialogueIndex];

        //
        dialogueNameText.text    = words.TalkerName + ":";
        dialogueContentText.text = words.Words;
    }
Ejemplo n.º 5
0
    private void DoOneWords(DialogueWords words)
    {
        string talkerName = words.TalkerName;

        if (currentDialogue)
        {
            talkerName = currentDialogue.model.UseUnifiedNPC ? (currentDialogue.model.UseCurrentTalkerInfo ? currentTalker.GetData <TalkerData>().Info.Name : currentDialogue.model.UnifiedNPC.Name) : talkerName;
        }
        if (words.TalkerType == TalkerType.Player && PlayerManager.Instance.PlayerInfo)
        {
            talkerName = PlayerManager.Instance.PlayerInfo.Name;
        }
        nameText.text  = talkerName;
        wordsText.text = MiscFuntion.HandlingKeyWords(words.Content, true);
        HandlingWords();
    }
Ejemplo n.º 6
0
 /// <summary>
 /// 转到下一句话
 /// </summary>
 public void SayNextWords()
 {
     if (wordsToSay.Count < 1)
     {
         return;
     }
     MakeContinueOption();
     if (wordsToSay.Count > 0 && wordsToSay.Peek().Options.Count > 0)
     {
         MakeTalkerCmpltQuestOption();
         if (AllOptionComplete())
         {
             MakeTalkerObjectiveOption();
         }
     }
     MakeNormalOption();
     if (wordsToSay.Count >= 1)
     {
         currentWords = wordsToSay.Peek();
     }
     if (wordsToSay.Count == 1)
     {
         HandlingLastWords();                       //因为Dequeue之后,话就没了,Words.Count就不是1了,而是0,所以要在Dequeue之前做这一步,意思是倒数第二句做这一步
     }
     if (wordsToSay.Count >= 1)
     {
         string talkerName = currentDialog.UseUnifiedNPC ? (currentDialog.UseCurrentTalkerInfo ? CurrentTalker.Info.name : currentDialog.UnifiedNPC.name) : wordsToSay.Peek().TalkerName;
         if (wordsToSay.Peek().TalkerType == TalkerType.Player && PlayerManager.Instance.PlayerInfo)
         {
             talkerName = PlayerManager.Instance.PlayerInfo.name;
         }
         UI.nameText.text  = talkerName;
         UI.wordsText.text = HandlingWords(wordsToSay.Peek().Words);
         wordsToSay.Dequeue();
     }
     if (wordsToSay.Count == 0)
     {
         if (wordsOptionInstances.Count > 0) //分支栈不是空的,说明当前对话是其它某句话的一个分支
         {
             HandlingLastOptionWords();      //分支处理比较特殊,放到Dequque之后,否则分支最后一句不会讲
         }
         OnFinishDialogueEvent?.Invoke();
     }
 }
Ejemplo n.º 7
0
    private void ExecuteEvents(DialogueWords words)
    {
        foreach (var we in words.Events)
        {
            switch (we.EventType)
            {
            case WordsEventType.Trigger:
                break;

            case WordsEventType.GetAmity:
                break;

            case WordsEventType.LoseAmity:
                break;

            default:
                break;
            }
        }
    }
Ejemplo n.º 8
0
    private void ExecuteEvents(DialogueWords words)
    {
        foreach (var we in words.Events)
        {
            switch (we.EventType)
            {
            case WordsEventType.Trigger:
                TriggerManager.Instance.SetTrigger(we.WordsTrigrName, we.TriggerActType == TriggerActionType.Set);
                break;

            case WordsEventType.GetAmity:
                //TODO 增加好感
                break;

            case WordsEventType.LoseAmity:
                //TODO 减少好感
                break;

            default:
                break;
            }
        }
    }
Ejemplo n.º 9
0
 public void StartOneWords(DialogueWords words)
 {
     wordsToSay.Clear();
     wordsToSay.Push(new DialogueWordsData(words, null));
     DoSay();
 }
Ejemplo n.º 10
0
 public int IndexOfWords(DialogueWords words)
 {
     return(Words.IndexOf(words));
 }
Ejemplo n.º 11
0
    /// <summary>
    /// 处理最后一句分支对话
    /// </summary>
    private void HandlingLastOptionWords()
    {
        WordsOption topOptionInstance = wordsOptionInstances.Pop();

        if (topOptionInstance.runtimeDialogParent)
        {
            DialogueWords topWordsParent = null;
            if (topOptionInstance.runtimeWordsParentIndex > -1 && topOptionInstance.runtimeWordsParentIndex < topOptionInstance.runtimeDialogParent.Words.Count)
            {
                topWordsParent = topOptionInstance.runtimeDialogParent.Words[topOptionInstance.runtimeWordsParentIndex];//找到包含当前分支的语句
            }
            if (topWordsParent != null)
            {
                int    indexOfWordsParent = topOptionInstance.runtimeDialogParent.IndexOfWords(topWordsParent);
                string dialogParentID     = topOptionInstance.runtimeDialogParent.ID;

                if (topOptionInstance.OptionType == WordsOptionType.Choice && topWordsParent.NeedToChusCorrectOption)             //该对话需要选择正确选项,且该选项是选择型选项
                {
                    if (topWordsParent.IsCorrectOption(currentOption))                                                            //该选项是正确选项
                                                                                                                                  //传入currentOption而不是topOptionInstance是因为前者是存于本地的原始数据,后者是实例化的数据
                    {
                        foreach (WordsOption option in topWordsParent.Options.Where(x => x.OptionType == WordsOptionType.Choice)) //则其他选择型选项就跟着完成了
                        {
                            CompleteOption(option, out var result);
                            result.complete = true;
                            var choiceOptions = topWordsParent.Options.Where(x => x.OptionType == WordsOptionType.Choice).ToList();
                            for (int i = 0; i < choiceOptions.Count; i++)
                            {
                                if (result.IsOptionCmplt(i) || !choiceOptions[i].DeleteWhenCmplt)
                                {
                                    continue;
                                }
                                result.complete = false;
                                break;
                            }
                        }
                        StartDialogue(topOptionInstance.runtimeDialogParent, topOptionInstance.runtimeIndexToGoBack, false);
                    }
                    else if (topOptionInstance.DeleteWhenCmplt)//若该选项不是正确选项,但完成后需要删除
                    {
                        CompleteOption(currentOption, out _);
                    }
                }

                void CompleteOption(WordsOption option, out DialogueWordsData result)
                {
                    dialogueDatas.TryGetValue(dialogParentID, out var dFound);
                    if (dFound == null)
                    {
                        dFound = new DialogueData(option.runtimeDialogParent);
                        dialogueDatas.Add(dialogParentID, dFound);
                    }
                    result = dFound.wordsDatas.Find(x => x.wordsIndex == indexOfWordsParent);
                    if (result == null)
                    {
                        result = new DialogueWordsData(indexOfWordsParent);
                        dFound.wordsDatas.Add(result);
                    }
                    int indexOfOption = topWordsParent.IndexOfOption(option);

                    if (!result.cmpltOptionIndexes.Contains(indexOfOption))
                    {
                        result.cmpltOptionIndexes.Add(indexOfOption);                                                    //该分支已完成
                    }
                    //Debug.Log($"完成选项{indexOfOption}: " + option.Title);
                }

                if (dialogueDatas.TryGetValue(dialogParentID, out var dfind))
                {
                    if (dfind.wordsDatas.TrueForAll(x => x.complete))
                    {
                        ExecuteEvents(topWordsParent);
                    }
                }
                else if (!topWordsParent.NeedToChusCorrectOption)//找不到,且该句子不需要选择正确选项,可以直接完成
                {
                    ExecuteEvents(topWordsParent);
                }
                if (topWordsParent != null && topWordsParent.NeedToChusCorrectOption && !topWordsParent.IsCorrectOption(currentOption))//选择错误,则说选择错误时应该说的话
                {
                    StartOneWords(new DialogueWords(topWordsParent.TalkerInfo, topWordsParent.WordsWhenChusWB, topWordsParent.TalkerType),
                                  topOptionInstance.runtimeDialogParent, topOptionInstance.runtimeIndexToGoBack);
                }
                else if (topOptionInstance.GoBack)//处理普通的带返回的分支
                {
                    StartDialogue(topOptionInstance.runtimeDialogParent, topOptionInstance.runtimeIndexToGoBack, false);
                }
            }
        }
        currentOption = null;
    }