// selectInInventory.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 inventory.
* @method adventurejs.Parser#selectInInventory
* @memberOf adventurejs.Parser
* @param {Array} list
* @returns {Array}
*/
p.selectInInventory = function Parser_selectInInventory(list) {
if ("string" === typeof list) list = [list];
if (!Array.isArray(list)) {
this.game.log(
"warn",
"critical",
"selectInInventory.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 (object.areAnscestorsUnknown && object.areAnscestorsUnknown()) {
continue;
}
if (
!object.isIn(player) &&
!player.IOVisConnectedToAsset("hold", object)
) {
continue;
}
foundObjects.push(list[i]);
// TODO but is it nested in a closed object in player?
// and is it known? could be unseen inside an unopened thing
}
console.warn("selectInInventory returned " + foundObjects);
return foundObjects;
};
})();