// selectInInventory.js
(function () {
/* global adventurejs A */
var p = adventurejs.Parser.prototype;
/**
* Exclude from a list of assets all assets that are not in subject'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(
"L1275",
"error",
"critical",
["[selectInInventory.js] selectInInventory() received non-array", list],
"Parser"
);
return [];
}
this.game.log(
"L1159",
"log",
"high",
`[selectInInventory.js] selectInInventory() receive:\n${list}`,
"Parser"
);
var input = this.game.getInput();
var subject = input.getSubject();
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.isWithin(subject) &&
!subject.isConnectedToAsset("hold", object, "to_dov")
) {
continue;
}
foundObjects.push(list[i]);
}
// console.warn("selectInInventory returned " + JSON.stringify(foundObjects));
return foundObjects;
};
})();