Pre-release
Adventure.js Docs Downloads
Score: 0 Moves: 0
// incrementDoVerbCount.js
(function() {
	/*global adventurejs A*/ 
  "use strict";
  var p = adventurejs.Asset.prototype;	
  /**
   * <strong>incrementDoVerbCount</strong> takes a verb and an index and 
   * updates this asset's count of the number of times the verb has 
   * acted upon it. 
   * @method adventurejs.Asset#incrementDoVerbCount
   * @memberOf adventurejs.Asset
   * @param {String} verb 
   * @param {Int} index
   * 
   */
  p.incrementDoVerbCount = function Asset_incrementDoVerbCount( verb, index ) 
  {

  // this is questionable because it treats 
  // direct / indirect objects the same
  this.did_do_verb[verb] = true;

  /** @TODO replace linked_asset with a method to get any linked assets */
  var linked_asset;
  if( this.linked_asset ) 
  {
    linked_asset = this.game.getAsset( this.linked_asset );
    if(linked_asset) linked_asset.did_do_verb[verb] = true;
  }  

  if( !this.did_do_verb_count[ verb ] ) 
  {
    this.did_do_verb_count[ verb ] = { all:1, noun1:0, noun2:0, noun3:0 };
    if( linked_asset ) linked_asset.did_do_verb_count[ verb ] = { all:1, noun1:0, noun2:0, noun3:0 };
  } 
  else 
  {
    this.did_do_verb_count[ verb ].all++;
    if( linked_asset ) linked_asset.did_do_verb_count[ verb ].all++;
  }

  if( index ) 
  {
    // we have two verb counting systems
    // did_do_verb_count is the original
    // it counts verb attempts on all assets 
    // regardless of verb subscriptions
    this.did_do_verb_count[ verb ][ "noun" + index ]++;
    if( linked_asset ) linked_asset.did_do_verb_count[ verb ][ "noun" + index ]++;

    // DOVincrementDoCount came with verb subscriptions
    // it only counts verb attempts 
    // on assets with verb subscriptions
    switch(index){
      case 1: this.DOVincrementDoCount( verb ); break;
      case 2: 
        if(this.isIOV(verb) )
        {
          this.IOVincrementDoCount( verb ); 
        }
        // noun2 is usually indirect object but 
        // may be a direct object with some verbs
        else if(this.isDOV(verb) )
        {
          this.DOVincrementDoCount( verb ); 
        }
        break;
      case 3: this.IOVincrementDoCount( verb ); break;
    }
  }
}
}());