Each of the CompleteObjective() methods works together to fulfill the function of… well to be frank, completing the objective.
It starts in QuestCompletion… This is the component that goes on the object or character that signals that an objective has been completed.
public void CompleteObjective()
{
QuestList questList = GameObject.FindGameObjectWithTag("Player").GetComponent<QuestList>();
questList.CompleteObjective(quest, objective);
}
This CompleteObjective then finds the player’s QuestList.
The QuestList maintains a list of QuestStatus objects. CompleteObjective() in the QuestList locates the appropriate quest and informs it that the objective is complete:
public void CompleteObjective(Quest quest, string objective)
{
QuestStatus status = GetQuestStatus(quest);
status.CompleteObjective(objective);
if (status.IsComplete())
{
GiveReward(quest);
}
if (onUpdate != null)
{
onUpdate();
}
}
The QuestStatus representing that quest then adds the objective to the list of completed objectives.
public void CompleteObjective(string objective)
{
if (quest.HasObjective(objective))
{
completedObjectives.Add(objective);
}
}
None of these things should be done by one single method in a truly object oriented approach. The QuestCompletion tells the QuestList that tells the QuestStatus. In all of these cases, the most logical name for the method is CompleteObjective. Remember that it’s best, whenever possible, to use method names that say exactly what the purpose of the method is.