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

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

  /**
   * @augments {adventurejs.Verb}
   * @class swing_across_on
   * @ajsnode game.dictionary.verbs.swing_across_on
   * @ajsconstruct MyGame.createVerb({ "name": "swing_across_on", [...] });
   * @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 across shaft on rope</span>
   * You grab the Princess. She kisses you for good luck. You leap
   * into space, swing across the bottomless shaft, and land on
   * the ledge on the other side.
   * </pre>
   * <p>
   * <strong>Swing across</strong> one
   * {@link adventurejs.Tangible|Tangible}
   * {@link adventurejs.Asset|Asset} on another.
   * Requires that the direct object has its
   * <a class="code" href="/doc/adventurejs.Tangible.html#property_can_swing_across">can.swing_across</a>
   * property set to true, and the indirect object has its
   * <a class="code" href="/doc/adventurejs.Tangible.html#property_can_swing_on">can_swing.on</a>
   * property set to true.
   * The verb is intended for statements like
   * <code class="property">swing across chasm on vine<code>,
   * but no special logic is provided.
   * 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>
   */
  A.Preverbs.swing_across_on = {
    name: "swing_across_on",
    prettyname: "swing across",
    synonyms: [],
    verb_prep_noun_prep_noun: ["swing across on", "swing across over"],

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

    phrase1: {
      accepts_noun: true,
      requires_noun: true,
      //accepts_preposition: true,
      //requires_preposition: true,
      //accepts_these_prepositions: [ 'across', 'over', 'to' ], /* @todo */
      noun_must_be: {
        known: true,
        tangible: true,
        present: true,
        visible: true,
        //reachable: true,
      },
    },

    phrase2: {
      accepts_noun: true,
      requires_noun: true /* @todo this goes away on consolidate swing */,
      //accepts_preposition: true,
      //requires_preposition: true,
      //accepts_these_prepositions: [ 'on', 'with' ], /* @todo */
      noun_must_be: {
        known: true,
        tangible: true,
        present: true,
        visible: true,
        reachable: true,
      },
    },

    doTry: function () {
      var input = this.game.getInput();
      var direct_object = input.getAsset(1);
      var indirect_object = input.getAsset(2);
      var player = this.game.getPlayer();
      var nest_preposition = player.getNestPreposition();
      var nest_parent_id = player.getNestId();
      var nest_parent_object = player.getNestAsset();

      // not something you could be on anyway
      if (false === direct_object.can.swing_across) {
        var msg =
          "$(We) can't swing across " + direct_object.articlename + ". ";
        this.handleFailure(msg);
        return null;
      }

      // not something you could be on anyway
      if (false === indirect_object.can.swing_on) {
        var msg = "$(We) can't swing on " + direct_object.articlename + ". ";
        this.handleFailure(msg);
        return null;
      }

      // nested
      //if( player.isNested() )
      // {
      // is player's nest in direct_object's list of
      //}

      // not nested

      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 nest_preposition = player.getNestPreposition();
      var nest_parent_id = player.getNestId();
      var nest_parent_object = player.getNestAsset();
      var results;

      var msg =
        "$(We) swing across " +
        direct_object.articlename +
        " on " +
        indirect_object.articlename +
        ". ";
      //var msg = "Perhaps $(we) should try swinging to or from something. ";

      // nested
      // results = player.onUnnestThisFromThat( nest_parent_object );
      // if( false === results ) { return false; }
      // else if ( null === results ) { return null; }

      // not nested

      this.handleSuccess(msg, direct_object);
      return true;
    },
  };
})(); // swing_across_on