/// <summary> /// If the given <paramref name="page"/> is a dialog-less page, this will skip to the next page /// that contains dialog. If the <paramref name="page"/> has dialog, this will just return /// that same <paramref name="page"/>. /// </summary> /// <param name="page">The page to attempt to skip through.</param> /// <returns>The page to use, or null if the dialog has ended.</returns> NPCChatDialogItemBase GetNextDialogPage(NPCChatDialogItemBase page) { // Skip until we find a null page, or we are no longer at a branch while (page != null && page.IsBranch) { // Evaluate the branch to get the response var branchResponse = page.EvaluateBranch(_user, _chattingWith); // Make sure we execute any actions on the response if (branchResponse.Actions != null) { foreach (var action in branchResponse.Actions) { action.Execute(_user, _chattingWith); } } // Get the next dialog item page from the response page = ChatDialog.GetDialogItem(branchResponse.Page); } return(page); }
/// <summary> /// Progresses the chat dialog by using the given <paramref name="responseIndex"/>. /// </summary> /// <param name="responseIndex">The index of the response to use for the current dialog page.</param> /// <exception cref="Exception">The <see cref="_responseConditionalFailureType"/> is invalid.</exception> public void EnterResponse(byte responseIndex) { // Ensure there is a chat session going on if (!IsChatting) { const string errmsg = "Could not enter response of index `{0}` since there is no chat session active."; if (log.IsErrorEnabled) { log.ErrorFormat(errmsg, responseIndex); } Debug.Fail(string.Format(errmsg, responseIndex)); return; } // Check for a valid range if (!_user.Intersects(_chattingWith)) { if (log.IsInfoEnabled) { log.Info("Dialog aborted since the User is no longer near the target."); } EndChat(); return; } // Get the response var response = _dialogItem.GetResponse(responseIndex); if (response == null) { EndChat(); return; } Debug.Assert(response.Value == responseIndex, "Something went wrong, and we got the wrong response. lolwtf?"); // Ensure the selected response index is allowed (response conditionals check) if (!response.CheckConditionals(_user, _chattingWith)) { #pragma warning disable 162 switch (_responseConditionalFailureType) { case ResponseConditionalFailureHandleType.EndDialog: EndChat(); return; case ResponseConditionalFailureHandleType.ResendDialogItem: NotifyUserOfNewPage(); return; default: throw new Exception("Invalid _responseConditionalFailureType."); } #pragma warning restore 162 } // Execute the actions if (response.Actions != null) { foreach (var action in response.Actions) { action.Execute(_user, _chattingWith); } } // Get the next page var nextPage = ChatDialog.GetDialogItem(response.Page); nextPage = GetNextDialogPage(nextPage); // Set the new page _dialogItem = nextPage; // Check if the dialog has ended, otherwise just notify the user of the new page if (_dialogItem == null) { EndChat(); } else { NotifyUserOfNewPage(); } }