Please tell me something

Why do we have so many redundant things going on?

Makes me go in circles…

Seems very redundant…

Is this common?

The reason i ask is the Third time we made a function named CompleteObjective i became concerned that we are spinning our wheels reaching for stars… lol

Very spread out lectures – seems to start at the back end of things and work forward…

sorry but i am lost because of the backward approach to this logic.

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.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms