Pre-release
AdventureJS Docs Downloads
Score: 0 Moves: 0
// get.js

(function () {
  /*global adventurejs A*/

  /**
   * @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 },
    gerund: "getting",

    /**
     * @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,
     *   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,
     *   },
     *   accepts_preposition: true,
     *   accepts_preposition_without_noun: true,
     * },
     */

    phrase1: {
      accepts_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,
      },
      accepts_preposition: true,
      accepts_preposition_without_noun: 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 player = this.game.getPlayer();
      var verb_phrase = input.verb_phrase;
      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.log(
          "L1367",
          "log",
          "high",
          `${this.name}.js > ${this.name} ${direct_object.name}: infer ${target}`,
          "Verbs"
        );
      }

      // sentence structure: verb preposition ----------
      else if (input.hasStructure("verb preposition")) {
        switch (direct_preposition) {
          case "up":
            target = "stand";
            break;
          case "down":
            if (player.isNested()) {
              input.setAsset(1, player.getNestAsset());
              input.setPreposition(1, "off");
              input.setStructure("verb preposition noun");
              target = "go";
            } else target = "sit";
            break;
          case "off":
            if (player.isNested()) {
              input.setAsset(1, player.getNestAsset());
              input.setStructure("verb preposition noun");
              target = "go";
            } else {
              this.game.debug(`D1020 | ${this.name}.js | player is not nested`);
              msg += `Neither the time nor the place. `;
              this.handleFailure(msg);
              return null;
            }
            break;
          case "on":
            if (player.isNested()) {
              this.game.debug(
                `D1037 | ${this.name}.js | player is ${player.getNestAspect().id} ${player.getNestAsset().id}`
              );
              msg += `$(We're) ${player.getNestAspect().id} ${player.getNestAsset().articlename}. `;
              this.handleFailure(msg);
              return null;
            } else {
              // no asset provided but can we infer from last turn?
              let last = this.game.getAsset(
                this.game.getLastTurn().verified_sentence.phrase1?.parsedNoun
                  ?.qualified_object_id
              );
              if (
                last &&
                last.hasAspectAt(last.default_aspect) &&
                last.getAspectAt(last.default_aspect).canPlayer("enter")
              ) {
                input.setAsset(1, last);
                input.setStructure("verb preposition noun");
                target = "go";
              } else {
                // prompt for a direct object
                input.setSoftPrompt({
                  index: 1,
                  type: "noun",
                  input_verb: this.name,
                  verb: this.name,
                  noun1: true,
                  structure: "verb preposition noun",
                });
                this.game.debug(
                  `D1038 | ${this.name}.js | no noun provided or inferrable, soft prompt noun1`
                );
                msg += `What would $(we) like to ${this.name} on? `;
                this.handleFailure(msg);
                return null;
              }
            }
            break;
          case "in":
            var direction = this.game.getExitFromDirection("in");
            if (direction && !direction.is.global) {
              target = "go";
              input.setAsset(1, direction);
              input.setPreposition(1, "");
              input.setStructure("verb noun");
            } else {
              // prompt for a direct object
              input.setSoftPrompt({
                input_verb: this.name,
                verb: this.name,
                noun1: true,
                structure: "verb preposition noun",
              });
              this.game.debug(
                `D1039 | ${this.name}.js | no noun provided or inferrable, soft prompt noun1`
              );
              msg += `What would $(we) like to ${this.name} in? `;
              this.handleFailure(msg);
              return null;
            }
            break;
          default:
            target = "go";
            break;
        }
        this.game.log(
          "L1368",
          "log",
          "high",
          `${this.name}.js > ${this.name} ${direct_preposition}: infer ${target}`,
          "Verbs"
        );
      }

      // sentence structure: verb preposition noun ----------
      else if (input.hasStructure("verb preposition noun")) {
        target = direct_preposition === "from" ? "take" : "go";
        this.game.log(
          "L1369",
          "log",
          "high",
          `${this.name}.js > ${this.name} ${direct_preposition} ${direct_object.name}: infer ${target}`,
          "Verbs"
        );
      }

      // sentence structure: verb noun preposition noun ----------
      else if (input.hasStructure("verb noun preposition noun")) {
        target = direct_object.direction ? "go" : "take";
        this.game.log(
          "L1370",
          "log",
          "high",
          `${this.name}.js > ${this.name} ${direct_object.name} ${indirect_preposition} ${indirect_object.name}: infer ${target}`,
          "Verbs"
        );
      }

      // sentence structure: verb preposition noun preposition noun ----------
      else if (input.hasStructure("verb preposition noun preposition noun")) {
        target = "go";
        this.game.log(
          "L1371",
          "log",
          "high",
          `${this.name}.js > ${this.name} ${direct_preposition} ${direct_object.name} ${indirect_preposition} ${indirect_object.name}: infer ${target}`,
          "Verbs"
        );
      }

      // sentence structure: verb preposition noun preposition noun preposition noun ----------
      else if (
        input.hasStructure(
          "verb preposition noun preposition noun preposition noun"
        )
      ) {
        target = "go";
        this.game.log(
          "L1372",
          "log",
          "high",
          `${this.name}.js > ${this.name} ${direct_preposition} ${direct_object.name} ${indirect_preposition} ${indirect_object.name} ${indirect_preposition2} ${indirect_object2.name}: infer ${target}`,
          "Verbs"
        );
      }

      // input.input_verb = target;
      return this.game.dictionary.doVerb(target);
    },
  };
})(); // get