Advertisement
FunnyPocketBook

Untitled

Jun 1st, 2020
859
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let x = 504;
  2. let y = 499;
  3. let spearAmnt = 1;
  4. let swordAmnt = 0;
  5. let axeAmnt = 0;
  6. let archerAmnt = 0;
  7. let spyAmnt = 0;
  8. let lightAmnt = 0;
  9. let marcherAmnt = 0;
  10. let heavyAmnt = 0;
  11. let ramAmnt = 0;
  12. let catapultAmnt = 0;
  13. let knightAmnt = 0;
  14. let snobAmnt = 0;
  15. let catAttack = "main";
  16.  
  17. let iterator = 0;
  18.  
  19. let key;
  20. let value;
  21.  
  22. /**
  23.  * Get the weird obfuscated key and value which is stored in the rally point
  24.  */
  25. function getKey() {
  26.   $.get("game.php?village=" + game_data.village.id + "&screen=place", function(response) {
  27.     const parser = new DOMParser();
  28.     const dom = parser.parseFromString(response, "text/html");
  29.     key = dom.querySelector("#command-data-form > input:nth-child(1)").getAttribute("name");
  30.     value = dom.querySelector("#command-data-form > input:nth-child(1)").value;
  31.   });
  32. }
  33. let data = {
  34.   key: value,
  35.   "template_id": "",
  36.   "source_village": game_data.village.id,
  37.   "spear": spearAmnt,
  38.   "sword": swordAmnt,
  39.   "axe": axeAmnt,
  40.   "archer": archerAmnt,
  41.   "spy": spyAmnt,
  42.   "light": lightAmnt,
  43.   "marcher": marcherAmnt,
  44.   "heavy": heavyAmnt,
  45.   "ram": ramAmnt,
  46.   "catapult": catapultAmnt,
  47.   "knight": knightAmnt,
  48.   "snob": snobAmnt,
  49.   "x": x,
  50.   "y": y,
  51.   "target_type": "coord",
  52.   "input": "",
  53.   "attack": "Attack",
  54. };
  55.  
  56. function random(superior, inferior) {
  57.   var numPosib = superior - inferior;
  58.   var aleat = Math.random() * numPosib;
  59.   return Math.round(parseInt(inferior) + aleat);
  60. }
  61.  
  62. setInterval(attack, random(2330, 3550));
  63.  
  64. /**
  65.  * Send post request to attack dialog
  66.  */
  67. function attack() {
  68.  
  69.   let xvalsint = getCoordsX();
  70.   let yvalsint = getCoordsY();
  71.   x = parseInt(xvalsint[iterator]);
  72.   y = parseInt(yvalsint[iterator]);
  73.   data.x = x;
  74.   data.y = y;
  75.   let url = "game.php?village=" + game_data.village.id + "&screen=place&try=confirm";
  76.   $.post(url, data).done(function(response) {
  77.     const parser = new DOMParser();
  78.     const dom = parser.parseFromString(response, "text/html");
  79.     if (dom.querySelector(".error_box")) {
  80.       console.error("Error: " + dom.querySelector(".error_box").innerText.trim());
  81.     } else {
  82.       const ch = dom.getElementsByName("ch")[0].getAttribute("value");
  83.       const timeout = Math.floor(Math.random() * 1000 + 500);
  84.       setTimeout(function() {
  85.         sendAttack(ch);
  86.       }, timeout);
  87.       console.log("Wait " + timeout + "ms");
  88.     }
  89.   });
  90. }
  91.  
  92. function getCoordsX() {
  93.   var x, y, vill, arr;
  94.   var fin = [];
  95.   var xvals = [];
  96.   var yvals = [];
  97.   for (x = 0; x < TWMap.size[1]; x++) {
  98.     for (y = 0; y < TWMap.size[1]; y++) {
  99.       if (vill = TWMap.map.coordByPixel(TWMap.map.pos[0] + TWMap.tileSize[0] * y, TWMap.map.pos[1] + TWMap.tileSize[1] * x)) {
  100.         if ((arr = TWMap.villages[vill.join("")]) && arr.owner === "0") {
  101.           fin.push(vill.join("|"));
  102.           xvals.push(vill[0]);
  103.           yvals.push(vill[1]);
  104.         }
  105.       }
  106.     }
  107.   }
  108.   return xvals;
  109. }
  110.  
  111. function getCoordsY() {
  112.   var x, y, vill, arr;
  113.   var fin = [];
  114.   var xvals = [];
  115.   var yvals = [];
  116.   for (x = 0; x < TWMap.size[1]; x++) {
  117.     for (y = 0; y < TWMap.size[1]; y++) {
  118.       if (vill = TWMap.map.coordByPixel(TWMap.map.pos[0] + TWMap.tileSize[0] * y, TWMap.map.pos[1] + TWMap.tileSize[1] * x)) {
  119.         if ((arr = TWMap.villages[vill.join("")]) && arr.owner === "0") {
  120.           fin.push(vill.join("|"));
  121.           xvals.push(vill[0]);
  122.           yvals.push(vill[1]);
  123.         }
  124.       }
  125.     }
  126.   }
  127.   return yvals;
  128. }
  129.  
  130. function sendAttack(ch) {
  131.   let xvalsint = getCoordsX();
  132.   let yvalsint = getCoordsY();
  133.   x = parseInt(xvalsint[iterator]);
  134.   y = parseInt(yvalsint[iterator]);
  135.   console.log(x);
  136.   console.log(y);
  137.   getKey();
  138.  
  139.   data = {
  140.     "attack": true,
  141.     "ch": ch,
  142.     "x": x,
  143.     "y": y,
  144.     "source_village": game_data.village.id,
  145.     "village": game_data.village.id,
  146.     "attack_name": "",
  147.     "spear": spearAmnt,
  148.     "sword": swordAmnt,
  149.     "axe": axeAmnt,
  150.     "archer": archerAmnt,
  151.     "spy": spyAmnt,
  152.     "light": lightAmnt,
  153.     "marcher": marcherAmnt,
  154.     "heavy": heavyAmnt,
  155.     "ram": ramAmnt,
  156.     "catapult": catapultAmnt,
  157.     "knight": knightAmnt,
  158.     "snob": snobAmnt,
  159.     "building": catAttack
  160.   };
  161.   iterator++;
  162.   url = "game.php?village=" + game_data.village.id + "&screen=place&ajaxaction=popup_command&h=" + game_data.csrf + "&client_time" + Math.floor(Timing.getCurrentServerTime() / 1000);
  163.   $.post(url, data).done(function(response) {
  164.     if (response.includes("redirect")) {
  165.       console.log("Attack successfully sent!");
  166.     } else {
  167.       console.log(response);
  168.     }
  169.   });
  170. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement