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

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

  /**
   * @augments {adventurejs.Verb}
   * @class taste
   * @ajsnode game.dictionary.verbs.taste
   * @ajsconstruct MyGame.createVerb({ "name": "taste", [...] });
   * @ajsconstructedby adventurejs.Dictionary#createVerb
   * @hideconstructor
   * @ajsinstanceof Verb
   * @ajsnavheading SensationVerbs
   * @summary Verb meaning taste, as in "taste toad venom".
   * @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; taste fruit</span>
   * You taste the forbidden fruit. Did you think that only
   * tasting it and not eating it would protect you from the
   * curse of knowledge? Well, forget it, buddy. Now you know.
   * NOW. YOU. KNOW. Now get outta my garden!
   * </pre>
   * <p>
   * <strong>Taste</strong> requires that the
   * {@link adventurejs.Tangible|Tangible}
   * {@link adventurejs.Asset|Asset} to be tasted has
   * asset.dov.taste.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>
   * <p>
   * Taste and {@link lick|lick} behave identically if they're
   * not given any special reactions.
   * </p>
   * @ajsverbreactions
   * @ajsverbphases doBeforeTry, doAfterTry, doBeforeSuccess, doAfterSuccess
   */
  A.Preverbs.taste = {
    name: "taste",
    prettyname: "taste",
    past_tense: "tasted",
    synonyms: ["taste"],

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

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

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

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

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

      // single use direct object?
      if (
        direct_object.DOVallowOnce(this.name) &&
        direct_object.DOVdidDo(this.name)
      ) {
        this.game.debug(
          `F1994 | ${this.name}.js | ${direct_object.id}.dov.${this.name}.once and ${direct_object.id}.dov.${this.name}.did_do `
        );
        msg += `$(We've) already ${this.past_tense} enough of ${direct_object.articlename}. `;
        this.handleFailure(msg);
        return false;
      }

      if (!direct_object.hasDescription("taste")) {
        this.game.debug(
          `F1433 | ${this.name}.js | ${direct_object.id}.descriptions.taste is unset `
        );
        msg += `${direct_object.Articlename} has no particular taste. `;
        this.handleFailure(msg);
        return null;
      }

      return true;
    },

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

      this.game.debug(`F1434 | ${this.name}.js | print doSuccess `);

      // compose output
      msg += `$(We) gently nibble at ${direct_object.articlename}. `;
      msg += direct_object.getDescription("taste");

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