Pre-release
Adventure.js Docs Downloads
Score: 0 Moves: 0
// qualifyParsedVerb.js

(function () {
  /*global adventurejs A*/
  "use strict";

  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) {
    this.game.log("log", "high", "qualifyParsedVerb.js > Begin", "Parser");
    if (!params.parsed_verb_name) return false;
    let dictionary_verb = this.dictionary.verbs[params.parsed_verb_name];
    if (!dictionary_verb) return false;
    let player = this.game.getPlayer();
    let room = this.game.getCurrentRoom();
    let nest = player.getPlaceAspect();
    let output_class = "";

    let msg = "";
    let qualifiers = dictionary_verb.player_must_be;

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

    if (qualifiers.not_constrained) {
      if (player.is.constrained) {
        this.game.debug(
          `F1879 | qualifyParsedVerb.js | ${dictionary_verb.name}.player_must_be.not_constrained `
        );
        msg +=
          A.getSAF.call(this.game, player.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_crawl) {
      this.game.debug(
        `F1410 | qualifyParsedVerb.js | ${dictionary_verb.name}.player_must_be.able_to_crawl `
      );
      if (
        !player.can.crawl ||
        !player.getNestOrPlaceAspect().player.can.crawl
      ) {
        msg += "$(We) can't crawl right now. ";
        this.game.print(msg, output_class);
        return false;
      }
    }

    if (qualifiers.able_to_float) {
      this.game.debug(
        `F1880 | qualifyParsedVerb.js | ${dictionary_verb.name}.player_must_be.able_to_float `
      );
      if (
        !player.can.float ||
        !player.getNestOrPlaceAspect().player.can.float
      ) {
        msg += "$(We) can't float right now. ";
        this.game.print(msg, output_class);
        return false;
      }
    }

    if (qualifiers.able_to_fly) {
      this.game.debug(
        `F1881 | qualifyParsedVerb.js | ${dictionary_verb.name}.player_must_be.able_to_fly `
      );
      if (!player.can.fly || !player.getNestOrPlaceAspect().player.can.fly) {
        msg += "$(We) can't fly right now. ";
        this.game.print(msg, output_class);
        return false;
      }
    }

    if (qualifiers.able_to_jump) {
      this.game.debug(
        `F1012 | qualifyParsedVerb.js | ${dictionary_verb.name}.player_must_be.able_to_jump `
      );
      if (!player.can.jump || !player.getNestOrPlaceAspect().player.can.jump) {
        msg += "$(We) can't jump right now. ";
        this.game.print(msg, output_class);
        return false;
      }
    }

    if (qualifiers.able_to_hop) {
      this.game.debug(
        `F1020 | qualifyParsedVerb.js | ${dictionary_verb.name}.player_must_be.able_to_hop `
      );
      if (!player.can.hop || !player.getNestOrPlaceAspect().player.can.hop) {
        msg += "$(We) can't hop right now. ";
        this.game.print(msg, output_class);
        return false;
      }
    }

    if (qualifiers.able_to_hover) {
      this.game.debug(
        `F1411 | qualifyParsedVerb.js | ${dictionary_verb.name}.player_must_be.able_to_hover `
      );
      if (
        !player.can.hover ||
        !player.getNestOrPlaceAspect().player.can.hover
      ) {
        msg += "$(We) can't hover right now. ";
        this.game.print(msg, output_class);
        return false;
      }
    }

    if (qualifiers.able_to_ride) {
      this.game.debug(
        `F1318 | qualifyParsedVerb.js | ${dictionary_verb.name}.player_must_be.able_to_ride `
      );
      if (!player.can.ride || !player.getNestOrPlaceAspect().player.can.ride) {
        msg += "$(We) can't ride right now. ";
        this.game.print(msg, output_class);
        return false;
      }
    }

    if (qualifiers.able_to_run) {
      this.game.debug(
        `F1316 | qualifyParsedVerb.js | ${dictionary_verb.name}.player_must_be.able_to_run `
      );
      if (!player.can.run || !player.getNestOrPlaceAspect().player.can.run) {
        msg += "$(We) can't run here. ";
        this.game.print(msg, output_class);
        return false;
      }
    }

    if (qualifiers.able_to_slither) {
      this.game.debug(
        `F1877 | qualifyParsedVerb.js | ${dictionary_verb.name}.player_must_be.able_to_slither `
      );
      if (
        !player.can.slither ||
        !player.getNestOrPlaceAspect().player.can.slither
      ) {
        msg += "$(We) can't slither right now. ";
        this.game.print(msg, output_class);
        return false;
      }
    }

    if (qualifiers.able_to_swim) {
      this.game.debug(
        `F1882 | qualifyParsedVerb.js | ${dictionary_verb.name}.player_must_be.able_to_swim `
      );
      if (!player.can.swim || !player.getNestOrPlaceAspect().player.can.swim) {
        msg += "$(We) can't swim here. ";
        this.game.print(msg, output_class);
        return false;
      }
    }

    if (qualifiers.able_to_walk) {
      this.game.debug(
        `F1317 | qualifyParsedVerb.js | ${dictionary_verb.name}.player_must_be.able_to_walk `
      );
      if (!player.can.walk || !player.getNestOrPlaceAspect().player.can.walk) {
        msg += "$(We) can't walk here. ";
        this.game.print(msg, output_class);
        return false;
      }
    }

    return dictionary_verb;
  };
})();