/// <summary> /// Requests a list of topics /// </summary> /// <param name="npc">Required, reference to the topics owning npc</param> /// <param name="player">Required, reference to the conversing player</param> /// <param name="worldContext">Not required, but could be, depending on the settings of certain dialogs</param> /// <param name="language">The language the conversing player should receive an answer in</param> /// <returns></returns> public Conversation GetAvailableTopics(IDialogRelevantNpc npc, IDialogRelevantPlayer player, IDialogRelevantWorld worldContext, DialogLanguage language) { var availableTopics = new List<Dialog>(); for (var i = 0; i < _conversations.Count; i++) { if (CheckAvailability(_conversations[i], npc, player, worldContext)) { availableTopics.Add(_conversations[i]); } } if (availableTopics.Count == 1) //return directly { var title = GetDialogStringOrFallback(language, _conversations[0].Title.GetString, _conversations[0].ID); var text = GetDialogStringOrFallback(language, _conversations[0].GetText().GetString, _conversations[0].ID); return new Conversation(availableTopics[0].ID, title, text, availableTopics[0].Tag, ConversationType.Single, GetAvailableAnswers(availableTopics[0], npc, player, worldContext, language)); } if (availableTopics.Count > 1) //create list { var answers = new List<Conversation.Answer>(); for (var i = 0; i < availableTopics.Count; i++) { var title = GetDialogStringOrFallback(language, availableTopics[i].Title.GetString, availableTopics[i].ID); var ca = new Conversation.Answer(availableTopics[i].ID, title, availableTopics[i].Tag); answers.Add(ca); } return new Conversation(-1, "", "", "", ConversationType.TopicList, answers); } return null; }
/// <summary> /// Set the text of the current node for given language/gender /// This will only work in a starting conditional script (action taken comes after the text is displayed) /// </summary> /// <param name="text">The text for the node.</param> /// <param name="language">The language of the text.</param> /// <param name="gender">The gender for the text.</param> public static void SetCurrentNodeText(string text, DialogLanguage language = DialogLanguage.English, Gender gender = Gender.Male) { string sFunc = "SetCurrentNodeText"; NWNX_PushArgumentInt(NWNX_Dialog, sFunc, (int)gender); NWNX_PushArgumentInt(NWNX_Dialog, sFunc, (int)language); NWNX_PushArgumentString(NWNX_Dialog, sFunc, text); NWNX_CallFunction(NWNX_Dialog, sFunc); }
/// <summary> /// Get the text of the current node /// </summary> /// <param name="language">The language of the text.</param> /// <param name="gender">The gender for the text.</param> /// <returns></returns> public static string GetCurrentNodeText(DialogLanguage language = DialogLanguage.English, Gender gender = Gender.Male) { string sFunc = "GetCurrentNodeText"; NWNX_PushArgumentInt(NWNX_Dialog, sFunc, (int)gender); NWNX_PushArgumentInt(NWNX_Dialog, sFunc, (int)language); NWNX_CallFunction(NWNX_Dialog, sFunc); return(NWNX_GetReturnValueString(NWNX_Dialog, sFunc)); }
private void ApplyLang(DialogLanguage Lang) { Title = Lang.Title; textBlock.Text = Lang.ErrorMsg; ContainsData.Text = Lang.CantainsData; Report.Content = Lang.ReportError; DoNotReport.Content = Lang.DoNotReportError; IgnoreB.Content = Lang.IgnoreTheError; CurrentLanguage = Lang; }
string GetDialogStringOrFallback(DialogLanguage lang, LocalizedString.LocalizedStringDelegate getString, int referenceID) { string txt; if (getString(lang, out txt)) { return txt; } switch (Fallback) { case LocalizationFallback.Language: if (getString(FallbackLanguage, out txt)) { return txt; } goto default; // ReSharper disable once RedundantCaseLabel case LocalizationFallback.DebugOutput: default: return string.Format(DebugStringFormat, referenceID); case LocalizationFallback.EmptyString: return string.Empty; } }
List<Conversation.Answer> GetAvailableAnswers(Dialog d, IDialogRelevantNpc npc, IDialogRelevantPlayer player, IDialogRelevantWorld worldContext, DialogLanguage language) { var answers = new List<Conversation.Answer>(); for (var i = 0; i < d.Options.Count; i++) { if (d.Options[i].NextDialog == null) { var text = GetDialogStringOrFallback(language, d.Options[i].Text.GetString, d.ID); answers.Add(new Conversation.Answer(i, text, d.Options[i].Tag)); } else if (CheckAvailability(d.Options[i].NextDialog, npc, player, worldContext)) { var text = GetDialogStringOrFallback(language, d.Options[i].Text.GetString, d.ID); answers.Add(new Conversation.Answer(i, text, d.Options[i].Tag)); } } if (answers.Count == 0 && UseEndConversationfallback) { var txt = GetDialogStringOrFallback(language, _endConversationFallback.GetString, -1); answers.Add(new Conversation.Answer(-1, txt, "")); } return answers; }
/// <summary> /// Retrieves the dialog following the supplied answer from a previous conversation /// </summary> /// <param name="npc">Required, reference to the topics owning npc</param> /// <param name="player">Required, reference to the conversing player</param> /// <param name="worldContext">Not required, but could be, depending on the settings of certain dialogs</param> /// <param name="previous">Conversation the answer is based on</param> /// <param name="answer">Answer of the previous dialog</param> /// <param name="language">The language the conversing player should receive an answer in</param> /// <returns></returns> public Conversation Answer(IDialogRelevantNpc npc, IDialogRelevantPlayer player, IDialogRelevantWorld worldContext, Conversation previous, Conversation.Answer answer, DialogLanguage language) { if (previous == null) { return null; } Dialog activeDialog; if (previous.ID == -1) //from list return selected { activeDialog = GetDialog(answer.Index); if (activeDialog == null || !CheckAvailability(activeDialog, npc, player, worldContext)) { Debug.LogWarning("Selection from topicList invalid"); return null; } var title = GetDialogStringOrFallback(language, activeDialog.Title.GetString, activeDialog.ID); var text = GetDialogStringOrFallback(language, activeDialog.GetText().GetString, activeDialog.ID); return new Conversation(activeDialog.ID, title, text, activeDialog.Tag, ConversationType.Single, GetAvailableAnswers(activeDialog, npc, player, worldContext, language)); } activeDialog = GetDialog(previous.ID); if (activeDialog == null) { return null; } if (answer.Index >= 0 && answer.Index < activeDialog.Options.Count) { var chosenOption = activeDialog.Options[answer.Index]; for (var i = 0; i < chosenOption.Actions.Count; i++) { chosenOption.Actions[i].Execute(activeDialog, player, npc, worldContext); } if (chosenOption.NextDialog == null) return null; if (chosenOption.IgnoreRequirements || CheckAvailability(chosenOption.NextDialog, npc, player, worldContext)) { var title = GetDialogStringOrFallback(language, chosenOption.NextDialog.Title.GetString, chosenOption.NextDialog.ID); var text = GetDialogStringOrFallback(language, chosenOption.NextDialog.GetText().GetString, chosenOption.NextDialog.ID); return new Conversation(chosenOption.NextDialog.ID, title, text, chosenOption.NextDialog.Tag, ConversationType.Single, GetAvailableAnswers(chosenOption.NextDialog, npc, player, worldContext, language)); } } else { if (answer.Index < 0) //dialog end { return null; } Debug.LogWarning("AnswerIndex out of bounds"); } return null; }