Exemple #1
0
 public KillQuestEvaluator(KillQuest kq)
 {
     killQuest         = kq;
     enemies           = new List <GameObject>();
     deadCounter       = 0;
     numspawnedEnemies = 0;
 }
    //--

    // Use this for initialization
    void Start()
    {
        database = GameObject.Find("Inventory").GetComponent <ItemDatabase> ();
        pi       = GameObject.FindGameObjectWithTag("Player").GetComponent <player_interaction>();
        cq       = GameObject.FindGameObjectWithTag("Player").GetComponent <ClassQuest>();
        ps       = GameObject.FindGameObjectWithTag("UI_Player").GetComponent <PlayerUI_Script>();
        pb       = GameObject.FindGameObjectWithTag("Player").GetComponent <Player_battle>();
        kq       = GetComponent <KillQuest>();
        aic      = GetComponent <AIControl>();
    }
Exemple #3
0
 private void OnTriggerEnter2D(Collider2D other)
 {
     if (active)
     {
         return;
     }
     if (other.CompareTag("Player"))
     {
         if (QuestManager.instance.GetActive().GetType() == typeof(KillQuest))
         {
             KillQuest currQuest = (KillQuest)QuestManager.instance.GetActive();
             if (currQuest.target.name == enemyToSpawn.name)
             {
                 GameObject g = Instantiate(enemyToSpawn, spawnPoint);
                 g.name = enemyToSpawn.name;
                 active = true;
             }
         }
     }
 }
Exemple #4
0
 void CheckKillQuest(List <string> tags)
 {
     foreach (Quest quest in QuestManager.questManager.currentQuests)
     {
         if (quest.questType == Quest.QuestType.KILL)
         {
             KillQuest killQuest = (KillQuest)quest;
             foreach (string tag in tags)
             {
                 if (killQuest.killTargetTag == tag && quest.questProgress == Quest.QuestProgress.CURRENT)
                 {
                     killQuest.killsCompleted += 1;
                     if (killQuest.killsCompleted >= killQuest.killsRequired)
                     {
                         CompleteQuest(killQuest);
                     }
                 }
             }
         }
     }
 }
Exemple #5
0
 // Update is called once per frame
 void Update()
 {
     if (enemyInfo && enemyInfo.PlayerHealth <= 0 && isDying)
     {
         // Just to check for kill quest
         if (gameObject.GetComponent <KillQuest>())
         {
             kill = gameObject.GetComponent <KillQuest>();
             kill.CheckIfMonsterDied();
         }
         if (GameObject.Find("New Game Object"))
         {
             Destroy(GameObject.Find("New Game Object"));
         }
         if (GameObject.Find("New Game Object(Clone)"))
         {
             Destroy(GameObject.Find("New Game Object(Clone)"));
         }
         StartCoroutine(KillDelay());
         GameInformation.CurrentXp += 20 * enemyInfo.PlayerLevel;
     }
 }
