From 5a33ba1a24a331364336aafc46a8ee5fced58a72 Mon Sep 17 00:00:00 2001 From: Jon Atkins Date: Thu, 12 Dec 2013 18:32:28 +0000 Subject: [PATCH] more portal summary data utility functions - link/field count functions - useful when we only need numbers - approximate AP gains, based only on summary data --- code/portal_data.js | 55 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/code/portal_data.js b/code/portal_data.js index cf5aa62b..6afdf9b1 100644 --- a/code/portal_data.js +++ b/code/portal_data.js @@ -21,6 +21,11 @@ window.getPortalLinks = function(guid) { return links; } +window.getPortalLinksCount = function(guid) { + var links = getPortalLinks(); + return links.in.length+links.out.length; +} + // search through the fields for all that reference a portal window.getPortalFields = function(guid) { @@ -40,6 +45,11 @@ window.getPortalFields = function(guid) { return fields; } +window.getPortalFieldsCount = function(guid) { + var fields = getPortalFields(); + return fields.length; +} + // find the lat/lon for a portal, using any and all available data // (we have the list of portals, the cached portal details, plus links and fields as sources of portal locations) @@ -79,3 +89,48 @@ window.findPortalLatLng = function(guid) { // no luck finding portal lat/lng return undefined; } + + +// get the AP gains from a portal, based only on the brief summary data from portals, links and fields +// not entirely accurate - but available for all portals on the screen +window.getPortalApGain = function(guid) { + + var p = window.portals[guid]; + if (p) { + var data = p.options.data; + + var linkCount = getPortalLinksCount(guid); + var fieldCount = getPortalFieldsCount(guid); + + var result = portalApGainMaths(data.resCount, linkCount, fieldCount); + return result; + } + + return undefined; +} + +// given counts of resonators, links and fields, calculate the available AP +// doesn't take account AP for resonator upgrades or AP for adding mods +window.portalApGainMaths = function(resCount, linkCount, fieldCount) { + + var deployAp = (8-resCount)*DEPLOY_RESONATOR; + if (resCount == 0) deployAp += CAPTURE_PORTAL; + if (resCount != 8) deployAp += COMPLETION_BONUS; + // there could also be AP for upgrading existing resonators, and for deploying mods - but we don't have data for that + var friendlyAp = deployAp; + + var destroyResoAp = resCount*DESTROY_RESONATOR; + var destroyLinkAp = linkCount*DESTROY_LINK; + var destroyFieldAp = fieldCount*DESTROY_FIELD; + var captureAp = CAPTURE_PORTAL + 8 * DEPLOY_RESONATOR + COMPLETION_BONUS; + var destroyAp = destroyResoAp+destroyLinkAp+destroyFieldAp; + var enemyAp = destroyAp+captureAp; + + return { + friendlyAp: friendlyAp, + enemyAp: enemyAp, + destroyAp: destroyAp, + destroyResoAp: destroyResoAp, + captureAp: captureAp + } +}