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

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

  /**
   * @augments {adventurejs.Verb}
   * @class tear
   * @ajsnode game.dictionary.verbs.tear
   * @ajsconstruct MyGame.createVerb({ "name": "tear", [...] });
   * @ajsconstructedby adventurejs.Dictionary#createVerb
   * @hideconstructor
   * @ajsinstanceof Verb
   * @ajsnavheading DestructionVerbs
   * @summary Verb meaning tear, as in "tear envelope".
   * @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; tear card</span>
   * You tear the punch card, despite the explicit warning on it
   * that says, "Do not fold, spindle, or mutilate". The menacing
   * robot stops pursuing you and grinds to a halt. Smoke trickles
   * out of its chassis as it audibly breaks down. It begins to
   * vibrate and wobble. One panel flies off and then another, and
   * the robot begins ejecting cogs and gears at high velocity.
   * Finally, the robot collapses entirely into a pile of greasy parts.
   * </pre>
   * <p>
   * <strong>Tear</strong> requires that the
   * {@link adventurejs.Tangible|Tangible}
   * {@link adventurejs.Asset|Asset} to be torn has
   * asset.dov.tear.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.tear = {
    name: "tear",
    prettyname: "tear",
    past_tense: "tore",
    synonyms: ["tear", "rip"],
    state: "torn",

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

    /**
     * @memberof tear
     * @ajsverbphrase
     * phrase1:
     * {
     *   accepts_noun:true,
     *   requires_noun:true,
     *   noun_must_be:
     *   {
     *     known: true,
     *     tangible: true,
     *     present: true,
     *     visible: true,
     *     reachable: true,
     *   },
     *   accepts_preposition: true,
     *   accepts_these_prepositions: ["up"],
     * },
     */
    phrase1: {
      accepts_noun: true,
      requires_noun: true,
      noun_must_be: {
        known: true,
        tangible: true,
        present: true,
        visible: true,
        reachable: true,
      },
      accepts_preposition: true,
      accepts_these_prepositions: ["up"],
    },

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

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

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

      // single use direct object?
      if (
        direct_object.DOVallowOnce(this.name) &&
        direct_object.DOVdidDo(this.name)
      ) {
        this.game.debug(
          `F1992 | ${this.name}.js | ${direct_object.id}.dov.${this.name}.once and ${direct_object.id}.dov.${this.name}.did_do `,
        );
        msg += `${direct_object.Articlename} has already been ${this.past_tense}. `;
        this.handleFailure(msg);
        return false;
      }

      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(`F1436 | ${this.name}.js | print doSuccess `);

      var already_torn = direct_object.isState(this.state);

      // apply state changes
      this.setState(direct_object, true);

      // compose output
      msg += `$(We) tear ${direct_object.articlename}${already_torn ? " some more" : ""}. `;

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