Advertisement
Guest User

Untitled

a guest
Mar 25th, 2019
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 29.24 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Buscas
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description try to take over the world!
  6. // @author You
  7. // @match https://*.tribalwars.com.pt/game.php?village=*&screen=place&mode=scavenge*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. javascript:
  12. //Creators: Sophie "Shinko to Kuma" - Mitchell "Superdog"
  13. /*Update list:
  14. V1.0 - Updated 2/03 - Added automatic grabbing of iables!
  15. V1.1 - Updated 7/03 - Functionality on all servers!
  16. V1.2 - Updated 8/03 - rewrote script to fix some big bugs, condensed code, retiring old version
  17. V1.3 - Updated 9/03 - Adjusted script to work on mobile APP!
  18. */
  19. function scavenge() {
  20.  
  21. //checking correct page
  22. const doc = document;
  23. if (window.frames.length > 0 && window.main != null) doc = window.main.document;
  24.  
  25. if (window.location.href.indexOf('screen=place&mode=scavenge') < 0) {
  26. window.location.assign(game_data.link_base_pure + "place&mode=scavenge");
  27. }
  28. var lackadaisicalLooters = document.getElementsByClassName("title")[0].innerHTML;
  29. var humbleHaulers = document.getElementsByClassName("title")[1].innerHTML;
  30. var cleverCollectors = document.getElementsByClassName("title")[2].innerHTML;
  31. var greatGatherers = document.getElementsByClassName("title")[3].innerHTML;
  32. var scavengeInfo = JSON.parse($('html').find('script:contains("ScavengeScreen")').html().match(/\{.*\:\{.*\:.*\}\}/g)[0]);
  33. var duration_factor = scavengeInfo[1].duration_factor;
  34. var duration_exponent = scavengeInfo[1].duration_exponent;
  35. var duration_initial_seconds = scavengeInfo[1].duration_initial_seconds;
  36. //var loot_factor = scavengeInfo[1].loot_factor
  37.  
  38.  
  39.  
  40.  
  41. function setScavTime() {
  42. //check if duration is preset already
  43. if ("ScavengeTime" in sessionStorage) {
  44. hours = parseInt(sessionStorage.getItem("ScavengeTime"));
  45. } else {
  46. hours = 6;
  47. }
  48. sessionStorage.setItem("ScavengeTime", hours);
  49.  
  50.  
  51. }
  52. setScavTime();
  53.  
  54.  
  55. if ($('button').length == 0) {
  56. //create interface and button
  57. haulCategory = 0;
  58. sessionStorage.setItem("haulCategory", haulCategory);
  59. button = document.createElement("button");
  60. button.classList.add("btn-confirm-yes");
  61. button.innerHTML = "Adjust scavenge time";
  62. button.style.visibility = 'hidden';
  63. body = document.getElementById("scavenge_screen");
  64. body.prepend(button);
  65.  
  66. scavDiv = document.createElement('div');
  67. //check if archer world or not, depending on outcome make table with or without archers
  68. if ($('.units-entry-all[data-unit=archer]').text() != "") {
  69. htmlString = '<div ID= scavTable >\
  70. <table class="scavengeTable" width="15%" style="border: 7px solid rgba(121,0,0,0.71); border-image-slice: 7 7 7 7; border-image-source: url(https://dsen.innogamescdn.com/asset/cf2959e7/graphic/border/frame-gold-red.png);">\
  71. <tbody>\
  72. <tr>\
  73. <th style="text-align:center" colspan="8">Select unittypes to scavenge with</th>\
  74. </tr>\
  75. <tr>\
  76. <th style="text-align:center" width="35"><a href="#" class="unit_link" data-unit="spear"><img src="https://dsen.innogamescdn.com/asset/cf2959e7/graphic/unit/unit_spear.png" title="Spear fighter" alt="" class=""></a></th>\
  77. <th style="text-align:center" width="35"><a href="#" class="unit_link" data-unit="sword"><img src="https://dsen.innogamescdn.com/asset/cf2959e7/graphic/unit/unit_sword.png" title="Swordsman" alt="" class=""></a></th>\
  78. <th style="text-align:center" width="35"><a href="#" class="unit_link" data-unit="axe"><img src="https://dsen.innogamescdn.com/asset/cf2959e7/graphic/unit/unit_axe.png" title="Axeman" alt="" class=""></a></th>\
  79. <th style="text-align:center" width="35"><a href="#" cl ass="unit_link" data-unit="archer"><img src="https://dsen.innogamescdn.com/asset/cf2959e7/graphic/unit/unit_archer.png" title="Archer" alt="" class=""></a></th>\
  80. <th style="text-align:center" width="35"><a href="#" class="unit_link" data-unit="light"><img src="https://dsen.innogamescdn.com/asset/cf2959e7/graphic/unit/unit_light.png" title="Light cavalry" alt="" class=""></a></th>\
  81. <th style="text-align:center" width="35"><a href="#" class="unit_link" data-unit="marcher"><img src="https://dsen.innogamescdn.com/asset/cf2959e7/graphic/unit/unit_marcher.png" title="Mounted Archer" alt="" class=""></a></th>\
  82. <th style="text-align:center" width="35"><a href="#" class="unit_link" data-unit="heavy"><img src="https://dsen.innogamescdn.com/asset/cf2959e7/graphic/unit/unit_heavy.png" title="Heavy cavalry" alt="" class=""></a></th>\
  83. <th style="text-align:center" nowrap>Target runtime</th>\
  84. </tr>\
  85. <tr>\
  86. <td align="center"><input type="checkbox" ID="spear" name="spear" checked = "checked" ></td>\
  87. <td align="center"><input type="checkbox" ID="sword" name="sword" ></td>\
  88. <td align="center"><input type="checkbox" ID="axe" name="axe" ></td>\
  89. <td align="center"><input type="checkbox" ID="archer" name="archer" ></td>\
  90. <td align="center"><input type="checkbox" ID="light" name="light" ></td>\
  91. <td align="center"><input type="checkbox" ID="marcher" name="marcher" ></td>\
  92. <td align="center"><input type="checkbox" ID="heavy" name="heavy" ></td>\
  93. <td ID="runtime" align="center"><input type="text" ID="hours" name="hours" size="4" maxlength="2" align=left > hours</td>\
  94. </tbody>\
  95. </table>\
  96. </br>\
  97. </div>\
  98. ';
  99. } else {
  100. htmlString = '<div ID= scavTable>\
  101. <table class="scavengeTable" width="15%" style="border: 7px solid rgba(121,0,0,0.71); border-image-slice: 7 7 7 7; border-image-source: url(https://dsen.innogamescdn.com/asset/cf2959e7/graphic/border/frame-gold-red.png);">\
  102. <tbody>\
  103. <tr>\
  104. <th style="text-align:center" colspan="6">Select unittypes to scavenge with</th>\
  105. </tr>\
  106. <tr>\
  107. <th style="text-align:center" width="35"><a href="#" class="unit_link" data-unit="spear"><img src="https://dsen.innogamescdn.com/asset/cf2959e7/graphic/unit/unit_spear.png" title="Spear fighter" alt="" class=""></a></th>\
  108. <th style="text-align:center" width="35"><a href="#" class="unit_link" data-unit="sword"><img src="https://dsen.innogamescdn.com/asset/cf2959e7/graphic/unit/unit_sword.png" title="Swordsman" alt="" class=""></a></th>\
  109. <th style="text-align:center" width="35"><a href="#" class="unit_link" data-unit="axe"><img src="https://dsen.innogamescdn.com/asset/cf2959e7/graphic/unit/unit_axe.png" title="Axeman" alt="" class=""></a></th>\
  110. <th style="text-align:center" width="35"><a href="#" class="unit_link" data-unit="light"><img src="https://dsen.innogamescdn.com/asset/cf2959e7/graphic/unit/unit_light.png" title="Light cavalry" alt="" class=""></a></th>\
  111. <th style="text-align:center" width="35"><a href="#" class="unit_link" data-unit="heavy"><img src="https://dsen.innogamescdn.com/asset/cf2959e7/graphic/unit/unit_heavy.png" title="Heavy cavalry" alt="" class=""></a></th>\
  112. <th style="text-align:center" nowrap>Target runtime</th>\
  113. </tr>\
  114. <tr>\
  115. <td align="center"><input type="checkbox" ID="spear" name="spear"></td>\
  116. <td align="center"><input type="checkbox" ID="sword" name="sword" ></td>\
  117. <td align="center"><input type="checkbox" ID="axe" name="axe" ></td>\
  118. <td align="center"><input type="checkbox" ID="light" name="light" ></td>\
  119. <td align="center"><input type="checkbox" ID="heavy" name="heavy" ></td>\
  120. <td ID="runtime" align="center"><input type="text" ID="hours" name="hours" size="4" maxlength="2" align=left > hours</td>\
  121. </tbody>\
  122. </table>\
  123. </br>\
  124. </div>\
  125. ';
  126. }
  127. scavDiv.innerHTML = htmlString;
  128. scavenge_screen.prepend(scavDiv.firstChild);
  129.  
  130. document.getElementById("hours").addEventListener("change", function () {
  131. hours = parseInt(document.getElementById("hours").value);
  132. sessionStorage.setItem("ScavengeTime", hours);
  133. haulCategory=0;
  134. sessionStorage.setItem("haulCategory", haulCategory);
  135. calculateHauls();
  136. clear();
  137. setScavTime();
  138. scavenge();
  139. document.getElementById("hours").focus();
  140. });
  141. }
  142.  
  143. if ($(".scavengeTable")[0]) {
  144. document.getElementById("hours").value = hours;
  145. }
  146.  
  147. checkboxValues = JSON.parse(localStorage.getItem('checkboxValues')) || {}, $checkboxes = $("#scavTable :checkbox");
  148. $checkboxes.on("change", function () {
  149. $checkboxes.each(function () {
  150. checkboxValues[this.id] = this.checked;
  151. });
  152. localStorage.setItem("checkboxValues", JSON.stringify(checkboxValues));
  153. calculateHauls();
  154. haulCategory = 0;
  155. sessionStorage.setItem("haulCategory", haulCategory);
  156. scavenge();
  157. });
  158.  
  159. $.each(checkboxValues, function (key, value) {
  160. $("#" + key).prop('checked', value);
  161. });
  162.  
  163.  
  164. if ($(".scavengeTable").length) {
  165. spears = $('.units-entry-all[data-unit=spear]').text().match(/\((\d+)\)/)[1];
  166. swords = $('.units-entry-all[data-unit=sword]').text().match(/\((\d+)\)/)[1];
  167. axes = $('.units-entry-all[data-unit=axe]').text().match(/\((\d+)\)/)[1];
  168. lightC = $('.units-entry-all[data-unit=light]').text().match(/\((\d+)\)/)[1];
  169. heavyC = $('.units-entry-all[data-unit=heavy]').text().match(/\((\d+)\)/)[1];
  170. if ($('.units-entry-all[data-unit=archer]').text() != "") {
  171. archer = $('.units-entry-all[data-unit=archer]').text().match(/\((\d+)\)/)[1]
  172. } else archer = 0;
  173.  
  174. if ($('.units-entry-all[data-unit=marcher]').text() != "") {
  175. marcher = $('.units-entry-all[data-unit=marcher]').text().match(/\((\d+)\)/)[1]
  176. } else marcher = 0;
  177. checkboxStatus();
  178. }
  179. else {
  180. spears = $('.units-entry-all[data-unit=spear]').text().match(/\((\d+)\)/)[1];
  181. swords = $('.units-entry-all[data-unit=sword]').text().match(/\((\d+)\)/)[1];
  182. axes = $('.units-entry-all[data-unit=axe]').text().match(/\((\d+)\)/)[1];
  183. lightC = $('.units-entry-all[data-unit=light]').text().match(/\((\d+)\)/)[1];
  184. heavyC = $('.units-entry-all[data-unit=heavy]').text().match(/\((\d+)\)/)[1];
  185. if ($('.units-entry-all[data-unit=archer]').text() != "") {
  186. archer = $('.units-entry-all[data-unit=archer]').text().match(/\((\d+)\)/)[1]
  187. } else archer = 0;
  188.  
  189. if ($('.units-entry-all[data-unit=marcher]').text() != "") {
  190. marcher = $('.units-entry-all[data-unit=marcher]').text().match(/\((\d+)\)/)[1]
  191. } else marcher = 0;
  192. }
  193.  
  194. function checkboxStatus() {
  195. if (document.getElementById("spear").checked == false) {
  196. spears = 0;
  197. haulcategory = 0;
  198. }
  199. if (document.getElementById("sword").checked == false) {
  200. swords = 0;
  201. haulcategory = 0;
  202. }
  203. if (document.getElementById("axe").checked == false) {
  204. axes = 0;
  205. haulcategory = 0;
  206. }
  207. if (document.getElementById("light").checked == false) {
  208. lightC = 0;
  209. haulcategory = 0;
  210. }
  211. if (document.getElementById("heavy").checked == false) {
  212. heavyC = 0;
  213. haulcategory = 0;
  214. }
  215. if ($('.units-entry-all[data-unit=archer]').text() != "") {
  216. if (document.getElementById("archer").checked == false) {
  217. archer = 0;
  218. haulcategory = 0;
  219. }
  220. }
  221. if ($('.units-entry-all[data-unit=marcher]').text() != "") {
  222. if (document.getElementById("marcher").checked == false) {
  223. marcher = 0;
  224. haulcategory = 0;
  225. }
  226. }
  227.  
  228. }
  229.  
  230.  
  231. function calculateHauls() {
  232.  
  233. checkboxStatus();
  234.  
  235. totalLoot = spears * 25 + swords * 15 + axes * 10 + lightC * 80 + heavyC * 50 + archer * 10 + marcher * 50;
  236. totalSpSwLoot = spears * 25 + swords * 15;
  237. possibleLoot = spears * 25 + swords * 15 + axes * 10 + lightC * 80 + heavyC * 50 + archer * 10 + marcher * 50;
  238. spearRatio = spears / (spears * 25 + swords * 15);
  239. swordRatio = swords / (spears * 25 + swords * 15);
  240.  
  241. time = hours * 3600;
  242. haul = ((time / duration_factor - duration_initial_seconds) ** (1 / (duration_exponent)) / 100) ** (1 / 2);
  243. haul1 = haul / 0.1;
  244. haul2 = haul / 0.25;
  245. haul3 = haul / 0.5;
  246. haul4 = haul / 0.75;
  247. totalHaul = haul1 + haul2 + haul3 + haul4;
  248.  
  249. }
  250. calculateHauls();
  251.  
  252. if ("haulCategory" in sessionStorage) {
  253. haulCategory = sessionStorage.getItem("haulCategory");
  254. } else {
  255. haulCategory = 0;
  256. sessionStorage.setItem("haulCategory", haulCategory);
  257. }
  258.  
  259.  
  260. if (totalLoot > totalHaul) {
  261. if (totalSpSwLoot > totalHaul) {
  262. if (haulCategory == 0) {
  263. haulCategory = 1;
  264. sessionStorage.setItem("haulCategory", haulCategory);
  265. }
  266. } else {
  267. if (haulCategory == 0) {
  268. haulCategory = 2;
  269. sessionStorage.setItem("haulCategory", haulCategory);
  270. }
  271. }
  272. } else {
  273. if (haulCategory == 0) {
  274. haulCategory = 3;
  275. sessionStorage.setItem("haulCategory", haulCategory);
  276. }
  277. }
  278.  
  279. if (haulCategory == 1) {
  280. scavengeOptions = {};
  281. scavengeOptions[greatGatherers] = [
  282. {
  283. type: 'spear',
  284. count: (haul4 * spearRatio)
  285. },
  286. {
  287. type: 'sword',
  288. count: (haul4 * swordRatio)
  289. },
  290. {
  291. type: 'axe',
  292. count: 0
  293. },
  294. {
  295. type: 'archer',
  296. count: 0
  297. },
  298. {
  299. type: 'light',
  300. count: 0
  301. },
  302. {
  303. type: 'marcher',
  304. count: 0
  305. },
  306. {
  307. type: 'heavy',
  308. count: 0
  309. },
  310. ];
  311. scavengeOptions[cleverCollectors] = [
  312. {
  313. type: 'spear',
  314. count: (haul3 * spearRatio)
  315. },
  316. {
  317. type: 'sword',
  318. count: (haul3 * swordRatio)
  319. },
  320. {
  321. type: 'axe',
  322. count: 0
  323. },
  324. {
  325. type: 'archer',
  326. count: 0
  327. },
  328. {
  329. type: 'light',
  330. count: 0
  331. },
  332. {
  333. type: 'marcher',
  334. count: 0
  335. },
  336. {
  337. type: 'heavy',
  338. count: 0
  339. },
  340. ];
  341. scavengeOptions[humbleHaulers] = [
  342. {
  343. type: 'spear',
  344. count: (haul2 * spearRatio)
  345. },
  346. {
  347. type: 'sword',
  348. count: (haul2 * swordRatio)
  349. },
  350. {
  351. type: 'axe',
  352. count: 0
  353. },
  354. {
  355. type: 'archer',
  356. count: 0
  357. },
  358. {
  359. type: 'light',
  360. count: 0
  361. },
  362. {
  363. type: 'marcher',
  364. count: 0
  365. },
  366. {
  367. type: 'heavy',
  368. count: 0
  369. },
  370. ];
  371. scavengeOptions[lackadaisicalLooters] = [
  372. {
  373. type: 'spear',
  374. count: (haul1 * spearRatio)
  375. },
  376. {
  377. type: 'sword',
  378. count: (haul1 * swordRatio)
  379. },
  380. {
  381. type: 'axe',
  382. count: 0
  383. },
  384. {
  385. type: 'archer',
  386. count: 0
  387. },
  388. {
  389. type: 'light',
  390. count: 0
  391. },
  392. {
  393. type: 'marcher',
  394. count: 0
  395. },
  396. {
  397. type: 'heavy',
  398. count: 0
  399. },
  400. ];
  401.  
  402. } else {
  403. if (haulCategory == 2) {
  404. scavengeOptions = {};
  405. scavengeOptions[greatGatherers] = [
  406. {
  407. type: 'spear',
  408. count: (haul4 * (spears / possibleLoot))
  409. },
  410. {
  411. type: 'sword',
  412. count: (haul4 * (swords / possibleLoot))
  413. },
  414. {
  415. type: 'axe',
  416. count: (haul4 * (axes / possibleLoot))
  417. },
  418. {
  419. type: 'light',
  420. count: (haul4 * (lightC / possibleLoot))
  421. },
  422. {
  423. type: 'heavy',
  424. count: (haul4 * (heavyC / possibleLoot))
  425. },
  426. {
  427. type: 'archer',
  428. count: (haul4 * (archer / possibleLoot))
  429. },
  430. {
  431. type: 'marcher',
  432. count: (haul4 * (marcher / possibleLoot))
  433. },
  434. ];
  435. scavengeOptions[cleverCollectors] = [
  436. {
  437. type: 'spear',
  438. count: (haul3 * (spears / possibleLoot))
  439. },
  440. {
  441. type: 'sword',
  442. count: (haul3 * (swords / possibleLoot))
  443. },
  444. {
  445. type: 'axe',
  446. count: (haul3 * (axes / possibleLoot))
  447. },
  448. {
  449. type: 'light',
  450. count: (haul3 * (lightC / possibleLoot))
  451. },
  452. {
  453. type: 'heavy',
  454. count: (haul3 * (heavyC / possibleLoot))
  455. },
  456. {
  457. type: 'archer',
  458. count: (haul3 * (archer / possibleLoot))
  459. },
  460. {
  461. type: 'marcher',
  462. count: (haul3 * (marcher / possibleLoot))
  463. },
  464. ];
  465. scavengeOptions[humbleHaulers] = [
  466. {
  467. type: 'spear',
  468. count: (haul2 * (spears / possibleLoot))
  469. },
  470. {
  471. type: 'sword',
  472. count: (haul2 * (swords / possibleLoot))
  473. },
  474. {
  475. type: 'axe',
  476. count: (haul2 * (axes / possibleLoot))
  477. },
  478. {
  479. type: 'light',
  480. count: (haul2 * (lightC / possibleLoot))
  481. },
  482. {
  483. type: 'heavy',
  484. count: (haul2 * (heavyC / possibleLoot))
  485. },
  486. {
  487. type: 'archer',
  488. count: (haul2 * (archer / possibleLoot))
  489. },
  490. {
  491. type: 'marcher',
  492. count: (haul2 * (marcher / possibleLoot))
  493. },
  494. ];
  495. scavengeOptions[lackadaisicalLooters] = [
  496. {
  497. type: 'spear',
  498. count: (haul1 * (spears / possibleLoot))
  499. },
  500. {
  501. type: 'sword',
  502. count: (haul1 * (swords / possibleLoot))
  503. },
  504. {
  505. type: 'axe',
  506. count: (haul1 * (axes / possibleLoot))
  507. },
  508. {
  509. type: 'light',
  510. count: (haul1 * (lightC / possibleLoot))
  511. },
  512. {
  513. type: 'heavy',
  514. count: (haul1 * (heavyC / possibleLoot))
  515. },
  516. {
  517. type: 'archer',
  518. count: (haul1 * (archer / possibleLoot))
  519. },
  520. {
  521. type: 'marcher',
  522. count: (haul1 * (marcher / possibleLoot))
  523. },
  524. ];
  525. } else {
  526. if (haulCategory == 3) {
  527. scavengeOptions = {};
  528. scavengeOptions[greatGatherers] = [
  529. {
  530. type: 'spear',
  531. count: ((totalLoot / totalHaul * haul4) * (spears / possibleLoot))
  532. },
  533. {
  534. type: 'sword',
  535. count: ((totalLoot / totalHaul * haul4) * (swords / possibleLoot))
  536. },
  537. {
  538. type: 'axe',
  539. count: ((totalLoot / totalHaul * haul4) * (axes / possibleLoot))
  540. },
  541. {
  542. type: 'light',
  543. count: ((totalLoot / totalHaul * haul4) * (lightC / possibleLoot))
  544. },
  545. {
  546. type: 'heavy',
  547. count: ((totalLoot / totalHaul * haul4) * (heavyC / possibleLoot))
  548. },
  549. {
  550. type: 'archer',
  551. count: ((totalLoot / totalHaul * haul4) * (archer / possibleLoot))
  552. },
  553. {
  554. type: 'marcher',
  555. count: ((totalLoot / totalHaul * haul4) * (marcher / possibleLoot))
  556. },
  557. ];
  558. scavengeOptions[cleverCollectors] = [
  559. {
  560. type: 'spear',
  561. count: ((totalLoot / (totalHaul - haul4) * haul3) * (spears / possibleLoot))
  562. },
  563. {
  564. type: 'sword',
  565. count: ((totalLoot / (totalHaul - haul4) * haul3) * (swords / possibleLoot))
  566. },
  567. {
  568. type: 'axe',
  569. count: ((totalLoot / (totalHaul - haul4) * haul3) * (axes / possibleLoot))
  570. },
  571. {
  572. type: 'light',
  573. count: ((totalLoot / (totalHaul - haul4) * haul3) * (lightC / possibleLoot))
  574. },
  575. {
  576. type: 'heavy',
  577. count: ((totalLoot / (totalHaul - haul4) * haul3) * (heavyC / possibleLoot))
  578. },
  579. {
  580. type: 'archer',
  581. count: ((totalLoot / (totalHaul - haul4) * haul3) * (archer / possibleLoot))
  582. },
  583. {
  584. type: 'marcher',
  585. count: ((totalLoot / (totalHaul - haul4) * haul3) * (marcher / possibleLoot))
  586. },
  587. ];
  588. scavengeOptions[humbleHaulers] = [
  589. {
  590. type: 'spear',
  591. count: ((totalLoot / (totalHaul - haul4 - haul3) * haul2) * (spears / possibleLoot))
  592. },
  593. {
  594. type: 'sword',
  595. count: ((totalLoot / (totalHaul - haul4 - haul3) * haul2) * (swords / possibleLoot))
  596. },
  597. {
  598. type: 'axe',
  599. count: ((totalLoot / (totalHaul - haul4 - haul3) * haul2) * (axes / possibleLoot))
  600. },
  601. {
  602. type: 'light',
  603. count: ((totalLoot / (totalHaul - haul4 - haul3) * haul2) * (lightC / possibleLoot))
  604. },
  605. {
  606. type: 'heavy',
  607. count: ((totalLoot / (totalHaul - haul4 - haul3) * haul2) * (heavyC / possibleLoot))
  608. },
  609. {
  610. type: 'archer',
  611. count: ((totalLoot / (totalHaul - haul4 - haul3) * haul2) * (archer / possibleLoot))
  612. },
  613. {
  614. type: 'marcher',
  615. count: ((totalLoot / (totalHaul - haul4 - haul3) * haul2) * (marcher / possibleLoot))
  616. },
  617. ];
  618. scavengeOptions[lackadaisicalLooters] = [
  619. {
  620. type: 'spear',
  621. count: (totalLoot * (spears / possibleLoot))
  622. },
  623. {
  624. type: 'sword',
  625. count: (totalLoot * (swords / possibleLoot))
  626. },
  627. {
  628. type: 'axe',
  629. count: (totalLoot * (axes / possibleLoot))
  630. },
  631. {
  632. type: 'light',
  633. count: (totalLoot * (lightC / possibleLoot))
  634. },
  635. {
  636. type: 'heavy',
  637. count: (totalLoot * (heavyC / possibleLoot))
  638. },
  639. {
  640. type: 'archer',
  641. count: (totalLoot * (archer / possibleLoot))
  642. },
  643. {
  644. type: 'marcher',
  645. count: (totalLoot * (marcher / possibleLoot))
  646. },
  647. ];
  648. }
  649. }
  650. }
  651.  
  652. run();
  653.  
  654. function run() {
  655. let btn = null;
  656. for (const option in scavengeOptions) {
  657. btn = findNextButton(option);
  658.  
  659. if (btn) {
  660. fillInTroops(option, getAvailableUnits(), btn);
  661. break;
  662. }
  663. }
  664. }
  665.  
  666. function clear() {
  667. let btn = null;
  668. for (const option in scavengeOptions) {
  669. btn = findNextButton(option);
  670. if (btn) {
  671. emptyTroops(option);
  672. break;
  673. }
  674. }
  675. }
  676.  
  677. function fillInTroops(option, availableUnits, button) {
  678. scavengeOptions[option].forEach(units => {
  679. const type = units.type;
  680. const count = units.count;
  681. let requiredCapacity = availableUnits[type] < count ? availableUnits[type] : count;
  682.  
  683. $(`input.unitsInput[name='${type}']`).val(requiredCapacity).trigger("change");
  684. window.setTimeout(function(){
  685. $(button).click();
  686. }, 300);
  687.  
  688. });
  689. }
  690.  
  691. function emptyTroops(option) {
  692. scavengeOptions[option].forEach(units => {
  693. const type = units.type;
  694. $(`input.unitsInput[name='${type}']`).val("").trigger("change");
  695. });
  696. }
  697.  
  698. function findNextButton(option) {
  699. startButtonName=document.getElementsByClassName("btn btn-default free_send_button")[0].innerHTML;
  700. let btn = $(`.scavenge-option:contains("${option}")`).find('a:contains('+startButtonName+')');
  701. if (btn.length > 0 && !$(btn).hasClass('btn-disabled')) return btn;
  702. }
  703.  
  704.  
  705. function getAvailableUnits() {
  706. let availableUnits = {};
  707.  
  708. $('.units-entry-all').each((i, e) => {
  709. const unitName = $(e).attr("data-unit");
  710. const count = $(e).text().replace(/[()]/, '');
  711. availableUnits[unitName] = parseInt(count);
  712. });
  713. return availableUnits;
  714. }
  715.  
  716.  
  717. }
  718.  
  719. scavenge();
  720. function aleatorio(inferior, superior) {
  721. var numPosibilidades = superior - inferior
  722. var aleat = Math.random() * numPosibilidades
  723. return Math.round(parseInt(inferior) + aleat)
  724. }
  725. function altAldeia()
  726. {
  727. $('.arrowRight').click();
  728. $('.groupRight').click();
  729. }
  730. try{
  731. /*window.setTimeout(function(){
  732. scavenge();
  733. }, aleatorio(500,1000));
  734. window.setTimeout(function(){
  735. scavenge();
  736. }, aleatorio(1500,2000));
  737. window.setTimeout(function(){
  738. scavenge();
  739. }, aleatorio(2500,3000));
  740. window.setTimeout(function(){
  741. scavenge();
  742. }, aleatorio(3500,4000));*/
  743. setInterval(scavenge, aleatorio(500,1000));
  744. setInterval(scavenge, aleatorio(1500,2000));
  745. setInterval(scavenge, aleatorio(2500,3000));
  746. setInterval(scavenge, aleatorio(3500,4000));
  747. setInterval(altAldeia, aleatorio(9500,1000));
  748. }catch(err){};
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement