예제 #1
0
    void Awake()
    {
        //Check if instance already exists
        if (instance == null)
        {
            instance = this;
        }

        //If instance already exists and it's not this then destroy
        else if (instance != this)
        {
            Destroy(gameObject);
        }

        if (curGameObjectA.GetComponent <QuestNode>())
        {
            curQuestA = curGameObjectA.GetComponent <QuestNode>();
        }

        if (curGameObjectB.GetComponent <QuestNode>())
        {
            curQuestB = curGameObjectB.GetComponent <QuestNode>();
        }

        if (curQuestA == curQuestB)
        {
            sameQuest = true;
        }
    }
예제 #2
0
        public static bool TestRun(QuestNode __instance, ref bool __result, Slate slate)
        {
            int tid = Thread.CurrentThread.ManagedThreadId;

            lock (RimThreaded.timeoutExemptThreads2)
            {
                RimThreaded.timeoutExemptThreads2.Add(tid, 30000); //30 s
            }

            //尝试下看看行不行
            try
            {
                Action <QuestNode, Slate> action;
                if (slate.TryGet <Action <QuestNode, Slate> >("testRunCallback", out action, false) && action != null)
                {
                    action(__instance, slate);
                }
                __result = (bool)TestRunInt.Invoke(__instance, new object[] { slate });
            }
            catch (Exception ex)
            {
                Log.Error(string.Concat(new object[]
                {
                    "Exception test running ",
                    __instance.GetType().Name,
                    ": ",
                    ex,
                    "\n\nSlate vars:\n",
                    slate.ToString()
                }), false);
                __result = false;
            }

            return(false);
        }
