Merge pull request #687 from fkloft/guess-player-levels

Fix guess-player-levels
This commit is contained in:
Jon Atkins 2013-12-05 14:35:29 -08:00
commit 231178123f

View File

@ -2,7 +2,7 @@
// @id iitc-plugin-guess-player-levels@breunigs // @id iitc-plugin-guess-player-levels@breunigs
// @name IITC plugin: guess player level // @name IITC plugin: guess player level
// @category Info // @category Info
// @version 0.5.0.@@DATETIMEVERSION@@ // @version 0.5.1.@@DATETIMEVERSION@@
// @namespace https://github.com/jonatkins/ingress-intel-total-conversion // @namespace https://github.com/jonatkins/ingress-intel-total-conversion
// @updateURL @@UPDATEURL@@ // @updateURL @@UPDATEURL@@
// @downloadURL @@DOWNLOADURL@@ // @downloadURL @@DOWNLOADURL@@
@ -119,56 +119,80 @@ window.plugin.guessPlayerLevels.extractPortalData = function(data) {
var r = data.details.resonatorArray.resonators; var r = data.details.resonatorArray.resonators;
//due to the Jarvis Virus/ADA Refactor it's possible for a player to own resonators on a portal /* Due to the Jarvis Virus/ADA Refactor it's possible for a player to own resonators on a portal at a higher level
//at a higher level than the player themselves. It is not possible to detect for sure when this than the player themselves. It is not possible to detect for sure when this has happened, but in many cases it will
//has happened, but in many cases it will result in an impossible deployment arrangement result in an impossible deployment arrangement (more than 1 L8/7 res, more than 2 L6/5 res, etc). If we detect this
//(over 1 L8/7 res, over 2 L6/5 res, etc). if we detect this case, ignore all resonators owned case, we ignore all resonators owned by that player on the portal
//by that player on the portal Hint: This can only happen to the owner of the portal, so resonators by other players can be used to determine
their minimal level */
// TODO? go further, and just ignore all resonators owned by the portal owner? var owner = data.details.captured && data.details.captured.capturingPlayerId || "";
// or; have a 'guessed' level and a 'certain' level. 'certain' comes from res from non-owner, and COMM deploy var ownerModCount = 0;
// while 'guessed' comes from resonators of the portal owner data.details.portalV2.linkedModArray.forEach(function(mod) {
if(mod && mod.installingUser == owner)
ownerModCount++;
});
var perPlayerResMaxLevel = {}; var players = {};
var perPlayerResMaxLevelCount = {};
$.each(r, function(ind, reso) { $.each(r, function(ind, reso) {
if(!reso) return true; if(!reso) return true;
if(!perPlayerResMaxLevel[reso.ownerGuid] || reso.level > perPlayerResMaxLevel[reso.ownerGuid]) { if(!players[reso.ownerGuid]) players[reso.ownerGuid] = [];
perPlayerResMaxLevel[reso.ownerGuid] = reso.level;
perPlayerResMaxLevelCount[reso.ownerGuid] = 0; if(players[reso.ownerGuid][reso.level] === undefined)
} players[reso.ownerGuid][reso.level] = 1
if (reso.level == perPlayerResMaxLevel[reso.ownerGuid]) perPlayerResMaxLevelCount[reso.ownerGuid]++; else
players[reso.ownerGuid][reso.level]++;
}); });
$.each(perPlayerResMaxLevel, function(guid, level) { for(nickname in players) {
if (perPlayerResMaxLevelCount[guid] <= window.MAX_RESO_PER_PLAYER[level]) { var ignore = false;
window.plugin.guessPlayerLevels.savePlayerLevel(guid, level); var minLevel = 0;
if(nickname == owner) {
if(ownerModCount > 2) // more than 2 mods by capturing player --> portal was flipped, ignore their resonators
continue;
var certain = false;
} else { // not deployed by owner - player must be at least that level
var certain = true;
} }
});
players[nickname].forEach(function(count, level) {
if(MAX_RESO_PER_PLAYER[level] < count)
ignore = true;
if(count > 0)
minLevel = level;
});
if(ignore)
continue;
window.plugin.guessPlayerLevels.savePlayerLevel(nickname, minLevel, certain);
}
} }
window.plugin.guessPlayerLevels.extractChatData = function(data) { window.plugin.guessPlayerLevels.extractChatData = function(data) {
data.raw.result.forEach(function(msg) { data.raw.result.forEach(function(msg) {
var plext = msg[2].plext; var plext = msg[2].plext;
if(plext.plextType == 'SYSTEM_BROADCAST' if(plext.plextType == 'SYSTEM_BROADCAST'
&& plext.markup.length==5 && plext.markup.length==5
&& plext.markup[0][0] == 'PLAYER' && plext.markup[0][0] == 'PLAYER'
&& plext.markup[1][0] == 'TEXT' && plext.markup[1][0] == 'TEXT'
&& plext.markup[1][1].plain == ' deployed an ' && plext.markup[1][1].plain == ' deployed an '
&& plext.markup[2][0] == 'TEXT' && plext.markup[2][0] == 'TEXT'
&& plext.markup[2][0] == 'TEXT' && plext.markup[2][0] == 'TEXT'
&& plext.markup[3][0] == 'TEXT' && plext.markup[3][0] == 'TEXT'
&& plext.markup[3][1].plain == ' Resonator on ') { && plext.markup[3][1].plain == ' Resonator on ') {
var nick = plext.markup[0][1].plain; var nick = plext.markup[0][1].plain;
var lvl = parseInt(plext.markup[2][1].plain.substr(1)); var lvl = parseInt(plext.markup[2][1].plain.substr(1));
window.plugin.guessPlayerLevels.savePlayerLevel(nick, lvl, true); window.plugin.guessPlayerLevels.savePlayerLevel(nick, lvl, true);
} }
}); });
}; };
window.plugin.guessPlayerLevels.savePlayerLevel = function(nick, level, safe) { window.plugin.guessPlayerLevels.savePlayerLevel = function(nick, level, certain) {
var cache = window.plugin.guessPlayerLevels._loadLevels(); var cache = window.plugin.guessPlayerLevels._loadLevels();
var details = cache['#' + nick]; var details = cache['#' + nick];
@ -177,7 +201,7 @@ window.plugin.guessPlayerLevels.savePlayerLevel = function(nick, level, safe) {
if(typeof details === 'number') if(typeof details === 'number')
details = {min: 1, guessed: details}; details = {min: 1, guessed: details};
if(safe) { if(certain) {
if(details.min >= level) if(details.min >= level)
return; return;