protected virtual bool Visit <T>(ResponseNode <T> node)
 {
     IncreaseDepth();
     Visit(node.Output);
     DecreaseDepth();
     return(true);
 }
Пример #2
0
 private void ConfigureResponseNodes(NodeGraphConfiguration configuration, List <INode> nodes)
 {
     if (configuration.ResponseNodes != null)
     {
         foreach (var responseNodeConfiguration in configuration.ResponseNodes)
         {
             var node = new ResponseNode
             {
                 Name         = responseNodeConfiguration.Name,
                 Disabled     = responseNodeConfiguration.Disabled,
                 StatusCode   = responseNodeConfiguration.StatusCode,
                 ReasonPhrase = responseNodeConfiguration.ReasonPhrase ?? "OK",
                 Content      = responseNodeConfiguration.Content ?? string.Empty,
                 ContentFile  = responseNodeConfiguration.ContentFile,
             };
             if (responseNodeConfiguration.Headers != null)
             {
                 node.HeaderNames  = responseNodeConfiguration.Headers.Select(h => h.HeaderName).ToArray();
                 node.HeaderValues = responseNodeConfiguration.Headers.Select(h => h.HeaderValue).ToArray();
             }
             responseNodeConfiguration.Node = node;
             nodes.Add(node);
         }
     }
 }
        static RemoveActivation AddActivation(RoutingEngineConfigurator configurator,
                                              Activation <Response <T> > consumerNode)
        {
            var messageActivation = new ResponseNode <T>(consumerNode);

            return(configurator.Add(messageActivation));
        }
    void AddNewResponse()
    {
        int        pnodeid    = nodeWindows.FindIndex(x => x.WindowId == resToAdd);
        DialogNode parentNode = nodeWindows[pnodeid].Node;

        resToAdd = -1;

        if (_newDKey == null || _newDKey == "" || _newStrKey == null || _newStrKey == "")
        {
            Debug.Log("Error adding response: missing dialog key and/or string id key");
            return;
        }

        ResponseNode newNode = new ResponseNode(_newDKey, _newStrKey);

        if (dm.Graph.Contains(newNode))
        {
            Debug.Log("Key already exist! Please enter another key");
            return;
        }

        dm.Graph.Add(newNode);
        dm.Graph.AddLink(parentNode, newNode);

        LanguageController.Instance.AddWord(_newStrKey, _newdialog);
    }
        public BaseResponse(string xmlResponseStr)
        {
            Response     = XDocument.Parse(xmlResponseStr);
            ResponseNode = Response.Descendants().Where(x => x.Name == "resp").First();

            var statusValue = ResponseNode.Attributes().Where(a => a.Name == "status").First().Value;

            bool b = false;
            int  i = 0;

            if (bool.TryParse(statusValue, out b))
            {
                Status = b;
            }
            else if (int.TryParse(statusValue, out i))
            {
                Status = Convert.ToBoolean(i);
            }
            else
            {
                Status = false;
            }

            var errorNode = ResponseNode.Descendants().Where(x => x.Name == "error").FirstOrDefault();

            if (errorNode != null)
            {
                var descNode = errorNode.Descendants().Where(x => x.Name == "desc").FirstOrDefault();
                if (descNode != null)
                {
                    ErrorMessage = descNode.Value;
                }
            }
        }
    void OnGUI()
    {
        Event currentEvent = Event.current;

        if (currentEvent.type == EventType.MouseDrag)
        {
            panX += Event.current.delta.x;
            panY += Event.current.delta.y;
        }

        DrawLinks();

        if (nodesToLink.Count >= 2)
        {
            UpdateLink();
        }

        if (resToRemove != null)
        {
            dm.Graph.Remove(resToRemove);
            resToRemove = null;
        }

        if (dialogToRemove > -1)
        {
            RemoveDialog();
            dialogToRemove = -1;
        }
        if (startDialog != -1)
        {
            SetStartDialog();
        }
        if (resToAdd != -1)
        {
            AddNewResponse();
        }

        //GUI.BeginGroup(new Rect(panX, panY, 10000, 10000));
        BeginWindows();

        for (int i = 0; i < windows.Count; ++i)
        {
            windows[i] = GUILayout.Window(nodeWindows[i].WindowId, windows[i], nodeWindows[i].DrawNodeWindow, nodeWindows[i].Node.DKey);
        }

        if (addButton)
        {
            AddNewNode();
        }

        EndWindows();
        //GUI.EndGroup();

        // Draw Side Window
        sideWindowWidth = Math.Min(600, Math.Max(200, (int)(position.width / 5)));
        GUILayout.BeginArea(sideWindowRect, GUI.skin.box);
        DrawSideWindow();
        GUILayout.EndArea();
    }
