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

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

  /**
   * @augments {adventurejs.Verb}
   * @class flip
   * @ajsnode game.dictionary.verbs.flip
   * @ajsconstruct MyGame.createVerb({ "name": "flip", [...] });
   * @ajsconstructedby adventurejs.Dictionary#createVerb
   * @hideconstructor
   * @ajsinstanceof Verb
   * @ajsnavheading ManipulationVerbs
   * @summary Verb meaning flip an asset.
   * @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; flip griddlecake</span>
   * You flip the griddlecake on the grill.
   * Ahh, it's a perfect golden brown.
   * </pre>
   * <p>
   * <strong>Flip</strong> requires that the
   * {@link adventurejs.Tangible|Tangible}
   * {@link adventurejs.Asset|Asset} to be flipped has
   * asset.dov.flip.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.flip = {
    name: "flip",
    prettyname: "flip",
    past_tense: "flipped",
    synonyms: ["flip"],
    verb_prep_noun: ["turn over"],

    /**
     * @memberof flip
     * @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 flip
     * @ajsverbparams
     * with_params: {},
     */
    with_params: {},

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

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

      return true;
    },

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

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

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