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

(function () {
  /* global adventurejs A */

  /**
   * @augments {adventurejs.Verb}
   * @class yell
   * @ajsnode game.dictionary.verbs.yell
   * @ajsconstruct MyGame.createVerb({ "name": "yell", [...] });
   * @ajsconstructedby adventurejs.Dictionary#createVerb
   * @hideconstructor
   * @ajsinstanceof Verb
   * @ajsnavheading ConversationVerbs
   * @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="ajs-player-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", "scream", "shout"],
    gerund: "yelling",

    /**
     * @ajsverbstructures
     * @memberof yell
     */
    accepts_structures: [
      "verb",
      "verb noun",
      "verb preposition noun",
      "verb noun preposition noun",
      "verb preposition noun preposition noun",
    ],

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

    /**
     * @memberof yell
     * @ajsverbphrase
     * phrase2:
     * {
     *   accepts_noun: true,
     *   noun_must_be:
     *   {
     *     known: true,
     *   },
     *   accepts_preposition: true,
     *   requires_preposition: true,
     * },
     */
    phrase2: {
      accepts_noun: true,
      noun_must_be: { known: true },
      accepts_preposition: true,
      requires_preposition: true,
      // preposition_must_be: ["at"],
    },

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

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

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

      if (room.is.vacuum) {
        this.game.debug(`D1507 | ${this.name}.js | ${room.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 subject = input.getSubject();
      var direct_object = input.getAsset(1);
      var direct_preposition = input.getPreposition(1);
      var indirect_object = input.getAsset(2);
      var indirect_preposition = input.getPreposition(2);
      var room = this.game.getRoom();
      var results;
      var msg = "";

      // compose output
      if (input.hasStructure("verb")) {
        msg += `WILHELM!!! `;
      } else {
        msg +=
          `{We} ${this.agree()}` +
          `${direct_preposition ? " " + direct_preposition : ""}` +
          `${
            direct_object
              ? direct_object.hasClass("GlobalString")
                ? " " + input.strings[0]
                : " " + direct_object.articlename
              : ""
          }` +
          `${indirect_preposition ? " " + indirect_preposition : ""}` +
          `${indirect_object ? " " + indirect_object.articlename : ""}` +
          `. `;
      }

      // --------------------------------------------------
      // print output
      // --------------------------------------------------
      return this.handleSuccess(msg, direct_object ? direct_object : room);
    },
  };
})();