Pre-release
AdventureJS Docs Downloads
Score: 0 Moves: 0
// down.js
// OK 09 2023
(function () {
  /*global adventurejs A*/

  /**
   * @augments {adventurejs.Verb}
   * @class down
   * @ajsnode game.dictionary.verbs.down
   * @ajsconstruct MyGame.createVerb({ "name": "down", [...] });
   * @ajsconstructedby adventurejs.Dictionary#createVerb
   * @hideconstructor
   * @ajsinstanceof Verb
   * @ajsnavheading DirectionVerbs
   * @summary Verb meaning travel down.
   * @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; down</span>
   * You slide down through the dark hole and quickly get eaten by a grue.
   * </pre>
   * <p>
   * Direction verb: go <strong>down</strong>.
   * To learn about {@link adventurejs.Exit|Exits},
   * see <a href="/doc/GetStarted_CreateAnExit.html">Create an Exit</a>.
   * </p>
   * @ajsverbreactions doRemoveThisFromThat, doRemoveThatFromThis, doMoveThisToThat, doMoveThatToThis
   * @ajsverbphases doBeforeTry, doAfterTry, doBeforeSuccess, doAfterSuccess
   */
  A.Preverbs.down = {
    name: "down",
    is_direction: true,
    is_relative_direction: true,
    synonyms: ["down", "d"],
    type: { direction: true },
    adjective: "downward",

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

    doTry: function () {
      var input = this.game.getInput();
      var subject = input.getSubject();
      var nest_asset = subject.getNestAsset();
      var nest_aspect = subject.getNestAspect();
      var input = this.game.getInput();
      var verb_phrase = input.verb_phrase;
      var msg = "";
      var results;
      var newverb, newprep;

      // is subject nested?
      if (nest_asset) {
        // climb down?
        if (
          nest_aspect.scale_increment > 0 &&
          subject.getY() > nest_asset.getY() + nest_aspect.scale_increment
        ) {
          newverb = this.game.hasVerb("climb") ? "climb" : "go";
          newprep = "down";
        }

        // get off?
        else if (nest_asset) {
          newverb = "go";
          newprep = "off";
        }

        if (newverb) {
          this.game.debug(
            `D1137 | ${this.name}.js | subject is nested ${nest_aspect.preposition} ${nest_asset.id}, infer doVerb ${newverb} ${newprep}`
          );
          input.input_verb = newverb;
          input.setVerb(1, newverb);
          input.setAsset(1, nest_asset);
          input.setPreposition(1, newprep);
          input.setStructure("verb preposition noun");
          return this.game.dictionary.doVerb(newverb);
        }
      }

      // just go down
      results = this.game.tryTravel(this.name);
      if (!results) {
        this.handleFailure();
      }
      return results;
    },

    doSuccess: function () {
      return this.handleSuccess();
    },
  };
})();