Advertisement
Guest User

Untitled

a guest
Dec 12th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.23 KB | None | 0 0
  1. // ==UserScript==
  2. // @name FARM C COM DISTANCIA MAXIMA "FREE"
  3. // @author Freekiller
  4. // @description Farms automatically with loot assistant
  5. // @version 1.2.3.8
  6. // @require https://code.jquery.com/jquery-3.2.1.min.js
  7. // @include https://*/game.php?village=*&screen=am_farm*
  8. // ==/UserScript==
  9.  
  10. // Set maximum farm distance
  11. window.maxDistance = 35; // Change this value to set maximum farm distance for A
  12. window.maxDistanceBC = 35; // Change this value to set maximum farm distance for B and C
  13.  
  14. var refreshPage = 1; //
  15. var speed = 350; //
  16. var x = 0; //
  17. var myVar = ""; //
  18. var removeAttacks = 0; //
  19. var menu = $('#am_widget_Farm a.farm_icon_c'); // Use farm button C to farm
  20. var switchVillSpeed = 1; //
  21.  
  22. // Create arrays to store units in farm button A and B and units present in village
  23. var butA = [];
  24. var butB = [];
  25. var unitInVill = [];
  26.  
  27. // Put units in button A into array
  28. for(var i = 0;i < 9;i++){
  29. butA[i] = parseInt($("#content_value").children().eq(2).children().eq(1).children().children().children().children().eq(1).children().eq(i).children().val());
  30. }
  31. // Put units in button A into array
  32. for(var i = 0;i < 9;i++){
  33. butB[i] = parseInt($("#content_value").children().eq(2).children().eq(1).children().eq(1).children().children().children().eq(1).children().eq(i).children().val());
  34. }
  35.  
  36. // Put units present in village into array
  37. unitInVill[0] = parseInt($("#spear").text()); // Get the number of spear units present in village
  38. unitInVill[1] = parseInt($("#sword").text()); // Get the number of sword units present in village
  39. unitInVill[2] = parseInt($("#axe").text()); // Get the number of axe units present in village
  40. unitInVill[3] = parseInt($("#archer").text()); // Get the number of archer units present in village
  41. unitInVill[4] = parseInt($("#spy").text()); // Get the number of spy units present in village
  42. unitInVill[5] = parseInt($("#light").text()); // Get the number of light units present in village
  43. unitInVill[6] = parseInt($("#marcher").text()); // Get the number of marcher units present in village
  44. unitInVill[7] = parseInt($("#heavy").text()); // Get the number of heavy units present in village
  45. unitInVill[8] = parseInt($("#knight").text()); // Get the number of knight units present in village
  46.  
  47. var butABoo = 35; // This will be used later to set the maximum distance and which button to farm with
  48. var butBBoo = 35; // This will be used later to set the maximum distance and which button to farm with
  49. var butCBoo = 35; // This will be used later to set the maximum distance and which button to farm with
  50.  
  51. if (removeAttacks == 1) {
  52. $('img').each(function() {
  53. var tempStr = $(this).attr('src');
  54. if (tempStr.indexOf('attack') !== -1) {
  55. $(this).addClass('tooltip')
  56. }
  57. });
  58. }
  59.  
  60. if (refreshPage == 1) {
  61. setInterval(function() {
  62. window.location.reload();
  63. }, 10000);
  64. }
  65.  
  66. // Sets the time how long it takes to switch villages
  67. if (switchVillSpeed == "1") {
  68. var switchVillSpeed = random(2000, 4000); //
  69. } else {
  70. var switchVillSpeed = parseInt(switchVillSpeed) + parseInt(random(82353, 35356));
  71. }
  72. 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){
  73. switchVillSpeed = random(1000, 1500); // Switch village after 200-400ms if there aren't many units in the village left.
  74. }
  75. console.log("Wait " + switchVillSpeed + " milliseconds to switch villages.");
  76.  
  77. function random(maximum, minimum) {
  78. numPossibilities = maximum - minimum
  79. aleat = Math.random() * numPossibilities
  80. return Math.round(parseInt(minimum) + aleat)
  81. }
  82.  
  83. // 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
  84. 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]){
  85. butABoo = 0;
  86. } else {
  87. butABoo = 0;
  88. }
  89. // 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
  90. 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]){
  91. butBBoo = 0;
  92. } else {
  93. butBBoo = 0;
  94. }
  95.  
  96. // If butABoo was set to 1/true in the if-statement above, button A will be chosen to execute the farm script.
  97. if(butABoo){
  98. menu = $('#am_widget_Farm a.farm_icon_c'); // Choose button A to farm with
  99. } else if(butBBoo){
  100. menu = $('#am_widget_Farm a.farm_icon_c'); // Choose button B to farm with
  101. window.maxDistance = window.maxDistanceBC; // Change maximum distance because there are swordmen in button B and they are much slower than lcav.
  102. } else {
  103. menu = $('#am_widget_Farm a.farm_icon_c'); // Choose button C to farm with
  104. window.maxDistance = window.maxDistanceBC; // Change maximum distance because there are swordmen in button C and they are much slower than lcav.
  105. }
  106.  
  107. // The actual script to launch the attacks.
  108. var distance = 0; // Instantiate distance. It will record the distance from the village to the first barbarian village in the farm assistant.
  109. for (i = 0; i < 100; i++) {
  110. distance = parseInt($("#plunder_list").children().children().eq(2 + i).children().eq(7).text()); // Get the distance to the barb villa
  111. 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.
  112. $(menu).eq(i).each(function() {
  113. if (!($(this).parent().parent().find('img.tooltip').length)) {
  114. var speedNow = (speed * ++x) - random(250, 400);
  115. setTimeout(function(myVar) {
  116. $(myVar).click();
  117. }, speedNow, this);
  118. }
  119. })
  120. }
  121. }
  122.  
  123. // Function to switch villages
  124. function switchVillage() {
  125. $('.arrowRight').click();
  126. $('.groupRight').click();
  127. }
  128. setInterval(switchVillage, switchVillSpeed);
  129. console.log("Changed by FunnyPocketBook");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement