public void ExpandQuestString(Quest parentQuest, ref string questString) { Macro macro = GetMacro(questString); if (macro.type == MacroTypes.ContextMacro) { questString = questString.Replace(macro.token, MacroHelper.GetValue(macro.token, parentQuest)); } }
/// <summary> /// Expands any macros found inside quest message tokens. /// </summary> /// <param name="parentQuest">Parent quest of message.</param> /// <param name="tokens">Array of message tokens to expand macros inside of.</param> public void ExpandQuestMessage(Quest parentQuest, ref TextFile.Token[] tokens) { // Iterate message tokens for (int token = 0; token < tokens.Length; token++) { // Split token text into individual words string[] words = GetWords(tokens[token].text); // Iterate words to find macros for (int word = 0; word < words.Length; word++) { Macro macro = GetMacro(words[word]); if (macro.type == MacroTypes.ContextMacro) { words[word] = words[word].Replace(macro.token, MacroHelper.GetValue(macro.token, parentQuest)); } else { // Ask resource to expand macro if possible QuestResource resource = parentQuest.GetResource(macro.symbol); if (resource != null) { string result; if (resource.ExpandMacro(macro.type, out result)) { words[word] = words[word].Replace(macro.token, result); } } } // TODO: Need to store previous macro resource for pronomial context expansions } // Reassemble words and expanded macros back into final token text string final = string.Empty; for (int i = 0; i < words.Length; i++) { final += words[i]; if (i != words.Length - 1) { final += " "; } } // Store result back into token tokens[token].text = final; } }
/// <summary> /// Expands any macros found inside quest message tokens. /// </summary> /// <param name="parentQuest">Parent quest of message.</param> /// <param name="tokens">Array of message tokens to expand macros inside of.</param> /// <param name="resolveDialogLinks">will reveal dialog linked resources in talk window (this must be false for all calls to this function except if caller is talk manager when expanding answers).</param> public void ExpandQuestMessage(Quest parentQuest, ref TextFile.Token[] tokens, bool revealDialogLinks = false) { // Iterate message tokens for (int token = 0; token < tokens.Length; token++) { // Split token text into individual words string[] words = GetWords(tokens[token].text); // Iterate words to find macros for (int word = 0; word < words.Length; word++) { Macro macro = GetMacro(words[word]); if (macro.type == MacroTypes.ContextMacro) { words[word] = words[word].Replace(macro.token, MacroHelper.GetValue(macro.token, parentQuest)); } else { // Ask resource to expand macro if possible QuestResource resource = parentQuest.GetResource(macro.symbol); if (resource != null) { string result; if (resource.ExpandMacro(macro.type, out result)) { words[word] = words[word].Replace(macro.token, result); } // reveal dialog linked resources in talk window if (revealDialogLinks) { System.Type t = resource.GetType(); if (t.Equals(typeof(DaggerfallWorkshop.Game.Questing.Place))) { GameManager.Instance.TalkManager.AddDialogForQuestInfoResource(parentQuest.UID, result, TalkManager.QuestInfoResourceType.Location); } else if (t.Equals(typeof(DaggerfallWorkshop.Game.Questing.Person))) { GameManager.Instance.TalkManager.AddDialogForQuestInfoResource(parentQuest.UID, result, TalkManager.QuestInfoResourceType.Person); } else if (t.Equals(typeof(DaggerfallWorkshop.Game.Questing.Item))) { GameManager.Instance.TalkManager.AddDialogForQuestInfoResource(parentQuest.UID, result, TalkManager.QuestInfoResourceType.Thing); } } } } // TODO: Need to store previous macro resource for pronomial context expansions } // Reassemble words and expanded macros back into final token text string final = string.Empty; for (int i = 0; i < words.Length; i++) { final += words[i]; if (i != words.Length - 1) { final += " "; } } // Store result back into token tokens[token].text = final; } }
/// <summary> /// Expands any macros found inside quest message tokens. /// </summary> /// <param name="parentQuest">Parent quest of message.</param> /// <param name="tokens">Array of message tokens to expand macros inside of.</param> /// <param name="resolveDialogLinks">will reveal dialog linked resources in talk window (this must be false for all calls to this function except if caller is talk manager when expanding answers or for quest popups).</param> public void ExpandQuestMessage(Quest parentQuest, ref TextFile.Token[] tokens, bool revealDialogLinks = false) { // Iterate message tokens for (int token = 0; token < tokens.Length; token++) { // Split token text into individual words string[] words = GetWords(tokens[token].text); // Iterate words to find macros for (int word = 0; word < words.Length; word++) { Macro macro = GetMacro(words[word]); if (macro.type == MacroTypes.ContextMacro) { words[word] = words[word].Replace(macro.token, MacroHelper.GetValue(macro.token, parentQuest, parentQuest.ExternalMCP)); } else { // fix for bug when parent quest is no longer available (http://forums.dfworkshop.net/viewtopic.php?f=24&t=1002) in case // quest injected entries and rumors stay in list due to other bugs // so parentQuest is no longer available if (parentQuest == null) { return; } // Ask resource to expand macro if possible QuestResource resource = parentQuest.GetResource(macro.symbol); if (resource != null) { string result; if (resource.ExpandMacro(macro.type, out result)) { words[word] = words[word].Replace(macro.token, result); } // reveal dialog linked resources in talk window if (revealDialogLinks && macro.type == MacroTypes.NameMacro1) // only resolve if their true name was expanded (given) which is MacroTypes.NameMacro1 { System.Type t = resource.GetType(); if (t.Equals(typeof(DaggerfallWorkshop.Game.Questing.Place))) { GameManager.Instance.TalkManager.AddDialogForQuestInfoResource(parentQuest.UID, macro.symbol, TalkManager.QuestInfoResourceType.Location); } else if (t.Equals(typeof(DaggerfallWorkshop.Game.Questing.Person))) { GameManager.Instance.TalkManager.AddDialogForQuestInfoResource(parentQuest.UID, macro.symbol, TalkManager.QuestInfoResourceType.Person); } else if (t.Equals(typeof(DaggerfallWorkshop.Game.Questing.Item))) { GameManager.Instance.TalkManager.AddDialogForQuestInfoResource(parentQuest.UID, macro.symbol, TalkManager.QuestInfoResourceType.Thing); } } } } // TODO: Need to store previous macro resource for pronomial context expansions } // Reassemble words and expanded macros back into final token text string final = string.Empty; for (int i = 0; i < words.Length; i++) { final += words[i]; if (i != words.Length - 1) { final += " "; } } // Store result back into token tokens[token].text = final; } }