// selectInHands.js
(function() {
/*global adventurejs A*/
"use strict";
var p = adventurejs.Parser.prototype;
/**
* Exclude from a list of assets all assets that are not in player's hands.
* @method adventurejs.Parser#selectInHands
* @memberOf adventurejs.Parser
* @param {Array} list
* @returns {Array}
*/
p.selectInHands = function Parser_selectInHands(list)
{
// we already know it's present and visible and reachable
if("string" === typeof list) list = [list];
if( !Array.isArray( list ) )
{
this.game.log( "warn", "critical", "selectInHands.js > received non-array", 'Parser' );
return [];
}
var foundObjects = [];
for(var i = 0; i < list.length; i++)
{
var object = this.game.getAsset( list[i] );
var player = this.game.getPlayer();
if( object instanceof adventurejs.Substance )
{
continue;
}
// if it hasn't got a parent it can't be in hands
// not originally intended but this applies directly to substances
if( !object.getPlaceAsset )
{
continue;
}
var parent = object.getPlaceAsset();
if( !parent )
{
continue;
}
if( parent.id !== player.id
&& !player.IOVisConnectedToAsset('hold',object) )
{
continue;
}
if( parent.id === player.id
&& object.is.worn )
{
continue;
}
foundObjects.push( list[i] );
}
return foundObjects;
}
}());