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

/**
 * Figure out what player is swinging on then forward to swingFromToOn
 */
(function () {
  /*global adventurejs A*/
  "use strict";

  /**
   * @augments {adventurejs.Verb}
   * @class swing_from
   * @ajsnode game.dictionary.verbs.swing_from
   * @ajsconstruct MyGame.createVerb({ "name": "swing_from", [...] });
   * @ajsconstructedby adventurejs.Dictionary#createVerb
   * @hideconstructor
   * @ajsinstanceof Verb
   * @ajsnavheading DeprecatedVerbs
   * @summary Summary.
   * @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; swing from tree</span>
   * What would you like to swing to
   * </pre>
   * <p>
   * <strong>Swing from</strong> is a catchall that soft prompts for a
   * second noun, with a redirect to
   * {@link swing_from_to}.
   * </p>
   */
  A.Preverbs.swing_from = {
    name: "swing_from",
    prettyname: "swing from",
    synonyms: [],
    verb_prep_noun: ["swing from"],

    player_must_be: {
      not_on_floor: true,
      not_constrained: true,
      not_under: true,
      not_behind: true,
      not_nested_elsewhere: true,
    },

    phrase1: {
      accepts_noun: true,
      requires_noun: true,
      //accepts_preposition: true,
      //requires_preposition: true,
      //accepts_these_prepositions: [ 'from' ], /* @todo */
      noun_must_be: {
        player_parent: true,
      },
    },

    doTry: function () {
      var input = this.game.getInput();
      var direct_object = input.getAsset(1);
      var player = this.game.getPlayer();
      var nest_parent_object = player.getNestAsset();

      var msg = "What would you like to swing to? ";

      // soft prompt for untiewith object
      input.setSoftPrompt({ noun2: true, verb: "swing_from_to" });
      this.handleFailure(msg);
      return null;
    },

    doSuccess: function () {
      var input = this.game.getInput();
      var player = this.game.getPlayer();

      var msg = "$(We) swing from " + input.parsedNoun1.articlename + ". ";
      if (msg) this.game.print(msg, input.output_class);
      return null;
    },
  };
})(); // swing_from