// selectNotNestedInventoryIfAll.js
(function () {
/*global adventurejs A*/
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(
"L1242",
"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.isWithin(player) && parent.id !== player.id) {
continue;
}
// exclude held things
if (player.isConnectedToAsset("hold", object, "to_dov")) {
continue;
}
foundObjects.push(list[i]);
}
return foundObjects;
};
})();