<commit_before>'use strict';

module.exports = (srcPath) => {
  const Broadcast = require(srcPath + 'Broadcast');
  const Parser = require(srcPath + 'CommandParser').CommandParser;
  const say = Broadcast.sayAt;

  class QuestCommand {
    static list(state, player, options) {
      if (!options.length) {
        return say(player, "List quests from whom? quest list <npc>");
      }

      const search = options[0];
      const npc = Parser.parseDot(search, player.room.npcs);
      if (!npc) {
        return say(player, `No quest giver [${search}] found.`);
      }

      if (!npc.quests) {
        return say(player, `${npc.name} has no quests.`);
      }

      let availableQuests = npc.quests
        .map(qid => state.QuestFactory.create(state, qid, player))
        .filter(quest => (player.questTracker.canStart(quest) || player.questTracker.isActive(quest.id)))
      ;

      if (!availableQuests.length) {
        return say(player, `${npc.name} has no quests.`);
      }

      for (let i in availableQuests) {
        let quest = availableQuests[i];
        const displayIndex = parseInt(i, 10) + 1;
        if (player.questTracker.canStart(quest)) {
          say(player, `[<b><yellow>!</yellow></b>] - ${displayIndex}. ${quest.config.title}`);
        } else if (player.questTracker.isActive(quest.id)) {
          quest = player.questTracker.get(quest.id);
          const symbol = quest.getProgress().percent >= 100 ? '?' : '%';
          say(player, `[<b><yellow>${symbol}</yellow></b>] - ${displayIndex}. ${quest.config.title}`);
        }
      }
    }

    static start(state, player, options) {
      if (options.length < 2) {
        return say(player, "Start which quest from whom? 'quest start <npc> <number>'");
      }

      let [search, questIndex] = options;
      questIndex = parseInt(questIndex, 10);

      const npc = Parser.parseDot(search, player.room.npcs);
      if (!npc) {
        return say(player, `No quest giver [${search}] found.`);
      }

      if (!npc.quests) {
        return say(player, `${npc.name} has no quests.`);
      }

      if (isNaN(questIndex) || questIndex < 0 || questIndex > npc.quests.length) {
        return say(player, `Invalid quest, use 'quest list ${search}' to see their quests.`);
      }

      let availableQuests = npc.quests
        .map(qid => state.QuestFactory.create(state, qid, player))
        .filter(quest => (player.questTracker.canStart(quest) || player.questTracker.isActive(quest.id)))
      ;

      const targetQuest = availableQuests[questIndex - 1];

      if (player.questTracker.isActive(targetQuest.id)) {
        return say(player, "You've already started that quest. Use 'quest log' to see your active quests.");
      }

      player.questTracker.start(targetQuest);
    }

    static log(state, player, options) {
      const active = [...player.questTracker.activeQuests];
      if (!active.length) {
        return say(player, "You have no active quests.");
      }

      for (let i in active) {
        const [, quest] = active[i];<commit_msg>Add 'accept' as alias for quest start<commit_after>'use strict';

module.exports = (srcPath) => {
  const Broadcast = require(srcPath + 'Broadcast');
  const Parser = require(srcPath + 'CommandParser').CommandParser;
  const say = Broadcast.sayAt;

  class QuestCommand {
    static list(state, player, options) {
      if (!options.length) {
        return say(player, "List quests from whom? quest list <npc>");
      }

      const search = options[0];
      const npc = Parser.parseDot(search, player.room.npcs);
      if (!npc) {
        return say(player, `No quest giver [${search}] found.`);
      }

      if (!npc.quests) {
        return say(player, `${npc.name} has no quests.`);
      }

      let availableQuests = npc.quests
        .map(qid => state.QuestFactory.create(state, qid, player))
        .filter(quest => (player.questTracker.canStart(quest) || player.questTracker.isActive(quest.id)))
      ;

      if (!availableQuests.length) {
        return say(player, `${npc.name} has no quests.`);
      }

      for (let i in availableQuests) {
        let quest = availableQuests[i];
        const displayIndex = parseInt(i, 10) + 1;
        if (player.questTracker.canStart(quest)) {
          say(player, `[<b><yellow>!</yellow></b>] - ${displayIndex}. ${quest.config.title}`);
        } else if (player.questTracker.isActive(quest.id)) {
          quest = player.questTracker.get(quest.id);
          const symbol = quest.getProgress().percent >= 100 ? '?' : '%';
          say(player, `[<b><yellow>${symbol}</yellow></b>] - ${displayIndex}. ${quest.config.title}`);
        }
      }
    }

    static start(state, player, options) {
      if (options.length < 2) {
        return say(player, "Start which quest from whom? 'quest start <npc> <number>'");
      }

      let [search, questIndex] = options;
      questIndex = parseInt(questIndex, 10);

      const npc = Parser.parseDot(search, player.room.npcs);
      if (!npc) {
        return say(player, `No quest giver [${search}] found.`);
      }

      if (!npc.quests) {
        return say(player, `${npc.name} has no quests.`);
      }

      if (isNaN(questIndex) || questIndex < 0 || questIndex > npc.quests.length) {
        return say(player, `Invalid quest, use 'quest list ${search}' to see their quests.`);
      }

      let availableQuests = npc.quests
        .map(qid => state.QuestFactory.create(state, qid, player))
        .filter(quest => (player.questTracker.canStart(quest) || player.questTracker.isActive(quest.id)))
      ;

      const targetQuest = availableQuests[questIndex - 1];

      if (player.questTracker.isActive(targetQuest.id)) {
        return say(player, "You've already started that quest. Use 'quest log' to see your active quests.");
      }

      player.questTracker.start(targetQuest);
    }

    static accept(...args) {
      QuestCommand.start(...args);
    }

    static log(state, player, options) {
      const active = [...player.questTracker.activeQuests];
      if (!active.length) {
        return say(player, "You have no active quests.");
      }

      for (let i in active) {
        const [, quest] = active[i];
{'fraction_non_alphanumeric': 0.15240857096826163, 'fraction_numerical': 0.0038666022232962784, 'mean_word_length': 2.617715617715618, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 39, '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': '7045617', 'n_tokens_mistral': 1956, 'n_tokens_neox': 1920, 'n_words': 460}