// IOVallowWithAsset.js
(function() {
/*global adventurejs A*/
"use strict";
var p = adventurejs.Asset.prototype;
/**
* <strong>IOVallowWithAsset</strong> is a method
* to check whether this asset is subscribed to act
* as an indirect object with the specified verb and direct object.
* @memberOf adventurejs.Asset
* @method adventurejs.Asset#IOVallowWithAsset
* @param {String} verb
* @param {Object} asset
* @returns {Boolean}
*/
p.IOVallowWithAsset = function Asset_isIOVWithAsset(verb, asset)
{
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.isIOV(verb)) return false;
verb = this.game.dictionary.verbs[verb];
// ex: do verb close with this to direct_object
// and direct_object.is.closed
if( verb.state && asset.is[verb.state] ) return false;
// ex: do verb open with this to direct_object
// and !direct_object.is.closed
if( verb.unstate && !asset.is[verb.unstate] ) return false;
// is asset id inthis.iov[verb].with_assets ?
if( -1 !== this.iov[verb.name].with_assets.indexOf( asset.id ) )
{
return true;
}
// is asset class in this.iov[verb].with_classes ?
var classes = this.iov[verb.name].with_classes;
for(var i = 0; i < classes.length; i++ ) {
if( asset instanceof adventurejs[ classes[i] ] )
{
return true;
}
}
return false;
}
}());