Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Farmbotty_ae
- // @namespace Tribalwars
- // @description Farm from the Farm-Assistant
- // @version 2.3
- // @author Bassem
- // @copyright (C) 2014 Bassem
- // @grant GM_log
- // @grant GM_getValue
- // @grant GM_setValue
- // @grant GM_deleteValue
- // @include http://ae*.tribalwars.ae/game.php?*screen=am_farm*
- // ==/UserScript==
- (function() {'use strict';
- if (!(/http:\/\/(\w{2,3}\d+|hp|www)\./).test(location.href)) {
- return;
- }
- document.addEventListener('DOMContentLoaded', ready, false);
- })();
- function ready() {'use strict';
- /* Variables to modify */
- /*========= Wall Level =============*/
- var wall = 15;
- /*== the number of the page the script will stop at ====*/
- var page = 3;
- /*===== activate\deactivate resources function =====*/
- /* false or true */
- var initResFunc = true;
- /*===== hide\show Low Resource Rows =====*/
- /* false or true */
- var hideLowResRows = true;
- /*===== the minimum amount of resources =====*/
- var minResValue = 1000;
- /*===== Hide/show Attacks =====*/
- /* false or true */
- var hide_attacks = true;
- /*===== skip/reattack already attacked villages =====*/
- /* false or true */
- var fa_skipAttackedVillages = true;
- /*===== the maximum distance to send units =====*/
- var distance = 42;
- var nullFunction = function() {
- };
- var doc = document;
- var win = unsafeWindow || window;
- var texts, game_data, screen;
- var jQuery = win.jQuery;
- var image_base = win.image_base;
- /*===== for catching the spys number =====*/
- var spys, distanceFar, lc;
- /*=============================================*/
- /* >>>>> Function for storage & get/set values to localstorage >>>>>>>*/
- var lib = (function($) {
- // Hypix's storage-class; thanks for providing!
- var prefix = 'dsfbot', debug, storage, getGameData, alert, success, error, fireEvent, server, lang, world, worldString, hasPA;
- debug = (function() {
- function dumpPHP(obj, lnbr) {
- var lineEnd = lnbr ? '\n' : '', ret = typeof (obj) + ' ' + obj + ( lnbr ? '\n' : '');
- if ( typeof (obj) == 'number') {
- ret = 'Number(' + obj + ')' + lineEnd;
- } else if ( typeof (obj) == 'string') {
- ret = 'String(' + obj.length + ') "' + obj + '"' + lineEnd;
- } else if (is_array(obj)) {
- ret = 'array(' + obj.length + ') { ' + lineEnd;
- } else if ( typeof (obj) == 'object') {
- ret = 'object { ' + lineEnd;
- }
- if ( typeof (obj) == 'object') {
- for (var key in obj) {
- ret += '[' + ( typeof (key) == 'string' ? '"' : '') + key + ( typeof (key) == 'string' ? '"' : '') + '] => ' + dumpPHP(obj[key], lnbr) + ( lnbr ? '' : ' ');
- }
- ret += '}' + lineEnd;
- }
- return ret;
- }
- function dumpStr(obj, tabs) {
- var str;
- if (!tabs) {
- tabs = '';
- str = '\nDumpObj:\n{';
- } else {
- str = '\n' + tabs + '{';
- }
- var ntabs = tabs + '\t';
- for (var key in obj) {
- if ( typeof (obj[key]) == 'object') {
- str += '\n' + ntabs + key + ':';
- str += dumpStr(obj[key], ntabs);
- } else if ( typeof (obj[key]) != 'function') {
- if ( typeof (obj[key]) == 'string') {
- str += '\n' + ntabs + key + ': "' + obj[key] + '"';
- } else {
- str += '\n' + ntabs + key + ': ' + obj[key];
- }
- }
- }
- str += '\n' + tabs + '}';
- return str;
- }
- // public methods
- function log() {
- /* jshint boss:true */
- for (var i = 0, msg; ( msg = arguments[i]) !== undefined; i++) {
- if ( typeof (console) != 'undefined') {
- console.log(msg);
- } else if ( typeof (GM_log) != 'undefined')
- /* jshint newcap:false */
- {
- GM_log(msg);
- } else if ( typeof (opera) != 'undefined') {
- opera.postError(msg);
- }
- }
- }
- function dumpObj(obj) {
- var str = dumpStr(obj);
- log(str);
- return str;
- }
- function dumpVar(obj, lnbr) {
- log(dumpPHP(obj, lnbr));
- }
- return {
- log : log,
- dumpObj : dumpObj,
- dumpVar : dumpVar
- };
- })();
- storage = (function(prefix) {
- var gm = typeof (unsafeWindow) != 'undefined' && navigator.userAgent.indexOf('Firefox') > -1, ls = false, intGetValue, intSetValue, intDeleteValue;
- try {
- ls = typeof (win.localStorage) != 'undefined';
- } catch(e) {
- debug.log(e.message);
- }
- if (gm) {
- prefix = prefix + '_' + document.location.host.split('.')[0];
- intSetValue = function(key, value) {
- /* jshint newcap:false */
- GM_setValue(prefix + '_' + key, value);
- };
- intGetValue = function(key, defaultValue) {
- /* jshint newcap:false */
- return GM_getValue(prefix + '_' + key, defaultValue);
- };
- intDeleteValue = function(key) {
- /* jshint newcap:false */
- GM_deleteValue(prefix + '_' + key);
- };
- } else if (ls) {
- intSetValue = function(key, value) {
- localStorage.setItem(prefix + '_' + key, value);
- };
- intGetValue = function(key, defaultValue) {
- var value = localStorage.getItem(prefix + '_' + key);
- if (value) {
- return value;
- } else {
- return defaultValue;
- }
- };
- intDeleteValue = function(key) {
- localStorage.removeItem(prefix + '_' + key);
- };
- } else {
- throw new Error('No suitable storage capability found!');
- }
- function setValue(key, value) {
- switch (typeof(value)) {
- case 'object':
- case 'function':
- intSetValue(key, 'j' + JSON.stringify(value));
- break;
- case 'number':
- intSetValue(key, 'n' + value);
- break;
- case 'boolean':
- intSetValue(key, 'b' + ( value ? 1 : 0));
- break;
- case 'string':
- intSetValue(key, 's' + value);
- break;
- case 'undefined':
- intSetValue(key, 'u');
- break;
- }
- }
- function getValue(key, defaultValue) {
- var str = intGetValue(key);
- if ( typeof (str) != 'undefined') {
- switch (str[0]) {
- case 'j':
- try {
- return JSON.parse(str.substring(1));
- } catch(e) {
- alert(key + ': ' + texts.gui.valueError);
- }
- return defaultValue;
- case 'n':
- return parseFloat(str.substring(1));
- case 'b':
- return str[1] == '1';
- case 's':
- return str.substring(1);
- default:
- intDeleteValue(key);
- }
- }
- return defaultValue;
- }
- function deleteValue(key) {
- intDeleteValue(key);
- }
- function getString(key) {
- return intGetValue(key);
- }
- function setString(key, value) {
- intSetValue(key, value);
- }
- return {
- setValue : setValue,
- getValue : getValue,
- deleteValue : deleteValue,
- getString : getString,
- setString : setString
- };
- })(prefix);
- function getGameData() {
- var game_data = win.game_data || null;
- if (!game_data && document && document.body) {
- var script = document.body.appendChild(document.createElement('script'));
- script.type = 'application/javascript';
- script.textContent = 'var input=document.body.appendChild(document.createElement("input"));' + 'input.type="hidden";' + 'input.value=JSON.stringify(game_data);' + 'input.id="game_data";';
- var input = document.getElementById('game_data');
- if (input) {
- eval('game_data=' + input.value + ';');
- }
- document.body.removeChild(script);
- }
- if (!game_data) {
- throw new Error('No GameData found!');
- }
- return game_data;
- }
- function fireEvent(node, evt) {
- if (node.nodeName.toUpperCase() == 'INPUT' && node.type.toUpperCase() == 'CHECKBOX') {
- node.checked = !node.checked;
- }
- var evObj = document.createEvent('HTMLEvents');
- evObj.initEvent(evt, true, true);
- var ok = node.dispatchEvent(evObj);
- if (ok && node.nodeName == 'A' && node.href) {
- location.href = node.href;
- }
- }
- function alert(message, fadeOutTime, mclass) {
- var script = document.body.appendChild(document.createElement('script'));
- script.type = 'text/javascript';
- if (arguments.length < 2) {
- script.innerHTML = 'jQuery(document).ready(function(){ UI.InfoMessage("' + message + '"); });';
- } else if (arguments.length > 2) {
- script.innerHTML = 'jQuery(document).ready(function(){ UI.InfoMessage("' + message + '",' + fadeOutTime + ',"' + mclass + '"); });';
- }
- }
- function success(message, fadeOutTime, mclass) {
- fadeOutTime = fadeOutTime || 2000;
- mclass = mclass || '';
- alert(message, fadeOutTime, mclass + ' success');
- }
- function error(message, fadeOutTime, mclass) {
- fadeOutTime = fadeOutTime || 2000;
- mclass = mclass || '';
- alert(message, fadeOutTime, mclass + ' error');
- }
- game_data = getGameData();
- hasPA = game_data.player.premium;
- return {
- debug : debug,
- storage : storage,
- alert : alert,
- success : success,
- error : error,
- fireEvent : fireEvent,
- hasPA : hasPA
- };
- })(jQuery), state = lib.storage.getValue('z', 0), startVillage = lib.storage.getValue('s', 0), mOver = false;
- /* >>>>> End >>>>>>>*/
- /*
- * >>>>>>>>>>>>>>>>>>> start of
- *--------------
- * DOM functions
- * --------------
- */
- function __(id) {
- return doc.getElementById(id);
- }
- function _T(context, tagName, num) {
- var sel = [];
- if (context)
- sel = context.getElementsByTagName(tagName);
- return _select(sel, num);
- }
- function _C(context, className, num) {
- var sel = [];
- if (context)
- sel = context.getElementsByClassName(className);
- return _select(sel, num);
- }
- function _TC(context, tagName, className, num) {
- var sel = [];
- if (context)
- sel = context.getElementsByTagName(tagName);
- for (var i = 0, el; el = sel[i]; i++)
- if (!el.classList.contains(className))
- sel = _splice(sel, i--, 1);
- return _select(sel, num);
- }
- function _select(sel, num) {
- if ( typeof (num) == 'number') {
- if (sel.length <= num)
- return null;
- sel = sel[num];
- } else if (num == 'last') {
- if (!sel.length)
- return null;
- sel = sel[sel.length - 1];
- }
- return sel;
- }
- function _splice(els, start, num) {
- if (!els)
- return [];
- var left = [], right = [];
- if (start > 0)
- left = _slice(els, 0, start - 1);
- if (num < els.length - start)
- right = _slice(els, start + num);
- return left.concat(right);
- }
- function _next(el) {
- if (!el)
- return null;
- return el.nextElementSibling;
- }
- function _slice(els, start, end) {
- if (!els)
- return [];
- if ( typeof (end) == 'number')
- return Array.prototype.slice.call(els, start, end);
- return Array.prototype.slice.call(els, start);
- }
- /*
- * Modifier
- */
- function _ce(element, html, options) {
- if ( typeof (html) == 'object') {
- options = html;
- html = null;
- }
- var el = doc.createElement(element);
- // html is not undefined and if it is a string, not empty:
- if (html != undefined && ( typeof (html) != 'string' || html))
- el.innerHTML = html;
- if ( typeof (options) == 'object') {
- for (var key in options)
- el.setAttribute(key, options[key]);
- }
- return el;
- }
- // return: newEl
- function _append(newEl, parent) {
- if (!newEl || !parent)
- return null;
- return parent.appendChild(newEl);
- }
- // return: newEl
- function _before(newEl, beforeEl) {
- if (!newEl || !beforeEl.parentNode)
- return null;
- return beforeEl.parentNode.insertBefore(newEl, beforeEl);
- }
- // return: newEl
- function _after(newEl, afterEl) {
- var nextEl = _next(afterEl);
- if (!nextEl)
- return _append(newEl, afterEl.parentNode);
- return _before(newEl, nextEl);
- }
- /*
- * Sonstiges
- */
- function _show(el) {
- if (!el)
- return null;
- if (el.oldDisplay)
- el.style.display = el.oldDisplay;
- else if (el.tagName == 'DIV' || el.tagName == 'IMG')
- el.style.display = 'block';
- else
- el.style.display = '';
- return el;
- }
- function _hide(el) {
- if (!el)
- return null;
- if (el.style.display == 'none')
- return el;
- el.oldDisplay = el.style.display;
- el.style.display = 'none';
- return el;
- }
- /*
- * >>>>>>>>>>>>>>>>>>> end of
- *--------------
- * DOM functions
- * --------------
- */
- /*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/
- /*
- * >>>>>>>>>>>>>>>>>>> start of
- *--------------
- * Functions
- * --------------
- */
- var regex = {
- // isNaN returns true for floating numbers... this one not:
- NaN : /[^\d]/,
- viewID : /view=(\d+)/,
- ID : /[&\?]id=(\d+)/,
- targetID : /target=(\d+)/,
- captcha : /\/human\.php/,
- villageChangeReplacer : /^.+\/game\.php\?(.*)([\?&]?)village=\d+/,
- coords : /\((\d{1,3}\|\d{1,3})\)/,
- unitKey : /unit\/unit_(.+)\.png/,
- attackImgPath : /command\/attack(_small|_medium|_large)?\.png/,
- attackImg : /<img[^>]*src="[^"]+command\/attack(_small|_medium|_large)?\.png/,
- red_blue : /graphic\/dots\/red_blue.png?/,
- red_yellow : /graphic\/dots\/red_yellow.png?/
- };
- var Style = (function() {
- function add(name) {
- var newStyle = name && __('dsplusStyle_' + name);
- if (!newStyle) {
- newStyle = document.createElement('style');
- newStyle.type = 'text/css';
- if (name)
- newStyle.id = 'dsplusStyle_' + name;
- document.head.appendChild(newStyle);
- }
- function setInnerHTML(css) {
- newStyle.innerHTML = css;
- return newStyle;
- }
- return {
- element : newStyle,
- set : setInnerHTML
- };
- }
- function am_farm() {
- add('am_farm').set('tr.attack > td { background-color: #f0727e !important; }');
- }
- function filter() {
- add('filter').set('#dsplus_filterLink { vertical-align: middle; }');
- }
- return {
- add : add,
- am_farm : am_farm,
- filter : filter
- };
- })();
- var PA_Features = {
- fa_initGUI : function() {
- var am_widget_Farm = __('am_widget_Farm');
- var amFarmTable = _T(am_widget_Farm, 'table', 0);
- if (initResFunc) {
- if (!__('stone_header')) {
- var resourceHeader = _T(amFarmTable, 'th', 5);
- resourceHeader.id = 'wood_header';
- resourceHeader.style.textAlign = 'center';
- var resourceImg = _T(resourceHeader, 'img', 0);
- resourceImg.src = image_base + 'holz.png';
- var stoneHeader = _ce('th', '', {
- 'id' : 'stone_header',
- 'style' : 'text-align: center;'
- });
- var stoneImg = resourceImg.cloneNode(true);
- stoneImg.src = image_base + 'lehm.png';
- stoneHeader.appendChild(stoneImg);
- _after(stoneHeader, resourceHeader);
- var ironHeader = _ce('th', '', {
- 'id' : 'iron_header',
- 'style' : 'text-align: center;'
- });
- var ironImg = resourceImg.cloneNode(true);
- ironImg.src = image_base + 'eisen.png';
- ironHeader.appendChild(ironImg);
- _after(ironHeader, stoneHeader);
- var rows = amFarmTable.rows;
- for (var i = 0, len = rows.length; i < len; i++) {
- var row = rows[i];
- var numTds = _T(row, 'td').length;
- if (numTds > 1) {
- var resTypes = ['wood', 'stone', 'iron'];
- var resTypeIdx = 0;
- var res = {};
- var resClass = {};
- var resAmount = {};
- /*get the wood cells*/
- var resourceCell = row.cells[5];
- //console.log(resourceCell);
- var spans = _T(row.cells[5], 'span');
- //console.log(spans);
- //console.log(resTypeIdx);
- for (var j = 0, span; ( span = spans[j]) && resTypeIdx < 3; j++) {
- //console.log(resTypeIdx);
- if (span.classList.contains('res') || span.classList.contains('warn') || span.classList.contains('warn_90')) {
- var resType = resTypes[resTypeIdx++];
- //console.log(resType);
- /*the amount number of resources*/
- var html = span.innerHTML;
- //console.log(html);
- res[resType] = html;
- //console.log(res[resType]);
- resClass[resType] = span.className;
- //console.log(resClass[resType]);
- var value = parseInt(span.textContent.replace(/\./g, ''), 10);
- //console.log(value);
- resAmount[resType] = value;
- }
- }
- resourceCell.innerHTML = res.wood || '?';
- //console.log(resourceCell.innerHTML);
- resourceCell.className = resClass.wood || 'res';
- resourceCell.style.textAlign = 'right';
- var stoneCell = _ce('td', (res.stone || '?'), {
- 'class' : resClass.stone || 'res',
- 'style' : 'text-align: right;'
- });
- _after(stoneCell, resourceCell);
- var ironCell = _ce('td', (res.iron || '?'), {
- 'class' : resClass.iron || 'res',
- 'style' : 'text-align: right;'
- });
- _after(ironCell, stoneCell);
- if (hideLowResRows) {
- var resSum = resAmount.wood + resAmount.stone + resAmount.iron;
- if (resSum < minResValue)
- _hide(row);
- }
- } else if (numTds > 0) {
- row.cells[0].colSpan += 2;
- }
- }
- }
- }
- PA_Features.fa_hideAttacks();
- Style.am_farm();
- PA_Features.fa_colorAttackedRows();
- PA_Features.fa_addControl();
- },
- fa_addControl : function() {
- var str = '<‡ Start Farmbotty ‡>', color = 'green';
- if (state) {
- str = '<‡ Stop Farmbotty ‡>';
- color = 'red';
- }
- jQuery("div#am_widget_Farm").find('h4').eq(0).append('<a id="farmbotty_start" href="javascript:;" style="float: right; color: ' + color + ';">' + str + '</a>');
- jQuery('#farmbotty_start').get(0).addEventListener('click', function() {
- state = state ? 0 : 1;
- saveState();
- if (state) {
- setStartVill();
- /*
- if (sortByDistance()) {
- return;
- }
- */
- }
- location.reload();
- }, false);
- jQuery('#farmbotty_start').get(0).addEventListener('mouseover', function() {
- mOver = true;
- }, false);
- jQuery('#farmbotty_start').get(0).addEventListener('mouseout', function() {
- mOver = false;
- }, false);
- },
- fa_colorAttackedRows : function() {
- var widget = __('am_widget_Farm');
- var rows = _T(widget, 'tr');
- // var shownRows = 0;
- for (var i = 0, row; row = rows[i]; i++) {
- var classList = row.classList;
- if (classList.contains('row_a') || classList.contains('row_b')) {
- if (regex.attackImgPath.test(row.cells[3].innerHTML)) {
- classList.add('attack');
- }
- }
- }
- },
- fa_hideAttacks : function() {
- var $rows = jQuery('tr.row_a, tr.row_b');
- $rows.each(function() {
- if (hide_attacks && this.cells.length > 3 && regex.attackImg.test(this.cells[3].innerHTML)) {
- _hide(this);
- } else if (!hide_attacks && !this.classList.contains('inactive') && regex.attackImg.test(this.cells[3].innerHTML)) {
- _show(this);
- }
- });
- },
- fa_clickButton : function() {
- if (jQuery('.autoHideBox.error').length) {
- nextVillage();
- return;
- }
- var clicked = false;
- jQuery('div#am_widget_Farm a.farm_icon_c:visible').each(function() {
- spys = parseInt(jQuery('#units_home').find('td[id="spy"]').text().match(/\d+/)[0], 10);
- lc = parseInt(jQuery('#units_home').find('td[id="light"]').text().match(/\d+/)[0], 10);
- var wallHTML = jQuery(this).parents('td').eq(0).prev('td').prev('td').prev('td').prev('td').text();
- var wallTest = parseInt(wallHTML, 10);
- var distanceFar = parseInt(jQuery(this).parents('td').eq(0).prev('td').prev('td').prev('td').text(), 10);
- var reportDotCell = jQuery(this).parents('tr').eq(0).find('td').eq(0).next('td').html();
- if (clicked || spys == 0 || wallTest > wall || wallHTML == '?' || distanceFar > distance || jQuery(this).hasClass('farm_icon_disabled') || regex.red_blue.test(reportDotCell) || regex.red_yellow.test(reportDotCell)) {
- return;
- }
- var attackImg = (regex.attackImg).test(jQuery(this).parents('tr').eq(0).find('td').eq(3).html());
- var runningAttack = attackImg && regex.attackImgPath.test(attackImg.src);
- if (runningAttack && fa_skipAttackedVillages) {
- return;
- }
- this.click();
- jQuery(this).addClass('farm_icon_disabled');
- clicked = true;
- //console.log('Remaning spys in clickButtonC() =' + spys);
- });
- if (clicked) {
- var max = 800;
- if (!Math.floor(Math.random() * 50)) {
- max += Math.floor(Math.random() * 1000);
- }
- setRandom(PA_Features.fa_clickButton, 400, max);
- } else {
- changePage();
- }
- }
- };
- // at Captcha:
- if (jQuery('#bot_check').length || jQuery('#bot_check_error').length || jQuery('#bot_check_image').length || jQuery('#bot_check_form').length || jQuery('#bot_check_code').length || jQuery('#bot_check_submit').length || (/<[Hh]2>\s*Botschutz\s*<\/[Hh]2>/).test(jQuery('body').html()) || (/\/game\.php\?captcha/).test(jQuery('body').html()) || (/&test=sound/).test(location.href)) {
- var sound = function() {
- var vol = 50, audio = new Audio();
- audio.src = 'http://fileface.de/sound/voy-neelix-donotdisturb.ogg';
- audio.volume = vol / 100;
- audio.play();
- };
- window.setInterval(sound, 120000);
- sound();
- return;
- }
- var $tBody = jQuery('#all_village_checkbox').parents('tbody').eq(0);
- function saveState() {
- lib.storage.setValue('z', state);
- }
- function setStartVill() {
- startVillage = game_data.village.id;
- lib.storage.setValue('s', startVillage);
- }
- function setRandom(func, min, max) {
- window.setTimeout(function() {
- function f() {
- if (!mOver) {
- window.clearInterval(fInt);
- func.apply(null);
- }
- }
- if (mOver) {
- var fInt = window.setInterval(f, 100);
- jQuery('body').prepend('<div style="width: ' + jQuery(window).width() + 'px; height: ' + jQuery(window).height() + 'px; position: fixed; top: 0px; left: 0px; z-index: -1; background-color: #002; opacity: 0.5;"></div>');
- } else {
- f();
- }
- }, Math.floor(min + Math.random() * (max - min)));
- }
- function sortByDistance() {
- var $link, i = -3, $ths = $tBody.find('th');
- while (i > -5) {
- $link = $ths.eq(i).find('a');
- if ($link.length) {
- if ($link.attr('href').indexOf('dir=desc') > -1) {
- state = -1;
- saveState();
- }
- $link.get(0).click();
- return true;
- }
- i--;
- }
- return false;
- }
- function nextVillage() {
- state = 4;
- saveState();
- var $link = jQuery('#village_switch_right');
- setRandom(function() {
- $link.get(0).click();
- }, 500, 1000);
- }
- function changePage() {
- var $nextLink = $tBody.children().last().find('strong').next('a');
- var $allLink = $tBody.children().last().find('a');
- var stopChangePage = parseInt($tBody.children().last().find('strong').text().match(/\d+/)[0], 10);
- if ($nextLink.length && stopChangePage < page && spys > 0 && distanceFar < distance && lc !== 0) {
- //console.log('Remaning spys in changePage() =' + spys);
- //console.log('Remaning light in changePage() =' + lc);
- setRandom(function() {
- $nextLink.get(0).click();
- }, 500, 1000);
- } else {
- nextVillage();
- }
- }
- function Go_to_the_first_page() {
- var $nextLink = $tBody.children().last().find('strong').prevAll('a');
- if ($nextLink.length) {
- setRandom(function() {
- $nextLink.last().get(0).click();
- }, 300, 800);
- } else {
- run();
- }
- }
- /*
- * >>>>>>>>>>>>>>>>>>> end of
- *--------------
- * Functions
- * --------------
- */
- /*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/
- /* ===== Excute the Fiunctions =====*/
- /* Checking whether everything is correct */
- //*
- if (game_data.screen != 'am_farm') {
- return;
- }
- if (!lib.hasPA || !game_data.player.farm_manager) {
- lib.error('PA and Farm-Assistent is needed!');
- return;
- }
- PA_Features.fa_initGUI();
- /* >>>>>>>>>>>> main function >>>>>>>>>>>>>>> */
- function run() {
- /*
- if (state == -1) {
- // Sort by distance
- state = 1;
- saveState();
- setRandom(function() {
- sortByDistance();
- }, 300, 700);
- } else
- */
- if (state == 1) {
- // Go to the first page: the Start Village
- state = 2;
- saveState();
- Go_to_the_first_page();
- } else if (state == 2) {
- // the button click C: in the start village
- PA_Features.fa_clickButton();
- } else if (state == 3) {
- // Click the button C, if the start village is not reached yet
- if (game_data.village.id == startVillage) {
- state = 5;
- saveState();
- run();
- } else {
- PA_Features.fa_clickButton();
- }
- } else if (state == 4) {
- // Village change: go to the first page
- state = 3;
- saveState();
- Go_to_the_first_page();
- } else if (state == 5) {
- // once: wait and then start all over again
- state = 1;
- saveState();
- setRandom(function() {
- location.reload();
- }, 10 * 60000, 20 * 60000);
- }
- }
- //*
- if (state) {
- setRandom(function() {
- run();
- }, 10000, 20000);
- }
- //*/
- }
Add Comment
Please, Sign In to add comment