<commit_before>/*
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */
package com.volumetricpixels.questy;

import com.volumetricpixels.questy.objective.Objective;
import com.volumetricpixels.questy.objective.ObjectiveProgress;

import java.util.function.Predicate;

/**
 * Represents the 'outline' of a quest. There is a single {@link Quest} object
 * created for each scripted or configured quest which is loaded.
 */
public final class Quest {
    /**
     * The {@link QuestManager} this Quest is attached to.
     */
    private final QuestManager questManager;
    /**
     * The name of this Quest, used for identification as well as a name which
     * can be read by humans, so it should always be unique.
     */
    private final String name;
    /**
     * The description of this Quest, human-readable.
     */
    private final String description;
    /**
     * All of the {@link Objective}s which are a part of this Quest.
     */
    private final Objective[] objectives;
    /**
     * A {@link Predicate} specifying the test for whether a quester can embark
     * on this Quest by checking the requirements.
     */
    private final Predicate<String> predicate;

    /**
     * Main Quest constructor. Should primarily be accessed by {@link
     * com.volumetricpixels.questy.loading.QuestBuilder#build()}
     * but can be used elsewhere.
     *
     * This constructor automatically attaches the Quest to the given {@link
     * QuestManager}.
     *
     * @param questManager the {@link QuestManager} to attach the Quest to
     * @param name the unique and human-readable name of the Quest
     * @param description the human-readable description of the Quest
     * @param objectives the {@link Objective}s present in the Quest
     * @param prerequisites quests which must be completed to start the Quest
     */
    public Quest(QuestManager questManager, String name, String description,
            Objective[] objectives, String[] prerequisites) {
        this.questManager = questManager;
        this.name = name;
        this.description = description;
        this.objectives = objectives;

        predicate = quester -> {
            if (prerequisites != null && prerequisites.length > 0) {
                for (String qst : prerequisites) {
                    if (!questManager.hasCompleted(questManager.getQuest(qst),
                            quester)) {
                        return false;
                    }<commit_msg>Don't create a QuestInstance if the player has already completed the quest<commit_after>/*
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */
package com.volumetricpixels.questy;

import com.volumetricpixels.questy.objective.Objective;
import com.volumetricpixels.questy.objective.ObjectiveProgress;

import java.util.function.Predicate;

/**
 * Represents the 'outline' of a quest. There is a single {@link Quest} object
 * created for each scripted or configured quest which is loaded.
 */
public final class Quest {
    /**
     * The {@link QuestManager} this Quest is attached to.
     */
    private final QuestManager questManager;
    /**
     * The name of this Quest, used for identification as well as a name which
     * can be read by humans, so it should always be unique.
     */
    private final String name;
    /**
     * The description of this Quest, human-readable.
     */
    private final String description;
    /**
     * All of the {@link Objective}s which are a part of this Quest.
     */
    private final Objective[] objectives;
    /**
     * A {@link Predicate} specifying the test for whether a quester can embark
     * on this Quest by checking the requirements.
     */
    private final Predicate<String> predicate;

    /**
     * Main Quest constructor. Should primarily be accessed by {@link
     * com.volumetricpixels.questy.loading.QuestBuilder#build()}
     * but can be used elsewhere.
     *
     * This constructor automatically attaches the Quest to the given {@link
     * QuestManager}.
     *
     * @param questManager the {@link QuestManager} to attach the Quest to
     * @param name the unique and human-readable name of the Quest
     * @param description the human-readable description of the Quest
     * @param objectives the {@link Objective}s present in the Quest
     * @param prerequisites quests which must be completed to start the Quest
     */
    public Quest(QuestManager questManager, String name, String description,
            Objective[] objectives, String[] prerequisites) {
        this.questManager = questManager;
        this.name = name;
        this.description = description;
        this.objectives = objectives;

        predicate = quester -> {
            if (questManager.hasCompleted(this, quester)) {
                return false; // TODO: repeatable quests
            }

            if (prerequisites != null && prerequisites.length > 0) {
                for (String qst : prerequisites) {
                    if (!questManager.hasCompleted(questManager.getQuest(qst),
                            quester)) {
                        return false;
                    }
{'fraction_non_alphanumeric': 0.0810512773387245, 'fraction_numerical': 0.001837897445322551, 'mean_word_length': 2.490699166132136, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4934853', 'n_tokens_mistral': 1424, 'n_tokens_neox': 1355, 'n_words': 557}