Exemple #6
0
    static void ImportGameData()
    {
        TextAsset   questsData = Resources.Load("GameData", typeof(TextAsset)) as TextAsset;
        XmlDocument xmlDoc     = new XmlDocument();

        xmlDoc.LoadXml(questsData.text);

        //import icons
        Dictionary <string, Texture2D> icons = new Dictionary <string, Texture2D>();
        XmlNodeList listIcons = ((XmlElement)xmlDoc.GetElementsByTagName("Icons")[0]).GetElementsByTagName("Icon");
        TexturePool tpool     = (Resources.Load("TexturePools/NPCPortraits") as GameObject).GetComponent <TexturePool>();

        foreach (XmlElement xmlIcon in listIcons)
        {
            string iconName    = xmlIcon.Attributes.GetNamedItem("name").InnerXml;
            string texturePath = xmlIcon.Attributes.GetNamedItem("texture").InnerXml;

            Texture2D texture = tpool.getFromList(texturePath);

            icons.Add(iconName, texture);
        }

        //import dialogs
        Dictionary <string, GameObject> dialogs = new Dictionary <string, GameObject>();
        XmlNodeList listDialogs = ((XmlElement)xmlDoc.GetElementsByTagName("Dialogs")[0]).GetElementsByTagName("Dialog");

        foreach (XmlElement xmlDialog in listDialogs)
        {
            string dialogName = xmlDialog.Attributes.GetNamedItem("name").InnerXml;

            //create an empty gameobject but make it inactive
            GameObject go = new GameObject();
            go.active = false;
            Dialog dialog = go.AddComponent <Dialog>();

            //write each message configuration
            XmlNodeList listMessages = xmlDialog.GetElementsByTagName("Message");

            for (int i = 0; i < listMessages.Count; i++)
            {
                DialogMessage dm = new DialogMessage();
                processDialogMessage(icons, ref dm, listMessages[i] as XmlElement, dialogName, i);
                dialog.messages.Add(dm);
            }

            //process the event data
            processEvent(go, xmlDialog.GetElementsByTagName("Event"));

            //add it as a prefab
            string prefabPath     = "Assets/Resources/Dialogs/" + dialogName + ".prefab";
            string prefabFullPath = Application.dataPath + "/Resources/Dialogs/" + dialogName + ".prefab";
            string directory      = prefabFullPath.Substring(0, prefabFullPath.LastIndexOf('/') + 1);

            //create the directory where the prefab will exists if not created
            if (!Directory.Exists(directory))
            {
                Directory.CreateDirectory(directory);
            }

            Object     p      = PrefabUtility.CreateEmptyPrefab(prefabPath);
            GameObject prefab = EditorUtility.ReplacePrefab(go, p, ReplacePrefabOptions.ConnectToPrefab);

            GameObject.DestroyImmediate(go);

            if (dialogs.ContainsKey(dialogName))
            {
                Debug.Log(dialogName + " already exists");
            }
            else
            {
                dialogs.Add(dialogName, prefab);
            }
        }

        AudioPool QuestThemePool = null;

        GameObject QuestThemes = Resources.Load("Audio/QuestThemes") as GameObject;

        if (QuestThemes != null)
        {
            QuestThemePool = QuestThemes.GetComponent <AudioPool>();
        }

        //import quests
        Dictionary <string, GameObject> quests = new Dictionary <string, GameObject>();
        XmlNodeList listQuests = ((XmlElement)xmlDoc.GetElementsByTagName("Quests")[0]).GetElementsByTagName("Quest");

        QuestPool qpool = Resources.Load("Quests/QuestPool", typeof(QuestPool)) as QuestPool;

        qpool.pool = new QuestDependency[listQuests.Count];
        int nQuestsInPool = 0;

        foreach (XmlElement xmlQuest in listQuests)
        {
            string questName = xmlQuest.Attributes.GetNamedItem("name").InnerXml;

            GameObject go = new GameObject();
            go.active = false;

            Quest quest = go.AddComponent <Quest>();

            string     title       = xmlQuest.Attributes.GetNamedItem("title").InnerXml;
            GameObject startDialog = null;

            if (xmlQuest.Attributes.GetNamedItem("startDialog") != null)
            {
                string dialogName = xmlQuest.Attributes.GetNamedItem("startDialog").InnerXml;
                if (dialogs.ContainsKey(dialogName))
                {
                    startDialog = dialogs[dialogName];
                }
                else
                {
                    Debug.Log("Quest " + questName + " uses " + dialogName + " dialog, but it doesn't exist");
                }
            }

            string     backgroundPath = "Prefabs/" + xmlQuest.Attributes.GetNamedItem("background").InnerXml;
            Game.Towns townId         = Game.getTownId(xmlQuest.Attributes.GetNamedItem("town").InnerXml);
            GameObject background     = Resources.Load(backgroundPath) as GameObject;

            quest.title      = title;
            quest.town       = townId;
            quest.background = background;
            if (startDialog != null)
            {
                quest.startDialog = startDialog.GetComponent <Dialog>();
            }

            if (xmlQuest.Attributes.GetNamedItem("award") != null)
            {
                quest.baseCoinsAward = System.Int32.Parse(xmlQuest.Attributes.GetNamedItem("award").InnerXml);
            }

            if (QuestThemes != null && xmlQuest.Attributes.GetNamedItem("music") != null)
            {
                string themeName = xmlQuest.Attributes.GetNamedItem("music").InnerXml;
                foreach (AudioSource src in QuestThemePool.audioPool)
                {
                    if (themeName.ToLower() == src.name.ToLower())
                    {
                        quest.audioQuest = src;
                        break;
                    }
                }
            }


            XmlNodeList awardList = xmlQuest.GetElementsByTagName("Award");
            foreach (XmlElement xmlAward in awardList)
            {
                QuestAward qa = go.AddComponent <QuestAward>();
                processAttributes(qa, xmlAward);
            }

            XmlNodeList listKillQuests = xmlQuest.GetElementsByTagName("KillQuest");
            foreach (XmlElement xmlKillQuest in listKillQuests)
            {
                KillQuest kq = go.AddComponent <KillQuest>();
                processAttributes(kq, xmlKillQuest);
            }

            XmlNodeList listLootQuests = xmlQuest.GetElementsByTagName("LootQuest");
            foreach (XmlElement xmlLootQuest in listLootQuests)
            {
                LootQuest lq = go.AddComponent <LootQuest>();
                processAttributes(lq, xmlLootQuest);
            }

            XmlNodeList listRescueQuests = xmlQuest.GetElementsByTagName("RescueQuest");
            foreach (XmlElement xmlRescueQuest in listRescueQuests)
            {
                RescueQuest rq = go.AddComponent <RescueQuest>();
                processAttributes(rq, xmlRescueQuest);
            }

            //process the event data
            processEvent(go, xmlQuest.GetElementsByTagName("Event"));

            XmlNodeList listCinematics = xmlQuest.GetElementsByTagName("Cinematic");
            foreach (XmlElement xmlCinematic in listCinematics)
            {
                string         componentName  = xmlCinematic.Attributes.GetNamedItem("name").InnerXml;
                CinematicEvent cinematicEvent = go.AddComponent(componentName) as CinematicEvent;

                processAttributes(cinematicEvent, xmlCinematic);
            }

            //add it as a prefab
            string resourcePath   = "Quests/" + questName;
            string prefabPath     = "Assets/Resources/" + resourcePath + ".prefab";
            string prefabFullPath = Application.dataPath + "/Resources/" + resourcePath + ".prefab";
            string directory      = prefabFullPath.Substring(0, prefabFullPath.LastIndexOf('/') + 1);

            //create the directory where the prefab will exists if not created
            if (!Directory.Exists(directory))
            {
                Directory.CreateDirectory(directory);
            }

            //create an empty prefab in the specified path and copy the dialog component to the prefab
            Object     p      = PrefabUtility.CreateEmptyPrefab(prefabPath);
            GameObject prefab = EditorUtility.ReplacePrefab(go, p, ReplacePrefabOptions.ConnectToPrefab);

            //destroy the gameobject
            GameObject.DestroyImmediate(go);

            quests.Add(questName, prefab);
            //qpool.pool[nQuestsInPool] = prefab.GetComponent<Quest>();

            qpool.pool[nQuestsInPool]      = new QuestDependency();
            qpool.pool[nQuestsInPool].name = resourcePath;
            qpool.pool[nQuestsInPool].town = townId;
            nQuestsInPool++;
        }

        //set quests dependencies
        foreach (XmlElement xmlQuest in listQuests)
        {
            string questName  = "Quests/" + xmlQuest.Attributes.GetNamedItem("name").InnerXml;
            int    questIndex = -1;
            for (int i = 0; i < qpool.pool.Length; i++)
            {
                if (qpool.pool[i].name.ToLower() == questName.ToLower())
                {
                    questIndex = i;
                }
            }

            if (questIndex == -1)
            {
                continue;
            }

            XmlNodeList listDependencies = xmlQuest.GetElementsByTagName("Dependency");
            qpool.pool[questIndex].dependencies = new int[listDependencies.Count];
            int count = 0;
            foreach (XmlElement xmlDependency in listDependencies)
            {
                string dependencyName = "Quests/" + xmlDependency.Attributes.GetNamedItem("name").InnerXml;
                qpool.pool[questIndex].dependencies[count] = -1;
                for (int i = 0; i < qpool.pool.Length; i++)
                {
                    if (qpool.pool[i].name.ToLower() == dependencyName.ToLower())
                    {
                        qpool.pool[questIndex].dependencies[count] = i;
                        break;
                    }
                }
                count++;
            }
            questIndex++;
        }

        XmlNodeList xmlMetaQuests = ((XmlElement)xmlDoc.GetElementsByTagName("MetaQuests")[0]).GetElementsByTagName("MetaQuest");

        MetaQuestPool mqpool = Resources.Load("MetaQuests/MetaQuestPool", typeof(MetaQuestPool)) as MetaQuestPool;

        mqpool.pool = new QuestDependency[xmlMetaQuests.Count];
        int nMetaQuestsInPool = 0;

        foreach (XmlElement mq in xmlMetaQuests)
        {
            string     metaName = mq.Attributes.GetNamedItem("name").InnerXml;
            Game.Towns townId   = Game.getTownId(mq.Attributes.GetNamedItem("town").InnerXml);

            GameObject go = new GameObject();
            go.active = false;

            MetaQuest meta = go.AddComponent <MetaQuest>();

            mqpool.pool[nMetaQuestsInPool]      = new QuestDependency();
            mqpool.pool[nMetaQuestsInPool].name = "MetaQuests/" + metaName;
            mqpool.pool[nMetaQuestsInPool].town = townId;

            //process the attributes
            processAttributes(meta, mq);

            //add the kill quests
            XmlNodeList listKillQuests = mq.GetElementsByTagName("KillQuest");
            foreach (XmlElement xmlKillQuest in listKillQuests)
            {
                MetaKillQuest kq = go.AddComponent <MetaKillQuest>();
                processAttributes(kq, xmlKillQuest);
            }

            //add the lootquests
            XmlNodeList listLootQuests = mq.GetElementsByTagName("LootQuest");
            foreach (XmlElement xmlLootQuest in listLootQuests)
            {
                LootQuest lq = go.AddComponent <LootQuest>();
                processAttributes(lq, xmlLootQuest);
            }

            //add the rescue quests
            XmlNodeList listRescueQuests = mq.GetElementsByTagName("RescueQuest");
            foreach (XmlElement xmlRescueQuest in listRescueQuests)
            {
                RescueQuest rq = go.AddComponent <RescueQuest>();
                processAttributes(rq, xmlRescueQuest);
            }

            //process messages
            XmlNodeList listMessages = ((XmlElement)mq.GetElementsByTagName("Messages")[0]).GetElementsByTagName("Message");
            for (int i = 0; i < listMessages.Count; i++)
            {
                DialogMessage dm = new DialogMessage();
                processDialogMessage(icons, ref dm, listMessages[i] as XmlElement, metaName, i);
                meta.messages.Add(dm);
            }

            //set dependencies
            XmlNodeList dependencies = mq.GetElementsByTagName("Dependency");
            if (dependencies != null && dependencies.Count > 0)
            {
                mqpool.pool[nMetaQuestsInPool].dependencies = new int[dependencies.Count];
                int nDependencies = 0;
                foreach (XmlElement xmlDependency in dependencies)
                {
                    string dependencyName = ("Quests/" + xmlDependency.Attributes.GetNamedItem("name").InnerXml).ToLower();
                    for (int i = 0; i < qpool.pool.Length; i++)
                    {
                        if (qpool.pool[i].name.ToLower() == dependencyName)
                        {
                            mqpool.pool[nMetaQuestsInPool].dependencies[nDependencies] = i;
                            nDependencies++;
                            break;
                        }
                    }
                }
            }

            //add it as a prefab
            string prefabPath     = "Assets/Resources/MetaQuests/" + metaName + ".prefab";
            string prefabFullPath = Application.dataPath + "/Resources/MetaQuests/" + metaName + ".prefab";
            string directory      = prefabFullPath.Substring(0, prefabFullPath.LastIndexOf('/') + 1);

            //create the directory where the prefab will exists if not created
            if (!Directory.Exists(directory))
            {
                Directory.CreateDirectory(directory);
            }

            //create an empty prefab in the specified path and copy the dialog component to the prefab
            Object p = PrefabUtility.CreateEmptyPrefab(prefabPath);
            /*GameObject prefab = */ EditorUtility.ReplacePrefab(go, p, ReplacePrefabOptions.ConnectToPrefab);

            nMetaQuestsInPool++;

            //destroy the gameobject
            GameObject.DestroyImmediate(go);
        }
    }
