Advertisement
Guest User

Untitled

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