// allowVerbWithAsset.js
(function () {
/*global adventurejs A*/
var p = adventurejs.Asset.prototype;
/**
* <strong>allowVerbWithAsset</strong> is a method
* to check whether this asset is subscribed to act
* as an object with the specified verb and object.
* @memberOf adventurejs.Asset
* @method adventurejs.Asset#allowVerbWithAsset
* @param {String} verb The name of a verb.
* @param {Object} asset A game asset.
* @param {String} ov Direct or indirect object of verb.
* @returns {Boolean}
*/
p.allowVerbWithAsset = function Asset_allowVerbWithAsset(verb, asset, ov) {
if (!ov || (ov !== "dov" && ov !== "iov")) ov = "dov";
if ("string" === typeof asset) asset = this.game.getAsset(asset);
if (!asset || !asset.id) return false;
if (!verb || !this.game.dictionary.verbs[verb]) return false;
if (!this["is" + ov.toUpperCase()](verb)) return false; // isDOV, isIOV
verb = this.game.dictionary.verbs[verb];
if (this[ov][verb.name].with_assets.includes(asset.id)) {
return true;
}
// is asset class in this[ov][verb].with_classes ?
let classes = this[ov][verb.name].with_classes;
for (let i = 0; i < classes.length; i++) {
if (asset instanceof adventurejs[classes[i]]) {
return true;
}
}
return false;
};
})();