Pre-release
Adventure.js Docs Downloads
Score: 0 Moves: 0
// getRopesThatBlockTravel.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, preventing player from leaving room.
   * Return a list of assets that meet this qualification.
   * @memberOf adventurejs.Tangible
   * @method adventurejs.Tangible#getRopesThatBlockTravel
   * @return {Array}
   */
  p.getRopesThatBlockTravel = function Tangible_getRopesThatBlockTravel() {
    var carried_ropes = this.findClassInThis("Rope");
    var tied_ropes = this.iov.tie?.with_params.connections;
    var all_ropes = carried_ropes.concat(
      Array.isArray(tied_ropes) && tied_ropes.length ? tied_ropes : []
    );
    var travel_blocking_ropes = [];

    // look for ropes which are children
    for (var i = 0; i < all_ropes.length; i++) {
      var rope = this.game.getAsset(all_ropes[i]);
      if (rope && 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 === travel_blocking_ropes.indexOf(rope.id)) {
              travel_blocking_ropes.push(rope.id);
            }
          }
        }
      }
    }
    return travel_blocking_ropes;
  };
})();