Pre-release
Adventure.js Docs Downloads
Score: 0 Moves: 0
// getTiedThingsThatDragOnTravel.js
(function () {
  /*global adventurejs A*/
  "use strict";
  var p = adventurejs.Tangible.prototype;
  /**
   * Check if player is holding a rope, or tied by a rope, that
   * is tied at the other end to an asset that can travel with player.
   * Return a list of assets that meet this qualification.
   * @memberOf adventurejs.Tangible
   * @method adventurejs.Tangible#getTiedThingsThatDragOnTravel
   * @return {Array}
   */
  p.getTiedThingsThatDragOnTravel =
    function Tangible_getTiedThingsThatDragOnTravel() {
      var carried_ropes = this.findClassInThis("Rope");
      var tied_ropes = this.iov.tie.with_params.connections;
      var all_ropes = carried_ropes.concat(tied_ropes);
      var draggedThings = [];

      // look for ropes which are children
      for (var i = 0; i < all_ropes.length; i++) {
        var rope = this.game.getAsset(all_ropes[i]);
        if (0 < rope.dov.tie.with_params.connections.length) {
          for (
            var r = 0;
            r < rope.dov.tie.with_params.connections.length;
            r++
          ) {
            var tiedThing = this.game.getAsset(
              rope.dov.tie.with_params.connections[r]
            );
            console.warn("tiedThing", tiedThing);

            // it's in this and tied to this, don't care
            if (tiedThing.id === this.id) continue;

            // tied to something external
            if (
              !tiedThing.isIn(this) &&
              /* and can't stretch outside the room */
              !rope.can.be_in_multiple_rooms &&
              /* and can't be dragged behind */
              tiedThing.on_tie_to_drag_behind_rope
            ) {
              if (-1 === draggedThings.indexOf(tiedThing.id)) {
                draggedThings.push(tiedThing.id);
              }
            }
          }
        }
      }

      return draggedThings;
    };
})();