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

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

  /**
   * @augments {adventurejs.Verb}
   * @class kick
   * @ajsnode game.dictionary.verbs.kick
   * @ajsconstruct MyGame.createVerb({ "name": "kick", [...] });
   * @ajsconstructedby adventurejs.Dictionary#createVerb
   * @hideconstructor
   * @ajsinstanceof Verb
   * @ajsnavheading DestructionVerbs
   * @summary Verb meaning kick asset.
   * @ajssynonyms kick, punt
   * @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; kick tires</span>
   * You kick the used car's tires. They seem a little soft.
   * The old Mustang rocks a bit from the contact, causing
   * something under the hood to rattle.
   * </pre>
   * <p>
   * <strong>Kick</strong> requires that the
   * {@link adventurejs.Tangible|Tangible}
   * {@link adventurejs.Asset|Asset} to be kicked has
   * <code>dov.kick</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 more.
   * </p>
   * @ajsverbreactions
   * @ajsverbphases doBeforeTry, doAfterTry, doBeforeSuccess, doAfterSuccess
   */
  A.Preverbs.kick = {
    name: "kick",
    prettyname: "kick",
    past_tense: "kicked",
    synonyms: ["kick", "punt"],

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

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

    /**
     * @memberof kick
     * @ajsverbphrase
     * phrase1:
     * {
     *   accepts_noun:true,
     *   requires_noun: true,
     *   noun_must_be:
     *   {
     *     known: true,
     *     tangible: true,
     *     present: true,
     *     visible: true,
     *     reachable: true,
     *     not_worn: true,
     *     //not_in_inventory: true,
     *   },
     * },
     */
    phrase1: {
      accepts_noun: true,
      requires_noun: true,
      noun_must_be: {
        known: true,
        tangible: true,
        present: true,
        visible: true,
        reachable: true,
        not_worn: true,
      },
    },

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

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

      // verb enabled?
      if (!direct_object.isDOV("kick")) {
        this.game.debug(
          `F1321 | ${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;
      }

      // verb state? skip

      if (
        direct_object.getPlaceAssetId() === player.id &&
        !direct_object.can.kick_while_held
      ) {
        this.game.debug(
          `F1322 | ${this.name}.js | ${direct_object.id}.can.kick_while_held is false `,
        );
        msg += `$(We) can't ${this.name} ${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(
          `F1960 | ${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(`F1323 | ${this.name}.js | print doSuccess `);

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

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