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 })); } } } } } } }
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 and OnExecute() event): 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); destinationEntry.onExecute.Invoke(); 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, DialogueLua.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 })); } } } } } } }