Pre-release
AdventureJS Docs Downloads
Score: 0 Moves: 0
// qualifyParsedVerb.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#qualifyParsedVerb
   * @param {Object} params
   * @returns {adventurejs.parsedVerb}
   */
  p.qualifyParsedVerb = function Parser_qualifyParsedVerb(params) {
    if (!params.parsed_verb_name) return false;
    this.game.log(
      "L1252",
      "log",
      "high",
      `[qualifyParsedVerb.js] qualifyParsedVerb() receive: ${params.parsed_verb_name}`,
      "Parser"
    );
    var dictionary_verb = this.dictionary.verbs[params.parsed_verb_name];
    if (!dictionary_verb) return false;

    var input = this.game.getInput();
    var player = this.game.getPlayer();
    var subject = input.getSubject();
    var subject_is_player = subject.id === player.id;

    var room = this.game.getRoom();
    var nest_asset = subject.getNestOrPlaceAsset();
    var nest_aspect = subject.getNestOrPlaceAspect();
    var nest_prep = subject.getNestOrPlacePreposition();
    var output_class = "";

    var player_cant = !subject.can[dictionary_verb.name];
    var nest_cant =
      !nest_aspect ||
      !nest_aspect.nest ||
      !nest_aspect.nest.can[dictionary_verb.name];
    var player_cant_msg = ` and ${subject.id}.can.${dictionary_verb.name} is false`;
    var nest_cant_msg = nest_aspect
      ? ` and ${nest_aspect.context_id}.aspects.${nest_aspect.preposition}.can.${dictionary_verb.name} is false`
      : ``;

    var msg = "";
    var qualifiers = dictionary_verb.subject_must_be;

    if (qualifiers.player) {
      if (!subject_is_player) {
        this.game.debug(
          `D1378 | qualifyParsedVerb.js | ${dictionary_verb.name}.subject_must_be.player `
        );
        let user_pronoun =
          this.game.dictionary.pronouns[this.game.getPlayer().pronouns]["our"];

        msg += subject.ignore_msg || `{We} ignores ${user_pronoun} command. `;

        this.game.print(msg, output_class);
        return false;
      }
    }

    if (qualifiers.not_on_floor) {
      if (subject.isOnFloor()) {
        this.game.debug(
          `D1878 | qualifyParsedVerb.js | ${dictionary_verb.name}.subject_must_be.not_on_floor `
        );
        msg += `{We} can't do that from {our} position 
          ${subject.getPostureGerund()} on the 
          ${subject.isNested() ? subject.getNestAsset().name : "floor"}. `;
        this.game.print(msg, output_class);
        return false;
      }
    }

    if (qualifiers.not_constrained) {
      if (subject.is.constrained) {
        this.game.debug(
          `D1879 | qualifyParsedVerb.js | ${dictionary_verb.name}.subject_must_be.not_constrained `
        );
        msg +=
          A.getSAF.call(this.game, subject.constrained_msg) ||
          "{We're} constrained. ";
        this.game.print(msg, output_class);
        return false;
      }
    }

    if (qualifiers.not_under) {
      // if(  ) {
      //   msg += "The verb \""
      //   + dictionary_verb.prettyname
      //   this.game.print( msg, output_class );
      //   return false;
      //}
    }

    if (qualifiers.not_behind) {
      // if(  ) {
      //   msg += "The verb \""
      //   + dictionary_verb.prettyname
      //   this.game.print( msg, output_class );
      //   return false;
      //}
    }

    if (qualifiers.not_nested_elsewhere) {
      // if(  ) {
      //   msg += "The verb \""
      //   + dictionary_verb.prettyname
      //   this.game.print( msg, output_class );
      //   return false;
      //}
    }

    if (qualifiers[`able_to_${dictionary_verb.name}`]) {
      if (
        !subject.can[dictionary_verb.name] ||
        !nest_aspect.nest.can[dictionary_verb.name]
      ) {
        this.game.debug(
          `D1410 | qualifyParsedVerb.js | ${dictionary_verb.name}.subject_must_be.able_to_${dictionary_verb.name}${
            player_cant ? player_cant_msg : ""
          }${nest_cant ? nest_cant_msg : ""}`
        );
        msg += `{We} can't ${dictionary_verb.name} `;
        if (nest_cant)
          msg += `while {we're} ${nest_prep} ${nest_asset.articlename}. `;
        else msg += `right now. `;
        this.game.print(msg, output_class);
        return false;
      }
    }

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