Пример #7
0
        protected override bool Visit <T>(ResponseNode <T> node)
        {
            _current = GetVertex(node.GetHashCode(), () => "P", typeof(ResponseNode <>), typeof(T));

            LinkFromParent();

            return(WithVertex(() => base.Visit(node)));
        }
Пример #8
0
 internal static ODataResponse FromNode(ITypeCache typeCache, ResponseNode node, IEnumerable <KeyValuePair <string, string> > headers)
 {
     return(new ODataResponse(typeCache)
     {
         Feed = node.Feed ?? new AnnotatedFeed(node.Entry != null ? new[] { node.Entry } : null),
         Headers = headers
     });
 }
Пример #9
0
    public void DrawNodeWindow(int windowId)
    {
        string dialogStr = node.StrKey + "=" + node.GetText();

        GUILayout.Label(dialogStr.Length > 30 ? dialogStr.Substring(0, 30) + "..." : dialogStr);

        if (GUILayout.Button("Attatch"))
        {
            DialogManagerEditor.nodesToLink.Push(node);
        }

        AdjacencyList responses = node.Neighbors;

        GUILayout.BeginVertical();

        foreach (Link l in responses)
        {
            ResponseNode resNode = (ResponseNode)l.Neighbor;

            string resStr = resNode.DKey + ":" + resNode.StrKey + "=" + resNode.GetText();

            GUILayout.BeginHorizontal();

            GUILayout.Box(resStr.Length > 30 ? resStr.Substring(0, 30) + "..." : resStr, GUILayout.MinWidth(230));

            int select = GUILayout.Toolbar(-1, new string[] { "A", "x" }, GUILayout.MaxWidth(45));
            if (select == 0)
            {
                DialogManagerEditor.nodesToLink.Push(resNode);
            }
            else if (select == 1)
            {
                DialogManagerEditor.resToRemove = resNode;
            }

            GUILayout.EndHorizontal();
        }

        GUILayout.EndVertical();

        Event currentEvent = Event.current;

        if (currentEvent.type == EventType.MouseUp && currentEvent.button == 1)
        {
            GenericMenu menu = new GenericMenu();
            menu.AddItem(new GUIContent("Add new response"), false, AddNewResponse, WindowId);
            menu.AddItem(new GUIContent("Remove the dialog"), false, RemoveDialog, WindowId);
            menu.AddItem(new GUIContent("Set as starting dialog"), false, SetStartDialog, WindowId);
            menu.ShowAsContext();
            currentEvent.Use();
        }

        GUI.DragWindow();
    }
