Ejemplo n.º 1
0
        public Quest AssignQuest(string questSlug, bool loadingFromSave = false)
        {
            bool  isNewQuest = false;
            Quest questToAdd = null;

            if (!IsQuestCompleted(questSlug) && FindActiveQuest(questSlug) == null || loadingFromSave)
            {
                // Add a new quest
                questToAdd = (Quest)gameObject.AddComponent(System.Type.GetType(questSlug));
                assignedQuests.Add(questToAdd);
                try {
                    isNewQuest = questDatabase.AddQuest(questToAdd);
                } catch {
                    questToAdd.goal.countCurrent = questDatabase.GetCurrentQuestCount(questSlug);
                }
            }
            else
            {
                // Quest already exists - Find instance of it
                questToAdd = (Quest)gameObject.GetComponent(System.Type.GetType(questSlug));
            }

            if (isNewQuest || !questDatabase.Completed(questToAdd.slug))
            {
                QuestUIItem questUI = Instantiate(questUIItem, questUIParent);

                questUI.Setup(questToAdd);
                return(questToAdd);
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 2
0
        public Quest AssignQuest(string questName)
        {
            //check to make sure the quest is not assigned twice in a row, or assigned while it is already active
            if (assignedQuests.Find(quest => quest.questName == questName))
            {
                Debug.Log("Quest is already assigned please complete it!");
                return(null);
            }

            //create a component from a name (a script name)
            Quest questToAdd = (Quest)gameObject.AddComponent(System.Type.GetType(questName));

            //assign the quest to the assignedQuests list
            assignedQuests.Add(questToAdd);
            //Add quest to questDatabase
            questDatabase.AddQuest(questToAdd);

            //Instantiate the UI item
            QuestUIItem questUI = Instantiate(questUIItem, questUIParent);

            //setup data for the UI item.
            questUI.Setup(questToAdd);
            //return the quest being added so the "Quest giver" has a reference to the quest that was just created.
            return(questToAdd);
        }