Fix guess-player-levels

(Under certain circumstances, flipped portals weren't detected correctly. Also, guessing has improved: Resonators not deployed by the owner can safely be used for level guessing)
This commit is contained in:
fkloft 2013-12-05 19:03:55 +01:00
parent c676354a15
commit c70b7ac1ca

View File

@ -119,33 +119,47 @@ 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
// while 'guessed' comes from resonators of the portal owner
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;
}
players[nickname].forEach(function(count, level) {
if(MAX_RESO_PER_PLAYER[level] < count) {
ignore = true;
if(count > 0)
minLevel = level;
});
if(ignore)
return;
if(nickname == owner)
window.plugin.guessPlayerLevels.savePlayerLevel(nickname, minLevel);
else // not deployed by owner - player must be at least that level
window.plugin.guessPlayerLevels.savePlayerLevel(nickname, minLevel, true);
}); });
} }