Esempio n. 1
0
        /// <summary>
        /// Adds a Conversation to the database.
        /// </summary>
        /// <param name='conversation'>
        /// The conversation to add.
        /// </param>
        public void AddConversation(Conversation conversation)
        {
            SetupCaches();
            var title = conversation.Title;

            //--- Removed for speed: if (DialogueDebug.logInfo) Debug.Log("Dialogue System: Add Conversation: " + title);
            if (!conversationTitleCache.ContainsKey(title))
            {
                conversationTitleCache.Add(title, conversation);
            }
            conversations.Add(conversation);
            LinkUtility.SortOutgoingLinks(this, conversation);
        }
 private void EvaluateLinksAtPriority(ConditionPriority priority, DialogueEntry entry, List <Response> npcResponses,
                                      List <Response> pcResponses, List <DialogueEntry> visited,
                                      bool stopAtFirstValid = false)
 {
     if (entry != null)
     {
         for (int ol = 0; ol < entry.outgoingLinks.Count; ol++)
         {
             var           link             = entry.outgoingLinks[ol];
             DialogueEntry destinationEntry = m_database.GetDialogueEntry(link);
             if ((destinationEntry != null) && (/*(destinationEntry.conditionPriority == priority) ||*/ (link.priority == priority))) // Note: Only observe link priority. Why does Chat Mapper even have conditionPriority?
             {
                 CharacterType characterType = m_database.GetCharacterType(destinationEntry.ActorID);
                 Lua.Run("thisID = " + destinationEntry.id);
                 bool isValid = Lua.IsTrue(destinationEntry.conditionsString, DialogueDebug.logInfo, m_allowLuaExceptions) &&
                                ((isDialogueEntryValid == null) || isDialogueEntryValid(destinationEntry));
                 if (isValid || (m_includeInvalidEntries && (characterType == CharacterType.PC)))
                 {
                     // Condition is true (or blank), so add this link:
                     if (destinationEntry.isGroup)
                     {
                         // For groups, evaluate their links (after running the group node's Lua code):
                         if (DialogueDebug.logInfo)
                         {
                             Debug.Log(string.Format("{0}: Add Group ({1}): ID={2}:{3} '{4}' ({5})", new System.Object[] { DialogueDebug.Prefix, GetActorName(m_database.GetActor(destinationEntry.ActorID)), link.destinationConversationID, link.destinationDialogueID, destinationEntry.Title, isValid }));
                         }
                         Lua.Run(destinationEntry.userScript, DialogueDebug.logInfo, m_allowLuaExceptions);
                         for (int i = (int)ConditionPriority.High; i >= 0; i--)
                         {
                             int originalResponseCount = npcResponses.Count + pcResponses.Count;;
                             EvaluateLinksAtPriority((ConditionPriority)i, destinationEntry, npcResponses, pcResponses, visited);
                             if ((npcResponses.Count + pcResponses.Count) > originalResponseCount)
                             {
                                 break;
                             }
                         }
                     }
                     else
                     {
                         // For regular entries, just add them:
                         if (DialogueDebug.logInfo)
                         {
                             Debug.Log(string.Format("{0}: Add Link ({1}): ID={2}:{3} '{4}' ({5})", new System.Object[] { DialogueDebug.Prefix, GetActorName(m_database.GetActor(destinationEntry.ActorID)), link.destinationConversationID, link.destinationDialogueID, GetLinkText(characterType, destinationEntry), isValid }));
                         }
                         if (characterType == CharacterType.NPC)
                         {
                             // Add NPC response:
                             npcResponses.Add(new Response(FormattedText.Parse(destinationEntry.subtitleText, m_database.emphasisSettings), destinationEntry, isValid));
                         }
                         else
                         {
                             // Add PC response, wrapping old responses in em tags if specified:
                             string text = destinationEntry.responseButtonText;
                             if (m_emTagForOldResponses != EmTag.None)
                             {
                                 string simStatus     = Lua.Run(string.Format("return Conversation[{0}].Dialog[{1}].SimStatus", new System.Object[] { destinationEntry.conversationID, destinationEntry.id })).asString;
                                 bool   isOldResponse = string.Equals(simStatus, "WasDisplayed");
                                 if (isOldResponse)
                                 {
                                     text = string.Format("[em{0}]{1}[/em{0}]", (int)m_emTagForOldResponses, text);
                                 }
                             }
                             if (m_emTagForInvalidResponses != EmTag.None)
                             {
                                 if (!isValid)
                                 {
                                     text = string.Format("[em{0}]{1}[/em{0}]", (int)m_emTagForInvalidResponses, text);
                                 }
                             }
                             pcResponses.Add(new Response(FormattedText.Parse(text, m_database.emphasisSettings), destinationEntry, isValid));
                             DialogueLua.MarkDialogueEntryOffered(destinationEntry);
                         }
                     }
                     if (stopAtFirstValid)
                     {
                         return;
                     }
                 }
                 else
                 {
                     // Condition is false, so block or pass through according to destination entry's setting:
                     if (LinkUtility.IsPassthroughOnFalse(destinationEntry))
                     {
                         if (DialogueDebug.logInfo)
                         {
                             Debug.Log(string.Format("{0}: Passthrough on False Link ({1}): ID={2}:{3} '{4}' Condition='{5}'", new System.Object[] { DialogueDebug.Prefix, GetActorName(m_database.GetActor(destinationEntry.ActorID)), link.destinationConversationID, link.destinationDialogueID, GetLinkText(characterType, destinationEntry), destinationEntry.conditionsString }));
                         }
                         List <Response> linkNpcResponses = new List <Response>();
                         List <Response> linkPcResponses  = new List <Response>();
                         EvaluateLinks(destinationEntry, linkNpcResponses, linkPcResponses, visited);
                         npcResponses.AddRange(linkNpcResponses);
                         pcResponses.AddRange(linkPcResponses);
                     }
                     else
                     {
                         if (DialogueDebug.logInfo)
                         {
                             Debug.Log(string.Format("{0}: Block on False Link ({1}): ID={2}:{3} '{4}' Condition='{5}'", new System.Object[] { DialogueDebug.Prefix, GetActorName(m_database.GetActor(destinationEntry.ActorID)), link.destinationConversationID, link.destinationDialogueID, GetLinkText(characterType, destinationEntry), destinationEntry.conditionsString }));
                         }
                     }
                 }
             }
         }
     }
 }
Esempio n. 3
0
 /// <summary>
 /// Adds a Conversation to the database.
 /// </summary>
 /// <param name='conversation'>
 /// The conversation to add.
 /// </param>
 public void AddConversation(Conversation conversation)
 {
     conversations.Add(conversation);
     LinkUtility.SortOutgoingLinks(this, conversation);
 }