Pre-release
AdventureJS Docs Downloads Bundler Devlog Score: 0 Moves: 0
// qualifyVerbAble.js

(function () {
  /* global AdventureJS A */

  var p = AdventureJS.Parser.prototype;

  /**
   * End turn if input verb can't act upon noun or in current circumstance.
   * @memberOf AdventureJS.Parser
   * @method AdventureJS.Parser#qualifyVerbAble
   * @param {Object} params
   * @returns Object
   */
  p.qualifyVerbAble = function Parser_qualifyVerbAble(dictionary_verb) {
    if (!dictionary_verb) return false;
    this.game.log(
      "L1736",
      "log",
      "high",
      `[qualifyVerbAble.js] qualifyVerbAble() receive: ${dictionary_verb}`,
      "Parser"
    );

    const qualifiers = dictionary_verb.subject_must_be;

    if (qualifiers[`able_to_${dictionary_verb.name}`]) {
      let msg = "";

      const input = this.game.getInput();
      const subject = input.getSubject();
      if (!subject.can[dictionary_verb.name]) {
        this.game.debug(
          `D1410`,
          `qualifyVerbAble.js `,
          `${dictionary_verb.name}.subject_must_be.able_to_${dictionary_verb.name} and ${subject.id}.can.${dictionary_verb.name} is false`
        );
        msg += `subject can't: {We} can't ${dictionary_verb.name} right now. `;
        this.game.print(msg);
        return false;
      }

      let target_aspect;
      const preposition = input.getPreposition(1);
      const target = input.getAsset(1);
      if (target && preposition) target_aspect = target.getAspect(preposition);
      console.warn(`target_aspect`, target_aspect);

      if (target_aspect && !target_aspect?.nest?.can[dictionary_verb.name]) {
        this.game.debug(
          `D1790`,
          `qualifyVerbAble.js `,
          `${dictionary_verb.name}.subject_must_be.able_to_${dictionary_verb.name} 
          and ${target.id}.aspects.${preposition}.nest.can.${dictionary_verb.name} is false`
        );
        msg += `target can't: {We} can't ${dictionary_verb.name} ${preposition} ${target.article_name}. `;
        this.game.print(msg);
        return false;
      }

      const nest_asset = subject.getNestOrPlaceAsset();
      const nest_aspect = subject.getNestOrPlaceAspect();
      const nest_prep = subject.getNestOrPlacePreposition();

      console.warn({ preposition, target, target_aspect });
      if (!target_aspect && !nest_aspect?.nest?.can[dictionary_verb.name]) {
        this.game.debug(
          `D1843`,
          `qualifyVerbAble.js `,
          ` ${dictionary_verb.name}.subject_must_be.able_to_${dictionary_verb.name}
           and ${nest_aspect.context_id}.aspects.${nest_aspect.preposition}.can.${dictionary_verb.name} is false`
        );
        msg += `nest can't: {We} can't ${dictionary_verb.name} `;
        if (nest_asset.hasClass("Room")) {
          msg += `here. `;
        } else {
          msg += `while {we're} ${nest_prep} ${nest_asset.article_name}. `;
        }
        this.game.print(msg);
        return false;
      }
    }

    this.game.log(
      "L1737",
      "log",
      "high",
      `[qualifyVerbAble.js] qualifyVerbAble() return: ${dictionary_verb.name}`,
      "Parser"
    );
    return dictionary_verb;
  };
})();