utility functions to

- get mods from portal details, filtered by type and sorted by strength
- get mitigation values
TODO: convert existing plugins to use these new functions
This commit is contained in:
Jon Atkins 2013-09-18 07:45:30 +01:00
parent 1f635f0e50
commit a9c9d5ff41

View File

@ -205,3 +205,74 @@ window.getPortalImageUrl = function(d) {
} }
} }
window.getPortalModsByType = function(d, type) {
var mods = [];
$.each(d.portalV2.linkedModArray || [], function(i,mod) {
if (mod && mod.type == type) mods.push(mod);
});
var sortKey = {
RES_SHIELD: 'MITIGATION',
FORCE_AMP: 'FORCE_AMPLIFIER',
TURRET: 'HIT_BONUS', // and/or ATTACK_FREQUENCY??
HEATSINK: 'HACK_SPEED',
MULTIHACK: 'BURNOUT_INSULATION',
LINK_AMPLIFIER: 'LINK_RANGE_MULTIPLIER'
};
// prefer to sort mods by stat - so if stats change (as they have for shields and turrets) we still put the highest first
if (sortKey[type]) {
// we have a stat type to sort by
var key = sortKey[type];
mods.sort (function(a,b) {
return b.stats[key] - a.stats[key];
});
} else {
// no known stat type - sort by rarity
mods.sort (function(a,b) {
// rarity values are COMMON, RARE and VERY_RARE. handy, as that's alphabetical order!
if (a.rarity < b.rarity) return -1;
if (a.rarity > b.rarity) return 1;
return 0;
});
}
return mods;
}
window.getPortalShieldMitigation = function(d) {
var shields = getPortalModsByType(d, 'RES_SHIELD');
var mitigation = 0;
$.each(shields, function(i,s) {
mitigation += parseInt(s.stats.MITIGATION);
});
return mitigation;
}
window.getPortalLinksMitigation = function(d) {
var links = (d.portalV2.linkedEdges||[]).length;
var mitigation = Math.round(400/9*Math.atan(links/Math.E));
return mitigation;
}
window.getPortalMitigationDetails = function(d) {
var mitigation = {
shields: getPortalShieldMitigation(d),
links: getPortalLinksMitigation(d)
};
// mitigation is limited to 95% (as confirmed by Brandon Badger on G+)
mitigation.total = Math.min(95, mitigation.shields+mitigation.links);
mitigation.excess = (mitigation.shields+mitigation.links) - mitigation.total;
return mitigation;
}