Pre-release
AdventureJS Docs Downloads
Score: 0 Moves: 0
// getTiedThingsThatDragOnTravel.js
(function () {
  /*global adventurejs A*/
  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.findNestedAssetsWithClass("Rope");
      var tied_ropes = this.getVerbConnections("tie", "to_dov");
      for (let i = 0; i < tied_ropes.length; i++) {
        tied_ropes[i] = this.game.getAsset(tied_ropes[i]);
      }
      var all_ropes = carried_ropes.concat(
        Array.isArray(tied_ropes) && tied_ropes.length ? tied_ropes : []
      );
      var draggedThings = [];

      // look for ropes which are children
      for (var i = 0; i < all_ropes.length; i++) {
        var rope = all_ropes[i];
        let count = rope.getVerbConnectionCount("tie", "to_iov");
        if (count > 0) {
          for (var r = 0; r < count; r++) {
            var tiedThing = this.game.getAsset(
              rope.is.connected_by.tie.to_iov[r]
            );

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

            // tied to something external
            if (
              !tiedThing.isWithin(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;
    };
})();