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

  /**
   * @augments {adventurejs.Verb}
   * @class right
   * @ajsnode game.dictionary.verbs.right
   * @ajsconstruct MyGame.createVerb({ "name": "right", [...] });
   * @ajsconstructedby adventurejs.Dictionary#createVerb
   * @hideconstructor
   * @ajsinstanceof Verb
   * @ajsnavheading DirectionVerbs
   * @summary Verb meaning travel to right 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; right</span>
   * You turn to the right. You turn to the left.
   * You turn to the right. You do the hokey pokey
   * and you turn yourself about.
   * </pre>
   * <p>
   * Direction verb: go <strong>right</strong>. Because right is a relative
   * direction, it's assumed that there probably won't be a right exit, though
   * it does support one. The verb logic looks for a starboard exit first,
   * which would be right in nautical terms, then looks for a right exit,
   * then defaults to telling the player they turn in place.
   * 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.right = {
    name: "right",
    is_direction: true,
    is_relative_direction: true,
    synonyms: ["right"],
    type: { direction: true },
    adjective: "rightward",
    article: "the",

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

    doTry: function () {
      var results;
      if (this.game.getCurrentRoom().exits.starboard) {
        results = this.game.tryTravel("starboard");
        if (!results) {
          this.handleFailure();
        }
      } else if (this.game.getCurrentRoom().exits.right) {
        results = this.game.tryTravel("right");
        if (!results) {
          this.handleFailure();
        }
        return results;
      }
      return true;
    },

    doSuccess: function () {
      // compose output
      var msg = `$(We) turn to the ${this.name}. `;

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