Esempio n. 1
0
 private void EvaluateLinksAtPriority(ConditionPriority priority, DialogueEntry entry, List <Response> npcResponses, List <Response> pcResponses, List <DialogueEntry> visited)
 {
     if (entry != null)
     {
         foreach (Link link in entry.outgoingLinks)
         {
             DialogueEntry destinationEntry = database.GetDialogueEntry(link);
             if ((destinationEntry != null) && ((destinationEntry.conditionPriority == priority) || (link.priority == priority)))
             {
                 CharacterType characterType = database.GetCharacterType(destinationEntry.ActorID);
                 bool          isValid       = Lua.IsTrue(destinationEntry.conditionsString, DialogueDebug.LogInfo, allowLuaExceptions) &&
                                               ((IsDialogueEntryValid == null) || IsDialogueEntryValid(destinationEntry));
                 if (isValid)
                 {
                     // 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}'", new System.Object[] { DialogueDebug.Prefix, GetActorName(database.GetActor(destinationEntry.ActorID)), link.destinationConversationID, link.destinationDialogueID, destinationEntry.Title }));
                         }
                         Lua.Run(destinationEntry.userScript, DialogueDebug.LogInfo, 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}'", new System.Object[] { DialogueDebug.Prefix, GetActorName(database.GetActor(destinationEntry.ActorID)), link.destinationConversationID, link.destinationDialogueID, GetLinkText(characterType, destinationEntry) }));
                         }
                         if (characterType == CharacterType.NPC)
                         {
                             // Add NPC response:
                             npcResponses.Add(new Response(FormattedText.Parse(destinationEntry.SubtitleText, database.emphasisSettings), destinationEntry));
                         }
                         else
                         {
                             // Add PC response, wrapping old responses in em tags if specified:
                             string text = destinationEntry.ResponseButtonText;
                             if (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)emTagForOldResponses, text);
                                 }
                             }
                             pcResponses.Add(new Response(FormattedText.Parse(text, database.emphasisSettings), destinationEntry));
                             DialogueLua.MarkDialogueEntryOffered(destinationEntry);
                         }
                     }
                 }
                 else
                 {
                     // Condition is false, so block or pass through according to destination entry's setting:
                     if (LinkTools.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(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(database.GetActor(destinationEntry.ActorID)), link.destinationConversationID, link.destinationDialogueID, GetLinkText(characterType, destinationEntry), destinationEntry.conditionsString }));
                         }
                     }
                 }
             }
         }
     }
 }
Esempio n. 2
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);
     LinkTools.SortOutgoingLinks(this, conversation);
 }