// selectInInventoryIfTakeable.js
(function () {
/* global AdventureJS A */
var p = AdventureJS.Parser.prototype;
/**
* Exclude from a list of assets all assets that are not takeable from subject inventory.
* @method AdventureJS.Parser#selectInInventoryIfTakeable
* @memberOf AdventureJS.Parser
* @param {Array} list
* @returns {Array}
*/
p.selectInInventoryIfTakeable = function Parser_selectInInventoryIfTakeable(
list
) {
if ("string" === typeof list) list = [list];
if (!Array.isArray(list)) {
this.game.log(
"L1227",
"error",
"critical",
[
"[selectInInventoryIfTakeable.js] selectInInventoryIfTakeable() received non-array",
list,
],
"Parser"
);
return [];
}
this.game.log(
"L1157",
"log",
"high",
`[selectInInventoryIfTakeable.js] selectInInventoryIfTakeable() receive:\n${list}`,
"Parser"
);
var input = this.game.getInput();
var subject = input.getSubject();
var foundObjects = [];
var dispensers = [];
for (var i = 0; i < list.length; i++) {
var object = this.game.getAsset(list[i]);
if (object.is.platonic && object.hasDispensers()) {
for (const i in object.fungible.dispensers) {
const dispenser = object.fungible.dispensers[i];
const [dispenser_aspect, dispenser_id] = Object.entries(dispenser)[0];
const select = this.selectInInventoryIfTakeable([dispenser_id]);
if (select.length) {
const quad = `fungible:${object.fungible.dispense_class}:${dispenser_aspect}:${dispenser_id}`;
foundObjects.push(quad);
}
}
continue;
}
if (!object.isDOV("take")) {
foundObjects.push(list[i]);
continue;
}
if (
"undefined" !== typeof object.areAnscestorsUnknown &&
object.areAnscestorsUnknown()
) {
continue;
}
if (
!object.isWithin(subject) &&
!subject.isConnectedToAsset("hold", object, "to_dov")
) {
continue;
}
foundObjects.push(list[i]);
}
this.game.log(
"L1654",
"log",
"high",
`[selectInInventoryIfTakeable.js] selectInInventoryIfTakeable() return:\n${foundObjects}`,
"Parser"
);
return foundObjects;
};
})();