예제 #1
0
 public void UpdateCurrentMission()
 {
     gameSystem       = GameObject.FindGameObjectWithTag("MainCamera").GetComponent <GameController>();
     current          = gameSystem.getCurrentQuest();
     topic.text       = current.QuestName;
     description.text = current.QuestDescription + "\n";
     if (current.GetType() == typeof(FindingQuest))
     {
         FindingQuest temp  = (FindingQuest)(current);
         string[]     name  = new string[1];
         int[]        sum   = new int[1];
         int[]        total = new int[1];
         temp.getItemQuest(out name, out sum, out total);
         for (int i = 0; i < name.Length && i < sum.Length; i++)
         {
             bool result = temp.checkCollectwithPrefab(name[i]);
             Debug.Log(result + "kuyynananasss");
             if (result)
             {
                 description.text += "<color=#008000>" + name[i] + " " + sum[i] + "/" + total[i] + "</color>\n";
             }
             else
             {
                 description.text += "<color=#FF0000>" + name[i] + " " + sum[i] + "/" + total[i] + "</color>\n";
             }
         }
     }
 }
    //check to see that is player already collect the quest item in this quest and map or not
    public bool isAlreadyHaveItem(int MapID, Spawn position)
    {
        bool haveItem = false;

        if (currentQuest != null)
        {
            if (currentQuest.GetType() == typeof(FindingQuest))
            {
                FindingQuest temp = (FindingQuest)currentQuest;
                haveItem = temp.IsCollect(MapID, position);
            }
        }
        return(haveItem);
    }
    //check to see that is there an item in the current quest and map, so that the game can spawn that item quest
    public bool IsItemInQuest(int MapID, Spawn position, out string item)
    {
        bool haveItem = false;

        item = "";
        if (currentQuest != null)
        {
            if (currentQuest.GetType() == typeof(FindingQuest))
            {
                FindingQuest temp = (FindingQuest)currentQuest;
                haveItem = temp.HaveItem(MapID, position, out item);
            }
        }

        return(haveItem);
    }
    //set player collect this quest item, so the next time player coming the quest item will not spawn
    public void SetHaveItem(int key, Spawn position)
    {
        if (currentQuest != null && currentQuest.GetType() == typeof(FindingQuest))
        {
            FindingQuest temp = (FindingQuest)currentQuest;
            temp.setIsCollect(key, position);
            currentQuest = temp;

            //if all item collected, change to destination quest
            if (temp.allItemCollected())
            {
                //convert finding quest to map quest
                currentQuest = new MapQuest(currentQuest.QuestID, currentQuest.QuestName, currentQuest.QuestDescription,
                                            currentQuest.getQuestStatus(), currentQuest.Score, 0, temp.FinalDestination);

                //also update dictionary in quest manager
                questManager.questList[currentQuest.QuestID] = currentQuest;
            }
        }
    }
    public void Initial()
    {
        /*FindingQuest temp = new FindingQuest(0, "Help Friend", "Go and rescue your friend", "incomplete", 100, 33);
         * temp.addItemQuest(new ItemQuest(1, "box", false, Spawn.one));
         * temp.addItemQuest(new ItemQuest(2, "box", false, Spawn.one));
         * temp.addItemQuest(new ItemQuest(3, "box", false, Spawn.one));
         * temp.addItemQuest(new ItemQuest(4, "box", false, Spawn.one));
         * temp.addMap(new int[]{5,11});
         * temp.randomItems();
         * temp.AddConversationMap(2, false);
         * questList.Add(0, temp);
         *
         * questList.Add(1, new MapQuest(1, "Find the way out", "Find the main door of the building", "incomplete", 30, 0, 33));
         *
         * Quest temp2 = new Quest(2, "Contact authority", "Find the way to contact authority for help", "incomplete", 100);
         * temp2.AddConversationMap(5, false);
         * questList.Add(2, temp2);
         *
         * BossQuest temp3 = new BossQuest(3, "Fight the boss", "Go to the boss room and beat him", "incomplete", 200, 30, false);
         * temp3.AddConversationMap(30, false);
         * questList.Add(3, temp3);*/

        //A00 - prologue
        MapQuest temp = new MapQuest(0, "Find the way out", "Avoid detection and escape from this place", "incomplete", 100, 0, 2);

        temp.AddConversationMap(1, false);
        temp.AddConversationMap(3, false);
        temp.AddConversationMap(4, false);
        temp.AddConversationMap(5, false);
        temp.AddConversationMap(10, false);
        questList.Add(0, temp);

        temp = new MapQuest(1, "A girl is the victim", "help a girl without alert ", "incomplete", 100, 4, 4);
        temp.AddConversationMap(3, false);
        questList.Add(1, temp);
        //A01
        temp = new MapQuest(2, "Help your friends", "Investigate the cell room and help your friend", "incomplete", 200, 3, 21);
        temp.AddConversationMap(22, false);
        questList.Add(2, temp);

        //A02
        temp = new MapQuest(3, "Find the useful information", "Go to the document room and find the useful information for escape",
                            "incomplete", 100, 3, 12);
        temp.AddConversationMap(13, false);
        questList.Add(3, temp);

        //B01
        temp = new MapQuest(4, "Contact Authority for help", "Sneak to the control room and find a way to contact authority",
                            "incomplete", 300, 0, 10);
        temp.AddConversationMap(11, false);
        questList.Add(4, temp);

        //B02_1
        temp = new MapQuest(5, "Find Amata", "Go to the destination point to see Amata", "incomplete", 100, 21, 17);
        temp.AddConversationMap(18, false);
        questList.Add(5, temp);

        //B02_2
        temp = new MapQuest(6, "Searching for Amata", "Locate and find Amata", "incomplete", 100, 17, 13);
        temp.AddConversationMap(13, false);
        questList.Add(6, temp);

        //B03
        FindingQuest temp2 = new FindingQuest(7, "Sabotage trafficker shipment", "Find the item for destroy the trafficker shipment",
                                              "incomplete", 400, 22);

        temp2.addItemQuest(new ItemQuest(1, "wood", false, Spawn.one));
        temp2.addItemQuest(new ItemQuest(2, "wood", false, Spawn.one));
        temp2.addItemQuest(new ItemQuest(3, "paper", false, Spawn.one));
        temp2.addItemQuest(new ItemQuest(4, "paper", false, Spawn.one));
        temp2.addItemQuest(new ItemQuest(5, "match", false, Spawn.one));
        temp2.addMap(new int[] { 5, 7, 9, 20, 24 });
        temp2.randomItems();
        temp2.AddConversationMap(23, false);
        questList.Add(7, temp2);

        //C01
        temp = new MapQuest(8, "Find the exit door", "Find the exit door to escape from this place",
                            "incomplete", 200, 0, 35);
        temp.AddConversationMap(38, false);
        questList.Add(8, temp);

        //C02
        BossQuest temp3 = new BossQuest(9, "Fight the boss", "Go to the boss room and beat him", "incomplete", 500, 30, false);

        temp3.AddConversationMap(30, false);
        questList.Add(9, temp3);

        //C03
        temp = new MapQuest(10, "Find hiding place", "Find the room for hiding until authority arrived", "incomplete", 200, 10, 26);
        temp.AddConversationMap(27, false);
        questList.Add(10, temp);

        //A01sub1
    }
    public void LoadData(int t)
    {
        system  = GameObject.FindGameObjectWithTag("MainCamera").GetComponent <GameController>();
        emotion = GameObject.FindGameObjectWithTag("Player").GetComponent <CharacterEmotion>();
        phone   = GameObject.FindGameObjectWithTag("PhoneCanvas").GetComponent <PhoneCanvas>().phone;
        XmlDocument xmlDoc = new XmlDocument();

        xmlDoc.LoadXml(PlayerPrefs.GetString("save"));
        XmlNodeList dataList  = xmlDoc.GetElementsByTagName("profile" + t);
        string      questType = "";

        foreach (XmlNode dataInfo in dataList)
        {
            XmlNodeList dataContent = dataInfo.ChildNodes;
            foreach (XmlNode dataItems in dataContent)
            {
                if (dataItems.Name == "score")
                {
                    system.setScore(int.Parse(dataItems.InnerText));
                }
                if (dataItems.Name == "Questtype")
                {
                    questType = dataItems.InnerText;
                }
                if (dataItems.Name == "QuestID")
                {
                    system.changeCurrentMission(int.Parse(dataItems.InnerText));
                }
                if (dataItems.Name == "questItem")
                {
                    FindingQuest raw = (FindingQuest)(system.getCurrentQuest());
                    XmlNodeList  dataContentInventory = dataItems.ChildNodes;
                    foreach (XmlNode dataItemInventory in dataContentInventory)
                    {
                        raw.setAllCurrentItemisCollect(int.Parse(dataItemInventory.Attributes["ID"].Value));
                    }
                    system.setCurrentMission(raw);
                }
                if (dataItems.Name == "courage")
                {
                    emotion.characterDetail.setEncouragementStat(int.Parse(dataItems.InnerText));
                }
                if (dataItems.Name == "bravery")
                {
                    emotion.characterDetail.setBraveryStat(int.Parse(dataItems.InnerText));
                }
                if (dataItems.Name == "trustness")
                {
                    emotion.characterDetail.setTrustnessStat(int.Parse(dataItems.InnerText));
                }
                if (dataItems.Name == "previous_map")
                {
                    system.previousMap = dataItems.InnerText;
                }
                if (dataItems.Name == "victimList")
                {
                    XmlNodeList dataContentInventory = dataItems.ChildNodes;
                    foreach (XmlNode dataItemInventory in dataContentInventory)
                    {
                        system.setVictimisHelpbyID(int.Parse(dataItemInventory.Attributes["ID"].Value), true);
                    }
                }
                if (dataItems.Name == "doc")
                {
                    XmlNodeList dataContentInventory = dataItems.ChildNodes;
                    foreach (XmlNode dataItemInventory in dataContentInventory)
                    {
                        phone.docManager.collectDoc(int.Parse(dataItemInventory.Attributes["ID"].Value), true);
                    }
                }
                if (dataItems.Name == "haveConveration")
                {
                    XmlNodeList dataContentInventory = dataItems.ChildNodes;
                    Quest       temps = system.getCurrentQuest();
                    foreach (XmlNode dataItemInventory in dataContentInventory)
                    {
                        temps.setConversationFinish(int.Parse(dataItemInventory.Attributes["MapID"].Value),
                                                    bool.Parse(dataItemInventory.Attributes["haveCon"].Value));
                    }
                    system.setCurrentMission(temps);
                }
                if (dataItems.Name == "smartSystem")
                {
                    XmlNodeList dataContentInventory = dataItems.ChildNodes;

                    foreach (XmlNode dataItemInventory in dataContentInventory)
                    {
                        system.setsmartValue(dataItemInventory.Attributes["MapID"].Value,
                                             int.Parse(dataItemInventory.Attributes["value"].Value));
                    }
                }
            }
        }

        Destroy(gameObject);
    }
    public void BuildData()
    {
        XmlElement rootElement = xml.CreateElement("player");

        xml.AppendChild(rootElement);
        // Create the player profile child element
        XmlElement profileElement = xml.CreateElement("profile" + choice);

        // Add the profileElement to the rootElement
        rootElement.AppendChild(profileElement);
        XmlElement profileInnerElement;

        profileInnerElement = xml.CreateElement("time");
        DateTime saveUtcNow = DateTime.UtcNow;

        profileInnerElement.InnerText = saveUtcNow.ToString();
        profileElement.AppendChild(profileInnerElement);

        profileInnerElement           = xml.CreateElement("score");
        profileInnerElement.InnerText = system.getScore() + "";
        profileElement.AppendChild(profileInnerElement);

        profileInnerElement = xml.CreateElement("Questtype");
        Quest temp = system.getCurrentQuest();

        if (temp.GetType() == typeof(FindingQuest))
        {
            profileInnerElement.InnerText = "Finding";
            profileElement.AppendChild(profileInnerElement);

            profileInnerElement = xml.CreateElement("questItem");
            FindingQuest raw    = (FindingQuest)temp;
            int[]        itemID = raw.getALLItemList();;
            for (int i = 0; i < itemID.Length; i++)
            {
                XmlElement elementItem = xml.CreateElement("document");
                elementItem.SetAttribute("ID", itemID[i] + "");
                profileInnerElement.AppendChild(elementItem);
            }
            profileElement.AppendChild(profileInnerElement);
        }
        else if (temp.GetType() == typeof(MapQuest))
        {
            profileInnerElement.InnerText = "Map";
            profileElement.AppendChild(profileInnerElement);
        }
        else if (temp.GetType() == typeof(BossQuest))
        {
            profileInnerElement.InnerText = "Boss";
            profileElement.AppendChild(profileInnerElement);
        }

        profileInnerElement           = xml.CreateElement("courage");
        profileInnerElement.InnerText = emotion.characterDetail.getEncouragementStat() + "";
        profileElement.AppendChild(profileInnerElement);

        profileInnerElement           = xml.CreateElement("bravery");
        profileInnerElement.InnerText = emotion.characterDetail.getBraveryStat() + "";
        profileElement.AppendChild(profileInnerElement);

        profileInnerElement           = xml.CreateElement("trustness");
        profileInnerElement.InnerText = emotion.characterDetail.getTrustnessStat() + "";
        profileElement.AppendChild(profileInnerElement);

        profileInnerElement           = xml.CreateElement("previous_map");
        profileInnerElement.InnerText = system.previousMap + "";
        profileElement.AppendChild(profileInnerElement);

        profileInnerElement = xml.CreateElement("victimList");
        int[] victims = system.getALLvictimList();
        for (int i = 0; i < victims.Length; i++)
        {
            XmlElement elementItem = xml.CreateElement("victim");
            elementItem.SetAttribute("ID", victims[i] + "");
            profileInnerElement.AppendChild(elementItem);
        }
        profileElement.AppendChild(profileInnerElement);

        profileInnerElement = xml.CreateElement("doc");
        int[] doc = phone.docManager.getALLDocCollect();
        for (int i = 0; i < doc.Length; i++)
        {
            XmlElement elementItem = xml.CreateElement("document");
            elementItem.SetAttribute("ID", doc[i] + "");
            profileInnerElement.AppendChild(elementItem);
        }
        profileElement.AppendChild(profileInnerElement);


        profileInnerElement = xml.CreateElement("haveConveration");
        int[]  mapIDQuest;
        bool[] haveConQuest;
        temp.getAllConversationMapID(out mapIDQuest, out haveConQuest);
        for (int i = 0; i < mapIDQuest.Length; i++)
        {
            XmlElement elementItem = xml.CreateElement("Con");
            elementItem.SetAttribute("MapID", mapIDQuest[i] + "");
            elementItem.SetAttribute("haveCon", haveConQuest[i] + "");
            profileInnerElement.AppendChild(elementItem);
        }
        profileElement.AppendChild(profileInnerElement);

        profileInnerElement = xml.CreateElement("smartSystem");
        string[] mapIDSmart;
        int[]    valueSmart;
        system.getALLsmartsystemvalue(out mapIDSmart, out valueSmart);
        for (int i = 0; i < mapIDQuest.Length; i++)
        {
            XmlElement elementItem = xml.CreateElement("smart");
            elementItem.SetAttribute("MapID", mapIDSmart[i] + "");
            elementItem.SetAttribute("value", valueSmart[i] + "");
            profileInnerElement.AppendChild(elementItem);
        }
        profileElement.AppendChild(profileInnerElement);

        for (int i = 0; i < xmlrawData.Length; i++)
        {
            if (i != choice && xmlrawData[i] != null)
            {
                rootElement.AppendChild(xmlrawData[i]);
            }
        }
        string data = xml.OuterXml;

        //System.IO.File.WriteAllText(filedata, data);
        PlayerPrefs.SetString("save", data);
        PlayerPrefs.Save();
        xml.RemoveAll();
    }