Advertisement
Guest User

Untitled

a guest
Jan 24th, 2020
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.44 KB | None | 0 0
  1. var autoAttacker = {
  2. parseCoords: function (text) {
  3. return text.substr(text.lastIndexOf("(") + 1, 7)
  4. },
  5. checkIfIsPlayer: function (text) {
  6. return !(text.indexOf("Aldeia de bárbaros") >= 0 || text.indexOf("Aldeia-Bonus") >= 0);
  7. },
  8. getData: function () {
  9.  
  10. const outCommands = document.getElementById("commands_outgoings");
  11. const elements = outCommands.getElementsByClassName("command-row");
  12.  
  13. const atk = [];
  14. const rtn = [];
  15.  
  16. for (let i = 0; i < elements.length; i++) {
  17.  
  18. const loop = elements[i];
  19.  
  20. let details = loop.getElementsByClassName("command_hover_details");
  21.  
  22. if (HTMLCollection.prototype.isPrototypeOf(details))
  23. details = details[0];
  24.  
  25. const cmdName = loop.getElementsByClassName("quickedit-label")[0].innerHTML;
  26. const type = details.dataset.commandType;
  27.  
  28. const info = {
  29. coords: this.parseCoords(cmdName),
  30. isPlayer: this.checkIfIsPlayer(cmdName)
  31. };
  32.  
  33. if (type === "attack")
  34. atk.push(info);
  35. else if (type === "return")
  36. rtn.push(info);
  37. }
  38.  
  39. return {atk, rtn};
  40. },
  41. unitAvailable: function (text) {
  42. return +(text.substr(1, text.length - 2));
  43. },
  44. getAvailableVillager: function () {
  45.  
  46. const {atk, rtn} = this.getData();
  47.  
  48. for (let i = 0; i < rtn.length; i++) {
  49.  
  50. const loop = rtn[i];
  51.  
  52. if (!atk.includes(loop))
  53. return loop;
  54. }
  55.  
  56. return null;
  57. },
  58. attackVillager: function (info) {
  59.  
  60. const input = document.getElementsByName("input")[0];
  61.  
  62. input.value = info.coords;
  63. input.dispatchEvent(new Event('change'));
  64.  
  65. const lightAmount = this.unitAvailable(document.getElementById("units_entry_all_light").innerHTML);
  66.  
  67. console.log(lightAmount);
  68.  
  69.  
  70. if (lightAmount >= 8) {
  71. document.getElementById("unit_input_light").value = info.isPlayer ? 8 : 4;
  72. document.getElementById("target_attack").click();
  73. }
  74. },
  75. tick: function () {
  76. let villager = autoAttacker.getAvailableVillager();
  77.  
  78. if (villager)
  79. autoAttacker.attackVillager(villager);
  80. },
  81. start: function () {
  82. setInterval(() => this.tick(), 10000);
  83. }
  84. };
  85.  
  86. autoAttacker.start();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement