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

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

  /**
   * @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 Verbs_Subscriptions
   * @tutorial AdvancedVerbs_VerbAnatomy
   * @tutorial AdvancedVerbs_VerbProcess
   * @tutorial AdvancedVerbs_ModifyVerbs
   * @tutorial AdvancedVerbs_ModifyVerbs
   * @classdesc
   * <pre class="display border outline">
   * <span class="ajs-player-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. By default, no special results will occur.
   * Authors wanting to make use of it may need to use a method such
   * as verb hooks. See
   * <a href="/doc/Verbs_PhaseHooks.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",
    gerund: "tearing",

    /**
     * @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,
     *   preposition_must_be: ["up"],
     * },
     */
    phrase1: {
      accepts_noun: true,
      requires_noun: true,
      noun_must_be: {
        known: true,
        tangible: true,
        present: true,
        visible: true,
        reachable: true,
      },
      accepts_preposition: true,
      preposition_must_be: ["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(
          `D1435 | ${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.allowVerbOnce(this.name, "dov") &&
        direct_object.didVerb(this.name, "dov")
      ) {
        this.game.debug(
          `D1992 | ${this.name}.js | ${direct_object.id}.dov.${this.name}.once and ${direct_object.id}.did.${this.name}.directly `
        );
        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 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 results;
      var msg = "";

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

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

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

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