Pre-release
Adventure.js Docs Downloads
Score: 0 Moves: 0
// yell.js

(function () {
  /*global adventurejs A*/
  "use strict";

  /**
   * @augments {adventurejs.Verb}
   * @class yell
   * @ajsnode game.dictionary.verbs.yell
   * @ajsconstruct MyGame.createVerb({ "name": "yell", [...] });
   * @ajsconstructedby adventurejs.Dictionary#createVerb
   * @hideconstructor
   * @ajsinstanceof Verb
   * @ajsnavheading Conversation Verbs
   * @summary Verb that means yell, as in "yell MORTAL COMBAT".
   * @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; yell</span>
   * Aaaaaah!
   * </pre>
   * <p>
   * <strong>Yell</strong> is intransitive, meaning it takes no object.
   * Yell doesn't provide any special logic.
   * Authors wanting to make use of it may need to use a method such
   * as verb hooks. See
   * <a href="/doc/Scripting_VerbPhases.html">Verb Phases</a>
   * to learn more.
   * </p>
   * @todo yell at character, yell idea at character
   * @ajsverbreactions
   * @ajsverbphases doBeforeTry, doAfterTry, doBeforeSuccess, doAfterSuccess
   */
  A.Preverbs.yell = {
    name: "yell",
    past_tense: "yelled",
    synonyms: ["yell"],

    /**
     * @memberof yell
     * @ajsverbphrase
     * phrase1:
     * {
     *   accepts_noun: true,
     *   accepts_preposition: true,
     *   noun_must_be:
     *   {
     *     known: true,
     *   },
     * },
     */
    phrase1: {
      accepts_noun: true,
      accepts_preposition: true,
      noun_must_be: {
        known: true,
      },
    },

    /**
     * @memberof yell
     * @ajsverbphrase
     * phrase2:
     * {
     *   accepts_noun: true,
     *   noun_must_be:
     *   {
     *     known: true,
     *   },
     * },
     */
    phrase2: {
      accepts_noun: true,
      noun_must_be: {
        known: true,
      },
    },

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

    doTry: function () {
      var input = this.game.getInput();
      var player = this.game.getPlayer();
      var currentRoom = this.game.getCurrentRoom();
      var msg = "";

      if (player.is.mute) {
        this.game.debug(`F1506 | ${this.name}.js | ${player.id}.is.mute `);
        msg += `$(We) can't yell at all. `;
        this.handleFailure(msg);
        return null;
      }

      if (currentRoom.is_vacuum) {
        this.game.debug(
          `F1507 | ${this.name}.js | ${currentRoom.id}.is_vacuum `
        );
        msg += `In space, no one can hear you scream. `;
        this.handleFailure(msg);
        return null;
      }

      return true;
    },

    doSuccess: function () {
      var input = this.game.getInput();
      var player = this.game.getPlayer();
      var currentRoom = this.game.getCurrentRoom();
      var msg = "";

      this.game.debug(`F1505 | ${this.name}.js | print doSuccess `);
      msg += `Aaaaaah! `;

      this.handleSuccess(msg, currentRoom);
      return true;
    },
  };
})();