Пример #10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="InboundXmlBuilder"/> class.
        /// </summary>
        public InboundXmlBuilder()
        {
            // sets the new document
            XDocument document = new XDocument();

            // creates the response node
            this.requestNode = new ResponseNode();

            // adds the response node to the document
            document.AddFirst(this.requestNode);
        }
 void ToggleLink(ResponseNode linking, DialogNode linkTo)
 {
     if (dm.Graph.ContainsLink(linking, linkTo))
     {
         dm.Graph.RemoveLink(linking, linkTo);
     }
     else
     {
         dm.Graph.AddLink(linking, linkTo);
     }
 }
    void DrawLinks()
    {
        int numNodes = windows.Count;

        for (int i = 0; i < numNodes; ++i)
        {
            Rect          parentNodeShape  = windows[i];
            DialogNodeGUI parentNodeWindow = nodeWindows[i];

            AdjacencyList adjLinks = parentNodeWindow.Node.Neighbors;

            int resIndex = 0;

            while (resIndex < adjLinks.Count)
            {
                ResponseNode resNode = (ResponseNode)adjLinks[resIndex].Neighbor;

                // Remove this link if linking node is removed
                if (!dm.Graph.Contains(resNode))
                {
                    adjLinks.RemoveAt(resIndex);
                    continue;
                }

                // skip current node if this response node does not connect to any dialog
                if (resNode.Neighbor == null)
                {
                    ++resIndex;
                    continue;
                }
                else if (!dm.Graph.Contains(resNode.Neighbor.Neighbor))
                {// if the node to link with does not exist, then remove the link and move to next response node
                    dm.Graph.RemoveLink(resNode, resNode.Neighbor.Neighbor);
                    ++resIndex;
                    continue;
                }

                int nextNodeIndex = nodeWindows.FindIndex(x => x.Node == resNode.Neighbor.Neighbor);

                if (nextNodeIndex < 0)
                {
                    Debug.Log("Cannot find the node to link with. Are you trying to link a response dialog with another response?");
                    dm.Graph.RemoveLink(resNode, resNode.Neighbor.Neighbor);
                    ++resIndex;
                    continue;
                }

                DrawNodeCurve(parentNodeShape, windows[nextNodeIndex], adjLinks.Count, resIndex);

                ++resIndex;
            }
        }
    }
 protected override void ConvertEntry(ResponseNode entryNode, object entry)
 {
     if (entry != null)
     {
         var odataEntry = entry as Microsoft.OData.Core.ODataEntry;
         foreach (var property in odataEntry.Properties)
         {
             entryNode.Entry.Data.Add(property.Name, GetPropertyValue(property.Value));
         }
         entryNode.Entry.SetAnnotations(CreateAnnotations(odataEntry));
     }
 }
Пример #14
0
 protected override void ConvertEntry(ResponseNode entryNode, object entry)
 {
     if (entry != null)
     {
         var odataEntry = entry as Microsoft.Data.OData.ODataEntry;
         foreach (var property in odataEntry.Properties)
         {
             entryNode.Entry.Data.Add(property.Name, GetPropertyValue(property.Value));
         }
         entryNode.Entry.SetAnnotations(CreateAnnotations(odataEntry));
     }
 }
            public static bool ResponseHasScrapPrice(ResponseNode responseNode, out int price)
            {
                foreach (var condition in responseNode.conditions)
                {
                    if (condition.conditionType == ConversationCondition.ConditionType.HASSCRAP)
                    {
                        price = condition.conditionAmount;
                        return(true);
                    }
                }

                price = 0;
                return(false);
            }
Пример #16
0
 protected override void ConvertEntry(ResponseNode entryNode, object entry, bool includeResourceTypeInEntryProperties)
 {
     if (entry != null)
     {
         var odataEntry = entry as Microsoft.OData.Core.ODataEntry;
         foreach (var property in odataEntry.Properties)
         {
             entryNode.Entry.Add(property.Name, GetPropertyValue(property.Value));
         }
         if (includeResourceTypeInEntryProperties)
         {
             var resourceType = odataEntry.TypeName;
             entryNode.Entry.Add(FluentCommand.ResourceTypeLiteral, resourceType.Split('.').Last());
         }
     }
 }
 protected override void ConvertEntry(ResponseNode entryNode, object entry, bool includeResourceTypeInEntryProperties)
 {
     if (entry != null)
     {
         var odataEntry = entry as Microsoft.Data.OData.ODataEntry;
         foreach (var property in odataEntry.Properties)
         {
             entryNode.Entry.Add(property.Name, GetPropertyValue(property.Value));
         }
         if (includeResourceTypeInEntryProperties)
         {
             var resourceType = odataEntry.TypeName;
             entryNode.Entry.Add(FluentCommand.ResourceTypeLiteral, resourceType.Split('.').Last());
         }
     }
 }
        private ODataResponse ReadResponse(ODataReader odataReader, IODataResponseMessageAsync responseMessage)
        {
            ResponseNode rootNode  = null;
            var          nodeStack = new Stack <ResponseNode>();

            while (odataReader.Read())
            {
                if (odataReader.State == ODataReaderState.Completed)
                {
                    break;
                }

                switch (odataReader.State)
                {
                case ODataReaderState.ResourceSetStart:
                case ODataReaderState.DeltaResourceSetStart:
                    StartFeed(nodeStack, CreateAnnotations(odataReader.Item as ODataResourceSetBase));
                    break;

                case ODataReaderState.ResourceSetEnd:
                case ODataReaderState.DeltaResourceSetEnd:
                    EndFeed(nodeStack, CreateAnnotations(odataReader.Item as ODataResourceSetBase), ref rootNode);
                    break;

                case ODataReaderState.ResourceStart:
                    StartEntry(nodeStack);
                    break;

                case ODataReaderState.ResourceEnd:
                    EndEntry(nodeStack, ref rootNode, odataReader.Item);
                    break;

                case ODataReaderState.NestedResourceInfoStart:
                    StartNavigationLink(nodeStack, (odataReader.Item as ODataNestedResourceInfo).Name);
                    break;

                case ODataReaderState.NestedResourceInfoEnd:
                    EndNavigationLink(nodeStack);
                    break;
                }
            }

            return(ODataResponse.FromNode(TypeCache, rootNode, responseMessage.Headers));
        }
