Inheritance: NodeData
Example #1
0
        protected override void UpdateOutEdges(Graph graph)
        {
            GameMasterNode arcFile = NodeFile.Owner;
            ArcNodeData    arc     = arcFile?.NodeData as ArcNodeData;

            if (arc != null)
            {
                foreach (string inEdgeName in mOutEdgeStrings)
                {
                    List <GameMasterNode> linkedEncounters = arc.GetEncountersWithInEdge(inEdgeName);
                    if (linkedEncounters.Count == 1 && linkedEncounters[0].Name.Equals(inEdgeName))
                    {
                        if (mChoiceEdgeInfo.ContainsKey(inEdgeName))
                        {
                            foreach (string choice in mChoiceEdgeInfo[inEdgeName])
                            {
                                Node choiceNode = graph.AddNode(NodeFile.Id + "#" + choice);
                                choiceNode.LabelText = '"' + choice + '"';
                                MakeNodePrivate(choiceNode);
                                graph.AddEdge(NodeFile.Id, choiceNode.Id).UserData            = inEdgeName;
                                graph.AddEdge(choiceNode.Id, linkedEncounters[0].Id).UserData = inEdgeName;
                            }
                        }
                        else
                        {
                            graph.AddEdge(NodeFile.Id, linkedEncounters[0].Id).UserData = inEdgeName;
                        }
                    }
                    else
                    {
                        Node arcOutNode = graph.AddNode(arcFile.Id + "#" + inEdgeName);
                        arcOutNode.LabelText = inEdgeName;
                        MakeNodePrivate(arcOutNode);
                        if (mChoiceEdgeInfo.ContainsKey(inEdgeName))
                        {
                            foreach (string choice in mChoiceEdgeInfo[inEdgeName])
                            {
                                Node choiceNode = graph.AddNode(NodeFile.Id + "#" + choice);
                                choiceNode.LabelText = '"' + choice + '"';
                                MakeNodePrivate(choiceNode);
                                graph.AddEdge(NodeFile.Id, choiceNode.Id).UserData   = inEdgeName;
                                graph.AddEdge(choiceNode.Id, arcOutNode.Id).UserData = inEdgeName;
                            }
                        }
                        else
                        {
                            graph.AddEdge(NodeFile.Id, arcOutNode.Id).UserData = inEdgeName;
                        }

                        foreach (GameMasterNode linkedEncounter in linkedEncounters)
                        {
                            graph.AddEdge(arcOutNode.Id, linkedEncounter.Id).UserData = inEdgeName;
                        }
                    }
                }
            }
        }
Example #2
0
        // Returns list of out edges
        private List <string> GetOutEdges()
        {
            List <string>  outEdges = new List <string>();
            GameMasterNode arcFile  = NodeFile.Owner;

            if (arcFile != null)
            {
                ArcNodeData arc = arcFile.NodeData as ArcNodeData;
                foreach (string inEdgeName in mOutEdgeStrings)
                {
                    foreach (GameMasterNode linkedEncounter in arc.GetEncountersWithInEdge(inEdgeName))
                    {
                        outEdges.Add(linkedEncounter.Id);
                    }
                }
            }

            return(outEdges);
        }
Example #3
0
        public override NodeData Clone(GameMasterNode nodeFile)
        {
            EncounterNodeData newNodeData = new EncounterNodeData();

            newNodeData.NodeFile        = nodeFile;
            newNodeData.mEncounterType  = mEncounterType;
            newNodeData.mInEdge         = mInEdge;
            newNodeData.mOutEdgeStrings = new List <string>();
            newNodeData.mIsStartNode    = mIsStartNode;

            if (NodeFile.Owner != null && NodeFile.Owner.NodeType == GameMasterNodeType.ARC)
            {
                ArcNodeData ownerArcData = NodeFile.Owner.NodeData as ArcNodeData;
                ownerArcData.AddEncounter(newNodeData);
                nodeFile.Owner = NodeFile.Owner;
            }

            return(newNodeData);
        }
Example #4
0
        public override bool AddOutEdge(GameMasterNode nodeFile)
        {
            if (nodeFile.NodeType != GameMasterNodeType.ENCOUNTER)
            {
                return(false);
            }

            EncounterNodeData encounterData = nodeFile.NodeData as EncounterNodeData;
            string            inEdge        = encounterData.InEdge;

            if (encounterData.IsStartNode)
            {
                // Cannot add start nodes to an encounter. they should be added to arc
                return(false);
            }

            List <string> outEdges = GetOutEdges();

            if (outEdges.Contains(nodeFile.Id))
            {
                // This item is already part of the out edges
                return(false);
            }

            if (!mOutEdgeStrings.Contains(inEdge))
            {
                // This out edge isn't already in the list of possible out edges, see if we can add it.
                switch (mEncounterType)
                {
                case "generator":
                    // Cannot add more than one edge to generator
                    return(false);

                case "random_out_edge":
                    JObject randomOutEdgesDictionary = (JObject)NodeFile.Json["random_out_edge_info"]["out_edges"];
                    randomOutEdgesDictionary.Add(inEdge, JObject.Parse(@"{""weight"":1 }"));
                    mOutEdgeStrings.Add(inEdge);
                    break;

                case "collection_quest":
                    return(false);

                case "dialog_tree":
                    // We can't add to a dialog tree, you have to specify a node.
                    return(false);

                case "counter":
                    // Cannot add to a counter because it either does fail or success
                    return(false);

                default:
                    NodeFile.Json.Remove("out_edge");
                    mOutEdgeStrings.Add(inEdge);
                    NodeFile.Json.Add("out_edge", JsonConvert.SerializeObject(mOutEdgeStrings));
                    break;
                }
            }

            if (nodeFile.Owner != NodeFile.Owner)
            {
                // make sure encounter is added to this tree
                ArcNodeData ownerArcData = NodeFile.Owner.NodeData as ArcNodeData;
                ownerArcData.AddEncounter(encounterData);
                nodeFile.Owner = NodeFile.Owner;
            }

            NodeFile.IsModified = true;
            return(true);
        }