Пример #1
0
        internal static void Main()
        {
            var nodeID = NWNXDialog.GetCurrentNodeID() - (NumberOfResponsesPerPage + 3);

            nodeID = Math.Abs(nodeID);

            NWGameObject player   = (_.GetPCSpeaker());
            var          playerID = _.GetGlobalID(player);
            PlayerDialog dialog   = Conversation.GetActivePlayerDialog(playerID);

            IConversation convo           = Conversation.FindConversation(dialog.ActiveDialogName);
            int           selectionNumber = nodeID + 1;
            int           responseID      = nodeID + (NumberOfResponsesPerPage * dialog.PageOffset);

            if (selectionNumber == NumberOfResponsesPerPage + 1) // Next page
            {
                dialog.PageOffset = dialog.PageOffset + 1;
            }
            else if (selectionNumber == NumberOfResponsesPerPage + 2) // Previous page
            {
                dialog.PageOffset = dialog.PageOffset - 1;
            }
            else if (selectionNumber == NumberOfResponsesPerPage + 3) // Back
            {
                string currentPageName = dialog.CurrentPageName;
                var    previous        = dialog.NavigationStack.Pop();

                // This might be a little confusing but we're passing the active page as the "old page" to the Back() method.
                // This is because we need to run any dialog-specific clean up prior to moving the conversation backwards.
                convo.Back(player, currentPageName, previous.PageName);

                // Previous page was in a different conversation. Switch to it.
                if (previous.DialogName != dialog.ActiveDialogName)
                {
                    Conversation.Load(player, dialog.DialogTarget, previous.DialogName);
                    dialog = Conversation.GetActivePlayerDialog(playerID);
                    dialog.ResetPage();

                    dialog.CurrentPageName = previous.PageName;
                    dialog.PageOffset      = 0;
                    // ActiveDialogName will have changed by this point. Get the new conversation.
                    convo = Conversation.FindConversation(dialog.ActiveDialogName);
                    convo.Initialize();
                    _.SetLocalInt(player, "DIALOG_SYSTEM_INITIALIZE_RAN", 1);
                }
                // Otherwise it's in the same conversation. Switch to that.
                else
                {
                    dialog.CurrentPageName = previous.PageName;
                    dialog.PageOffset      = 0;
                }
            }
            else if (selectionNumber != NumberOfResponsesPerPage + 4) // End
            {
                convo.DoAction(player, dialog.CurrentPageName, responseID + 1);
            }
        }
Пример #2
0
        public static void OnActionsTaken(int nodeID)
        {
            NWPlayer     player = (_.GetPCSpeaker());
            PlayerDialog dialog = LoadPlayerDialog(player.GlobalID);

            using (new Profiler(nameof(DialogService) + "." + nameof(OnActionsTaken) + "." + dialog.ActiveDialogName))
            {
                IConversation convo           = GetConversation(dialog.ActiveDialogName);
                int           selectionNumber = nodeID + 1;
                int           responseID      = nodeID + (NumberOfResponsesPerPage * dialog.PageOffset);

                if (selectionNumber == NumberOfResponsesPerPage + 1) // Next page
                {
                    dialog.PageOffset = dialog.PageOffset + 1;
                }
                else if (selectionNumber == NumberOfResponsesPerPage + 2) // Previous page
                {
                    dialog.PageOffset = dialog.PageOffset - 1;
                }
                else if (selectionNumber == NumberOfResponsesPerPage + 3) // Back
                {
                    string currentPageName = dialog.CurrentPageName;
                    var    previous        = dialog.NavigationStack.Pop();

                    // This might be a little confusing but we're passing the active page as the "old page" to the Back() method.
                    // This is because we need to run any dialog-specific clean up prior to moving the conversation backwards.
                    convo.Back(player, currentPageName, previous.PageName);

                    // Previous page was in a different conversation. Switch to it.
                    if (previous.DialogName != dialog.ActiveDialogName)
                    {
                        LoadConversation(player, dialog.DialogTarget, previous.DialogName, dialog.DialogNumber);
                        dialog = LoadPlayerDialog(player.GlobalID);
                        dialog.ResetPage();

                        dialog.CurrentPageName = previous.PageName;
                        dialog.PageOffset      = 0;
                        // ActiveDialogName will have changed by this point. Get the new conversation.
                        convo = GetConversation(dialog.ActiveDialogName);
                        convo.Initialize();
                        player.SetLocalInt("DIALOG_SYSTEM_INITIALIZE_RAN", 1);
                    }
                    // Otherwise it's in the same conversation. Switch to that.
                    else
                    {
                        dialog.CurrentPageName = previous.PageName;
                        dialog.PageOffset      = 0;
                    }
                }
                else if (selectionNumber != NumberOfResponsesPerPage + 4) // End
                {
                    convo.DoAction(player, dialog.CurrentPageName, responseID + 1);
                }
            }
        }
