Pre-release
AdventureJS Docs Downloads
Score: 0 Moves: 0
// incrementTryVerbCount.js
(function () {
  /*global adventurejs A*/
  var p = adventurejs.Asset.prototype;
  /**
   * <strong>incrementTryVerbCount</strong> takes a verb and an index and
   * updates this asset's count of the number of times the verb has
   * attempted upon it.
   * @method adventurejs.Asset#incrementTryVerbCount
   * @memberOf adventurejs.Asset
   * @param {String} verb
   * @param {Int} index
   */
  p.incrementTryVerbCount = function Asset_incrementTryVerbCount(verb, index) {
    var linked_asset;
    if (!this.tried[verb]) {
      this.tried[verb] = {};
    }
    if (this.linked_asset) {
      linked_asset = this.game.getAsset(this.linked_asset);
      if (!linked_asset.tried[verb]) {
        linked_asset.tried[verb] = {};
      }
    }

    if (index) {
      let ov = "";
      switch (index) {
        case 1:
          ov = "directly";
          break;
        case 2:
          if (this.isIOV(verb)) {
            ov = "indirectly";
          }
          // noun2 is usually indirect object but
          // may be a direct object with some verbs
          else if (this.isDOV(verb)) {
            ov = "directly";
          }
          break;
        case 3:
          ov = "indirectly";
          break;
      }

      if (!this.tried[verb][ov]) {
        this.tried[verb][ov] = 0;
      }
      this.tried[verb][ov]++;
      if (linked_asset) {
        if (!linked_asset.tried[verb][ov]) {
          linked_asset.tried[verb][ov] = 0;
        }
        linked_asset.tried[verb][ov]++;
      }
    }
  };
})();