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

  /**
   * @augments {adventurejs.Verb}
   * @class out
   * @ajsnode game.dictionary.verbs.out
   * @ajsconstruct MyGame.createVerb({ "name": "out", [...] });
   * @ajsconstructedby adventurejs.Dictionary#createVerb
   * @hideconstructor
   * @ajsinstanceof Verb
   * @ajsnavheading DirectionVerbs
   * @summary Verb meaning travel out.
   * @tutorial Scripting_VerbSubscriptions
   * @tutorial Verbs_VerbAnatomy
   * @tutorial Verbs_VerbProcess
   * @tutorial Verbs_ModifyVerbs
   * @tutorial Verbs_WriteVerbs
   * @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; out</span>
   * You overcome your fears and leap out of the plane.
   * Too bad you forgot the parachute.
   * </pre>
   * <p>
   * Direction verb: go <strong>out</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.out = {
    name: "out",
    is_direction: true,
    is_relative_direction: true,
    synonyms: ["out"],
    type: { direction: true },
    adjective: "outward",

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

    doTry: function () {
      var input = this.game.getInput();
      var subject = input.getSubject();
      var verb_phrase = input.verb_phrase;
      var msg = "";
      var results;

      if (subject.isNested()) {
        var p = subject.getNestPreposition();
        // we'll take "out" to mean out of in, under or behind
        if (p === "in" || p === "under" || p === "behind") {
          this.game.debug(
            `D1141 | ${
              this.name
            }.js | infer 'get out of ${subject.getNestId()}', doVerb go out`
          );
          input.setVerb(1, "go");
          input.setPreposition(1, "out");
          input.setStructure("verb preposition noun");
          input.setAsset(1, subject.getNestAsset());
          return this.game.dictionary.doVerb("go");
        }
      } // subject.isNested()

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

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