Pre-release
Adventure.js Docs Downloads
Score: 0 Moves: 0
// areAnscestorsUnknown.js
(function() {
	/*global adventurejs A*/ 
  "use strict";
  var p = adventurejs.Tangible.prototype;	
  /**
   * Checks to see if this asset or its containing parent(s)
   * are unknown to player. Takes into account nesting doll 
   * situations and looks all the way up the chain.
   * Useful for determining whether a player can "see"
   * a nested object.
   * @memberOf adventurejs.Tangible
	 * @method adventurejs.Tangible#areAnscestorsUnknown
   * @param {int} nestlevel
   * @returns {Boolean}
   */
  p.areAnscestorsUnknown = function Tangible_areAnscestorsUnknown(nestlevel) 
  {
    if("undefined" === typeof nestlevel) 
    {
      nestlevel = 0;
    } 
    else 
    {
      nestlevel++;
    }
    var player_knows_parent = true;
    var parent = this.getPlaceAsset();

    if( parent
    && "undefined" !== typeof parent.is.known
    && "undefined" !== typeof parent.areAnscestorsUnknown ) 
    {
      player_knows_parent = parent.areAnscestorsUnknown(nestlevel);
    }
    // We pass this call up and then back down the anscestor
    // chain, using nestlevel to keep track of our place in
    // the chain – but descendants need the opposite of the response
    // that we're going to send back to the original caller.
    nestlevel--;
    if ( !this.is.known || !player_knows_parent ) 
    {
      return ( -1 < nestlevel ? false : true );
    } 
    else 
    {
      return ( -1 < nestlevel ? true : false );
    }
  }  
}());