159 lines
4.6 KiB
JavaScript
159 lines
4.6 KiB
JavaScript
// ==UserScript==
|
|
// @name Grepolis Village Farmer
|
|
// @description Farms villages every 5minutes
|
|
//
|
|
// @author Jan Bader <jan@javil.eu>
|
|
// @downloadURL http://git.javil.eu/jan/userscripts/raw/master/grepolis.user.js
|
|
//
|
|
// @license GPLv3 - http://www.gnu.org/licenses/gpl-3.0.txt
|
|
// @copyright Copyright (C) 2014, by Jan Bader <jan@javil.eu>
|
|
//
|
|
// @match http://*.grepolis.com/game/*
|
|
//
|
|
// @version 1.0.62
|
|
// @updateURL http://git.javil.eu/jan/userscripts/raw/master/grepolis.user.js
|
|
// ==/UserScript==
|
|
|
|
|
|
(function() {
|
|
farmDuration = 300;
|
|
lastAmounts = "";
|
|
console.log("Initializing...");
|
|
windows = {};
|
|
//farm_ids = [1225, 1226, 1228, 1229, 1230, 1231];
|
|
farm_ids = [20466, 20472, 20471];
|
|
farm_ids.forEach(function(xFarmId) {
|
|
console.log("Setting timer to 5s for Farm " + xFarmId);
|
|
setTimeout(getWaresTick(xFarmId), 5000 + rand(5));
|
|
});
|
|
|
|
window.onclose = function() {
|
|
alert("test");
|
|
|
|
};
|
|
|
|
var logWindow = new GPWindow(-1, null);
|
|
logWindow.createWindow();
|
|
logWindowElement = $(logWindow.getElement());
|
|
var logWindowWrapper = logWindowElement.parent().parent();
|
|
logWindowWrapper.css({
|
|
"position": "absolute",
|
|
"z-index": 999999999,
|
|
"right": "16px",
|
|
"bottom": 0,
|
|
"width": "300px",
|
|
"height": "300px",
|
|
"align": "left",
|
|
"left": "auto",
|
|
"top": "auto"
|
|
});
|
|
logWindowElement.empty();
|
|
|
|
$("#ui-id-1").empty().append("<select id=choosefarmduration><option value=300>5min</option><option value=1200>20min</option><option value=5400>90min</option><option value=14400>4h</option></select>");
|
|
var choose = $("#choosefarmduration")[0];
|
|
choose.onchange = function() {
|
|
farmDuration = this.value;
|
|
log("Duration changed to: " + farmDuration);
|
|
}
|
|
|
|
function log(xText) {
|
|
var date = new Date(); // Timestamp to prepend
|
|
var timestamp = new Date(date.getTime() - (date.getTimezoneOffset() * 60000)).toJSON();
|
|
logWindowElement.append('<span title="' + timestamp +'">' + xText + "</span><br />");
|
|
logWindowElement.scrollTop(logWindowElement[0].scrollHeight);
|
|
}
|
|
|
|
function rand(min, max) {
|
|
return Math.floor((Math.random() * (max-min) * 1000) + min * 1000);
|
|
}
|
|
|
|
function rand(max) {
|
|
return Math.floor((Math.random() * max * 1000));
|
|
}
|
|
|
|
setTimeout(getWaresTick, 5000);
|
|
function getWaresTick(xFarmId) {
|
|
return function() {
|
|
var timeout = 60000;
|
|
try {
|
|
var amounts = $.map($(".indicator .amount"),function(v){return $(v).text()}).join(", ");
|
|
if(amounts != lastAmounts) {
|
|
log(amounts);
|
|
lastAmounts = amounts;
|
|
}
|
|
|
|
var windowId = windows[xFarmId];
|
|
if(windowId == undefined){
|
|
var wnd = GPWindowMgr.Create(
|
|
GPWindowMgr.TYPE_FARM_TOWN, '',
|
|
{'action': "claim_info"},
|
|
xFarmId);
|
|
windows[xFarmId] = wnd.getID();
|
|
timeout = 500;
|
|
return;
|
|
}
|
|
|
|
var wnd = GPWindowMgr.getWindowById(windowId);
|
|
if(wnd == undefined){
|
|
windows[xFarmId] = undefined;
|
|
timeout = rand(20);
|
|
return;
|
|
}
|
|
|
|
var wndElement = wnd.getElement();
|
|
if(wndElement == undefined){
|
|
windows[xFarmId] = undefined;
|
|
try {
|
|
wnd.close();
|
|
} catch(e) {
|
|
}
|
|
timeout = rand(20);
|
|
return;
|
|
}
|
|
|
|
var mood = parseFloat($(wndElement).find('#mood1').siblings().last().text());
|
|
var ts = $(wndElement).find(".farm_next_claim_time").text();
|
|
if(ts != "bereit") {
|
|
var minutes = ts.substring(2,4);
|
|
var seconds = minutes * 60 + ts.substring(5,7) * 1;
|
|
|
|
log("Wait " + ts + " for Farm " + xFarmId);
|
|
wnd.close();
|
|
|
|
timeout = seconds * 1000 + 1000;
|
|
return;
|
|
}
|
|
|
|
var loots = $(wndElement).find("#farmtown_loot").children().last().text().split('/');
|
|
var loot_current = parseFloat(loots[0]);
|
|
var loot_maximum = parseFloat(loots[1]);
|
|
var count_per_loot = parseFloat($(wndElement).find(".farm_claim_res0").text());
|
|
if(loot_current + count_per_loot*3 > loot_maximum) {
|
|
log("Wait 15:00 for Farm " + xFarmId + " to reset");
|
|
wnd.close();
|
|
|
|
timeout = 15 * 60 * 1000;
|
|
return;
|
|
}
|
|
|
|
getWaresFromFarm(wnd, mood, xFarmId);
|
|
} finally {
|
|
setTimeout(getWaresTick(xFarmId), timeout);
|
|
}
|
|
}
|
|
}
|
|
|
|
function getWaresFromFarm(xWindow, xMood, xFarmId) {
|
|
if(xMood - 6 > 80) {
|
|
log("Plündere " + xFarmId + " @ Mood: " + xMood);
|
|
xWindow.call('claimLoad', xFarmId.toString(), 'double', 300);
|
|
} else {
|
|
log("Fordere " + xFarmId + " @ Mood: " + xMood);
|
|
xWindow.call('claimLoad', xFarmId.toString(), 'normal', farmDuration);
|
|
}
|
|
}
|
|
|
|
function buttonIsInitialized() {
|
|
return typeof(btn) != "undefined" && btn != null && btn[0] != null;
|
|
}
|
|
})() |