Move potentialPortalLevel to main for common usage

This commit is contained in:
vita10gy
2013-04-12 22:53:30 -05:00
parent 0f1abe1fc7
commit 135d4b893d
2 changed files with 45 additions and 48 deletions

View File

@ -117,3 +117,43 @@ window.getAttackApGain = function(d) {
captureAp: captureAp
};
}
//This function will return the potential level a player can upgrade it to
window.potentialPortalLevel = function(d) {
var current_level = getPortalLevel(d);
var potential_level = current_level;
if(PLAYER.team === d.controllingTeam.team) {
var resonators_on_portal = d.resonatorArray.resonators;
var resonator_levels = new Array();
// figure out how many of each of these resonators can be placed by the player
var player_resontators = new Array();
for(var i=1;i<=MAX_PORTAL_LEVEL; i++) {
player_resontators[i] = i > PLAYER.level ? 0 : MAX_RESO_PER_PLAYER[i];
}
$.each(resonators_on_portal, function(ind, reso) {
if(reso !== null && reso.ownerGuid === window.PLAYER.guid) {
player_resontators[reso.level]--;
}
resonator_levels.push(reso === null ? 0 : reso.level);
});
resonator_levels.sort(function(a, b) {
return(a - b);
});
// Max out portal
var install_index = 0;
for(var i=MAX_PORTAL_LEVEL;i>=1; i--) {
for(var install = player_resontators[i]; install>0; install--) {
if(resonator_levels[install_index] < i) {
resonator_levels[install_index] = i;
install_index++;
}
}
}
//console.log(resonator_levels);
potential_level = resonator_levels.reduce(function(a, b) {return a + b;}) / 8;
}
return(potential_level);
}