/* * =========================================================================================================== * EVENTS STUFF * =========================================================================================================== */ /// <summary> /// Add an event to the QuestManager. This will be fired by the event generator. For example, if the player /// builds an extractor, the class CBuilding will call this method. /// </summary> /// <param name="eEvent"> One of the EQuestEvents </param> public void AddEventToTheQM(EQuestEvents eEvent) { // FIXME: I guess this code won't be needed switch(eEvent) { case EQuestEvents.BUILT_METAL_EXTRACTOR: // DEBUG Debug.LogWarning(this.transform + " Received a BUILT_METAL_EXTRACTOR event"); break; case EQuestEvents.BUILT_OXYGEN_EXTRACTOR: // DEBUG Debug.LogWarning(this.transform + " Received a BUILT_OXYGEN_EXTRACTOR event"); break; case EQuestEvents.FOUND_WATER_RESOURCE: // DEBUG Debug.LogWarning(this.transform + " Received a FOUND_WATER_EXTRACTOR event"); break; case EQuestEvents.FOUND_METAL_RESOURCE: // DEBUG Debug.LogWarning(this.transform + " Received a FOUND_METAL_EXTRACTOR event"); break; // TODO: add other events here... default: break; } // In all quests ... foreach(QuestEntry questEntry in lstQuests) { if(questEntry.bnDone) continue; // ... in all tasks foreach(TaskEntry taskEntry in questEntry.lstTasks) { // Task already done? Next task then if(taskEntry.bnDone) continue; // Event Match! if(taskEntry.eEvent == eEvent) { // Decrease the event counter taskEntry.nEventCount--; // Enough of theses events? Mark this task as done! if(taskEntry.nEventCount <= 0) { taskEntry.bnDone = true; // Increase the "tasks done" counter questEntry.nTasksDone++; // Check if we haven't completed the task if(questEntry.lstTasks.Count == questEntry.nTasksDone) { // Quest done! questEntry.bnDone = true; // DEBUG Debug.Log(this.transform + "Quest " + questEntry.stName + " done."); } } } } } }
/// <summary> /// Creates a task and add it to corresponding quest /// </summary> /// <param name="stQuestName"> The name of the quest to add this task. The quest is identified by it's name </param> /// <param name="stTaskDescription"> A string with the description of this task </param> /// <param name="eEvent"> A EQuestEvents enum with the type of event to perform this task </param> public void CreateTaskInQuest(string stQuestName, string stTaskDescription, EQuestEvents eEvent, int nCount) { // First of all, let's find the quest in the list QuestEntry questEntry = null; foreach(QuestEntry entry in lstQuests) { if(entry.stName == stQuestName) { questEntry = entry; break; } } if(questEntry != null) { // Ok, quest found. Create the task... TaskEntry taskEntry = new TaskEntry(); taskEntry.stTaskDescription = stTaskDescription; taskEntry.eEvent = eEvent; taskEntry.nEventCount = nCount; // ... and add it to the quest questEntry.lstTasks.Add(taskEntry); } }