fil

                Never    
// This was made as a firefox extension, this is the script that gets injected into the site
// This alone will probably not work
// I know it's really messy

var script_is_running = false;

var typeOfAnimal = ["Array index 0", "Rat", "Spider", "Snake", "Bat", "Wild Boar", "Wolf", "Bear", "Crocodile", "Tiger", "Elephant"];
var selectedAnimal = 9;

var player_x = -5;
var player_y = 9;
var oasis_x = 0;
var oasis_y = 0;
var distance_to_oasis = 0; // Math.hypot(player_x-oasis_x, player_y-oasis_y)

var json_data = {};

var oasis_with_selected_animal = []; // To be able to sort by distance
var cells_with_oasis = {};

function selectAnimal(animal_number){
  selectedAnimal = animal_number;
  console.log("Selected animal: " + typeOfAnimal[selectedAnimal]);
  fetchJSONAndContinue();
}

// Sorting filter/algorithm used to sort by closest distance to oasis
function sortByDistance(a, b) {
    if (a[0] === b[0]) {
        return 0;
    }
    else {
        return (a[0] < b[0]) ? -1 : 1;
    }
}

// Get all oasis cells as input, run MapDetails.get() on each cell to load it's data, then the run the function in second input after it's finished loading.
function getMapDetails(oasis_cells, callback){
  for(i=0; i<(oasis_cells.length); i++){
    MapDetails.get(oasis_cells[i].id).data;
  }
  var counter = 0;
  var interval = setInterval(function(){
    counter++;
    console.log("Loading all map tiles... " + counter + "/20 seconds");
  }, 1000);
  setTimeout(function(){
    clearInterval(interval);
    callback();
  }, 21000);

}

// Find oasis cells containing wanted animal, log out results in console
function findSelectedAnimal(){
  oasis_with_selected_animal = [];
  for(i=0; i<(cells_with_oasis.length); i++){
    var animals = MapDetails.get(cells_with_oasis[i].id).data.troops.units;
    if(Object.prototype.toString.call(animals) == "[object Object]"){
      if(!(isNaN(animals[selectedAnimal]))){
        distance_to_oasis = Math.hypot(player_x-cells_with_oasis[i].x, player_y-cells_with_oasis[i].y);
        oasis_with_selected_animal.push([distance_to_oasis, typeOfAnimal[selectedAnimal], animals[selectedAnimal], "(" + cells_with_oasis[i].x + "|" + cells_with_oasis[i].y + ")"]);
      }
    }
  }

  oasis_with_selected_animal.sort(sortByDistance)
  for(i=0; i<(oasis_with_selected_animal.length); i++){
    console.log(oasis_with_selected_animal[i][1] + ", " + oasis_with_selected_animal[i][3] + ", Amount: " + oasis_with_selected_animal[i][2]);
  }
  script_is_running = false;
}

// Fetch API JSON data, then return only Oasis cells, then run getMapDetails();
function fetchJSONAndContinue() {
  if(script_is_running){
    console.log("Script is already running, wait for it to finish and try again.");
    alert("Script is already running, wait for it to finish and try again.");
  }
  else{
    script_is_running = true;
    fetch('https://com7.kingdoms.com/api/external.php?action=getMapData&privateApiKey=ENTER_YOUR_OWN_API_KEY_HERE') // https://forum.kingdoms.com/thread/4099-api-for-external-tools/ send a get request to API url first to request your API key, replace "ENTER_YOUR_OWN_API_KEY_HERE" with your API key.
      .then(function(response) {
        return response.json();
      })
      .then(function(jsonData) {
        json_data = jsonData;
        cells_with_oasis = json_data.response.map.cells.filter(function(i) {
          return i.oasis > 0;
        });
        return cells_with_oasis;
      })
      .then(function(oasis_cells) {
        getMapDetails(oasis_cells, findSelectedAnimal);
      });
  }
}

Raw Text