// Check Condition Progress void CheckConditionProgress() { // If there are active quests if (liActiveQuests.Count > 0) { // Loop through the active quests for (int i = 0; i < liActiveQuests.Count; i++) { QuestProgressData currentQuest = aQuestProgress[liActiveQuests[i]]; print(currentQuest.abConditionsComplete.Length); // Loop through each condition for (int j = 0; j < currentQuest.aiConditionsProgress.Length; j++) { // If the condition hasn't been fulfilled if (!currentQuest.abConditionsComplete[j]) { // If the condition progress is higher than the required amount, // then set the condition complete to true if (currentQuest.aiConditionsProgress[j] >= QuestTypeData.aQuests[liActiveQuests[i]].aConditionList[j].iNumberRequired) { currentQuest.abConditionsComplete[j] = true; } } } } } }
// Check Quest Progress void CheckQuestProgress() { // If there are active quests if (liActiveQuests.Count > 0) { print(liActiveQuests.Count); // Loop through each quest for (int i = 0; i < liActiveQuests.Count; i++) { QuestProgressData currentQuest = aQuestProgress[liActiveQuests[i]]; // Number of complete conditions int conditionsComplete = 0; // Loop through each condition for (int j = 0; j < currentQuest.abConditionsComplete.Length; j++) { // If the condition is complete then increment conditionsComplete if (currentQuest.abConditionsComplete[j]) { conditionsComplete++; } } // If the number of complete conditions matches the number of conditions // then set the quest to complete and remove it from the active quests list if (conditionsComplete == QuestTypeData.aQuests[currentQuest.iID].iNoOfConditions) { aQuestProgress[liActiveQuests[i]].bQuestComplete = true; InventoryManager.AddGold(QuestTypeData.aQuests[currentQuest.iID].iGoldReward); LevelManager.iAddXP(QuestTypeData.aQuests[currentQuest.iID].iXPReward); liActiveQuests.RemoveAt(i); QuestCompleteWindow.iQuestID = liActiveQuests[i]; QuestCompleteWindow.bWindowActive = true; questSave.SaveData(); } } } }
// Load Data void DecodeData() { // Quest array QuestProgressData[] quests = new QuestProgressData[QuestTypeData.iNoOfQuests]; // Active Quest list List <int> activeQuests = new List <int>(); // Read data string dataTxt = sLoadData("QuestData", sFileName); dataTxt = dataTxt.Replace(" ", ""); // Check data to see if empty if (dataTxt == "" || dataTxt.Contains("NewUser") || dataTxt == null) { Debug.Log("No User Quest Data"); // Create empty quest data for each quest in the game for (int i = 0; i < QuestTypeData.iNoOfQuests; i++) { bool[] conditionsComplete = new bool[QuestTypeData.aQuests[i].iNoOfConditions]; int[] conditionsProgress = new int[QuestTypeData.aQuests[i].iNoOfConditions]; for (int j = 0; j < QuestTypeData.aQuests[i].iNoOfConditions; j++) { conditionsComplete[j] = false; conditionsProgress[j] = 0; } quests[i].SetValues(i, false, conditionsComplete, conditionsProgress); } } else { // Split the data string[] questTxt = dataTxt.Split('|'); // Active Quest data // If there are active quests then retrieve the active quest ids if (questTxt[0] != "") { string[] activeQuestData = questTxt[0].Split(','); for (int i = 0; i < activeQuestData.Length; i++) { print("Active Quest: " + activeQuestData[i]); int questID = int.Parse(activeQuestData[i]); activeQuests.Add(questID); } } // Loop through each quest and retrieve the progress data for each for (int j = 1; j < questTxt.Length; j++) { string[] questData = questTxt[j].Split(','); int id = int.Parse(questData[0]); bool achieved = bool.Parse(questData[1]); string[] conditionTxt = questData[2].Split('/'); bool[] conditionsComplete = new bool[conditionTxt.Length]; int[] conditionsProgress = new int[conditionTxt.Length]; for (int k = 0; k < conditionTxt.Length; k++) { string[] conditionData = conditionTxt[k].Split('#'); conditionsComplete[k] = bool.Parse(conditionData[0]); conditionsProgress[k] = int.Parse(conditionData[1]); } // Add the data for each quest quests[j - 1].SetValues(id, achieved, conditionsComplete, conditionsProgress); } } // Initialise the quest data QuestManager.Init(quests, activeQuests); }