Пример #19
0
        private ODataResponse ReadResponse(ODataReader odataReader, bool includeResourceTypeInEntryProperties)
        {
            ResponseNode rootNode  = null;
            var          nodeStack = new Stack <ResponseNode>();

            while (odataReader.Read())
            {
                if (odataReader.State == ODataReaderState.Completed)
                {
                    break;
                }

                switch (odataReader.State)
                {
                case ODataReaderState.FeedStart:
                    StartFeed(nodeStack, CreateFeedAnnotaions(odataReader.Item as ODataFeed));
                    break;

                case ODataReaderState.FeedEnd:
                    EndFeed(nodeStack, CreateFeedAnnotaions(odataReader.Item as ODataFeed), ref rootNode);
                    break;

                case ODataReaderState.EntryStart:
                    StartEntry(nodeStack);
                    break;

                case ODataReaderState.EntryEnd:
                    EndEntry(nodeStack, ref rootNode, odataReader.Item, includeResourceTypeInEntryProperties);
                    break;

                case ODataReaderState.NavigationLinkStart:
                    StartNavigationLink(nodeStack, (odataReader.Item as ODataNavigationLink).Name);
                    break;

                case ODataReaderState.NavigationLinkEnd:
                    EndNavigationLink(nodeStack);
                    break;
                }
            }

            return(rootNode.Feed != null
                ? ODataResponse.FromFeed(rootNode.Feed, rootNode.FeedAnnotations)
                : ODataResponse.FromEntry(rootNode.Entry));
        }
Пример #20
0
        private ODataResponse ReadResponse(ODataReader odataReader)
        {
            ResponseNode rootNode  = null;
            var          nodeStack = new Stack <ResponseNode>();

            while (odataReader.Read())
            {
                if (odataReader.State == ODataReaderState.Completed)
                {
                    break;
                }

                switch (odataReader.State)
                {
                case ODataReaderState.FeedStart:
                    StartFeed(nodeStack, CreateFeedDetails(odataReader.Item as ODataFeed));
                    break;

                case ODataReaderState.FeedEnd:
                    EndFeed(nodeStack, CreateFeedDetails(odataReader.Item as ODataFeed), ref rootNode);
                    break;

                case ODataReaderState.EntryStart:
                    StartEntry(nodeStack);
                    break;

                case ODataReaderState.EntryEnd:
                    EndEntry(nodeStack, ref rootNode, odataReader.Item);
                    break;

                case ODataReaderState.NavigationLinkStart:
                    StartNavigationLink(nodeStack, (odataReader.Item as ODataNavigationLink).Name);
                    break;

                case ODataReaderState.NavigationLinkEnd:
                    EndNavigationLink(nodeStack);
                    break;
                }
            }

            return(ODataResponse.FromNode(rootNode));
        }
