From 960f3ea29d08e8aa80998544cb79700ebf8d682f Mon Sep 17 00:00:00 2001 From: Jon Atkins Date: Fri, 6 Sep 2013 22:25:39 +0100 Subject: [PATCH] portal highlighter: shield+link mitugation --- plugins/portal-highlighter-mitigation.user.js | 76 +++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 plugins/portal-highlighter-mitigation.user.js diff --git a/plugins/portal-highlighter-mitigation.user.js b/plugins/portal-highlighter-mitigation.user.js new file mode 100644 index 00000000..35dfcfd4 --- /dev/null +++ b/plugins/portal-highlighter-mitigation.user.js @@ -0,0 +1,76 @@ +// ==UserScript== +// @id iitc-plugin-highlight-mitigation@jonatkins +// @name IITC plugin: hightlight portals total mitigation +// @category Highlighter +// @version 0.1.0.@@DATETIMEVERSION@@ +// @namespace https://github.com/jonatkins/ingress-intel-total-conversion +// @updateURL @@UPDATEURL@@ +// @downloadURL @@DOWNLOADURL@@ +// @description [@@BUILDNAME@@-@@BUILDDATE@@] Uses the fill color of the portals to show mitigation. Shades of red to the maximum of 95, then tints towards purple for over 95 +// @include https://www.ingress.com/intel* +// @include http://www.ingress.com/intel* +// @match https://www.ingress.com/intel* +// @match http://www.ingress.com/intel* +// @grant none +// ==/UserScript== + +@@PLUGINSTART@@ + +// PLUGIN START //////////////////////////////////////////////////////// + +// use own namespace for plugin +window.plugin.portalHighligherMitigation = function() {}; + +// taken from portalDefense plugin. needs to be moved into IITC core +window.plugin.portalHighligherMitigation.computeDef = function(portal) { + var m = portal.options.details.portalV2.linkedModArray; + var ret = {}; + ret.mod = 0; + ret.links = 0; + $.each(m, function(ind, mod) { + if (!mod) return true; + if(!mod.stats.MITIGATION) + return true; + ret.mod += parseInt(mod.stats.MITIGATION); + }); + var link = 0; + $(portal.options.details.portalV2.linkedEdges).each(function () { + link++; + }); + if (link > 0) { + ret.links = Math.round(400/9*Math.atan(link/Math.E)); + } + ret.total = Math.min(95, ret.mod + ret.links); + + return ret; +} + +window.plugin.portalHighligherMitigation.highlight = function(data) { + + var defense = window.plugin.portalHighligherMitigation.computeDef (data.portal); + + if (defense.total > 0) { + var fill_opacity = (defense.total/95)*.85 + .15; + + // maximum mitigation from links is approx 69, and from shields is 120, giving max of ~189 + // therefore maximum over mitigation is ~94. let's treat 80 as our max amount and scale that to the blue channel for colour tint + var over_mitigation = Math.max(0, defense.mod+defense.links-defense.total); + + var blue = Math.max(0,Math.min(255,Math.round(over_mitigation/80*255))); + + var colour = 'rgb(255,0,'+blue+')'; + + var params = {fillColor: colour, fillOpacity: fill_opacity}; + + data.portal.setStyle(params); + } + +} + +var setup = function() { + window.addPortalHighlighter('Mitigation (defense)', window.plugin.portalHighligherMitigation.highlight); +} + +// PLUGIN END ////////////////////////////////////////////////////////// + +@@PLUGINEND@@