Move potentialPortalLevel to main for common usage
This commit is contained in:
@ -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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user