Pre-release
AdventureJS Docs Downloads
Score: 0 Moves: 0
// setVerbWithAsset.js
(function () {
  /*global adventurejs A*/
  var p = adventurejs.Asset.prototype;
  /**
   * <strong>setVerbWithAsset</strong> is used to specify
   * another asset that can be used as an object with this
   * asset. For example, if this asset is a locking
   * chest, chest.setVerbWithAsset('unlock', 'gold key', 'iov') would add
   * the gold key as an indirect object of the chest.
   * @memberOf adventurejs.Asset
   * @method adventurejs.Asset#setVerbWithAsset
   * @param {String} verb The name of a verb.
   * @param {Object} asset
   * @param {String} ov Direct or indirect object of verb.
   * @returns {Boolean}
   */

  p.setVerbWithAsset = function Asset_setVerbWithAsset(verb, asset, ov) {
    if (!ov || (ov !== "dov" && ov !== "iov")) ov = "dov";
    if (!verb || !this.game.dictionary.verbs[verb]) return false;
    if ("string" === typeof asset) asset = this.game.getAsset(asset);
    if (!asset) return false;

    // verify that this is set as a direct object of verb
    if (!this["is" + ov.toUpperCase()](verb)) {
      // isDOV isIOV
      this["set" + ov.toUpperCase()](verb); // setDOV setIOV
    }

    // verify that indirect object isn't already set
    if (-1 === this[ov][verb].with_assets.indexOf(asset.id)) {
      this[ov][verb].with_assets.push(asset.id);
    }

    // that it works with an asset means it doesn't work with nothing
    this[ov][verb].with_nothing = false;

    return true;
  };
})();