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

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

  /**
   * @augments {adventurejs.Verb}
   * @class feed
   * @ajsnode game.dictionary.verbs.feed
   * @ajsconstruct MyGame.createVerb({ "name": "feed", [...] });
   * @ajsconstructedby adventurejs.Dictionary#createVerb
   * @hideconstructor
   * @ajsinstanceof Verb
   * @ajsnavheading ConsumptionVerbs
   * @summary Verb meaning feed a character.
   * @todo Full logic, this is just a skeleton.
   * @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; feed lettuce to turtle</span>
   * You feed the lettuce to the turtle. It chews contemplatively.
   * </pre>
   * <p>
   * <strong>Feed</strong> a
   * {@link adventurejs.Tangible|Tangible} or
   * {@link adventurejs.Substance|Substance}
   * {@link adventurejs.Asset|Asset} to an
   * {@link adventurejs.NPC|NPC} Asset. Requires
   * that the first Asset is in player's inventory.
   * </p>
   * @ajsverbreactions
   * @ajsverbphases doBeforeTry, doAfterTry, doBeforeSuccess, doAfterSuccess
   */
  A.Preverbs.feed = {
    name: "feed",
    prettyname: "feed",
    past_tense: "fed",
    synonyms: [],
    verb_noun_prep_noun: ["feed to"], // @todo move 'to' to preposition

    /**
     * @memberof feed
     * @ajsverbphrase
     * phrase1:
     * {
     *   accepts_noun:true,
     *   requires_noun:true,
     *   noun_must_be:
     *   {
     *     known: true,
     *     in_inventory: true, // @todo doesn't work with "feed thing"
     *   },
     * },
     */
    phrase1: {
      accepts_noun: true,
      requires_noun: true,
      noun_must_be: {
        known: true,
        in_inventory: true,
      },
    },

    /**
     * @memberof feed
     * @ajsverbphrase
     * phrase2:
     * {
     *   accepts_noun:true,
     *   noun_must_be:
     *   {
     *     known: true,
     *     tangible: true,
     *     present: true,
     *     reachable: true,
     *   },
     *   // accepts_preposition: true,
     *   // requires_preposition: true,
     *   // accepts_these_prepositions: ["to"], // @todo
     * },
     */
    phrase2: {
      accepts_noun: true,
      noun_must_be: {
        known: true,
        tangible: true,
        present: true,
        reachable: true,
      },
    },

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

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

      // can't feed to non-characters
      if (!(direct_object instanceof adventurejs.Character)) {
        this.game.debug(
          `F1280 | ${this.name}.js | ${direct_object.id} is not class Character`,
        );
        msg += `$(We) can't feed ${direct_object.articlename} to ${indirect_object.articlename}. `;
        this.handleFailure(msg);
        return null;
      }

      return true;
    },

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

      // feed x to y
      this.game.debug(`F1279 | ${this.name}.js | print doSuccess`);
      msg += `$(We) feed ${direct_object.articlename} to ${indirect_object.articlename}. `;

      // transfer of knowledge

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