Pre-release
AdventureJS Docs Downloads
Score: 0 Moves: 0
// getClosedAnscestors.js
(function () {
  /*global adventurejs A*/
  var p = adventurejs.Tangible.prototype;
  /**
   * Get a list of this asset's containing parent(s) that are closed.
   * Takes into account nesting doll
   * situations and looks all the way up the chain.
   * Useful for determining whether a player can interact
   * with a nested object.
   * @memberOf adventurejs.Tangible
   * @method adventurejs.Tangible#getClosedAnscestors
   * @returns {Array}
   */
  p.getClosedAnscestors = function Tangible_getClosedAnscestors() {
    var parent = this.getPlaceAsset();
    var anscestorsToOpen = [];

    if (
      parent &&
      parent.isDOV("close") &&
      "undefined" !== typeof parent.getClosedAnscestors
    ) {
      anscestorsToOpen = anscestorsToOpen.concat(parent.getClosedAnscestors());
    }
    if (this.isDOV("close") && this.is.closed) {
      anscestorsToOpen = anscestorsToOpen.concat(this.id);
    }
    return anscestorsToOpen;
  };
})();