コード例 #1
0
ファイル: UserChatDialogState.cs プロジェクト: wtfcolt/game
        /// <summary>
        /// Attempts to start a chat dialog with the given <paramref name="npc"/>.
        /// </summary>
        /// <param name="npc">NPC to start the chat dialog with.</param>
        /// <returns>True if the dialog was started with the <paramref name="npc"/>; otherwise false.</returns>
        public bool StartChat(NPC npc)
        {
            // Check if the chat can be started
            if (!CanStartChat(npc))
            {
                return(false);
            }

            _chattingWith = npc;

            // Tell the client to open the dialog
            using (var pw = ServerPacket.StartChatDialog(npc.MapEntityIndex, ChatDialog.ID))
            {
                _user.Send(pw, ServerMessageType.GUI);
            }

            // Get the first page to use
            var initialPage = ChatDialog.GetInitialDialogItem();

            Debug.Assert(initialPage != null);
            _dialogItem = GetNextDialogPage(initialPage);

            // Tell the user which page to use
            NotifyUserOfNewPage();

            return(true);
        }
コード例 #2
0
        public void SetPageIndex(NPCChatDialogItemID pageID, IEnumerable <byte> responsesToSkip)
        {
            _page = _dialog.GetDialogItem(pageID);

            if (_page == null)
            {
                const string errmsg =
                    "Page `{0}` in dialog `{1}` is null. The Client should never be trying to set an invalid page.";
                if (log.IsErrorEnabled)
                {
                    log.ErrorFormat(errmsg, pageID, _dialog);
                }
                Debug.Fail(string.Format(errmsg, pageID, _dialog));
                EndDialog();
                return;
            }

            if (responsesToSkip != null)
            {
                _responses = _page.Responses.Where(x => !responsesToSkip.Contains(x.Value)).OrderBy(x => x.Value).ToArray();
            }
            else
            {
                _responses = _page.Responses.OrderBy(x => x.Value).ToArray();
            }

            _dialogTextControl.Text = _page.Text;
            SetResponseOffset(0);
            IsVisible = true;
        }
コード例 #3
0
ファイル: UserChatDialogState.cs プロジェクト: wtfcolt/game
        /// <summary>
        /// Forces the chat session to end if it has not already.
        /// </summary>
        public void EndChat()
        {
            if (!IsChatting)
            {
                return;
            }

            _dialogItem   = null;
            _chattingWith = null;

            NotifyUserOfNewPage();
        }
コード例 #4
0
ファイル: UserChatDialogState.cs プロジェクト: wtfcolt/game
        /// <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);
        }
コード例 #5
0
ファイル: UserChatDialogState.cs プロジェクト: wtfcolt/game
        /// <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();
            }
        }