Pre-release
Adventure.js Docs Downloads
Score: 0 Moves: 0
// get.js - Use this file as a template to create new verbs.

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

  /**
   * @augments {adventurejs.Verb}
   * @class get
   * @ajsnode game.dictionary.verbs.get
   * @ajsconstruct MyGame.createVerb({ "name": "get", [...] });
   * @ajsconstructedby adventurejs.Dictionary#createVerb
   * @hideconstructor
   * @ajsinstanceof Verb
   * @ajsnavheading UtilityVerbs
   * @summary Summary.
   * @tutorial Scripting_VerbSubscriptions
   * @tutorial Verbs_VerbAnatomy
   * @tutorial Verbs_VerbProcess
   * @tutorial Verbs_ModifyVerbs
   * @tutorial Verbs_WriteVerbs
   * <pre class="display border outline">
   * <span class="input">&gt; get out</span>
   * You climb out of the transmogrifier box. You're a tiger!
   * </pre>
   * <pre class="display border outline">
   * <span class="input">&gt; get box</span>
   * You fold up the transmogrifier box into a compact square
   * and tuck it in your satchel.
   * </pre>
   * <strong>Get</strong> extends two verbs:
   * <a href="take.html">take</a> and
   * <a href="go.html">go</a>; and forwards
   * to one or the other depending on context.
   * @ajsverbphases
   */
  A.Preverbs.get = {
    name: "get",
    prettyname: "get",
    past_tense: "got",
    synonyms: ["get"],
    extends: { go: true, take: true },

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

    /**
     * @memberof verb
     * @ajsverbphrase
     * phrase1: {
     *   accepts_noun: true,
     *   accepts_preposition: true,
     *   accepts_preposition_without_noun: true,
     *   noun_must_be: {
     *     known: true,
     *     not_global: true,
     *     not_scenery: true,
     *     not_exit: true,
     *     tangible: true,
     *     present: true,
     *     visible: true,
     *     reachable: true,
     *     not_in_hands: true,
     *     not_worn: true,
     *     not_nested_inventory_if_all: true,
     *   },
     * },
     */

    phrase1: {
      accepts_noun: true,
      accepts_preposition: true,
      accepts_preposition_without_noun: true,
      noun_must_be: {
        known: true,
        not_global: true,
        not_scenery: true,
        not_exit: true,
        tangible: true,
        present: true,
        visible: true,
        reachable: true,
        //not_in_hands: true, // this breaks "get off bike"
        not_worn: true,
        not_nested_inventory_if_all: true,
      },
    },

    /**
     * @memberof verb
     * @ajsverbphrase
     * phrase1: {
     *   accepts_noun: true,
     *   accepts_preposition: true,
     *   requires_preposition: true,
     *   noun_must_be: {
     *     known: true,
     *     not_global: true,
     *     not_scenery: true,
     *     not_exit: true,
     *     tangible: true,
     *     present: true,
     *     visible: true,
     *     reachable: true,
     *   },
     * },
     */

    phrase2: {
      accepts_noun: true,
      accepts_preposition: true,
      requires_preposition: true,
      noun_must_be: {
        known: true,
        not_global: true,
        not_scenery: true,
        not_exit: true,
        tangible: true,
        present: true,
        visible: true,
        reachable: true,
      },
    },

    let_verb_handle_disambiguation: false,

    do: 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 indirect_object2 = input.getAsset(3);
      var indirect_preposition2 = input.getPreposition(3);
      var msg = "",
        target = "";

      // sentence structure: verb noun ----------
      if (input.hasStructure("verb noun")) {
        target =
          direct_object.direction || direct_object.is.exit ? "go" : "take";
        this.game.debug(
          `F1037 | ${this.name}.js | ${this.name} ${direct_object.name}: infer ${target}`,
        );
      }

      // sentence structure: verb preposition ----------
      if (input.hasStructure("verb preposition")) {
        target = direct_preposition === "up" ? "stand" : "go";
        this.game.debug(
          `F1038 | ${this.name}.js | ${this.name} ${direct_preposition}: infer ${target}`,
        );
      }

      // sentence structure: verb preposition noun ----------
      if (input.hasStructure("verb preposition noun")) {
        target = direct_preposition === "from" ? "take" : "go";
        this.game.debug(
          `F1039 | ${this.name}.js | ${this.name} ${direct_preposition} ${direct_object.name}: infer ${target}`,
        );
      }

      // sentence structure: verb noun preposition noun ----------
      if (input.hasStructure("verb noun preposition noun")) {
        target = direct_object.direction ? "go" : "take";
        this.game.debug(
          `F1040 | ${this.name}.js | ${this.name} ${direct_object.name} ${indirect_preposition} ${indirect_object.name}: infer ${target}`,
        );
      }

      // sentence structure: verb preposition noun preposition noun ----------
      if (input.hasStructure("verb preposition noun preposition noun")) {
        target = "go";
        this.game.debug(
          `F1872 | ${this.name}.js | ${this.name} ${direct_preposition} ${direct_object.name} ${indirect_preposition} ${indirect_object.name}: infer ${target}`,
        );
      }

      // sentence structure: verb preposition noun preposition noun preposition noun ----------
      if (
        input.hasStructure(
          "verb preposition noun preposition noun preposition noun",
        )
      ) {
        target = "go";
        this.game.debug(
          `F1873 | ${this.name}.js | ${this.name} ${direct_preposition} ${direct_object.name} ${indirect_preposition} ${indirect_object.name} ${indirect_preposition2} ${indirect_object2.name}: infer ${target}`,
        );
      }

      this.game.dictionary.doVerb(target);
      return null;
    },
  };
})(); // get