예제 #3
0
 public static bool HasMapNode(QuestNode node)
 {
     if (node is QuestNode_GenerateSite || node is QuestNode_GenerateWorldObject || node is QuestNode_GetSiteTile)
     {
         return(true);
     }
     else if (node is QuestNode_RandomNode randomNode)
     {
         foreach (var node2 in randomNode.nodes)
         {
             if (HasMapNode(node2))
             {
                 return(true);
             }
         }
     }
     else if (node is QuestNode_Sequence sequence)
     {
         foreach (var node3 in sequence.nodes)
         {
             if (HasMapNode(node3))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
예제 #4
0
 /// <summary>
 /// Adds quests to a quest log
 /// </summary>
 /// <param name="questToAdd">The quest</param>
 /// <param name="prerequisites">A list of prerequisite Quests</param>
 public void Add(Quest questToAdd, params Quest [] prerequisites)
 {
     if (head == null && prerequisites.Length != 0)
     {
         throw new ArgumentException("The first quest cannot have prerequisites");
     }
     else if (head == null)
     {
         head = new QuestNode(questToAdd);
     }
 }
예제 #5
0
 public override void OnBodyGUI()
 {
     base.OnBodyGUI();
     QuestNode  node  = target as QuestNode;
     QuestGraph graph = node.graph as QuestGraph;
     //if (GUILayout.Button("MoveNext Node")) node.MoveNext();
     //if (GUILayout.Button("Continue Graph")) graph.Continue();
     //if (GUILayout.Button("Set as current"))
     //{
     //    graph.leaves.Clear();
     //    graph.leaves.Add(node);
     //}
 }
예제 #6
0
 void PopulateObjects()
 {
     qLocs         = GameObject.FindObjectsOfType(typeof(QLocation)) as QLocation[];
     qNpcs         = GameObject.FindObjectsOfType(typeof(QNpc)) as QNpc[];
     typeBoxes     = new Dictionary <QuestNode, ComboBox>();
     npcBoxes      = new Dictionary <QuestNode, ComboBox>();
     locationBoxes = new Dictionary <QuestNode, ComboBox>();
     selNode       = new ComboBox();
     setUpComboBox();
     first        = new QuestNode("FirstNode", qNpcs[0] as MonoBehaviour, 0, 0);
     currentQuest = new QuestModel(first);
     typeBoxes.Add(first, new ComboBox());
     npcBoxes.Add(first, new ComboBox());
     locationBoxes.Add(first, new ComboBox());
 }
예제 #7
0
    public void GetNodeList(QuestNode node, Dictionary <string, QuestNode> oList)
    {
        if (node.getOutcomeNodes().Count > 0)
        {
            foreach (QuestNode n in node.getOutcomeNodes())
            {
                GetNodeList(n, oList);
            }
        }

        if (!oList.ContainsKey(node.getQuestID()))
        {
            oList.Add(node.getQuestID(), node);
        }
    }
예제 #8
0
        public override void OnHeaderGUI()
        {
            GUI.color = Color.white;
            QuestNode  node  = target as QuestNode;
            QuestGraph graph = node.graph as QuestGraph;

            //if (graph.leaves.Contains(node)) GUI.color = Color.yellow;
            if (node.Active)
            {
                GUI.color = Color.yellow;
            }
            string title = target.name;

            GUILayout.Label(title, NodeEditorResources.styles.nodeHeader, GUILayout.Height(30));
            GUI.color = Color.white;
        }
예제 #9
0
    private void InitNode(QuestNode q)
    {
        q.advanceConditions = new Dictionary <int, bool>();
        q.taskDescription   = new Dictionary <int, string> ();
        for (int j = 0; j < q.tasks.Length; ++j)
        {
            // Set every task to false.
            q.advanceConditions.Add(q.tasks[j], false);

            // Set the description of every task.
            q.taskDescription.Add(q.tasks[j], q.taskDescriptions[j]);
        }
        for (int k = 0; k < q.next.Length; ++k)
        {
            InitNode(q.next[k]);
        }
    }
예제 #10
0
    // Use this for initialization
    void Start()
    {
        if (curGameObjectA.GetComponent <QuestNode>())
        {
            curQuestA = curGameObjectA.GetComponent <QuestNode>();
        }

        if (curGameObjectB.GetComponent <QuestNode>())
        {
            curQuestB = curGameObjectB.GetComponent <QuestNode>();
        }

        if (curQuestA == curQuestB)
        {
            sameQuest = true;
        }
    }
예제 #11
0
        public override void OnDropObjects(UnityEngine.Object[] objects)
        {
            float offset = 100;

            for (int i = 0; i < objects.Length; i++)
            {
                UnityEngine.Object obj = objects[i];
                if (obj.GetType() == typeof(QuestGraph))
                {
                    QuestGraph draggedQuest = (QuestGraph)obj;
                    QuestGraph graph        = (QuestGraph)target;
                    QuestNode  closest      = null;
                    float      minDist      = float.PositiveInfinity;

                    foreach (Node n in graph.nodes)
                    {
                        if (n is QuestNode questNode)
                        {
                            Vector2 dist = NodeEditorWindow.current.MousePosition - questNode.position;
                            Debug.Log(dist.magnitude);

                            if (questNode == null || minDist > dist.magnitude)
                            {
                                Debug.Log("Set");
                                minDist = dist.magnitude;
                                closest = questNode;
                            }
                        }
                    }

                    if (closest == null)
                    {
                        QuestNode node = (QuestNode)CreateNode(typeof(QuestNode), new Vector2(i * offset, i * offset));
                        node.Quest = draggedQuest;
                        node.Quest.SetParent((QuestGraph)node.graph);
                    }
                    else
                    {
                        closest.Quest = draggedQuest;
                        draggedQuest.SetParent(graph);
                    }
                }
            }
        }
예제 #12
0
 public void TestNode(QuestNode node, Pawn questGiver, QuestScriptDef script)
 {
     if (node is QuestNode_Sequence sequence)
     {
         foreach (var newNode in sequence.nodes.ListFullCopy())
         {
             Log.Message(script + " - Node2: " + newNode);
             TestNode(newNode, questGiver, script);
         }
     }
     else if (node is QuestNode_RandomNode randomNode)
     {
         foreach (var newNode in randomNode.nodes)
         {
             Log.Message(script + " - Node2: " + newNode);
             TestNode(newNode, questGiver, script);
         }
     }
 }
예제 #13
0
    public void deleteNode(QuestNode node)
    {
        for (int i = 0; i < node.getOutcomeNodes().Count; i++)
        {
            QuestNode n = node.getOutcomeNodes()[i] as QuestNode;
            if (n.getOutcomeNodes().Count == 0)
            {
                node.removeOutcomeNode(n);

                typeBoxes.Remove(node);
                npcBoxes.Remove(node);
                locationBoxes.Remove(node);
                i--;
            }
            else
            {
                deleteNode(n);
                node.removeOutcomeNode(n);
                i--;
            }
        }
    }
예제 #14
0
    public void ProgressQuest()
    {
        if (curQuestA.isCompleted && curQuestA.GetNextNode())
        {
            questUI.UpdateQuest(curQuestA);
            curQuestA = curQuestA.GetNextNode();
            questUI.UpdateQuest(curQuestA);
        }

        if (sameQuest)
        {
            curQuestB = curQuestA;
            return;
        }

        if (curQuestB.isCompleted && curQuestB.GetNextNode())
        {
            questUI.UpdateQuest(curQuestB);
            curQuestB = curQuestB.GetNextNode();
            questUI.UpdateQuest(curQuestB);
        }
    }
예제 #15
0
 public void removeNodes(QuestNode toRemove)
 {
     questNodes.Remove(toRemove);
 }
예제 #16
0
 public void addNode(QuestNode newNode)
 {
     questNodes.Add(newNode);
 }
예제 #17
0
 public QuestModel(QuestNode rootNode)
 {
     questNodes = new ArrayList();
     questNodes.Add(rootNode);
     root = rootNode;
 }
    public Rect drawNode(QuestNode node, int r, int w)
    {
        int cHeight = 150;
        int x = (int)(r * nodeWidth * 1.3) + offsetX;
        yCol[r] += 25;
        int yInit = yCol[r] + offsetY;

        // Creates main node box with name at top
        GUI.Box(new Rect(x, yCol[r] + offsetY, nodeWidth, cHeight), node.getQuestID());
        yCol[r] += 25;

        // Creates the quest rename field below
        node.setQuestID(GUI.TextField(new Rect(x + 5, yCol[r] + offsetY, nodeWidth - 10, 20), node.getQuestID()));
        yCol[r] += 25;

        int selectedItemIndex = typeBoxes[node].GetSelectedItemIndex();
        int topBoxY = yCol[r] + offsetY;
        yCol[r] += 25;

        //Draw outcome nodes
        foreach (QuestNode n in node.getOutcomeNodes())
        {
            // draw child node -- maybe should just draw line to children (requires x,y info in node)?
            Rect childBox = drawNode(n, r + 1, nodeWidth);

            // draws line to child node
            GUIHelper.DrawLine(new Vector2(x + nodeWidth, (yCol[r]) + offsetY), new Vector2(childBox.x, childBox.y + childBox.height / 2), Color.black);

            // draws and activates the 'x' button for deletion
            if (GUI.Button(new Rect(childBox.x, childBox.y, 20, 20), "X"))
            {
                deleteNode(n);
                node.removeOutcomeNode(n);
            }
        }

        yCol[r] += 25;

        // outcome label
        GUI.Label(new Rect(x + 60, yCol[r] + offsetY + 5, 92, 20), "- Outcomes -");

        yCol[r] += 25;

        //Draw add node button
        if (GUI.Button(new Rect(x + 5, yCol[r] + offsetY, 92, 20), "New Child..."))
        {
            QuestNode newNode = new QuestNode("New Node " + max++, qNpcs[0], 0, 0);
            node.addOutcomeNode(newNode);
            currentQuest.addNode(newNode);

            typeBoxes.Add(newNode, new ComboBox());
            npcBoxes.Add(newNode, new ComboBox());
            locationBoxes.Add(newNode, new ComboBox());
        }

        // Draw 'Select Node' button
        if (GUI.Button(new Rect(x + 102, yCol[r] + offsetY, 92, 20), "Select Node..."))
        {
            Dictionary<string, QuestNode> qInventory = new Dictionary<string, QuestNode>();
            GetNodeList(first, qInventory);

            setupQuestCombos(qInventory);

            int selectedNode = selNode.List(
            new Rect(x + 102, yCol[r] +offsetY, 92, 20), "vvvvv", questComboBoxList, listStyle);
            Debug.Log("YOU REACHED ME!!!!	"+ selectedNode.ToString());

        }

        // NPC selected
        if (selectedItemIndex == 0)
        {
            int selectedNPC = npcBoxes[node].GetSelectedItemIndex();
            selectedNPC = npcBoxes[node].List(
            new Rect(x + 5, topBoxY + 25, nodeWidth - 10, 20), npcComboBoxList[selectedNPC].text, npcComboBoxList, listStyle);
            Debug.Log(selectedNPC);
        }
        // Object Selected
        else if (selectedItemIndex == 1)
        {

        }
        // Location Selected
        else
        {
            int selectedLoc = locationBoxes[node].GetSelectedItemIndex();
            selectedLoc = locationBoxes[node].List(
            new Rect(x + 5, topBoxY + 25, nodeWidth - 10, 20), locationComboBoxList[selectedLoc].text, locationComboBoxList, listStyle);
        }

        selectedItemIndex = typeBoxes[node].List(
            new Rect(x + 5, topBoxY, nodeWidth - 10, 20), typeComboBoxList[selectedItemIndex].text, typeComboBoxList, listStyle);

        yCol[r] += 30;
        return new Rect(x, yInit, nodeWidth, cHeight);
    }
 public void removeOutcomeNode(QuestNode node)
 {
     outcomeNodes.Remove(node);
 }
예제 #20
0
    // Use this for initialization
    void Start()
    {
        test = this.transform.GetChild(1);

        availableButtonList = new Dictionary <string, GameObject>();
        progressButtonList  = new Dictionary <string, GameObject>();
        completedButtonList = new Dictionary <string, GameObject>();

        questList = new Dictionary <string, int>();

        QuestNode questA = QuestSystem.instance.GetQuestA().GetComponent <QuestNode>();
        QuestNode questB = QuestSystem.instance.GetQuestA().GetComponent <QuestNode>();

        do
        {
            if (questA != null)
            {
                if (questA.isCompleted)
                {
                    Vector3    pos = new Vector3(xPos, topPos - completedButtonList.Count * 30.0f, 0);
                    GameObject obj = Instantiate(Resources.Load("QuestButton"), completedContent.transform, false) as GameObject;
                    obj.GetComponent <RectTransform>().sizeDelta        = buttonSize;
                    obj.GetComponent <RectTransform>().anchoredPosition = new Vector2(pos.x, pos.y);
                    completedButtonList.Add(questA.GetQuestName(), obj);
                    questList.Add(questA.GetQuestName(), 1);
                    obj.GetComponent <QuestButton>().SetQuestNode(questA);
                    SetQuestButton(obj);
                }
                else if (questA.isInProgress)
                {
                    Vector3    pos = new Vector3(xPos, topPos - progressButtonList.Count * 30.0f, 0);
                    GameObject obj = Instantiate(Resources.Load("QuestButton"), progressContent.transform, false) as GameObject;
                    obj.GetComponent <RectTransform>().sizeDelta        = buttonSize;
                    obj.GetComponent <RectTransform>().anchoredPosition = new Vector2(pos.x, pos.y);
                    progressButtonList.Add(questA.GetQuestName(), obj);
                    questList.Add(questA.GetQuestName(), 2);
                    obj.GetComponent <QuestButton>().SetQuestNode(questA);
                    SetQuestButton(obj);
                }
                else if (questA.GetParentNode() == null || questA.GetParentNode().isCompleted)
                {
                    Vector3    pos = new Vector3(xPos, topPos - availableButtonList.Count * 30.0f, 0);
                    GameObject obj = Instantiate(Resources.Load("QuestButton"), availableContent.transform, false) as GameObject;
                    obj.GetComponent <QuestButton>().SetQuestNode(questA);
                    obj.GetComponent <RectTransform>().sizeDelta        = buttonSize;
                    obj.GetComponent <RectTransform>().anchoredPosition = new Vector2(pos.x, pos.y);
                    availableButtonList.Add(questA.GetQuestName(), obj);
                    questList.Add(questA.GetQuestName(), 3);
                    SetQuestButton(obj);
                }

                questA = questA.GetNextNode();
            }

            if (QuestSystem.instance.GetSameQuest())
            {
                questB = questB.GetNextNode();
            }

            if (questB != null && !QuestSystem.instance.GetSameQuest())
            {
                if (questB.isCompleted)
                {
                    Vector3    pos = new Vector3(xPos, topPos - completedButtonList.Count * 30.0f, 0);
                    GameObject obj = Instantiate(Resources.Load("QuestButton"), completedContent.transform, false) as GameObject;
                    obj.GetComponent <RectTransform>().sizeDelta        = buttonSize;
                    obj.GetComponent <RectTransform>().anchoredPosition = new Vector2(pos.x, pos.y);
                    completedButtonList.Add(questB.GetQuestName(), obj);
                    questList.Add(questB.GetQuestName(), 1);
                    obj.GetComponent <QuestButton>().SetQuestNode(questB);
                    SetQuestButton(obj);
                }
                else if (questB.isInProgress)
                {
                    Vector3    pos = new Vector3(xPos, topPos - progressButtonList.Count * 30.0f, 0);
                    GameObject obj = Instantiate(Resources.Load("QuestButton"), progressContent.transform, false) as GameObject;
                    obj.GetComponent <RectTransform>().sizeDelta        = buttonSize;
                    obj.GetComponent <RectTransform>().anchoredPosition = new Vector2(pos.x, pos.y);
                    progressButtonList.Add(questB.GetQuestName(), obj);
                    questList.Add(questB.GetQuestName(), 2);
                    obj.GetComponent <QuestButton>().SetQuestNode(questB);
                    SetQuestButton(obj);
                }
                else if (questB.GetParentNode() == null || questB.GetParentNode().isCompleted)
                {
                    Vector3    pos = new Vector3(xPos, topPos - availableButtonList.Count * 30.0f, 0);
                    GameObject obj = Instantiate(Resources.Load("QuestButton"), availableContent.transform, false) as GameObject;
                    obj.GetComponent <RectTransform>().sizeDelta        = buttonSize;
                    obj.GetComponent <RectTransform>().anchoredPosition = new Vector2(pos.x, pos.y);
                    availableButtonList.Add(questB.GetQuestName(), obj);
                    questList.Add(questB.GetQuestName(), 3);
                    obj.GetComponent <QuestButton>().SetQuestNode(questB);
                    SetQuestButton(obj);
                }

                questB = questB.GetNextNode();
            }
        } while (questA != null || questB != null);
    }
예제 #21
0
 public void SetQuestNode(QuestNode quest)
 {
     questNode = quest;
     this.GetComponentInChildren <Text>().text = questNode.GetQuestName();
 }
 public QuestModel(QuestNode rootNode)
 {
     questNodes = new ArrayList();
     questNodes.Add(rootNode);
     root = rootNode;
 }
예제 #23
0
    public Rect drawNode(QuestNode node, int r, int w)
    {
        int cHeight = 150;
        int x       = (int)(r * nodeWidth * 1.3) + offsetX;

        yCol[r] += 25;
        int yInit = yCol[r] + offsetY;

        // Creates main node box with name at top
        GUI.Box(new Rect(x, yCol[r] + offsetY, nodeWidth, cHeight), node.getQuestID());
        yCol[r] += 25;

        // Creates the quest rename field below
        node.setQuestID(GUI.TextField(new Rect(x + 5, yCol[r] + offsetY, nodeWidth - 10, 20), node.getQuestID()));
        yCol[r] += 25;

        int selectedItemIndex = typeBoxes[node].GetSelectedItemIndex();
        int topBoxY           = yCol[r] + offsetY;

        yCol[r] += 25;

        //Draw outcome nodes
        foreach (QuestNode n in node.getOutcomeNodes())
        {
            // draw child node -- maybe should just draw line to children (requires x,y info in node)?
            Rect childBox = drawNode(n, r + 1, nodeWidth);

            // draws line to child node
            GUIHelper.DrawLine(new Vector2(x + nodeWidth, (yCol[r]) + offsetY), new Vector2(childBox.x, childBox.y + childBox.height / 2), Color.black);

            // draws and activates the 'x' button for deletion
            if (GUI.Button(new Rect(childBox.x, childBox.y, 20, 20), "X"))
            {
                deleteNode(n);
                node.removeOutcomeNode(n);
            }
        }

        yCol[r] += 25;

        // outcome label
        GUI.Label(new Rect(x + 60, yCol[r] + offsetY + 5, 92, 20), "- Outcomes -");

        yCol[r] += 25;


        //Draw add node button
        if (GUI.Button(new Rect(x + 5, yCol[r] + offsetY, 92, 20), "New Child..."))
        {
            QuestNode newNode = new QuestNode("New Node " + max++, qNpcs[0], 0, 0);
            node.addOutcomeNode(newNode);
            currentQuest.addNode(newNode);


            typeBoxes.Add(newNode, new ComboBox());
            npcBoxes.Add(newNode, new ComboBox());
            locationBoxes.Add(newNode, new ComboBox());
        }

        // Draw 'Select Node' button
        if (GUI.Button(new Rect(x + 102, yCol[r] + offsetY, 92, 20), "Select Node..."))
        {
            Dictionary <string, QuestNode> qInventory = new Dictionary <string, QuestNode>();
            GetNodeList(first, qInventory);

            setupQuestCombos(qInventory);

            int selectedNode = selNode.List(
                new Rect(x + 102, yCol[r] + offsetY, 92, 20), "vvvvv", questComboBoxList, listStyle);
            Debug.Log("YOU REACHED ME!!!!	"+ selectedNode.ToString());
        }

        // NPC selected
        if (selectedItemIndex == 0)
        {
            int selectedNPC = npcBoxes[node].GetSelectedItemIndex();
            selectedNPC = npcBoxes[node].List(
                new Rect(x + 5, topBoxY + 25, nodeWidth - 10, 20), npcComboBoxList[selectedNPC].text, npcComboBoxList, listStyle);
            Debug.Log(selectedNPC);
        }
        // Object Selected
        else if (selectedItemIndex == 1)
        {
        }
        // Location Selected
        else
        {
            int selectedLoc = locationBoxes[node].GetSelectedItemIndex();
            selectedLoc = locationBoxes[node].List(
                new Rect(x + 5, topBoxY + 25, nodeWidth - 10, 20), locationComboBoxList[selectedLoc].text, locationComboBoxList, listStyle);
        }

        selectedItemIndex = typeBoxes[node].List(
            new Rect(x + 5, topBoxY, nodeWidth - 10, 20), typeComboBoxList[selectedItemIndex].text, typeComboBoxList, listStyle);

        yCol[r] += 30;
        return(new Rect(x, yInit, nodeWidth, cHeight));
    }
    public void deleteNode(QuestNode node)
    {
        for(int i = 0; i < node.getOutcomeNodes().Count; i++)
            {
                QuestNode n = node.getOutcomeNodes()[i] as QuestNode;
                if (n.getOutcomeNodes().Count == 0)
                {
                    node.removeOutcomeNode(n);

                    typeBoxes.Remove(node);
                    npcBoxes.Remove(node);
                    locationBoxes.Remove(node);
                    i--;
                }
                else
                {
                    deleteNode(n);
                    node.removeOutcomeNode(n);
                    i--;
                }
            }
    }
 void PopulateObjects()
 {
     qLocs = GameObject.FindObjectsOfType(typeof(QLocation)) as QLocation[];
     qNpcs = GameObject.FindObjectsOfType(typeof(QNpc)) as QNpc[];
     typeBoxes = new Dictionary<QuestNode, ComboBox>();
     npcBoxes = new Dictionary<QuestNode, ComboBox>();
     locationBoxes = new Dictionary<QuestNode, ComboBox>();
     selNode = new ComboBox();
     setUpComboBox();
     first = new QuestNode("FirstNode", qNpcs[0] as MonoBehaviour, 0,0);
     currentQuest = new QuestModel(first);
     typeBoxes.Add(first,new ComboBox());
     npcBoxes.Add(first, new ComboBox());
     locationBoxes.Add(first, new ComboBox());
 }
    public void GetNodeList(QuestNode node, Dictionary<string, QuestNode> oList)
    {
        if (node.getOutcomeNodes().Count > 0)
        {
            foreach(QuestNode n in node.getOutcomeNodes())
            {
                GetNodeList(n, oList);
            }
        }

        if (!oList.ContainsKey(node.getQuestID()))
        {
            oList.Add(node.getQuestID(), node);
        }
    }
 public void addNode(QuestNode newNode)
 {
     questNodes.Add(newNode);
 }
예제 #28
0
 /// <summary>
 /// Sets the quest editor and the quest node about to be deleted
 /// </summary>
 /// <param name="editor">The editor who spawned this window</param>
 /// <param name="qn">The quest node being deleted</param>
 public void SetQuestEditor(CustomQuestEditor editor, QuestNode qn)
 {
     questEditor  = editor;
     nodeToDelete = qn;
 }
 public void removeNodes(QuestNode toRemove)
 {
     questNodes.Remove(toRemove);
 }
예제 #30
0
    public void UpdateQuest(QuestNode updateQuest)
    {
        if (questList.ContainsKey(updateQuest.GetQuestName()))
        {
            GameObject obj;
            Dictionary <string, GameObject> .ValueCollection value;
            int count = 0;
            switch (questList[updateQuest.GetQuestName()])
            {
            case 1:
                break;

            case 2:
                obj = progressButtonList[updateQuest.GetQuestName()];
                obj.transform.SetParent(completedContent.transform, false);
                progressButtonList.Remove(updateQuest.GetQuestName());
                completedButtonList.Add(updateQuest.GetQuestName(), obj);
                questList[updateQuest.GetQuestName()] = 1;

                value = progressButtonList.Values;
                foreach (GameObject other in value)
                {
                    other.GetComponent <RectTransform>().anchoredPosition = new Vector2(xPos, topPos - count++ *30.0f);
                }

                count = 0;
                value = completedButtonList.Values;
                foreach (GameObject other in value)
                {
                    other.GetComponent <RectTransform>().anchoredPosition = new Vector2(xPos, topPos - count++ *30.0f);
                }

                break;

            case 3:
                obj = availableButtonList[updateQuest.GetQuestName()];
                obj.transform.SetParent(progressContent.transform, false);
                availableButtonList.Remove(updateQuest.GetQuestName());
                progressButtonList.Add(updateQuest.GetQuestName(), obj);
                questList[updateQuest.GetQuestName()] = 2;

                value = availableButtonList.Values;
                foreach (GameObject other in value)
                {
                    other.GetComponent <RectTransform>().anchoredPosition = new Vector2(xPos, topPos - count++ *30.0f);
                }

                count = 0;
                value = progressButtonList.Values;
                foreach (GameObject other in value)
                {
                    other.GetComponent <RectTransform>().anchoredPosition = new Vector2(xPos, topPos - count++ *30.0f);
                }
                break;
            }
        }
        else
        {
            Vector3    pos = new Vector3(xPos, topPos - availableButtonList.Count * 30.0f, 0);
            GameObject obj = Instantiate(Resources.Load("QuestButton"), availableContent.transform, false) as GameObject;
            obj.GetComponent <RectTransform>().sizeDelta        = buttonSize;
            obj.GetComponent <RectTransform>().anchoredPosition = new Vector2(pos.x, pos.y);
            availableButtonList.Add(updateQuest.GetQuestName(), obj);
            questList.Add(updateQuest.GetQuestName(), 3);
            obj.GetComponent <QuestButton>().SetQuestNode(updateQuest);
            SetQuestButton(obj);
        }
    }
예제 #31
0
파일: QuestNode.cs 프로젝트: atxkirl/FYPJ2
 public void SetNextNode(QuestNode node)
 {
     childNode = node;
 }
 public void addOutcomeNode(QuestNode node)
 {
     outcomeNodes.Add(node);
 }
예제 #33
0
파일: QuestNode.cs 프로젝트: atxkirl/FYPJ2
 private void SetParentNode(QuestNode node)
 {
     parentNode = node;
 }
예제 #34
0
 /// <summary>
 /// Adds quests to a quest log
 /// </summary>
 /// <param name="questToAdd">The quest</param>
 /// <param name="prerequisites">A list of prerequisite Quests</param>
 public void Add(Quest questToAdd, params Quest [] prerequisites)
 {
     if(head == null && prerequisites.Length != 0)
     {
         throw new ArgumentException("The first quest cannot have prerequisites");
     }
     else if(head == null)
     {
         head = new QuestNode(questToAdd);
     }
 }
예제 #35
0
        public static Quest[] ReadQuestFromGraphml(XmlDocument doc, string filename)
        {
            if (doc == null)
                throw new NullReferenceException("Cannot load graph from NULL reference!");

            XmlNodeList conNodeList = doc.GetElementsByTagName("node");
            XmlNodeList conEdgeList = doc.GetElementsByTagName("edge");
            Dictionary<string, QuestNode> questNodes = new Dictionary<string, QuestNode>();
            List<QuestNode> conStartNodes = new List<QuestNode>(); // store conversation starts

            /* load nodes aka dialogue */
            QuestNode latestNode;
            foreach (XmlNode node in conNodeList)
            {
                latestNode = new QuestNode();
                latestNode.xmlID = node.Attributes["id"].Value;
                Debug.Assert(!questNodes.ContainsKey(latestNode.xmlID), "Duplicated nodes entries found in XML!");
                questNodes[latestNode.xmlID] = latestNode;

                // get important ATTRIBUTES for this node
                Dictionary<string, string> nodeDic = XmlNodesToDic(node.ChildNodes, "key");
                nodeDic.TryGetValue("label", out latestNode.GetMainGoal().label);

                if (nodeDic.ContainsKey("alignment"))
                    int.TryParse(nodeDic["alignment"], out latestNode.GetMainGoal().alignment);
                if (nodeDic.ContainsKey("isstart"))
                    conStartNodes.Add(latestNode);

                if (nodeDic.ContainsKey("activationevent"))
                {
                    Debug.Log(nodeDic["activationevent"] + ": Node Activation Event found!");
                }

                if (nodeDic.ContainsKey("requirement"))
                {
                    Debug.Log(nodeDic["requirement"] + ": Node requirement found!");
                }

                if (nodeDic.ContainsKey("goaldescs") && nodeDic.ContainsKey("goaltypes") && nodeDic.ContainsKey("goaldatas"))
                    latestNode.AddGoals(ParseGoals(nodeDic["goaldescs"], nodeDic["goaltypes"], nodeDic["goaldatas"]));
            }

            /* load edges aka responses */
            foreach (XmlNode edge in conEdgeList)
            {
                QuestOption option = new QuestOption();
                Dictionary<string, string> edgeDic = XmlNodesToDic(edge.ChildNodes, "key");
                option.nextNode = questNodes[edge.Attributes["target"].Value];   // set target node link
                questNodes[edge.Attributes["source"].Value].AddOption(option, edgeDic.ContainsKey("isside") && edgeDic["isside"].Equals("true"));   // set source node link

                // get important ATTRIBUTES for this edge
                edgeDic.TryGetValue("edgelabel", out option.label);

                if (edgeDic.ContainsKey("alignment"))
                    int.TryParse(edgeDic["alignment"], out option.alignment);

                if (edgeDic.ContainsKey("requirement"))
                {
                    Debug.Log(edgeDic["requirement"] + ": Node requirement found!");
                }

                if (edgeDic.ContainsKey("goaldescs") && edgeDic.ContainsKey("goaltypes") && edgeDic.ContainsKey("goaldatas"))
                    option.AddGoals(ParseGoals(edgeDic["goaldescs"], edgeDic["goaltypes"], edgeDic["goaldatas"]));
            }

            // separate nodes into multiple conversations, if necessary
            Quest[] newConArr = new Quest[(conStartNodes.Count > 0) ? conStartNodes.Count : 1];
            QuestNode[] questNodesArr = new QuestNode[questNodes.Count];
            questNodes.Values.CopyTo(questNodesArr, 0);

            if (conStartNodes.Count == 0)
            {
                Debug.LogError("A valid conversion file should ALWAYS have at least 1 conversation start!");
            }
            else
            {
                for (int i = 0; i < conStartNodes.Count; ++i)
                    newConArr[i] = new Quest(conStartNodes[i], questNodesArr, filename);
            }

            return newConArr;
        }