Pre-release
Adventure.js Docs Downloads
Score: 0 Moves: 0
// up.js
// OK 09 2023
(function () {
  /*global adventurejs A*/
  "use strict";

  /**
   * @augments {adventurejs.Verb}
   * @class up
   * @ajsnode game.dictionary.verbs.up
   * @ajsconstruct MyGame.createVerb({ "name": "up", [...] });
   * @ajsconstructedby adventurejs.Dictionary#createVerb
   * @hideconstructor
   * @ajsinstanceof Verb
   * @ajsnavheading DirectionVerbs
   * @summary Verb meaning travel to up direction.
   * @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; up</span>
   * You leap up and fail to avoid the rapidly spinning fan.
   * </pre>
   * <p>
   * Direction verb: go <strong>up</strong>.
   * To learn about {@link adventurejs.Exit|Exits},
   * see <a href="/doc/GetStarted_CreateAnExit.html">Create an Exit</a>.
   * </p>
   * @ajsverbphases doBeforeTry, doAfterTry, doBeforeSuccess, doAfterSuccess
   */
  A.Preverbs.up = {
    name: "up",
    is_direction: true,
    is_spatial_direction: true,
    synonyms: ["up", "u"],
    type: { direction: true },

    /**
     * @ajsverbstructures
     * @memberof up
     */
    accepts_structures: ["verb"],

    doTry: function () {
      var input = this.game.getInput();
      var player = this.game.getPlayer();
      var nest_asset = player.getNestAsset();

      if (
        player.isNested() &&
        player.getNestAsset().is.climbable &&
        player.position.y < player.getNestAsset().getYTop()
      ) {
        this.game.debug(
          `F1142 | ${
            this.name
          }.js | player is nested on ${player.getNestId()}, which is climbable, doVerb climb`
        );
        input.setVerb("climb");
        input.setAsset(1, nest_asset);
        input.setPreposition(1, "up");
        input.setStructure("verb preposition noun");
        this.game.dictionary.doVerb("climb");
        return null;
      }
    },

    doSuccess: function () {
      this.game.tryTravel(this.name);
      return true;
    },
  };
})();