Pre-release
Adventure.js Docs Downloads
Score: 0 Moves: 0
// DOVallowWithAsset.js
(function() {
	/*global adventurejs A*/ 
  "use strict";
  var p = adventurejs.Asset.prototype;	
  /**
   * <strong>DOVallowWithAsset</strong> is a method 
   * to check whether this asset is subscribed to act
   * as a direct object with the specified verb and indirect object.
   * @memberOf adventurejs.Asset
   * @method adventurejs.Asset#DOVallowWithAsset
   * @param {String} verb
   * @param {Object} asset
   * @returns {Boolean}
   */
  p.DOVallowWithAsset = function Asset_DOVallowWithAsset(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.isDOV(verb)) return false;

    verb = this.game.dictionary.verbs[verb];

    if( -1 !== this.dov[verb.name].with_assets.indexOf( asset.id ) )
    {
      return true;
    }

    // is asset class in this.dov[verb].with_classes ?
    let classes = this.dov[verb.name].with_classes;
    for(let i = 0; i < classes.length; i++ ) {
      if( asset instanceof adventurejs[ classes[i] ] )
      {
        return true;
      }
    }
    
    return false;

  }
}());