Slawer

GT Part 2

Sep 7th, 2019
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var doc = document;
  2. if (window.frames.length > 0 && window.main != null) doc = window.main.document;
  3. var url = doc.URL;
  4. if (url.indexOf('screen=place&mode=scavenge') == -1) window.location.assign("/game.php?screen=place&mode=scavenge");
  5.  
  6. var spears = document.getElementsByClassName("units-entry-all")[0].innerHTML;
  7. spears = spears.substr(1, spears.length - 2);
  8. spears = Math.max(spears - lance,0);
  9.  
  10. var swords = document.getElementsByClassName("units-entry-all")[1].innerHTML;
  11. swords = swords.substr(1, swords.length - 2);
  12. swords = Math.max(swords - epee,0);
  13.  
  14. var axes = document.getElementsByClassName("units-entry-all")[2].innerHTML;
  15. axes = axes.substr(1, axes.length - 2);
  16. axes = Math.max(axes - hache,0);
  17.  
  18. var archers = document.getElementsByClassName("units-entry-all")[3].innerHTML;
  19. archers = archers.substr(1, archers.length - 2);
  20. archers = Math.max(archers - archer,0);
  21.  
  22. var lightC = document.getElementsByClassName("units-entry-all")[4].innerHTML;
  23. lightC = lightC.substr(1, lightC.length - 2);
  24. lightC = Math.max(lightC - leger,0);
  25.  
  26. var mArchers = document.getElementsByClassName("units-entry-all")[5].innerHTML;
  27. mArchers = mArchers.substr(1, mArchers.length - 2);
  28. mArchers = Math.max(mArchers - marcher,0);
  29.  
  30. var heavyC = document.getElementsByClassName("units-entry-all")[6].innerHTML;
  31. heavyC = heavyC.substr(1, heavyC.length - 2);
  32. heavyC = Math.max(heavyC - lourd,0);
  33.  
  34.  
  35. var scavengeOptions;
  36.  
  37.  
  38.  
  39. scavengeOptions = {
  40.     'Collecte massive': [{
  41.             type: 'spear',
  42.             count: spears * (1 / 13)
  43.         },
  44.         {
  45.             type: 'sword',
  46.             count: swords * (1 / 13)
  47.         },
  48.         {
  49.             type: 'axe',
  50.             count: axes * (1 / 13)
  51.         },
  52.         {
  53.             type: 'archer',
  54.             count: archers * (1 / 13)
  55.         },
  56.         {
  57.             type: 'light',
  58.             count: lightC * (1 / 13)
  59.         },
  60.         {
  61.             type: 'marcher',
  62.             count: mArchers * (1 / 13)
  63.         },
  64.         {
  65.             type: 'heavy',
  66.             count: heavyC * (1 / 13)
  67.         },
  68.     ],
  69.     'Grosse collecte': [{
  70.             type: 'spear',
  71.             count: spears / (12 / 13) * (3 / 26)
  72.         },
  73.         {
  74.             type: 'sword',
  75.             count: swords / (12 / 13) * (3 / 26)
  76.         },
  77.         {
  78.             type: 'axe',
  79.             count: axes / (12 / 13) * (3 / 26)
  80.         },
  81.         {
  82.             type: 'light',
  83.             count: lightC / (12 / 13) * (3 / 26)
  84.         },
  85.         {
  86.             type: 'archer',
  87.             count: archers / (12 / 13) * (3 / 26)
  88.         },
  89.         {
  90.             type: 'marcher',
  91.             count: mArchers / (12 / 13) * (3 / 26)
  92.         },
  93.         {
  94.             type: 'heavy',
  95.             count: heavyC / (12 / 13) * (3 / 26)
  96.         },
  97.     ],
  98.     'Collecte moyenne': [{
  99.             type: 'spear',
  100.             count: spears / (21 / 26) * (3 / 13)
  101.         },
  102.         {
  103.             type: 'sword',
  104.             count: swords / (21 / 26) * (3 / 13)
  105.         },
  106.         {
  107.             type: 'axe',
  108.             count: axes / (21 / 26) * (3 / 13)
  109.         },
  110.         {
  111.             type: 'archer',
  112.             count: archers / (21 / 26) * (3 / 13)
  113.         },
  114.         {
  115.             type: 'marcher',
  116.             count: mArchers / (21 / 26) * (3 / 13)
  117.         },
  118.         {
  119.             type: 'light',
  120.             count: lightC / (21 / 26) * (3 / 13)
  121.         },
  122.         {
  123.             type: 'heavy',
  124.             count: heavyC / (21 / 26) * (3 / 13)
  125.         },
  126.     ],
  127.     'Petite collecte': [{
  128.             type: 'spear',
  129.             count: spears
  130.         },
  131.         {
  132.             type: 'sword',
  133.             count: swords
  134.         },
  135.         {
  136.             type: 'axe',
  137.             count: axes
  138.         },
  139.         {
  140.             type: 'archer',
  141.             count: archers
  142.         },
  143.         {
  144.             type: 'marcher',
  145.             count: mArchers
  146.         },
  147.         {
  148.             type: 'light',
  149.             count: lightC
  150.         },
  151.         {
  152.             type: 'heavy',
  153.             count: heavyC
  154.         },
  155.     ],
  156. };
  157.  
  158.  
  159. var unitsCapacity = {
  160.     'spear': 25,
  161.     'sword': 15,
  162.     'archer': 10,
  163.     'axe': 10,
  164.     'light': 80,
  165.     'heavy': 50,
  166.     'marcher': 50,
  167.     'knight': 100
  168. }
  169.  
  170. run();
  171.  
  172.  
  173. function run() {
  174.     let btn = null;
  175.     for (var option in scavengeOptions) {
  176.         btn = findNextButton(option);
  177.  
  178.         if (btn) {
  179.             fillInTroops(option, getAvailableUnits(), btn);
  180.             break;
  181.         }
  182.     }
  183.  
  184. }
  185.  
  186. function fillInTroops(option, availableUnits, button) {
  187.     scavengeOptions[option].forEach(units => {
  188.         var type = units.type;
  189.         var count = units.count;
  190.         let requiredCapacity = availableUnits[type] < count ? availableUnits[type] : count;
  191.  
  192.         $(`input.unitsInput[name='${type}']`).val(requiredCapacity).trigger("change");
  193.         $(button).focus();
  194.     });
  195. }
  196.  
  197. function findNextButton(option) {
  198.     let btn = $(`.scavenge-option:contains("${option}")`).find('a:contains("Lancer")');
  199.     if (btn.length > 0 && !$(btn).hasClass('btn-disabled')) return btn;
  200. }
  201.  
  202. function getAvailableUnits() {
  203.     let availableUnits = {};
  204.  
  205.     $('.units-entry-all').each((i, e) => {
  206.         var unitName = $(e).attr("data-unit");
  207.         if(unitName != "knight") {
  208.             var count = $(e).text().replace(/[()]/, '');
  209.             availableUnits[unitName] = parseInt(count);
  210.         }
  211.     });
  212.  
  213.     return availableUnits;
  214. }
Add Comment
Please, Sign In to add comment