// selectInHands.js
(function() {
/*global adventurejs A*/
"use strict";
var p = adventurejs.Parser.prototype;
/**
* Exclude from a list of assets all worn assets if player input "all".
* @method adventurejs.Parser#selectNotWornIfAll
* @memberOf adventurejs.Parser
* @param {Array} list
* @returns {Array}
*/
p.selectNotWornIfAll = function Parser_selectNotWornIfAll(list) {
if("string" === typeof list) list = [list];
if( !Array.isArray( list ) )
{
this.game.log( "warn", "critical", "selectNotWornIfAll.js > received non-array", 'Parser' );
return [];
}
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 worn
// not originally intended but this applies directly to substances
if( !object.getPlaceAsset ) continue;
var parent = object.getPlaceAsset();
if( !parent ) continue;
if( parent.id !== this.game.world._player ) continue;
if( parent.id === this.game.world._player
&& object.is.worn )
{
continue;
}
foundObjects.push( list[i] );
}
return foundObjects;
}
}());