Created
April 6, 2016 22:05
-
-
Save VirtuosiMedia/c968233189d4d157f06af80fb861d3a4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Retrieves a base price for a given good based on the base prices of all resources used to craft it. | |
* @param {string} good The good id. | |
* @return {numeric} The base price of the good. | |
*/ | |
getGoodBasePrice: function(good){ | |
if (!this.resources){ | |
this.resources = _.container(_.language.getDataSet('resources')); | |
} | |
if (!this.components){ | |
this.components = _.container(_.language.getDataSet('items')); | |
} | |
var price = 0; | |
if (this.resources.keys().contains(good)){ | |
price = this.resources[good].basePrice; | |
} else { | |
var costs = _.container(this.components[good].costs); | |
var self = this; | |
//Recursively get the cost for the component. | |
costs.each(function(quantity, resource){ | |
if (resource === 'items'){ | |
var components = _.container(quantity); | |
components.each(function(numComponents, component){ | |
price += numComponents * self.getGoodBasePrice(component); | |
}); | |
} else { | |
price += quantity * self.getGoodBasePrice(resource); | |
} | |
}); | |
} | |
return price; | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment