Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name FARM C COM DISTANCIA MAXIMA "FREE"
- // @author Freekiller
- // @description Farms automatically with loot assistant
- // @version 1.2.3.8
- // @require https://code.jquery.com/jquery-3.2.1.min.js
- // @include https://*/game.php?village=*&screen=am_farm*
- // ==/UserScript==
- // Set maximum farm distance
- window.maxDistance = 35; // Change this value to set maximum farm distance for A
- window.maxDistanceBC = 35; // Change this value to set maximum farm distance for B and C
- var refreshPage = 1; //
- var speed = 350; //
- var x = 0; //
- var myVar = ""; //
- var removeAttacks = 0; //
- var menu = $('#am_widget_Farm a.farm_icon_c'); // Use farm button C to farm
- var switchVillSpeed = 1; //
- // Create arrays to store units in farm button A and B and units present in village
- var butA = [];
- var butB = [];
- var unitInVill = [];
- // Put units in button A into array
- for(var i = 0;i < 9;i++){
- butA[i] = parseInt($("#content_value").children().eq(2).children().eq(1).children().children().children().children().eq(1).children().eq(i).children().val());
- }
- // Put units in button A into array
- for(var i = 0;i < 9;i++){
- butB[i] = parseInt($("#content_value").children().eq(2).children().eq(1).children().eq(1).children().children().children().eq(1).children().eq(i).children().val());
- }
- // Put units present in village into array
- unitInVill[0] = parseInt($("#spear").text()); // Get the number of spear units present in village
- unitInVill[1] = parseInt($("#sword").text()); // Get the number of sword units present in village
- unitInVill[2] = parseInt($("#axe").text()); // Get the number of axe units present in village
- unitInVill[3] = parseInt($("#archer").text()); // Get the number of archer units present in village
- unitInVill[4] = parseInt($("#spy").text()); // Get the number of spy units present in village
- unitInVill[5] = parseInt($("#light").text()); // Get the number of light units present in village
- unitInVill[6] = parseInt($("#marcher").text()); // Get the number of marcher units present in village
- unitInVill[7] = parseInt($("#heavy").text()); // Get the number of heavy units present in village
- unitInVill[8] = parseInt($("#knight").text()); // Get the number of knight units present in village
- var butABoo = 35; // This will be used later to set the maximum distance and which button to farm with
- var butBBoo = 35; // This will be used later to set the maximum distance and which button to farm with
- var butCBoo = 35; // This will be used later to set the maximum distance and which button to farm with
- if (removeAttacks == 1) {
- $('img').each(function() {
- var tempStr = $(this).attr('src');
- if (tempStr.indexOf('attack') !== -1) {
- $(this).addClass('tooltip')
- }
- });
- }
- if (refreshPage == 1) {
- setInterval(function() {
- window.location.reload();
- }, 10000);
- }
- // Sets the time how long it takes to switch villages
- if (switchVillSpeed == "1") {
- var switchVillSpeed = random(2000, 4000); //
- } else {
- var switchVillSpeed = parseInt(switchVillSpeed) + parseInt(random(82353, 35356));
- }
- if(unitInVill[0] < 7 && unitInVill[1] < 7 && unitInVill[2] < 7 && unitInVill[3] < 7 && unitInVill[5] < 7 && unitInVill[6] < 7 && unitInVill[7] < 7 && unitInVill[8] < 7){
- switchVillSpeed = random(1000, 1500); // Switch village after 200-400ms if there aren't many units in the village left.
- }
- console.log("Wait " + switchVillSpeed + " milliseconds to switch villages.");
- function random(maximum, minimum) {
- numPossibilities = maximum - minimum
- aleat = Math.random() * numPossibilities
- return Math.round(parseInt(minimum) + aleat)
- }
- // If any any of the units in the village that are present are fewer than button A requires, butABoo will be set to false, meaning there aren't enough units in the village to send an attack with button A
- if(unitInVill[0] < butA[0] || unitInVill[1] < butA[1] || unitInVill[2] < butA[2] || unitInVill[3] < butA[3] || unitInVill[4] < butA[4] || unitInVill[5] < butA[5] || unitInVill[6] < butA[6] || unitInVill[7] < butA[7] || unitInVill[8] < butA[8]){
- butABoo = 0;
- } else {
- butABoo = 0;
- }
- // If any any of the units in the village that are present are fewer than button B requires, butABoo will be set to false, meaning there aren't enough units in the village to send an attack with button B
- if(unitInVill[0] < butB[0] || unitInVill[1] < butB[1] || unitInVill[2] < butB[2] || unitInVill[3] < butB[3] || unitInVill[4] < butB[4] || unitInVill[5] < butB[5] || unitInVill[6] < butB[6] || unitInVill[7] < butB[7] || unitInVill[8] < butB[8]){
- butBBoo = 0;
- } else {
- butBBoo = 0;
- }
- // If butABoo was set to 1/true in the if-statement above, button A will be chosen to execute the farm script.
- if(butABoo){
- menu = $('#am_widget_Farm a.farm_icon_c'); // Choose button A to farm with
- } else if(butBBoo){
- menu = $('#am_widget_Farm a.farm_icon_c'); // Choose button B to farm with
- window.maxDistance = window.maxDistanceBC; // Change maximum distance because there are swordmen in button B and they are much slower than lcav.
- } else {
- menu = $('#am_widget_Farm a.farm_icon_c'); // Choose button C to farm with
- window.maxDistance = window.maxDistanceBC; // Change maximum distance because there are swordmen in button C and they are much slower than lcav.
- }
- // The actual script to launch the attacks.
- var distance = 0; // Instantiate distance. It will record the distance from the village to the first barbarian village in the farm assistant.
- for (i = 0; i < 100; i++) {
- distance = parseInt($("#plunder_list").children().children().eq(2 + i).children().eq(7).text()); // Get the distance to the barb villa
- if (distance <= window.maxDistance) { // It will only launch the attacks that are within window.maxDistance fields. This can be changed at the beginning of the code, default is at 20 fields, though that only applies to button A.
- $(menu).eq(i).each(function() {
- if (!($(this).parent().parent().find('img.tooltip').length)) {
- var speedNow = (speed * ++x) - random(250, 400);
- setTimeout(function(myVar) {
- $(myVar).click();
- }, speedNow, this);
- }
- })
- }
- }
- // Function to switch villages
- function switchVillage() {
- $('.arrowRight').click();
- $('.groupRight').click();
- }
- setInterval(switchVillage, switchVillSpeed);
- console.log("Changed by FunnyPocketBook");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement