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

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

  /**
   * @augments {adventurejs.Verb}
   * @class eat
   * @ajsnode game.dictionary.verbs.eat
   * @ajsconstruct MyGame.createVerb({ "name": "eat", [...] });
   * @ajsconstructedby adventurejs.Dictionary#createVerb
   * @hideconstructor
   * @ajsinstanceof Verb
   * @ajsnavheading ConsumptionVerbs
   * @summary Verb meaning eat asset.
   * @todo should handle solid/slurry substances
   * @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; eat flapjacks</span>
   * You eat the mountainous pile of flapjacks. You've won the
   * flapjack eating contest! You're awarded with a blue ribbon.
   * </pre>
   * <p>
   * <strong>Eat</strong> requires that the
   * {@link adventurejs.Tangible|Tangible}
   * {@link adventurejs.Asset|Asset} to be eaten has
   * asset.dov.eat.enabled
   * set to true. If Asset's
   * <a class="code" href="/doc/adventurejs.Tangible.html#property_on_eat_destroy">on_eat_destroy</a>
   * property is set to true, Asset will be destroyed.
   * No other 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>
   * @ajsverbphases doBeforeTry, doAfterTry, doBeforeSuccess, doAfterSuccess
   */
  A.Preverbs.eat = {
    name: "eat",
    prettyname: "eat",
    past_tense: "ate",
    synonyms: ["eat"],

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

    /**
     * @memberof eat
     * @ajsverbphrase
     * phrase1:
     * {
     *   accepts_noun:true,
     *   noun_must_be:
     *   {
     *     known: true,
     *     tangible: true, // @TODO matter // eat dirt?
     *     present: true,
     *     visible: true,
     *     reachable: true,
     *   },
     * },
     */
    phrase1: {
      accepts_noun: true,
      noun_must_be: {
        known: true,
        tangible: true, // @TODO matter // eat dirt?
        present: true,
        visible: true,
        reachable: true,
      },
    },

    /**
     * @memberof eat
     * @ajsverbphrase
     * phrase2:
     * {
     *   accepts_noun: true,
     *   noun_must_be:
     *   {
     *     in_inventory: true,
     *     known: true,
     *   },
     *   accepts_preposition: true,
     *   requires_preposition: true,
     *   accepts_these_prepositions: ["with"],  // @TODO from
     * },
     */
    phrase2: {
      accepts_noun: true,
      noun_must_be: {
        in_inventory: true,
        known: true,
      },
      accepts_preposition: true,
      requires_preposition: true,
      accepts_these_prepositions: ["with"], // @TODO from
    },

    /**
     * @memberof eat
     * @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 indirect_object = input.getAsset(2);
      var indirect_preposition = input.getPreposition(2);
      var player = this.game.getPlayer();
      var results;
      var msg = "";

      // parsed sentence structure: verb
      if (input.hasStructure("verb")) {
      }

      // parsed sentence structure: verb noun
      if (input.hasStructure("verb noun")) {
      } // verb noun

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

      if (input.hasStructure("verb noun")) {
      }

      if (input.hasStructure("verb noun preposition noun")) {
        if (!indirect_object.isIOV("eat")) {
          this.game.debug(
            `F1148 | ${this.name}.js | ${indirect_object.id}.iov.eat.enabled is false `,
          );
          msg += `$(We) can't ${this.name} anything ${indirect_preposition} ${indirect_object.articlename}. `;
          this.handleFailure(msg);
          return false;
        }
      } // verb noun preposition noun

      return true;
    },

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

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

      // parsed sentence structure: verb
      if (input.hasStructure("verb")) {
      }

      // parsed sentence structure: verb noun
      if (input.hasStructure("verb noun")) {
      } // verb noun

      var msg = "$(We) eat " + direct_object.articlename;
      if (indirect_object) {
        msg += " with " + indirect_object.articlename;
      }
      msg += ". ";

      if (input.hasStructure("verb noun")) {
      } // verb noun

      if (input.hasStructure("verb noun preposition noun")) {
      } // verb noun preposition noun

      if (direct_object.on_eat_destroy) {
        direct_object.destroy();
      }

      // TODO
      // was food in a container? does it leave container behind?
      // was food one of many, like a grape

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