Пример #21
0
    void initDialogGraph()
    {
        graph = new DialogGraph();

        DialogNode d1  = new DialogNode("npc1q1", "where");
        DialogNode d2  = new ResponseNode("q1a1", "bigbrother");
        DialogNode d3  = new ResponseNode("q1a2", "here");
        DialogNode d4  = new DialogNode("npc1q2", "voteout");
        DialogNode d5  = new ResponseNode("q2a1", "watchfordrama");
        DialogNode d6  = new DialogNode("npc1q3", "blind");
        DialogNode d7  = new ResponseNode("q3a1", "surprised");
        DialogNode d11 = new ResponseNode("q3a2", "getperscription");
        DialogNode d8  = new DialogNode("npc1q4", "thedrama");
        DialogNode d9  = new DialogNode("npc1q5", "uhh");
        DialogNode d10 = new DialogNode("npc1q6", "notold");

        graph.Root = d1;
        graph.Add(d1);
        graph.Add(d2);
        graph.Add(d3);
        graph.Add(d4);
        graph.Add(d5);
        graph.Add(d6);
        graph.Add(d7);
        graph.Add(d8);
        graph.Add(d9);
        graph.Add(d10);
        graph.Add(d11);
        graph.AddLink(d1, d2);
        graph.AddLink(d1, d3);
        graph.AddLink(d2, d4);
        graph.AddLink(d4, d5);
        graph.AddLink(d5, d8);
        graph.AddLink(d3, d6);
        graph.AddLink(d6, d7);
        graph.AddLink(d6, d11);
        graph.AddLink(d7, d9);
        graph.AddLink(d11, d10);
        //graph.AddLink(d11, d1);
    }
Пример #22
0
    protected void EndEntry(Stack <ResponseNode> nodeStack, ref ResponseNode rootNode, object entry)
    {
        var entryNode = nodeStack.Pop();

        ConvertEntry(entryNode, entry);
        if (nodeStack.Any())
        {
            var node = nodeStack.Peek();
            if (node.Feed != null)
            {
                node.Feed.Entries.Add(entryNode.Entry);
            }
            else
            {
                node.Entry = entryNode.Entry;
            }
        }
        else
        {
            rootNode = entryNode;
        }
    }
Пример #23
0
        public ResponseTile(
            DrawingElement drawing,
            ResponseNode response,
            DashboardConfiguration.NodeConfiguration nodeConfiguration)
            : base(
                drawing,
                nodeConfiguration?.Title ?? "Response",
                "responder",
                response.Offline,
                2,
                response.Name)
        {
            LinkUrl = "/ui/node?name=" + response.Name;

            var details = new List <string>();

            details.Add(response.StatusCode + " " + response.ReasonPhrase);

            if (response.HeaderNames != null)
            {
                for (var i = 0; i < response.HeaderNames.Length; i++)
                {
                    details.Add(response.HeaderNames[i] + ": " + response.HeaderValues[i]);
                }
            }

            if (!string.IsNullOrEmpty(response.ContentFile))
            {
                details.Add("[" + response.ContentFile + "]");
            }
            else if (!string.IsNullOrWhiteSpace(response.Content))
            {
                details.Add(response.Content);
            }

            AddDetails(details, null, response.Offline ? "disabled" : string.Empty);
        }
Пример #24
0
 public virtual bool ContainsLink(DialogNode u, ResponseNode v)
 {
     return(u.Neighbors.Contains(v));
 }
Пример #25
0
 public virtual bool ContainsLink(ResponseNode u, DialogNode v)
 {
     return(u.Neighbor != null && (u.Neighbor.Neighbor == null || u.Neighbor.Neighbor.Equals(v)));
 }
Пример #26
0
    protected void EndFeed(Stack <ResponseNode> nodeStack, ODataFeedAnnotations feedAnnotations, ref ResponseNode rootNode)
    {
        var feedNode = nodeStack.Pop();

        if (nodeStack.Any())
        {
            nodeStack.Peek().Feed = feedNode.Feed;
        }
        else
        {
            rootNode = feedNode;
        }

        feedNode.Feed.SetAnnotations(feedAnnotations);
    }
