Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var autoAttacker = {
- parseCoords: function (text) {
- return text.substr(text.lastIndexOf("(") + 1, 7)
- },
- checkIfIsPlayer: function (text) {
- return !(text.indexOf("Aldeia de bárbaros") >= 0 || text.indexOf("Aldeia-Bonus") >= 0);
- },
- getData: function () {
- const outCommands = document.getElementById("commands_outgoings");
- const elements = outCommands.getElementsByClassName("command-row");
- const atk = [];
- const rtn = [];
- for (let i = 0; i < elements.length; i++) {
- const loop = elements[i];
- let details = loop.getElementsByClassName("command_hover_details");
- if (HTMLCollection.prototype.isPrototypeOf(details))
- details = details[0];
- const cmdName = loop.getElementsByClassName("quickedit-label")[0].innerHTML;
- const type = details.dataset.commandType;
- const info = {
- coords: this.parseCoords(cmdName),
- isPlayer: this.checkIfIsPlayer(cmdName)
- };
- if (type === "attack")
- atk.push(info);
- else if (type === "return")
- rtn.push(info);
- }
- return {atk, rtn};
- },
- unitAvailable: function (text) {
- return +(text.substr(1, text.length - 2));
- },
- getAvailableVillager: function () {
- const {atk, rtn} = this.getData();
- for (let i = 0; i < rtn.length; i++) {
- const loop = rtn[i];
- if (!atk.includes(loop))
- return loop;
- }
- return null;
- },
- attackVillager: function (info) {
- const input = document.getElementsByName("input")[0];
- input.value = info.coords;
- input.dispatchEvent(new Event('change'));
- const lightAmount = this.unitAvailable(document.getElementById("units_entry_all_light").innerHTML);
- console.log(lightAmount);
- if (lightAmount >= 8) {
- document.getElementById("unit_input_light").value = info.isPlayer ? 8 : 4;
- document.getElementById("target_attack").click();
- }
- },
- tick: function () {
- let villager = autoAttacker.getAvailableVillager();
- if (villager)
- autoAttacker.attackVillager(villager);
- },
- start: function () {
- setInterval(() => this.tick(), 10000);
- }
- };
- autoAttacker.start();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement