Advertisement
Guest User

Untitled

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