Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Event gwiazdka 2019 nithal/podgrodzie/nizina/gosciniec
- // @version 0.03
- // @description Szuka i tak lepiej niż noobki :)
- // @author Thinker
- // @match http://gefion.margonem.pl/
- // @grant none
- // ==/UserScript==
- $('#tutorial').hide();
- ceb = {};
- ceb.bestxy = 9999;
- ceb.run = 1;
- ceb.id = 0;
- ceb.block = "";
- ceb.xxxx = 0;
- ceb.blocked = 1;
- ceb.check2 = 0;
- ceb.check2 = 0;
- ceb.interv1 = "";
- ceb.interv2 = "";
- ceb.interv3 = "";
- var mapki = [];
- var nazwamapki;
- 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,
- 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)) continue;
- else {
- 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;
- }
- }
- function heuristic(p1, p2) {
- return Math.abs(p1.x - p2.x) + Math.abs(p1.y - p2.y);
- }
- function a_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();
- }
- function a_goTo(x, y) {
- let _road_ = a_getWay(x, y);
- if (!Array.isArray(_road_)) return;
- window.road = _road_;
- }
- var nithal = [[44, 8], [44, 7]];
- var podgrodzie = [[0, 6], [26, 63]];
- var nizina = [[28, 0], [95, 6]];
- var gosciniec = [[27, 94], [27, 95]];
- var koordy;
- var numer = 0;
- var nazwa_mapka;
- ceb.f1 = function() {
- nazwa_mapka = map.name;
- hero.nextx = '';
- hero.nexty = '';
- hero.nextx = koordy[numer][0];
- hero.nexty = koordy[numer][1];
- ceb.run = 1;
- ceb.blocked = 0;
- a_goTo(hero.nextx, hero.nexty);
- if((Math.abs(hero.rx - koordy[numer][0]) == 0 && Math.abs(hero.ry - koordy[numer][1]) == 0)) {
- numer++;
- }
- };
- ceb.f2 = function() {
- switch(map.name) {
- case "Nithal":
- koordy = nithal;
- if(nazwa_mapka == "Podgrodzie Nithal") {
- numer = 0;
- }
- break;
- case "Podgrodzie Nithal":
- koordy = podgrodzie;
- if(nazwa_mapka == "Nithal") {
- numer = 0;
- } else if (nazwa_mapka == "Nizina Wieśniaków") {
- numer = 1;
- }
- break;
- case "Nizina Wieśniaków":
- koordy = nizina;
- if(nazwa_mapka == "Podgrodzie Nithal") {
- numer = 0;
- } else if (nazwa_mapka == "Gościniec Bardów") {
- numer = 1;
- }
- break;
- case "Gościniec Bardów":
- koordy = gosciniec;
- if(nazwa_mapka == "Nizina Wieśniaków") {
- numer = 0;
- }
- break;
- }
- };
- ceb.f4 = function() {
- for (var i in g.npc) {
- var npc = g.npc[i];
- if (!isset(npc.del) && ( (npc.wt > 79 && npc.wt < 100)) ) {
- clearInterval(ceb.interv1);
- clearInterval(ceb.interv2);
- clearInterval(ceb.interv3);
- a_goTo(npc.x, npc.y);
- let audio = new Audio("https://www.myinstants.com/media/sounds/mlg-airhorn.mp3");
- audio.play();
- clearInterval(ceb.interv4);
- }
- }
- }
- nazwa_mapka = map.name;
- ceb.interv1 = setInterval(ceb.f1, 600);
- ceb.interv2 = setInterval(ceb.f2, 5);
- ceb.interv4 = setInterval(ceb.f4, 700);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement