Advertisement
Guest User

Untitled

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