Advertisement
Guest User

Untitled

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