// selectNotNestedInventoryIfAll.js
(function() {
/*global adventurejs A*/
"use strict";
var p = adventurejs.Parser.prototype;
/**
* Exclude from a list of assets all assets in player's inventory.
* @method adventurejs.Parser#selectNotNestedInventoryIfAll
* @memberOf adventurejs.Parser
* @param {Array} list
* @returns {Array}
*/
p.selectNotNestedInventoryIfAll = function Parser_selectNotNestedInventoryIfAll(list)
{
if("string" === typeof list) list = [list];
if( !Array.isArray( list ) )
{
this.game.log( "warn", "critical", "selectNotNestedInventoryIfAll.js > received non-array", 'Parser' );
return [];
}
var player = this.game.getPlayer();
var foundObjects = [];
for(var i = 0; i < list.length; i++)
{
var object = this.game.getAsset( list[i] );
// if it hasn't got a parent it can't be in inventory
// not originally intended but this applies directly to substances
if( !object.getPlaceAsset ) continue;
var parent = object.getPlaceAsset();
if( !parent ) continue;
// exclude inventory
if( object.isIn( player )
&& parent.id !== player.id )
{
continue;
}
// exclude held things
if( player.IOVisConnectedToAsset('hold',object) )
{
continue;
}
foundObjects.push( list[i] );
}
return foundObjects;
}
}());