// isConnectedToAsset.js
(function () {
/*global adventurejs A*/
var p = adventurejs.Asset.prototype;
/**
* Check whether this asset is currently connected as a direct
* object to the specified indirect object by the specified verb.
* For example, in the case of a computer plugged into an outlet,
* the computer would be the direct object, and calling this method
* on it would return true.
* @memberOf adventurejs.Asset
* @method adventurejs.Asset#isConnectedToAsset
* @param {String} verb The name of the verb to test.
* @param {Object|String} asset A game asset or asset id to test.
* @param {String} to_ov Connection to direct or indirect objects of verb.
* @return {Boolean}
*/
p.isConnectedToAsset = function Asset_isConnectedToAsset(verb, asset, to_ov) {
if ("string" === typeof asset) asset = this.game.getAsset(asset);
if (
!asset ||
!asset.id ||
!verb ||
!this.game.dictionary.verbs[verb] ||
!this.is.connected_by ||
!this.is.connected_by[verb]
) {
return false;
}
if (to_ov === "dov") to_ov = "to_dov";
if (to_ov === "iov") to_ov = "to_iov";
// if (to_ov !== "to_dov" && to_ov !== "to_iov") {
// if (this.isDOV(verb)) to_ov = "to_iov";
// else if (this.isIOV(verb)) to_ov = "to_dov";
// }
// received an ov
if (to_ov === "to_dov" || to_ov === "to_iov") {
if (
this.is.connected_by[verb][to_ov] &&
this.is.connected_by[verb][to_ov].includes(asset.id)
) {
return true;
}
}
// no ov provided, check both
else {
if (
this.is.connected_by[verb].to_dov &&
this.is.connected_by[verb].to_dov.includes(asset.id)
) {
return true;
}
if (
this.is.connected_by[verb].to_iov &&
this.is.connected_by[verb].to_iov.includes(asset.id)
) {
return true;
}
}
return false;
};
})();