Code:
function Claimer(towns) {
this.towns = towns;
this.claim_lvls = [5, 10, 20, 40, 90, 180, 240, 480]
this.claim_moral = [6, 10, 12, 20, 24, 40, 48, 80]
this.claim_level = 1;
this.time_for_farm_town = {min: 1500, max: 2500};
this.time_for_island_overview = {min: 2000, max: 3000};
this.time_for_player_town = {min: 4000, max: 5000};
this.time_for_claim = {min: 80000, max: 120000};
this.pause_time = {min: 1200000, max: 2400000};
this.running = false;
this.away = false;
this.ajax = new window.GPAjax(window.Layout, false);
this.claims = 0;
this.total_claims = 0;
this.pause_every = {min: 4, max: 6};
}
Claimer.prototype.claim = function() {
var obj = this;
this.away = false;
obj.claimTown(0);
this.total_claims += 1;
this.claims -= 1;
if (this.running) {
var timeout = this.random(this.time_for_claim);
if (this.claims <= 0) {
this.claims = this.random(this.pause_every);
this.away = true;
timeout = this.random(this.pause_time);
}
this.stopID = setTimeout(function() { obj.claim() }, this.claim_lvls[this.claim_level] * 60 * 1000 + this.random(this.time_for_claim));
}
}
Claimer.prototype.claimTown = function(town_id) {
if (town_id >= this.towns.length) {
return;
}
var town = this.towns[town_id];
var obj = this;
this.ajax.get('island_info', 'index', {island_id: town.island, town_id: town.town}, false, function(context, data, flags){
var now = Timestamp.now();
var farm_towns = data.json.farm_town_list.filter(function(ft) { return ft.rel == 1 && (ft.loot == null || ft.loot < now) });
setTimeout(function(){ obj.claimAllFarmTowns(farm_towns, town_id) }, obj.random(obj.time_for_island_overview))
});
}
Claimer.prototype.claimAllFarmTowns = function(farm_towns, town_id) {
var obj = this;
if (farm_towns.length <= 0) {
setTimeout(function() { obj.claimTown(town_id + 1) }, this.random(this.time_for_player_town));
}
var next = farm_towns.pop();
this.ajax.get('farm_town_info', 'claim_info', {id: next.id}, false, function(context, data, flag){
setTimeout(function() {
var ct = 'normal';
if (next.mood && next.mood - obj.claim_moral[obj.claim_level] >= 80) {
ct = 'double';
}
var oldTown = window.Game.townId;
window.Game.townId = obj.towns[town_id].town;
obj.ajax.post('farm_town_info', 'claim_load', {target_id: next.id, claim_type: ct, time: obj.claim_lvls[obj.claim_level] * 60}, false, function(context, data, flag) {
setTimeout(function() { obj.claimAllFarmTowns(farm_towns, town_id); }, obj.random(obj.time_for_farm_town));
});
window.Game.townId = oldTown;
}, obj.random(obj.time_for_farm_town));
});
}
Claimer.prototype.start = function() {
this.claims = this.random(this.pause_every);
this.running = true;
this.claim();
}
Claimer.prototype.stop = function() {
clearTimeout(this.stopID);
this.running = false;
}
Claimer.prototype.random = function(p) {
return p.min + Math.floor(Math.random()*(p.max - p.min));
}
mytowns = [{island: 123456, town: 12345}];
c = new Claimer(mytowns);
c.start();
Only catch is you have to update the list of your cities manually (see the mytowns array). As this script tries to mimic human behaviour (at least to some extend it may not be the fastest one around, but it may help you get past any heuristic InnoGames might have setup).