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

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

  /**
   * @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. 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 how to customize this verb.
   * </p>
   * @ajsverbreactions
   * @ajsverbphases doBeforeTry, doAfterTry, doBeforeSuccess, doAfterSuccess
   */
  A.Preverbs.stomp = {
    name: "stomp",
    prettyname: "stomp",
    past_tense: "stamped",
    synonyms: ["stomp", "stamp"],

    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_if_tangible: true,
     *     reachable_if_tangible: 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_if_tangible: true,
        reachable_if_tangible: true,
        visible: true,
        not_worn: 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 direct_object = input.getAsset(1);
      var direct_preposition = input.getPreposition(1);
      var input = this.game.getInput();
      var player = this.game.getPlayer();
      var msg = "";
      var containers;
      var direct_object_vessel;

      if (!direct_object) {
        this.game.debug(`F1652 | ${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
        ) {
          this.game.debug(
            `F1653 | ${this.name}.js | tryTravel ${direct_object.direction} `,
          );
          this.game.tryTravel(direct_object.direction);
          return null;
        }
      }

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

      // sentence structure: verb noun
      if (input.hasStructure("verb noun")) {
        // this.game.debug(`F1647 | ${this.name}.js | preposition required `);
        // msg += this.game.parser.getUnparsedMessage(input.input);
        // 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 so it must come from a substance container that
      // is a reachable substance body
      if (direct_object instanceof adventurejs.Substance) {
        // get a list of available bodies of substance
        containers = this.game.findSubstanceContainers(direct_object.id, [
          "Present",
          "Known",
          "Visible",
          "BodyOfSubstance",
        ]);
        console.warn("containers", containers);

        switch (containers.length) {
          case 0:
            this.game.debug(`F1657 | ${this.name}.js | no valid vessel found `);
            msg += `There doesn't appear to be any ${
              this.game.getAsset(direct_object.id).name
            } to stomp ${direct_preposition}. `;
            this.handleFailure(msg);
            return null;
          case 1:
            // set container as direct_object
            // and treat like "stomp in container"
            direct_object_vessel = this.game.getAsset(containers[0]);
            input.setAssumed(1, true);
            input.setVessel(1, direct_object_vessel);

            // is player in same location as substance?
            if (direct_object_vessel.id !== player.getNestOrPlaceAsset().id) {
              this.game.debug(
                `F1658 | ${this.name}.js | ${direct_object_vessel.id} !== ${
                  player.getNestOrPlaceAsset().id
                }`,
              );
              msg += `$(We're) not standing in it. `;
              this.handleFailure(msg);
              return null;
            }
            return true;
          //break;
          default:
            this.game.debug(
              `F1659 | ${this.name}.js | multiple containers found, disambiguate `,
            );
            // disambiguate - need to set parsedNoun.matches
            // save containers back to input for next turn disambiguation
            input.setParsedNounMatchesQualified(1, containers);
            this.game.parser.printNounDisambiguation({
              parsedNoun: input.getParsedNoun(1),
              nounIndex: 1,
            });
            return null;
        } // switch containers.length
      } // 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(`F1654 | ${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.hasAspectAt(direct_preposition) ||
          !direct_object.aspects[direct_preposition].player.can.enter)
      ) {
        this.game.debug(`F1660 | ${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(
          `F1655 | ${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(
          `F1990 | ${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;
      }

      // single use direct object?
      if (
        direct_object.DOVallowOnce(this.name) &&
        direct_object.DOVdidDo(this.name)
      ) {
        this.game.debug(
          `F1991 | ${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(`F1656 | ${this.name}.js | print doSuccess `);

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

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