// findAssetsByPronoun.js
(function () {
/* global adventurejs A */
var p = adventurejs.Tangible.prototype;
/**
* Find instances within this asset of the gender that matches
* the specific pronoun. For example, given "him" or "his",
* find all male assets within the room. Returns an array of assets.
* <br><br>
* DOES NOT ACCOUNT FOR CUSTOM PRONOUNS.
* @memberOf adventurejs.Tangible
* @method adventurejs.Tangible#findAssetsByPronoun
* @param {String} pronoun
* @returns {Array}
*/
p.findAssetsByPronoun = function Tangible_findAssetsByPronoun(
pronoun,
params = {}
) {
if ("string" !== typeof pronoun) return [];
if (!this.game.dictionary.objective_pronouns.includes(pronoun)) return [];
if (pronoun === "me") return [this.game.getPlayer()];
var contents = this.getAllNestedContents();
var foundInstances = [];
for (var i = 0; i < contents.length; i++) {
var asset_id = contents[i];
if (params.exclude?.includes(asset_id)) continue;
var asset = this.game.getAsset(asset_id);
if (!asset) continue;
if (["him", "his"].includes(pronoun) && asset.gender === "male") {
foundInstances.push(asset);
continue;
}
if (["her"].includes(pronoun) && asset.gender === "female") {
foundInstances.push(asset);
continue;
}
if (["it", "its"].includes(pronoun) && asset.gender === "nonhuman") {
foundInstances.push(asset);
continue;
}
if (
["them", "their"].includes(pronoun) &&
(asset.hasClass("Character") || asset.is.plural)
) {
foundInstances.push(asset);
continue;
}
const added_keys = Object.keys(
this.game.dictionary.added_objective_pronouns
);
// test added genders
if (added_keys.includes(pronoun)) {
const gender = this.game.dictionary.added_objective_pronouns[pronoun];
if (asset.gender === gender) {
foundInstances.push(asset);
continue;
}
}
}
return foundInstances;
};
})();