Training

by Yure Pereira

HTML

Meus treinos:

<div id="result"></div>

JavaScript

var skills = {
			strength : {id : "char_f0", index: 1, coeff : 2.6},
			dexterity : {id : "char_f1", index: 2, coeff : 2.5},
			agility : {id : "char_f2", index: 3, coeff : 2.3},
			constitution : {id : "char_f3", index: 4, coeff : 2.3},
			charisma : {id : "char_f4", index: 5, coeff : 2.5},
			intelligence : {id : "char_f5", index: 6, coeff : 2.4},    
};

var skill = {
	base: 180,
  coeff: skills.agility.coeff
};

var calculate = function(skill, upgrades, discount){
			// Cost
			var cost = 0;

			// Discount factor
			var factor = (100 - discount) / 100;

			// For each upgrade
			for(var i = upgrades - 1; i >= 0; i--){
				cost += Math.round(Math.pow(skill.base + i - 4, skill.coeff) * factor);
			}
			
			return cost;
}

var emulator = function() {

	var result = document.getElementById('result'),
  	cost = 0;
  

	for (var i = 1; i <= (118 * 5) - 530; i++) {
  
  	cost = calculate(skill, i, 80);
    
    console.log(cost);
    
    result.innerHTML += '<p>' + cost + '</p>';
  
  }

};

emulator();