// selectInHands.js
(function () {
/* global AdventureJS A */
var p = AdventureJS.Parser.prototype;
/**
* Exclude from a list of assets all assets that are not in subject'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(
"L1234",
"error",
"critical",
["[selectInHands.js] selectInHands() received non-array", list],
"Parser"
);
return [];
}
this.game.log(
"L1161",
"log",
"high",
`[selectInHands.js] selectInHands() 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.selectInHands([dispenser_id]);
if (select.length) {
const quad = `fungible:${object.fungible.dispense_class}:${dispenser_aspect}:${dispenser_id}`;
foundObjects.push(quad);
}
}
continue;
}
if (object instanceof AdventureJS.Assets.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 !== subject.id &&
!subject.isConnectedToAsset("hold", object, "to_dov")
) {
continue;
}
if (parent.id === subject.id && object.is.worn) {
continue;
}
foundObjects.push(list[i]);
}
this.game.log(
"L1651",
"log",
"high",
`[selectInHands.js] selectInHands() return:\n${foundObjects}`,
"Parser"
);
return foundObjects;
};
})();