// selectReservoirOrCarriedIfSubstance.js
(function () {
/*global adventurejs A*/
var p = adventurejs.Parser.prototype;
/**
* Exclude from a list of assets all assets that are not
* substance reservoirs such as a lake or a beach, or vessels
* carried by player, only if a substance was specified.
* @method adventurejs.Parser#selectReservoirOrCarriedIfSubstance
* @memberOf adventurejs.Parser
* @param {Array} list
* @returns {Array}
*/
p.selectReservoirOrCarriedIfSubstance =
function Parser_selectReservoirOrCarriedIfSubstance(list) {
this.game.log(
"L1231",
"log",
"high",
"selectReservoirOrCarriedIfSubstance.js > received " + String(list),
"Parser"
);
if ("string" === typeof list) list = [list];
if (!Array.isArray(list)) {
this.game.log(
"L1232",
"warn",
"critical",
"selectReservoirOrCarriedIfSubstance.js > received non-array",
"Parser"
);
return [];
}
var foundObjects = [];
for (var i = 0; i < list.length; i++) {
var split = list[i].split(":");
if (split.length === 1) {
foundObjects.push(list[i]);
continue;
}
var object;
object = this.game.getAsset(list[i]);
if (object.$is("reservoir") || object.isWithin(this.game.getPlayer())) {
foundObjects.push(list[i]);
continue;
}
}
this.game.log(
"L1233",
"log",
"high",
"selectReservoirOrCarriedIfSubstance.js > returns " +
String(foundObjects),
"Parser"
);
return foundObjects;
};
})();