Пример #27
0
 protected abstract void ConvertEntry(ResponseNode entryNode, object entry);
            public override string Intercept(NPCTalking npcTalking, BasePlayer player, ConversationData conversationData, ResponseNode responseNode)
            {
                if (responseNode.actionString != _matchResponseAction)
                {
                    return(string.Empty);
                }

                int vanillaPrice;

                if (!ConversationUtils.ResponseHasScrapPrice(responseNode, out vanillaPrice))
                {
                    return(string.Empty);
                }

                var priceConfig = _getVehicleConfig().GetPriceForPlayer(player.IPlayer, _freePermission);

                if (priceConfig == null || priceConfig.MatchesVanillaPrice(vanillaPrice))
                {
                    return(string.Empty);
                }

                var neededScrap           = PlayerInventoryUtils.GetPlayerNeededScrap(player, vanillaPrice);
                var canAffordVanillaPrice = neededScrap <= 0;
                var canAffordCustomPrice  = priceConfig.CanPlayerAfford(player);

                if (!canAffordCustomPrice)
                {
                    return(ConversationUtils.SpeechNodes.Goodbye);
                }

                // Add scrap so the vanilla checks will pass. Add full amount for simplicity.
                player.inventory.containerMain.AddItem(ItemManager.itemDictionary[ScrapItemId], vanillaPrice);

                // Check conditions just in case, to make sure we don't give free scrap.
                if (!responseNode.PassesConditions(player, npcTalking))
                {
                    _pluginInstance.LogError($"Price adjustment unexpectedly failed for price config (response: '{_matchResponseAction}', player: {player.userID}).");
                    player.inventory.containerMain.AddItem(ItemManager.itemDictionary[ScrapItemId], -vanillaPrice);
                    return(string.Empty);
                }

                priceConfig.TryChargePlayer(player, vanillaPrice);

                return(string.Empty);
            }
            public override string Intercept(NPCTalking npcTalking, BasePlayer player, ConversationData conversationData, ResponseNode responseNode)
            {
                int vanillaPrice;

                if (!ConversationUtils.PrecedesPaymentOption(conversationData, responseNode, _matchResponseAction, out vanillaPrice))
                {
                    return(string.Empty);
                }

                var priceConfig = _getVehicleConfig().GetPriceForPlayer(player.IPlayer, _freePermission);

                if (priceConfig == null || priceConfig.MatchesVanillaPrice(vanillaPrice))
                {
                    return(string.Empty);
                }

                var neededScrap           = PlayerInventoryUtils.GetPlayerNeededScrap(player, vanillaPrice);
                var canAffordVanillaPrice = neededScrap <= 0;
                var canAffordCustomPrice  = priceConfig.CanPlayerAfford(player);

                CostLabelUI.Create(player, priceConfig);

                if (canAffordCustomPrice == canAffordVanillaPrice)
                {
                    return(string.Empty);
                }

                if (!canAffordCustomPrice)
                {
                    // Reduce scrap that will be removed to just below the amount they need for vanilla.
                    neededScrap--;
                }

                // Add or remove scrap so the vanilla logic for showing the payment option will match the custom payment logic.
                PlayerInventoryUtils.UpdateWithFakeScrap(player, neededScrap);

                // This delay needs to be long enough for the text to print out, which could vary by language.
                player.Invoke(() => PlayerInventoryUtils.Refresh(player), 3f);

                return(string.Empty);
            }
Пример #30
0
 protected override void ConvertEntry(ResponseNode entryNode, object entry)
 {
     base.ConvertEntry(entryNode, entry);
 }
 public abstract string Intercept(NPCTalking npcTalking, BasePlayer player, ConversationData conversationData, ResponseNode responseNode);
            public override string Intercept(NPCTalking npcTalking, BasePlayer player, ConversationData conversationData, ResponseNode responseNode)
            {
                int vanillaPrice;

                if (!ConversationUtils.PrecedesPaymentOption(conversationData, responseNode, _matchResponseAction, out vanillaPrice))
                {
                    return(string.Empty);
                }

                if (!_getVehicleConfig().RequiresPermission)
                {
                    return(string.Empty);
                }

                if (_pluginInstance.HasPermissionAny(player.UserIDString, Permission_Allow_All, _allowPermission))
                {
                    return(string.Empty);
                }

                _pluginInstance.ChatMessage(player, "Error.Vehicle.NoPermission");
                return(ConversationUtils.SpeechNodes.Goodbye);
            }