Pre-release
AdventureJS Docs Downloads
Score: 0 Moves: 0
// step.js

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

  /**
   * @augments {adventurejs.Verb}
   * @class step
   * @ajsnode game.dictionary.verbs.step
   * @ajsconstruct MyGame.createVerb({ "name": "step", [...] });
   * @ajsconstructedby adventurejs.Dictionary#createVerb
   * @hideconstructor
   * @ajsinstanceof Verb
   * @ajsnavheading LocomotionVerbs
   * @summary Verb meaning step, as in "step on ant" or "step over threshold".
   * @tutorial Scripting_VerbSubscriptions
   * @tutorial Verbs_VerbAnatomy
   * @tutorial Verbs_VerbProcess
   * @tutorial Verbs_ModifyVerbs
   * @tutorial Verbs_WriteVerbs
   * @classdesc
   * <pre class="display border outline">
   * <span class="input">&gt; step over threshold</span>
   * You step over the threshold, carrying your new bride, careful to
   * avoid tripping over your own comically large feet. Your bride runs
   * her gloved hand through your rainbow colored perm, tickling your nose
   * with her colorful yellow and fuscia frill. She raises her head for
   * a kiss, and you mash your brightly painted red lips into hers,
   * commingling both your makeups into smears of red and white pancake.
   * You part breathlessly, and she honks your foam nose in connubial bliss.
   * </pre>
   * <p>
   * See
   * <a href="/doc/Scripting_VerbPhases.html">Verb Phases</a>
   * to learn how to customize this verb.
   * </p>
   * @ajsverbreactions doRemoveThisFromThat, doRemoveThatFromThis, doMoveThisToThat, doMoveThatToThis, doNestThatToThis, doNestThisToThat, doUnnestThatFromThis, doUnnestThisFromThat
   * @ajsverbphases doBeforeTry, doAfterTry, doBeforeSuccess, doAfterSuccess
   */
  A.Preverbs.step = {
    name: "step",
    prettyname: "step",
    past_tense: "stepped",
    synonyms: ["step"],
    gerund: "stepping",

    player_must_be: {
      not_constrained: true,
      not_on_floor: true,
      not_nested_elsewhere: true,
    },

    /**
     * @ajsverbstructures
     * @memberof step
     */
    accepts_structures: ["verb", "verb noun", "verb preposition noun"],

    /**
     * @memberof step
     * @ajsverbphrase
     * phrase1:
     * {
     *   accepts_noun:true,
     *   noun_must_be:
     *   {
     *     known: true,
     *     matter: true,
     *     present_if_tangible: true,
     *     reachable_if_tangible: true,
     *     visible_if_tangible: true,
     *     not_worn: true,
     *     not_in_inventory: true,
     *   },
     *   accepts_preposition: true,
     *   requires_preposition: true,
     * },
     */
    phrase1: {
      accepts_noun: true,
      noun_must_be: {
        known: true,
        matter: true,
        present: true,
        reachable: true,
        reservoir_if_substance: true,
        visible: true,
        not_in_inventory: true,
      },
      accepts_preposition: true,
      // requires_preposition: true,
    },

    /**
     * @memberof step
     * @ajsverbparams
     * with_params: {},
     */
    with_params: {},

    doTry: function () {
      var input = this.game.getInput();
      var verb_phrase = input.verb_phrase;
      var direct_object = input.getAsset(1);
      var direct_preposition = input.getPreposition(1);
      var direct_substance = input.getSubstance(1);
      var direct_container;
      var input = this.game.getInput();
      var verb_phrase = input.verb_phrase;
      var player = this.game.getPlayer();
      var nest_asset = player.getNestAsset();
      var msg = "";
      var containers, container;
      var results;

      if (!direct_object) {
        return true;
      }

      // this can be a travel verb - is noun a direction?
      if (direct_object.direction) {
        if (
          !direct_preposition ||
          "through" === direct_preposition ||
          "in" === direct_preposition
        ) {
          this.game.log(
            "L1374",
            "log",
            "high",
            `${this.name}.js | infer tryTravel ${direct_object.direction}`,
            "verbs"
          );
          return this.game.tryTravel(direct_object.direction);
        }
      }

      // no preposition
      if (!direct_preposition) {
        this.game.debug(`D1644 | ${this.name}.js | preposition required `);
        msg += this.game.parser.getUnparsedMessage(input.getInput());
        this.handleFailure(msg);
        return null;
      }

      // if (direct_substance) {
      //   direct_container = direct_object;
      //   direct_object = direct_substance;
      // }

      if (direct_object.id === nest_asset.id) {
        this.game.debug(
          `D2094 | ${this.name}.js | player is ${direct_preposition} ${direct_object.id} `
        );
        msg += `$(We're) ${player.getPostureGerund()} ${player.getNestPreposition()} ${
          direct_object.articlename
        }. `;
        this.handleFailure(msg);
        return null;
      }

      // did player mean to stand on the thing?
      if (
        direct_preposition === "on" &&
        direct_object.hasQuirk("step_on_means_stand_on") &&
        this.game.hasVerb("stand")
      ) {
        this.game.log(
          "L1375",
          "log",
          "high",
          `${this.name}.js | infer verb stand`,
          "verbs"
        );
        return this.game.dictionary.doVerb("stand");
      }

      if (
        "out" === direct_preposition &&
        nest_asset &&
        nest_asset.id === direct_object.id
      ) {
        this.game.log(
          "L1376",
          "log",
          "high",
          `${this.name}.js | infer verb go`,
          "verbs"
        );
        input.setVerb(1, "go");
        return this.game.dictionary.doVerb("go");
      }

      // did player input something like "step in tub" ?
      // let them go
      if (
        direct_object.hasAspectAt(direct_preposition) &&
        direct_object.getAspectAt(direct_preposition).canPlayer("enter")
      ) {
        this.game.log(
          "L1377",
          "log",
          "high",
          `${this.name}.js | infer verb go`,
          "verbs"
        );
        input.setVerb(1, "go");
        return this.game.dictionary.doVerb("go");
      }

      // does aspect exist but player can't enter it?
      if (
        direct_object.hasAspectAt(direct_preposition) &&
        !direct_object.getAspectAt(direct_preposition).canPlayer("enter")
      ) {
        this.game.debug(
          `D1417 | ${this.name}.js | ${direct_object.id}.aspects.${direct_preposition}.player.can.enter is false `
        );
        msg += `$(We) can't ${this.name} ${direct_preposition} ${direct_object.articlename}. `;
        this.handleFailure(msg);
        return null;
      }

      // for aspects other than on
      if (
        "on" !== direct_preposition &&
        !direct_object.getAspectAt(direct_preposition)?.canPlayer("enter")
      ) {
        this.game.debug(
          `D1647 | ${this.name}.js | ${direct_object.id}.aspects.${direct_preposition} is unset ${direct_object.id}.aspects.${direct_preposition}.player.can.enter is false `
        );
        msg += `$(We) can't ${this.name} ${direct_preposition} ${direct_object.articlename}. `;
        this.handleFailure(msg);
        return null;
      }

      if (
        !direct_object.hasClass("Room") &&
        direct_object.getPlaceAssetId() !== player.getPlaceAssetId() &&
        direct_object.getPlaceAssetId() !== player.getNestId()
      ) {
        let place = player.getNestOrPlaceAsset();
        let is_room = place.hasClass("Room");
        this.game.debug(
          `D1652 | ${this.name}.js | 
          ${direct_object.id}'s place is 
          ${direct_object.getPlacePreposition()} 
          ${direct_object.getPlaceAssetId()} and player is 
          ${player.getPlacePreposition()} 
          ${player.getPlaceAssetId()} `
        );

        msg +=
          `$(We) can't ${this.name} ${direct_preposition} ${direct_object.articlename} ` +
          `from $(our) position ` +
          `${is_room ? "on" : player.getNestOrPlacePreposition()} ` +
          `${is_room ? "the floor" : place.articlename} ` +
          `while ${direct_object.getPronoun("we're")} ` +
          `${direct_object.getPlacePreposition()} ` +
          `${direct_object.getPlaceAsset().articlename}. `;

        this.handleFailure(msg);
        return null;
      }

      return true;
    },

    doSuccess: function () {
      var input = this.game.getInput();
      var verb_phrase = input.verb_phrase;
      // if (input.did_tryTravel) return this.handleSuccess();

      var direct_object = input.getAsset(1);
      var direct_preposition = input.getPreposition(1);
      var direct_substance = input.getSubstance(1);
      var indirect_object = input.getAsset(2);
      var indirect_preposition = input.getPreposition(2);
      var player = this.game.getPlayer();
      var results;
      var msg = "";

      // compose output
      msg +=
        `$(We) ${this.name}` +
        `${direct_preposition ? " " + direct_preposition : ""}` +
        `${
          direct_substance ? " " + direct_substance.articlename + " of " : ""
        }` +
        `${direct_object ? " " + direct_object.articlename : ""}` +
        `${indirect_preposition ? " " + indirect_preposition : ""}` +
        `${indirect_object ? " " + indirect_object.articlename : ""}` +
        `. `;

      // print output
      return this.handleSuccess(msg, direct_object);
    },
  }; // END step
})();