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

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

  /**
   * @augments {adventurejs.Verb}
   * @class shake
   * @ajsnode game.dictionary.verbs.shake
   * @ajsconstruct MyGame.createVerb({ "name": "shake", [...] });
   * @ajsconstructedby adventurejs.Dictionary#createVerb
   * @hideconstructor
   * @ajsinstanceof Verb
   * @ajsnavheading ManipulationVerbs
   * @summary Verb meaning shake, as in "shake baby".
   * @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; shake baby</span>
   * You shake the baby gargoyle. The baby gargoyle
   * strenuously objects. It clamps a stone hand around
   * your wrist then, using that initial grip, proceeds
   * to climb hand-over-hand up your arms, shoulders, and
   * onto your head, where it takes up a perch that feels
   * unsettlingly permanent.
   * </pre>
   * <p>
   * <strong>Shake</strong> requires that the
   * {@link adventurejs.Tangible|Tangible}
   * {@link adventurejs.Asset|Asset} to be shaken has
   * asset.dov.shake.enabled
   * set to true. No special logic is provided with the verb.
   * 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>
   * @ajsverbreactions
   * @ajsverbphases doBeforeTry, doAfterTry, doBeforeSuccess, doAfterSuccess
   */
  A.Preverbs.shake = {
    name: "shake",
    prettyname: "shake",
    past_tense: "shook",
    synonyms: ["shake"],

    /**
     * @memberof shake
     * @ajsverbphrase
     * phrase1:
     * {
     *   accepts_noun:true,
     *   requires_noun:true,
     *   noun_must_be:
     *   {
     *     known: true,
     *     tangible: true,
     *     present: true,
     *     visible: true,
     *     reachable: true,
     *   },
     * },
     */
    phrase1: {
      accepts_noun: true,
      requires_noun: true,
      noun_must_be: {
        known: true,
        tangible: true,
        present: true,
        visible: true,
        reachable: true,
      },
    },

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

    doTry: function () {
      var input = this.game.getInput();
      var direct_object = input.getAsset(1);
      var msg = "";

      if (!direct_object.isDOV("shake")) {
        this.game.debug(
          `F1405 | ${this.name}.js | ${direct_object.id}.dov.shake.enabled is false `
        );
        msg += `$(We) can't shake ${direct_object.articlename}. `;
        this.handleFailure(msg);
        return null;
      }

      return true;
    },

    doSuccess: function () {
      var input = this.game.getInput();
      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 player = this.game.getPlayer();
      var results;
      var msg = "";

      this.game.debug(`F1406 | ${this.name}.js | print doSuccess `);
      msg += `$(We) shake ${direct_object.articlename}. `;

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