Exemple #7
0
    public void DisplayDialog()
    {
        if (!npc.dialogBox.activeSelf)
        {
            Quest.QuestProgress statusTest = questToGive.questProgress;

            Time.timeScale = 0f;

            GameManager.gm.data.overviewMap.SetActive(false);

            switch (statusTest)
            {
            case Quest.QuestProgress.AVAILABLE:
                npc.dialogText.text = questToGive.questDesc;
                GiveQuest();
                break;

            case Quest.QuestProgress.CURRENT:
            case Quest.QuestProgress.ACCEPTED:
                npc.dialogText.text = questToGive.questDesc;
                break;

            case Quest.QuestProgress.COMPLETED:
                npc.dialogText.text = questToGive.questCompleteText;
                if (questType == Quest.QuestType.FIND_ITEM)
                {
                    FindItem quest = (FindItem)questToGive;
                    quest.RemoveItem();
                }
                if (questType == Quest.QuestType.KILL)
                {
                    KillQuest quest = (KillQuest)questToGive;
                }
                if (questType == Quest.QuestType.LOCATION)
                {
                    LocateQuest quest = (LocateQuest)questToGive;
                }
                if (questType == Quest.QuestType.AWAKEN)
                {
                    AwakenQuest quest = (AwakenQuest)questToGive;
                }
                QuestManager.questManager.SetQuestStatus(questToGive.questID, Quest.QuestProgress.DONE);
                break;

            case Quest.QuestProgress.DONE:
                npc.dialogText.text = questToGive.questDoneText;
                questToGive.GiveRewards();
                if (questToGive.nextQuest == -1)
                {
                    this.gameObject.GetComponent <NonPlayerCharacter>().questToken.SetActive(false);
                    npc.isQuestGiver = false;
                    break;
                }
                questToGive = QuestManager.questManager.GetQuestById(questToGive.nextQuest);
                QuestManager.questManager.SetQuestStatus(questToGive.questID, Quest.QuestProgress.AVAILABLE);
                QuestManager.questManager.AcceptQuest(questToGive);
                questType = questToGive.questType;
                break;

            default:
                break;
            }

            Button button = Instantiate(npc.buttonPrefab, npc.displayBoard.transform) as Button;
            button.GetComponentInChildren <TextMeshProUGUI>().text = "Click to dismiss";
            button.onClick.AddListener(delegate
            {
                npc.CloseDialog();
            });

            npc.dialogBox.SetActive(true);
        }
        else
        {
            Time.timeScale = 1f;
            npc.dialogBox.SetActive(false);
            GameManager.gm.data.overviewMap.SetActive(true);
        }

        NPCManager.npcManager.UpdateNPCList(npc.ID, questToGive, npc.talkNotifier.activeSelf, npc.questToken.activeSelf);
    }
