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

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

  /**
   * @augments {adventurejs.Verb}
   * @class stomp
   * @ajsnode game.dictionary.verbs.stomp
   * @ajsconstruct MyGame.createVerb({ "name": "stomp", [...] });
   * @ajsconstructedby adventurejs.Dictionary#createVerb
   * @hideconstructor
   * @ajsinstanceof Verb
   * @ajsnavheading DestructionVerbs
   * @summary Verb meaning stomp, as in "stomp on wine glass".
   * @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; stomp on ant</span>
   * Forgetting the proportional strength of the irradiated ant,
   * you attempt to stomp on it. Using its gamma induced strength,
   * it throws you back on your bum.
   * </pre>
   * <p>
   * <strong>Stomp</strong> requires that the
   * {@link adventurejs.Tangible|Tangible}
   * {@link adventurejs.Asset|Asset} to be kicked has
   * <code>dov.stomp</code> 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/Scripting_VerbPhases.html">Verb Phases</a>
   * to learn how to customize this verb.
   * </p>
   * @ajsverbreactions doRemoveThisFromThat, doRemoveThatFromThis, doMoveThisToThat, doMoveThatToThis
   * @ajsverbphases doBeforeTry, doAfterTry, doBeforeSuccess, doAfterSuccess
   */
  A.Preverbs.stomp = {
    name: "stomp",
    prettyname: "stomp",
    past_tense: "stamped",
    synonyms: ["stomp", "stamp"],
    gerund: "stomping",

    player_must_be: {
      not_constrained: true,
      not_on_floor: true,
      not_nested_elsewhere: true,
    },

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

    /**
     * @memberof stomp
     * @ajsverbphrase
     * phrase1:
     * {
     *   noun_must_be:
     *   {
     *     known: true,
     *     matter: true,
     *     present: true,
     *     reachable: true,
     *     reservoir_if_substance: true,
     *     visible: true,
     *     not_worn: true,
     *     not_in_inventory: true,
     *   },
     *   accepts_preposition: true,
     *   accepts_these_prepositions: ["on","in"],
     * },
     */
    phrase1: {
      accepts_noun: true,
      noun_must_be: {
        known: true,
        matter: true,
        present: true,
        reachable: true,
        reservoir_if_substance: true,
        visible: true,
        not_in_inventory: true,
      },
      accepts_preposition: true,
      accepts_these_prepositions: ["on", "in"],
    },

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

    doTry: function () {
      var input = this.game.getInput();
      var verb_phrase = input.verb_phrase;
      var direct_object = input.getAsset(1);
      var direct_substance = input.getSubstance(1);
      var direct_container;
      var direct_preposition = input.getPreposition(1);
      var input = this.game.getInput();
      var verb_phrase = input.verb_phrase;
      var player = this.game.getPlayer();
      var msg = "";
      var results;

      if (!direct_object) {
        this.game.debug(`D1652 | ${this.name}.js | no direct object `);
        msg += `$(We) stomp $(our) pretty little feet. `;
        this.handleFailure(msg);
        return null;
      }

      // this can be a travel verb - is noun a direction?
      if (direct_object.direction) {
        if (
          !direct_preposition ||
          "through" === direct_preposition ||
          "in" === direct_preposition
        ) {
          return this.game.tryTravel(direct_object.direction);
        }
      }

      if (direct_substance) {
        direct_container = direct_object;
        direct_object = direct_substance;
      }

      // verb enabled?
      if (!direct_object.isDOV(this.name)) {
        this.game.debug(
          `D1989 | ${this.name}.js | ${direct_object.id}.dov.${this.name}.enabled is false `
        );
        msg += `$(We) can't ${this.name} ${
          direct_preposition ? direct_preposition : ""
        } ${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(
          `D1991 | ${this.name}.js | ${direct_object.id}.dov.${this.name}.once and ${direct_object.id}.did.${this.name}.directly `
        );
        msg += `$(We've) already ${this.past_tense} ${
          direct_preposition ? direct_preposition : ""
        } ${direct_object.articlename} enough. `;
        this.handleFailure(msg);
        return false;
      }

      // sentence structure: verb noun
      if (input.hasStructure("verb noun")) {
        // this.game.debug(` | ${this.name}.js | preposition required `);
        // msg += this.game.parser.getUnparsedMessage(input.getInput());
        // this.handleFailure(msg);
        // return null;
        direct_preposition = "on";
        input.setPreposition(1, "on");
        input.setStructure("verb preposition noun");
      } // verb noun

      // did player input something like "stomp on water" ?
      if (direct_substance) {
        // is player in same location as substance?
        if (direct_container.id !== player.getNestOrPlaceAsset().id) {
          this.game.debug(
            `D1658 | ${this.name}.js | ${direct_object.id} !== ${
              player.getNestOrPlaceAsset().id
            }`
          );
          msg += `$(We're) not standing in it. `;
          this.handleFailure(msg);
          return null;
        }
        return true;
      } // direct_object is substance

      // did player input something like "stomp in tub" ?
      // if they're in the tub let them do it
      if (
        player.getNestOrPlaceAsset().id === direct_object.id &&
        player.getNestOrPlacePreposition() === direct_preposition
      ) {
        this.game.debug(`D1654 | ${this.name}.js | allow stomp `);
        return true;
      }

      // did player input something like "stamp in desk" ?
      // but can't go in desk?
      if (
        "on" !== direct_preposition &&
        !direct_object.getAspectAt(direct_preposition)?.canPlayer("enter")
      ) {
        this.game.debug(`D1660 | ${this.name}.js | doVerb go `);
        msg += `$(We) can't stomp ${direct_preposition} ${direct_object.articlename}. `;
        this.handleFailure(msg);
        return null;
      }

      if (
        direct_object.getPlaceAssetId() !== player.getPlaceAssetId() &&
        direct_object.getPlaceAssetId() !== player.getNestId()
      ) {
        this.game.debug(
          `D1655 | ${this.name}.js | ${
            direct_object.id
          } is ${direct_object.getPlacePreposition()} ${direct_object.getPlaceAssetId()} and player is ${player.getPlacePreposition()} ${player.getPlaceAssetId()}`
        );
        msg += `$(We) can't stomp ${direct_preposition} ${
          direct_object.articlename
        } ${direct_object.getPlacePreposition()} ${
          direct_object.getPlaceAsset().articlename
        }. `;
        this.handleFailure(msg);
        return null;
      }

      if (direct_object.getPlaceAssetId() === player.id) {
        this.game.debug(
          `D1990 | ${this.name}.js | ${direct_object.id} is in player `
        );
        msg += `$(We) can't ${this.name} ${direct_preposition} ${direct_object.articlename} while holding it. `;
        this.handleFailure(msg);
        return null;
      }

      return true;
    },

    doSuccess: function () {
      var input = this.game.getInput();
      var verb_phrase = input.verb_phrase;
      //if (input.did_tryTravel) return this.handleSuccess();

      var direct_object = input.getAsset(1);
      var direct_preposition = input.getPreposition(1);
      var direct_substance = input.getSubstance(1);
      var indirect_object = input.getAsset(2);
      var indirect_preposition = input.getPreposition(2);
      var player = this.game.getPlayer();
      var results;
      var msg = "";

      // compose output
      msg +=
        `$(We) ${this.name}` +
        `${direct_preposition ? " " + direct_preposition : ""}` +
        `${direct_substance ? direct_substance.articlename + " of " : ""}` +
        `${direct_object ? " " + direct_object.articlename : ""}` +
        `. `;

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