Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Autox z menu
- // @version 1.0
- // @author yetrr#4049
- // @match https://*.margonem.pl/
- // @grant none
- // ==/UserScript==
- /* Konfiguracja */
- const SCRIPT_CONFIG = {
- whitelist: [],
- blacklist: [],
- mapStatus: 2,
- hz: 100,
- };
- const CONFIG = localStorage.getItem("autox-config") !== null ? JSON.parse(localStorage.getItem("autox-config")) : {
- windowPosition: ["0px", "0px"],
- windowExpanded: true,
- enabled: true,
- follow: true,
- distance: 15,
- attackClan: false,
- attackFriends: false,
- attackAllies: false,
- autoFight: false,
- minLvl: 100,
- maxLvl: 200,
- };
- !function load() {
- const box = document.createElement("div");
- box.style.left = CONFIG.windowPosition[0];
- box.style.top = CONFIG.windowPosition[1];
- box.id = "autox-box";
- if (CONFIG.windowExpanded) {
- box.style.height = "273px";
- } else {
- box.style.height = "30px";
- }
- const header = document.createElement("div");
- header.id = "autox-header";
- const label = document.createElement("span");
- label.classList.add("noselect");
- label.style.paddingLeft = "10px";
- label.textContent = "Konfiguracja autox";
- header.appendChild(label);
- const discord = document.createElement("img");
- discord.classList.add("noselect");
- discord.style.width = "20px";
- discord.style.height = "20px";
- discord.style.position = "fixed";
- discord.style.paddingLeft = "3px";
- discord.src = "https://i.imgur.com/Kq27VR5.png";
- discord.tip = "Discord: yetrr#4049";
- discord.addEventListener("click", () => {
- if (CONFIG.windowExpanded) {
- box.style.height = "30px";
- } else {
- box.style.height = "273px";
- }
- CONFIG.windowExpanded = !CONFIG.windowExpanded;
- toggleItemsVisibility();
- saveConfig();
- });
- const icon = document.createElement("span");
- icon.style.marginLeft = "28px";
- header.append(discord, icon);
- icon.addEventListener("click", () => {
- if (icon.classList.toString().includes("button-toggle-active")) {
- icon.classList.remove("button-toggle-active");
- icon.classList.add("button-toggle-inactive");
- } else {
- icon.classList.remove("button-toggle-inactive");
- icon.classList.add("button-toggle-active");
- }
- CONFIG.enabled = !CONFIG.enabled;
- saveConfig();
- });
- const slider = document.createElement("div");
- slider.classList.add("autox-dummy-item");
- slider.style.textAlign = "center";
- slider.style.paddingBottom = "10px";
- const sliderLabel = document.createElement("div");
- sliderLabel.classList.add("noselect");
- sliderLabel.style.textAlign = "center";
- sliderLabel.textContent = "Dystans: " + CONFIG.distance;
- const sliderInput = document.createElement("input");
- sliderInput.classList.add("slider");
- sliderInput.type = "range";
- sliderInput.min = "1";
- sliderInput.max = "16";
- slider.append(sliderLabel, sliderInput);
- sliderInput.addEventListener("mousemove", () => {
- CONFIG.distance = sliderInput.value;
- sliderLabel.textContent = "Dystans: " + CONFIG.distance;
- saveConfig();
- });
- box.append(header, slider);
- createConfigToggleableItem(box, "Pościg za graczem", CONFIG.follow, () => CONFIG.follow = !CONFIG.follow);
- createConfigToggleableItem(box, "Atakuj przyjaciół", CONFIG.attackFriends, () => CONFIG.attackFriends = !CONFIG.attackFriends);
- createConfigToggleableItem(box, "Atakuj klanowiczów", CONFIG.attackClan, () => CONFIG.attackClan = !CONFIG.attackClan);
- createConfigToggleableItem(box, "Atakuj sojuszników", CONFIG.attackAllies, () => CONFIG.attackAllies = !CONFIG.attackAllies);
- createConfigToggleableItem(box, "Szybka walka", CONFIG.autoFight, () => CONFIG.autoFight = !CONFIG.autoFight);
- createLevelInput(box, "Minimalny poziom", CONFIG.minLvl, (div) => div.style.paddingBottom = "5px", (input) => CONFIG.minLvl = input.value);
- createLevelInput(box, "Maksymalny poziom", CONFIG.maxLvl, () => {
- }, (input) => CONFIG.maxLvl = input.value);
- document.body.appendChild(box);
- initStyle();
- icon.classList.add(CONFIG.enabled ? "button-toggle-active" : "button-toggle-inactive");
- toggleItemsVisibility();
- draggable(box, "", "autox-drag")
- }();
- function draggable(a, b, c) {
- const d = this;
- const f = `undefined` !== typeof window.orientation || -1 !== navigator.userAgent.indexOf(`IEMobile`);
- a.ondragstart = () => {
- }
- a.addEventListener(f ? `touchstart` : `mousedown`, b => {
- window.g.lock.add(`autox-drag`);
- `INPUT` === b.target.tagName || (d[c] = !0,
- f && (d.x = b.touches[0].pageX,
- d.y = b.touches[0].pageY),
- d.start_x = d.x - a.offsetLeft,
- d.start_y = d.y - a.offsetTop)
- });
- document.addEventListener(f ? `touchmove` : `mousemove`, b => {
- if (b.pageX && (d.x = b.pageX, d.y = b.pageY), f && (d.x = b.touches[0].pageX, d.y = b.touches[0].pageY), d[c]) {
- let b = a.offsetWidth,
- c = a.offsetHeight,
- e = d.x - d.start_x,
- f = d.y - d.start_y;
- 0 > e && (e = 0);
- e + b > window.innerWidth && (e = window.innerWidth - b);
- a.style.left = `${e}px`;
- 0 > f && (f = 0);
- f + c > window.innerHeight && (f = window.innerHeight - c);
- a.style.top = `${f}px`;
- }
- });
- document.addEventListener(f ? `touchend` : `mouseup`, () => {
- window.g.lock.remove(`autox-drag`);
- CONFIG.windowPosition[0] = a.style.left;
- CONFIG.windowPosition[1] = a.style.top;
- saveConfig();
- d[c] = !1;
- });
- }
- function initStyle() {
- const style = document.createElement("style");
- const text =
- "#autox-box {" +
- "position: absolute;" +
- "z-index: 9999;" +
- "background: rgba(0, 0, 0, 0.5);" +
- "border: 2px solid gold;" +
- "border-radius: 15px;" +
- "width: 200px;" +
- "height: 273px;" +
- "}" +
- "#autox-header {" +
- "height: 20px;" +
- "border-radius: 15px;" +
- "padding-top: 5px;" +
- "padding-bottom: 5px;" +
- "color: white;" +
- "text-align: center;" +
- "}" +
- ".button-toggle-active {" +
- "position: relative;" +
- "top: 1px;" +
- "width: 18px;" +
- "height: 18px;" +
- "border-radius: 20px;" +
- "margin: 0 5px;" +
- "display: inline-block;" +
- "-webkit-transition: -webkit-box-shadow .2s ease-in-out;" +
- "transition: -webkit-box-shadow .2s ease-in-out;" +
- "transition: box-shadow .2s ease-in-out;" +
- "transition: box-shadow .2s ease-in-out,-webkit-box-shadow .2s ease-in-out;" +
- "background: radial-gradient(ellipse at center,#46a31d 0,#101010 100%);" +
- "-webkit-box-shadow: 0 0 5px 2px #46a31d;" +
- "box-shadow: 0 0 5px 2px #46a31d;" +
- "}" +
- ".button-toggle-inactive {" +
- "position: relative;" +
- "top: 1px;" +
- "width: 18px;" +
- "height: 18px;" +
- "border-radius: 20px;" +
- "margin: 0 5px;" +
- "display: inline-block;" +
- "-webkit-transition: -webkit-box-shadow .2s ease-in-out;" +
- "transition: -webkit-box-shadow .2s ease-in-out;" +
- "transition: box-shadow .2s ease-in-out;" +
- "transition: box-shadow .2s ease-in-out,-webkit-box-shadow .2s ease-in-out;" +
- "background: radial-gradient(ellipse at center,red 0,#101010 100%);" +
- "-webkit-box-shadow: 0 0 5px 2px red;" +
- "box-shadow: 0 0 5px 2px red;" +
- "}" +
- ".button-toggle-yellow {" +
- "position: relative;" +
- "top: 1px;" +
- "width: 18px;" +
- "height: 18px;" +
- "border-radius: 20px;" +
- "margin: 0 5px;" +
- "display: inline-block;" +
- "-webkit-transition: -webkit-box-shadow .2s ease-in-out;" +
- "transition: -webkit-box-shadow .2s ease-in-out;" +
- "transition: box-shadow .2s ease-in-out;" +
- "transition: box-shadow .2s ease-in-out,-webkit-box-shadow .2s ease-in-out;" +
- "background: radial-gradient(ellipse at center,yellow 0,#101010 100%);" +
- "-webkit-box-shadow: 0 0 5px 2px yellow;" +
- "box-shadow: 0 0 5px 2px yellow;" +
- "}" +
- ".slider {" +
- "-webkit-appearance: none;" +
- "width: 90%;" +
- "height: 15px;" +
- "border-radius: 5px; " +
- "background: #d3d3d3;" +
- "outline: none;" +
- "-webkit-transition: .2s;" +
- "transition: opacity .2s;" +
- "}" +
- ".slider::-webkit-slider-thumb {" +
- "-webkit-appearance: none;" +
- "appearance: none;" +
- "width: 19px;" +
- "height: 19px;" +
- "border-radius: 50%;" +
- "background: radial-gradient(ellipse at center,#46a31d 0,#101010 100%);" +
- "-webkit-box-shadow: 0 0 5px 2px #46a31d;" +
- "box-shadow: 0 0 5px 2px #46a31d;" +
- "cursor: pointer;" +
- "}" +
- ".autox-item {" +
- "padding-bottom: 3px;" +
- "}" +
- ".autox-dummy-item {}" +
- ".noselect {" +
- "-webkit-touch-callout: none;" +
- "-webkit-user-select: none;" +
- "-khtml-user-select: none;" +
- "-moz-user-select: none;" +
- "-ms-user-select: none;" +
- "user-select: none;" +
- "}" +
- "*:focus {" +
- "outline: 0;" +
- "}";
- style.appendChild(document.createTextNode(text));
- document.head.appendChild(style);
- }
- function createConfigToggleableItem(parent, label, value, wrapper) {
- const div = document.createElement("div"), icon = document.createElement("span"),
- text = document.createElement("span");
- div.classList.add("autox-item", "noselect"), text.textContent = label, div.append(icon, text);
- icon.classList.add(value ? "button-toggle-active" : "button-toggle-inactive"), parent.appendChild(div);
- icon.addEventListener("click", () => {
- if (icon.classList.toString().includes("button-toggle-active")) {
- icon.classList.remove("button-toggle-active");
- icon.classList.add("button-toggle-inactive");
- } else {
- icon.classList.remove("button-toggle-inactive");
- icon.classList.add("button-toggle-active");
- }
- wrapper();
- saveConfig();
- });
- }
- function createLevelInput(parent, text, value, callback = () => {
- }, changeCallback) {
- const div = document.createElement("div"), label = document.createElement("p"),
- input = document.createElement("input");
- div.classList.add("autox-dummy-item", "noselect"), input.classList.add("noselect");
- label.textContent = text;
- input.maxLength = 3;
- input.style.background = "#d3d3d3";
- input.style.height = "12px";
- input.style.textAlign = "center";
- input.style.borderRadius = "5px";
- input.style.outline = "none";
- input.style.webkitAppearance = "none";
- input.type = "text";
- div.style.textAlign = "center";
- input.value = value;
- callback(div);
- input.addEventListener("change", () => {
- changeCallback(input);
- saveConfig();
- });
- div.append(label, input);
- parent.append(div);
- }
- function toggleItemsVisibility() {
- Array.from(document.getElementsByClassName("autox-item")).concat(Array.from(document.getElementsByClassName("autox-dummy-item"))).forEach(item => {
- item.style.visibility = CONFIG.windowExpanded ? "visible" : "hidden";
- });
- }
- function saveConfig() {
- localStorage.setItem("autox-config", JSON.stringify(CONFIG));
- }
- class AStar {
- constructor(collisionsString, width, height, start, end, additionalCollisions) {
- this.width = width;
- this.height = height;
- this.collisions = this.parseCollisions(collisionsString, width, height);
- this.additionalCollisions = additionalCollisions || {};
- this.start = this.collisions[start.x][start.y];
- this.end = this.collisions[end.x][end.y];
- this.start.beginning = true;
- this.start.g = 0;
- this.start.f = heuristic(this.start, this.end);
- this.end.target = true;
- this.end.g = 0;
- this.addNeighbours();
- this.openSet = [];
- this.closedSet = [];
- this.openSet.push(this.start);
- }
- parseCollisions(collisionsString, width, height) {
- const collisions = new Array(width);
- for (let w = 0; w < width; w++) {
- collisions[w] = new Array(height);
- for (let h = 0; h < height; h++) {
- collisions[w][h] = new Point(w, h, collisionsString.charAt(w + h * width) === '1');
- }
- }
- return collisions;
- }
- addNeighbours() {
- for (let i = 0; i < this.width; i++) {
- for (let j = 0; j < this.height; j++) {
- this.addPointNeighbours(this.collisions[i][j]);
- }
- }
- }
- addPointNeighbours(point) {
- const x = point.x;
- const y = point.y;
- const neighbours = [];
- if (x > 0) neighbours.push(this.collisions[x - 1][y]);
- if (y > 0) neighbours.push(this.collisions[x][y - 1]);
- if (x < this.width - 1) neighbours.push(this.collisions[x + 1][y]);
- if (y < this.height - 1) neighbours.push(this.collisions[x][y + 1]);
- point.neighbours = neighbours;
- }
- anotherFindPath() {
- while (this.openSet.length > 0) {
- let currentIndex = this.getLowestF();
- let current = this.openSet[currentIndex];
- if (current === this.end) {
- return this.reconstructPath();
- } else {
- this.openSet.splice(currentIndex, 1);
- this.closedSet.push(current);
- for (const neighbour of current.neighbours) {
- if (!this.closedSet.includes(neighbour)) {
- const tentative_score = current.g + 1;
- let isBetter = false;
- if (this.end == this.collisions[neighbour.x][neighbour.y] || (!this.openSet.includes(neighbour) && !neighbour.collision && !this.additionalCollisions[neighbour.x + 256 * neighbour.y])) {
- this.openSet.push(neighbour);
- neighbour.h = heuristic(neighbour, this.end);
- isBetter = true;
- } else if (tentative_score < neighbour.g && !neighbour.collision) {
- isBetter = true;
- }
- if (isBetter) {
- neighbour.previous = current;
- neighbour.g = tentative_score;
- neighbour.f = neighbour.g + neighbour.h;
- }
- }
- }
- }
- }
- }
- getLowestF() {
- let lowestFIndex = 0;
- for (let i = 0; i < this.openSet.length; i++) {
- if (this.openSet[i].f < this.openSet[lowestFIndex].f) {
- lowestFIndex = i;
- }
- }
- return lowestFIndex;
- }
- reconstructPath() {
- const path = [];
- let currentNode = this.end;
- while (currentNode !== this.start) {
- path.push(currentNode);
- currentNode = currentNode.previous;
- }
- return path;
- }
- }
- class Point {
- constructor(x, y, collision) {
- this.x = x;
- this.y = y;
- this.collision = collision;
- this.g = 10000000;
- this.f = 10000000;
- this.neighbours = [];
- this.beginning = false;
- this.target = false;
- this.previous = undefined;
- }
- }
- const heuristic = (p1, p2) => {
- return Math.abs(p1.x - p2.x) + Math.abs(p1.y - p2.y);
- }
- const getWay = (x, y) => {
- return (new AStar(map.col, map.x, map.y, {x: hero.x, y: hero.y}, {x: x, y: y}, g.npccol)).anotherFindPath();
- }
- const goTo = (x, y) => {
- let _road_ = getWay(x, y);
- if (!Array.isArray(_road_)) {
- return;
- }
- road = _road_;
- }
- const _PI = parseInput;
- parseInput = (a, b, c) => {
- _PI(a, b, c);
- if (g.battle && $("#autobattleButton").css("display") == "block" && CONFIG.autoFight) {
- $("#autobattleButton").click();
- }
- };
- const attackNearbyOrFollow = player => {
- if (Math.abs(hero.x - player.x) <= 1 && Math.abs(hero.y - player.y) <= 1) {
- return _g(`fight&a=attack&id=${player.id}`);
- } else if (CONFIG.follow) {
- return goTo(player.x, player.y);
- }
- }
- function canMove(x, y) {
- for (let it in g.townname) {
- let coords = g.gwIds[it].split(".");
- if (coords[0] == x && coords[1] == y) {
- return false;
- }
- }
- return true;
- }
- const checkIfShouldAttack = player => {
- if (g.dead || g.battle || !CONFIG.enabled) {
- return false;
- }
- if (Math.sqrt(Math.pow(hero.x - player.x, 2) + Math.pow(hero.y - player.y, 2)) > CONFIG.distance) {
- return false;
- }
- if (SCRIPT_CONFIG.blacklist.includes(player.nick)) {
- return true;
- }
- if (!CONFIG.attackFriends && player.relation == "fr" || !CONFIG.attackClan && player.relation == "cl" || !CONFIG.attackAllies && player.relation == "cl-fr") {
- return false;
- }
- if (SCRIPT_CONFIG.whitelist.includes(player.nick)) {
- return false;
- }
- return canMove(player.x, player.y) && player.lvl >= CONFIG.minLvl && player.lvl <= CONFIG.maxLvl;
- }
- const old = newOther;
- newOther = players => {
- if (map.pvp != SCRIPT_CONFIG.mapStatus) {
- return old(players);
- }
- for (const id in players) {
- if (!player || !players[id].x || !g.other[id]) {
- continue;
- }
- if (checkIfShouldAttack(g.other[id])) {
- attackNearbyOrFollow(g.other[id]);
- }
- }
- return old(players);
- }
- g.loadQueue.push({
- fun: () => {
- if (map.pvp == SCRIPT_CONFIG.mapStatus) {
- setInterval(() => {
- for (const player of Object.values(g.other)) {
- if (checkIfShouldAttack(player)) {
- attackNearbyOrFollow(player);
- break;
- }
- }
- }, SCRIPT_CONFIG.hz);
- }
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement