// selectTakeable.js
(function () {
/* global AdventureJS A */
var p = AdventureJS.Parser.prototype;
/**
* Exclude from a list of assets all assets that can't be taken by subject.
* @method AdventureJS.Parser#selectTakeable
* @memberOf AdventureJS.Parser
* @param {Array} list
* @returns {Array}
*/
p.selectTakeable = function Parser_selectTakeable(list) {
// we already know it's present and visible and reachable
if ("string" === typeof list) list = [list];
if (!Array.isArray(list)) {
this.game.log(
"L1255",
"error",
"critical",
["[selectTakeable.js] selectTakeable() received non-array", list],
"Parser"
);
return [];
}
this.game.log(
"L1187",
"log",
"high",
`[selectTakeable.js] selectTakeable() 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.selectTakeable([dispenser_id]);
if (select.length) {
const quad = `fungible:${object.fungible.dispense_class}:${dispenser_aspect}:${dispenser_id}`;
foundObjects.push(quad);
}
}
continue;
}
if (!object.isDOV("take")) {
if (
object instanceof AdventureJS.Assets.Room &&
/* list[i].split(":")[3] === "substance" */
/* want to change this to */
list[i].includes(":") &&
list[i].split(":")[0] === "substance"
) {
// it's a substance in a room, which is not technically takeable,
// but we're going to let take verb handle that
foundObjects.push(list[i]);
}
continue;
}
// if object is a plug, test against its parent
if (object.isConnectedToAsset("plug", object.getPlaceAsset(), "to_dov")) {
object = object.getPlaceAsset();
}
// if it has no getParent method then it's not takeable
// not originally intended but this applies directly to substances
if (!object.getPlaceAsset) continue;
var parent = object.getPlaceAsset();
if (!parent) continue;
// subject's already holding it or wearing it
//if( parent.id === subject.id ) continue;
// going to let verbs handle this
/**
* If any of object's anscestors are closed we'll consider
* the object not takeable,
* unless it's nested in subject inventory. We'll be nice and
* let subject access their inventory without having to
* open every damned container.
*
* In theory we could do the same for any nested & known objects,
* but that could raise unpredictable conflicts in situations
* like taking objects from NPCs, or inadvertently triggering
* or bypassing custom functions.
*/
//if( false === object.areAnscestorsClosed()
if (
object.areAnscestorsClosed &&
object.areAnscestorsClosed() &&
!object.isWithin(subject)
) {
continue;
}
/**
* We don't handle this here because author is likely
* to want complex interaction on trying to take something
* from a Character. Leaving it commented for later exploration.
*/
// if( parent instanceof AdventureJS.Assets.Character
// && false === parent.isIOV("take")
// ) {
// continue;
// }
foundObjects.push(list[i]);
}
this.game.log(
"L1644",
"log",
"high",
`[selectTakeable.js] selectTakeable() return:\n${foundObjects}`,
"Parser"
);
return foundObjects;
};
})();