Exemple #8
0
    // Update is called once per frame
    void Update()
    {
        isNear = IsCharacterClose();
        if (isNear && Input.GetKeyDown(KeyCode.Z) && isAccepted && questText.activeInHierarchy == false)
        {
            isDisplayed = true;
            questText.SetActive(true);
            questText.GetComponentInChildren <Text>().text = "Hows that quest going?";
        }
        if (isDisplayed && Input.GetKeyDown(KeyCode.Z) && !isAccepted)
        {
            // Change the name to Enemy Information name <- found the looppole do in the morning
            FetchQuest quest = new FetchQuest();

            string temp = quest.GetObjective(questId);           // I need a system to after certian levels the quest iD for the npc changes, or after certain prerequistes are meet.
            if (!quest.isQuestComplete && temp.Contains("Kill")) // Maybe if i make an array of quest iDs then make as system to where the quest id changes
            {                                                    // After the player completes a prerequistes, also make NPC information that stores all of
                                                                 // There quest...
                                                                 // Also i have to add all the quest to a active quest list for the player.
                EnemyInformation[] temporary   = GameObject.FindObjectsOfType(typeof(EnemyInformation)) as EnemyInformation[];
                List <GameObject>  enemysFound = new List <GameObject>();
                for (int i = 0; i < temporary.Length; i++)
                {
                    if (temporary[i].name == quest.GetObjectiveName(questId))
                    {
                        enemysFound.Add(temporary[i].gameObject);
                    }
                }
                GameObject[] temp2 = enemysFound.ToArray();
                KillQuest    kill  = gameObject.GetComponent <KillQuest>();
                // Learn Regex-> this is how you convert find numbers in a string and add it to the string then parse
                string result    = Regex.Match(quest.GetObjective(questId), @"\d+").Value;
                int    resultNum = int.Parse(result);
                kill.InitializeKillQuest(temp2, resultNum);
                GameObject tempQuestText = GameObject.FindGameObjectWithTag("QuestNotif");
                tempQuestText.GetComponent <Text>().text = "Quest Started!!";
                StartCoroutine(GetRidOfCompleteText());
            }
            else if (temp.Contains("Save"))
            {
                GameObject tempQuestText = GameObject.FindGameObjectWithTag("QuestNotif");
                tempQuestText.GetComponent <Text>().text = "Quest Started!!";
                StartCoroutine(GetRidOfCompleteText());
                SaveQuest saveQuest = gameObject.GetComponent <SaveQuest>();
                saveQuest.StartSaveQuest(quest.GetObjectiveName(questId), this.gameObject);
            }
            else if (temp.Contains("Find"))
            {
                GameObject tempQuestText = GameObject.FindGameObjectWithTag("QuestNotif");
                tempQuestText.GetComponent <Text>().text = "Quest Started!!";
                DropQuests drop = gameObject.GetComponent <DropQuests>();
                drop.ItemToFind(2, this.gameObject, 5);
            }
            FetchQuest tempQuest = new FetchQuest();
            tempQuest = (FetchQuest)Quest.quest[questId - 1];
            GameInformation.activeQuest.Add(tempQuest);
            questList.AddToQuestLog();
            isAccepted = true;
        }
        if (isNear && Input.GetKeyDown(KeyCode.Z) && !isAccepted)
        {
            isDisplayed = true;
            questText.SetActive(true);
            FetchQuest quest = new FetchQuest();
            if (quest.GetRequriedLevel(questId) < GameInformation.PlayerLevel && quest.IsPlayerReady(questId))
            {
                questText.GetComponentInChildren <Text>().text = quest.GetDescription(questId) + "\n Press Z to accept quest";
                text.text = "";
            }
        }
    }