Пример #3
0
        protected void SwitchConversation(string conversationName)
        {
            PlayerDialog dialog = _dialog.LoadPlayerDialog(GetPC().GlobalID);

            _dialog.LoadConversation(GetPC(), dialog.DialogTarget, conversationName, dialog.DialogNumber);
            dialog = _dialog.LoadPlayerDialog(GetPC().GlobalID);

            dialog.ResetPage();
            ChangePage(dialog.CurrentPageName);

            IConversation convo = App.ResolveByInterface <IConversation>("Conversation." + dialog.ActiveDialogName);

            convo.Initialize();
            GetPC().SetLocalInt("DIALOG_SYSTEM_INITIALIZE_RAN", 1);
        }
Пример #4
0
        private async Task <bool> tryCreateConversation(ITelegramBotClient client, Update update)
        {
            if (update.Type != UpdateType.CallbackQuery)
            {
                return(false);
            }
            long   chatId           = update.CallbackQuery.Message.Chat.Id;
            string conversationType = update.CallbackQuery.Data;
            Type   t;

            switch (conversationType)
            {
            case TelegramHelper.SetTimeZoneCommand:
                t = typeof(Conversations.TimeZoneConversation);
                break;

            case TelegramHelper.AddReminderCommand:
                t = typeof(Conversations.AddReminderConversation);
                break;

            case TelegramHelper.RemoveReminderCommand:
                t = typeof(Conversations.RemoveReminderConversation);
                break;

            default:
                return(false);
            }
            await client.AnswerCallbackQueryAsync(update.CallbackQuery.Id);

            IConversation conv = (IConversation)Activator.CreateInstance(t);

            this.storeConversation(chatId, conv);
            await conv.Initialize(client, update);

            return(true);
        }
Пример #5
0
        public bool Run(params object[] args)
        {
            int nodeType = (int)args[0];
            int nodeID   = (int)args[1];

            NWPlayer     player = NWPlayer.Wrap(_.GetPCSpeaker());
            PlayerDialog dialog = _dialog.LoadPlayerDialog(player.GlobalID);
            DialogPage   page   = dialog.CurrentPage;
            int          currentSelectionNumber = nodeID + 1;
            bool         displayNode            = false;
            string       newNodeText            = string.Empty;
            int          dialogOffset           = (_dialog.NumberOfResponsesPerPage + 1) * (dialog.DialogNumber - 1);

            if (currentSelectionNumber == _dialog.NumberOfResponsesPerPage + 1) // Next page
            {
                int displayCount = page.NumberOfResponses - (_dialog.NumberOfResponsesPerPage * dialog.PageOffset);

                if (displayCount > _dialog.NumberOfResponsesPerPage)
                {
                    displayNode = true;
                }
            }
            else if (currentSelectionNumber == _dialog.NumberOfResponsesPerPage + 2) // Previous Page
            {
                if (dialog.PageOffset > 0)
                {
                    displayNode = true;
                }
            }
            else if (nodeType == 2)
            {
                int responseID = (dialog.PageOffset * _dialog.NumberOfResponsesPerPage) + nodeID;
                if (responseID + 1 <= page.NumberOfResponses)
                {
                    DialogResponse response = page.Responses[responseID];

                    if (response != null)
                    {
                        newNodeText = response.Text;
                        displayNode = response.IsActive;
                    }
                }
            }
            else if (nodeType == 1)
            {
                IConversation convo = App.ResolveByInterface <IConversation>("Conversation." + dialog.ActiveDialogName);
                if (player.GetLocalInt("DIALOG_SYSTEM_INITIALIZE_RAN") != 1)
                {
                    convo.Initialize();
                    player.SetLocalInt("DIALOG_SYSTEM_INITIALIZE_RAN", 1);
                }

                if (dialog.IsEnding)
                {
                    convo.EndDialog();
                    _dialog.RemovePlayerDialog(player.GlobalID);
                    player.DeleteLocalInt("DIALOG_SYSTEM_INITIALIZE_RAN");
                    return(false);
                }

                page        = dialog.CurrentPage;
                newNodeText = page.Header;

                _.SetCustomToken(90000 + dialogOffset, newNodeText);
                return(true);
            }

            _.SetCustomToken(90001 + nodeID + dialogOffset, newNodeText);
            return(displayNode);
        }