Refactored getDestroyAP
- Split the calculations into getAttackApGain. Allows for other functions to get the AP data. - Renamed to getAttackApGainText as it isn't just destroying it is also capturing. Originally the method only calculated the destroy values.
This commit is contained in:
parent
2396f34e7a
commit
ba0ff06771
@ -34,7 +34,7 @@ window.renderPortalDetails = function(guid) {
|
||||
// collect and html-ify random data
|
||||
var randDetails = [
|
||||
playerText, sinceText, getRangeText(d), getEnergyText(d),
|
||||
linksText, getAvgResoDistText(d), linkedFields, getDestroyAP(d)
|
||||
linksText, getAvgResoDistText(d), linkedFields, getAttackApGainText(d)
|
||||
];
|
||||
randDetails = '<table id="randdetails">' + genFourColumnTable(randDetails) + '</table>';
|
||||
|
||||
|
@ -135,35 +135,21 @@ window.renderResonatorDetails = function(slot, level, nrg, dist, nick) {
|
||||
return [meter, nick || ''];
|
||||
}
|
||||
|
||||
// calculate AP gain from destroying portal
|
||||
// so far it counts only resonators + links
|
||||
window.getDestroyAP = function(d) {
|
||||
var resoCount = 0;
|
||||
|
||||
$.each(d.resonatorArray.resonators, function(ind, reso) {
|
||||
if(!reso) return true;
|
||||
resoCount += 1;
|
||||
});
|
||||
|
||||
var linkCount = d.portalV2.linkedEdges ? d.portalV2.linkedEdges.length : 0;
|
||||
var fieldCount = d.portalV2.linkedFields ? d.portalV2.linkedFields.length : 0;
|
||||
|
||||
var resoAp = resoCount * DESTROY_RESONATOR;
|
||||
var linkAp = linkCount * DESTROY_LINK;
|
||||
var fieldAp = fieldCount * DESTROY_FIELD;
|
||||
var sum = resoAp + linkAp + fieldAp + CAPTURE_PORTAL + 8*DEPLOY_RESONATOR + COMPLETION_BONUS;
|
||||
// calculate AP gain from destroying portal and then capturing it by deploying resonators
|
||||
window.getAttackApGainText = function(d) {
|
||||
var breakdown = getAttackApGain(d);
|
||||
|
||||
function tt(text) {
|
||||
var t = 'Destroy & Capture:\n';
|
||||
t += resoCount + '×\tResonators\t= ' + digits(resoAp) + '\n';
|
||||
t += linkCount + '×\tLinks\t= ' + digits(linkAp) + '\n';
|
||||
t += fieldCount + '×\tFields\t= ' + digits(fieldAp) + '\n';
|
||||
t += breakdown.resoCount + '×\tResonators\t= ' + digits(breakdown.resoAp) + '\n';
|
||||
t += breakdown.linkCount + '×\tLinks\t= ' + digits(breakdown.linkAp) + '\n';
|
||||
t += breakdown.fieldCount + '×\tFields\t= ' + digits(breakdown.fieldAp) + '\n';
|
||||
t += '1×\tCapture\t= ' + CAPTURE_PORTAL + '\n';
|
||||
t += '8×\tDeploy\t= ' + (8*DEPLOY_RESONATOR) + '\n';
|
||||
t += '8×\tDeploy\t= ' + (8 * DEPLOY_RESONATOR) + '\n';
|
||||
t += '1×\tBonus\t= ' + COMPLETION_BONUS + '\n';
|
||||
t += 'Sum: ' + digits(sum) + ' AP';
|
||||
return '<tt title="'+t+'">' + digits(text) + '</tt>';
|
||||
t += 'Sum: ' + digits(breakdown.totalAp) + ' AP';
|
||||
return '<tt title="' + t + '">' + digits(text) + '</tt>';
|
||||
}
|
||||
|
||||
return [tt('AP Gain'), tt(sum)];
|
||||
}
|
||||
return [ tt('AP Gain'), tt(breakdown.totalAp) ];
|
||||
};
|
||||
|
@ -66,3 +66,35 @@ window.getAvgResoDist = function(d) {
|
||||
});
|
||||
return sum/resos;
|
||||
}
|
||||
|
||||
window.getAttackApGain = function(d) {
|
||||
var resoCount = 0;
|
||||
|
||||
$.each(d.resonatorArray.resonators, function(ind, reso) {
|
||||
if (!reso)
|
||||
return true;
|
||||
resoCount += 1;
|
||||
});
|
||||
|
||||
var linkCount = d.portalV2.linkedEdges ? d.portalV2.linkedEdges.length : 0;
|
||||
var fieldCount = d.portalV2.linkedFields ? d.portalV2.linkedFields.length : 0;
|
||||
|
||||
var resoAp = resoCount * DESTROY_RESONATOR;
|
||||
var linkAp = linkCount * DESTROY_LINK;
|
||||
var fieldAp = fieldCount * DESTROY_FIELD;
|
||||
var destroyAp = resoAp + linkAp + fieldAp;
|
||||
var captureAp = CAPTURE_PORTAL + 8 * DEPLOY_RESONATOR + COMPLETION_BONUS;
|
||||
var totalAp = destroyAp + captureAp;
|
||||
|
||||
return {
|
||||
totalAp : totalAp,
|
||||
destroyAp : destroyAp,
|
||||
captureAp : captureAp,
|
||||
resoCount : resoCount,
|
||||
resoAp : resoAp,
|
||||
linkCount : linkCount,
|
||||
linkAp : linkAp,
|
||||
fieldCount : fieldCount,
|
||||
fieldAp : fieldAp
|
||||
};
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user