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:
		@@ -119,33 +119,47 @@ window.plugin.guessPlayerLevels.extractPortalData = function(data) {
 | 
			
		||||
 | 
			
		||||
  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
 | 
			
		||||
  //at a higher level than the player themselves. It is not possible to detect for sure when this
 | 
			
		||||
  //has happened, but in many cases it will result in an impossible deployment arrangement
 | 
			
		||||
  //(over 1 L8/7 res, over 2 L6/5 res, etc). if we detect this case, ignore all resonators owned
 | 
			
		||||
  //by that player on the portal
 | 
			
		||||
  /* Due to the Jarvis Virus/ADA Refactor it's possible for a player to own resonators on a portal at a higher level
 | 
			
		||||
     than the player themselves. It is not possible to detect for sure when this has happened, but in many cases it will
 | 
			
		||||
     result in an impossible deployment arrangement (more than 1 L8/7 res, more than 2 L6/5 res, etc). If we detect this
 | 
			
		||||
     case, we ignore all resonators owned 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?
 | 
			
		||||
// 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 owner = data.details.captured && data.details.captured.capturingPlayerId || "";
 | 
			
		||||
 | 
			
		||||
  var perPlayerResMaxLevel = {};
 | 
			
		||||
  var perPlayerResMaxLevelCount = {};
 | 
			
		||||
  var players = {};
 | 
			
		||||
 | 
			
		||||
  $.each(r, function(ind, reso) {
 | 
			
		||||
    if(!reso) return true;
 | 
			
		||||
 | 
			
		||||
    if(!perPlayerResMaxLevel[reso.ownerGuid] || reso.level > perPlayerResMaxLevel[reso.ownerGuid]) {
 | 
			
		||||
      perPlayerResMaxLevel[reso.ownerGuid] = reso.level;
 | 
			
		||||
      perPlayerResMaxLevelCount[reso.ownerGuid] = 0;
 | 
			
		||||
    }
 | 
			
		||||
    if (reso.level == perPlayerResMaxLevel[reso.ownerGuid]) perPlayerResMaxLevelCount[reso.ownerGuid]++;
 | 
			
		||||
    if(!players[reso.ownerGuid]) players[reso.ownerGuid] = [];
 | 
			
		||||
 | 
			
		||||
    if(players[reso.ownerGuid][reso.level] === undefined)
 | 
			
		||||
      players[reso.ownerGuid][reso.level] = 1
 | 
			
		||||
    else
 | 
			
		||||
      players[reso.ownerGuid][reso.level]++;
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  $.each(perPlayerResMaxLevel, function(guid, level) {
 | 
			
		||||
    if (perPlayerResMaxLevelCount[guid] <= window.MAX_RESO_PER_PLAYER[level]) {
 | 
			
		||||
      window.plugin.guessPlayerLevels.savePlayerLevel(guid, level);
 | 
			
		||||
    }
 | 
			
		||||
  for(nickname in players) {
 | 
			
		||||
    var ignore = false;
 | 
			
		||||
    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);
 | 
			
		||||
  });
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user