Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let x = 504;
- let y = 499;
- let spearAmnt = 1;
- let swordAmnt = 0;
- let axeAmnt = 0;
- let archerAmnt = 0;
- let spyAmnt = 0;
- let lightAmnt = 0;
- let marcherAmnt = 0;
- let heavyAmnt = 0;
- let ramAmnt = 0;
- let catapultAmnt = 0;
- let knightAmnt = 0;
- let snobAmnt = 0;
- let catAttack = "main";
- let iterator = 0;
- let key;
- let value;
- /**
- * Get the weird obfuscated key and value which is stored in the rally point
- */
- function getKey() {
- $.get("game.php?village=" + game_data.village.id + "&screen=place", function(response) {
- const parser = new DOMParser();
- const dom = parser.parseFromString(response, "text/html");
- key = dom.querySelector("#command-data-form > input:nth-child(1)").getAttribute("name");
- value = dom.querySelector("#command-data-form > input:nth-child(1)").value;
- });
- }
- let data = {
- key: value,
- "template_id": "",
- "source_village": game_data.village.id,
- "spear": spearAmnt,
- "sword": swordAmnt,
- "axe": axeAmnt,
- "archer": archerAmnt,
- "spy": spyAmnt,
- "light": lightAmnt,
- "marcher": marcherAmnt,
- "heavy": heavyAmnt,
- "ram": ramAmnt,
- "catapult": catapultAmnt,
- "knight": knightAmnt,
- "snob": snobAmnt,
- "x": x,
- "y": y,
- "target_type": "coord",
- "input": "",
- "attack": "Attack",
- };
- function random(superior, inferior) {
- var numPosib = superior - inferior;
- var aleat = Math.random() * numPosib;
- return Math.round(parseInt(inferior) + aleat);
- }
- setInterval(attack, random(2330, 3550));
- /**
- * Send post request to attack dialog
- */
- function attack() {
- let xvalsint = getCoordsX();
- let yvalsint = getCoordsY();
- x = parseInt(xvalsint[iterator]);
- y = parseInt(yvalsint[iterator]);
- data.x = x;
- data.y = y;
- let url = "game.php?village=" + game_data.village.id + "&screen=place&try=confirm";
- $.post(url, data).done(function(response) {
- const parser = new DOMParser();
- const dom = parser.parseFromString(response, "text/html");
- if (dom.querySelector(".error_box")) {
- console.error("Error: " + dom.querySelector(".error_box").innerText.trim());
- } else {
- const ch = dom.getElementsByName("ch")[0].getAttribute("value");
- const timeout = Math.floor(Math.random() * 1000 + 500);
- setTimeout(function() {
- sendAttack(ch);
- }, timeout);
- console.log("Wait " + timeout + "ms");
- }
- });
- }
- function getCoordsX() {
- var x, y, vill, arr;
- var fin = [];
- var xvals = [];
- var yvals = [];
- for (x = 0; x < TWMap.size[1]; x++) {
- for (y = 0; y < TWMap.size[1]; y++) {
- if (vill = TWMap.map.coordByPixel(TWMap.map.pos[0] + TWMap.tileSize[0] * y, TWMap.map.pos[1] + TWMap.tileSize[1] * x)) {
- if ((arr = TWMap.villages[vill.join("")]) && arr.owner === "0") {
- fin.push(vill.join("|"));
- xvals.push(vill[0]);
- yvals.push(vill[1]);
- }
- }
- }
- }
- return xvals;
- }
- function getCoordsY() {
- var x, y, vill, arr;
- var fin = [];
- var xvals = [];
- var yvals = [];
- for (x = 0; x < TWMap.size[1]; x++) {
- for (y = 0; y < TWMap.size[1]; y++) {
- if (vill = TWMap.map.coordByPixel(TWMap.map.pos[0] + TWMap.tileSize[0] * y, TWMap.map.pos[1] + TWMap.tileSize[1] * x)) {
- if ((arr = TWMap.villages[vill.join("")]) && arr.owner === "0") {
- fin.push(vill.join("|"));
- xvals.push(vill[0]);
- yvals.push(vill[1]);
- }
- }
- }
- }
- return yvals;
- }
- function sendAttack(ch) {
- let xvalsint = getCoordsX();
- let yvalsint = getCoordsY();
- x = parseInt(xvalsint[iterator]);
- y = parseInt(yvalsint[iterator]);
- console.log(x);
- console.log(y);
- getKey();
- data = {
- "attack": true,
- "ch": ch,
- "x": x,
- "y": y,
- "source_village": game_data.village.id,
- "village": game_data.village.id,
- "attack_name": "",
- "spear": spearAmnt,
- "sword": swordAmnt,
- "axe": axeAmnt,
- "archer": archerAmnt,
- "spy": spyAmnt,
- "light": lightAmnt,
- "marcher": marcherAmnt,
- "heavy": heavyAmnt,
- "ram": ramAmnt,
- "catapult": catapultAmnt,
- "knight": knightAmnt,
- "snob": snobAmnt,
- "building": catAttack
- };
- iterator++;
- url = "game.php?village=" + game_data.village.id + "&screen=place&ajaxaction=popup_command&h=" + game_data.csrf + "&client_time" + Math.floor(Timing.getCurrentServerTime() / 1000);
- $.post(url, data).done(function(response) {
- if (response.includes("redirect")) {
- console.log("Attack successfully sent!");
- } else {
- console.log(response);
- }
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement