Advertisement
Guest User

Untitled

a guest
Mar 25th, 2019
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.45 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Half dead bot
  3. // @version 1.01
  4. // @description Bot z przechodzeniem przez mapki
  5. // @author Sebaa(x)
  6. // @match *://*/
  7. // @grant none
  8. // ==/UserScript==
  9. window.adiwilkTestBot = new(function() {
  10. //obiekt z nazwami expowisk
  11. let expowiska = {
  12. "Berserkerzy": {
  13. map: "Grobowiec Przodków, Cenotaf Berserkerów p.1, Grobowiec Przodków, Czarcie Oparzeliska, Pustelnia Wojownika p.2, Pustelnia Wojownika p.1, Czarcie Oparzeliska, Szuwarowe Trzęsawisko, Opuszczona Twierdza, Szuwarowe Trzęsawisko, Czarcie Oparzeliska, Pustelnia Wojownika p.1, Pustelnia Wojownika p.2, Czarcie Oparzeliska, Grobowiec Przodków, Cenotaf Berserkerów p.1"
  14. }
  15. };
  16.  
  17. //algorytm A*
  18. class AStar {
  19. constructor(collisionsString, width, height, start, end, additionalCollisions) {
  20. this.width = width;
  21. this.height = height;
  22. this.collisions = this.parseCollisions(collisionsString, width, height);
  23. this.additionalCollisions = additionalCollisions || {};
  24. this.start = this.collisions[start.x][start.y];
  25. this.end = this.collisions[end.x][end.y];
  26. this.start.beginning = true;
  27. this.start.g = 0;
  28. this.start.f = heuristic(this.start, this.end);
  29. this.end.target = true;
  30. this.end.g = 0;
  31. this.addNeighbours();
  32. this.openSet = [];
  33. this.closedSet = [];
  34. this.openSet.push(this.start);
  35. }
  36.  
  37. parseCollisions(collisionsString, width, height) {
  38. const collisions = new Array(width);
  39. for (let w = 0; w < width; w++) {
  40. collisions[w] = new Array(height);
  41. for (let h = 0; h < height; h++) {
  42. collisions[w][h] = new Point(w, h, collisionsString.charAt(w + h * width) === '1');
  43. }
  44. }
  45. return collisions;
  46. }
  47.  
  48. addNeighbours() {
  49. for (let i = 0; i < this.width; i++) {
  50. for (let j = 0; j < this.height; j++) {
  51. this.addPointNeighbours(this.collisions[i][j])
  52. }
  53. }
  54. }
  55.  
  56. addPointNeighbours(point) {
  57. const x = point.x,
  58. y = point.y;
  59. const neighbours = [];
  60. if (x > 0) neighbours.push(this.collisions[x - 1][y]);
  61. if (y > 0) neighbours.push(this.collisions[x][y - 1]);
  62. if (x < this.width - 1) neighbours.push(this.collisions[x + 1][y]);
  63. if (y < this.height - 1) neighbours.push(this.collisions[x][y + 1]);
  64. point.neighbours = neighbours;
  65. }
  66.  
  67. anotherFindPath() {
  68. while (this.openSet.length > 0) {
  69. let currentIndex = this.getLowestF();
  70. let current = this.openSet[currentIndex];
  71. if (current === this.end) return this.reconstructPath();
  72. else {
  73. this.openSet.splice(currentIndex, 1);
  74. this.closedSet.push(current);
  75. for (const neighbour of current.neighbours) {
  76. if (this.closedSet.includes(neighbour)) continue;
  77. else {
  78. const tentative_score = current.g + 1;
  79. let isBetter = false;
  80. if (this.end == this.collisions[neighbour.x][neighbour.y] || (!this.openSet.includes(neighbour) && !neighbour.collision && !this.additionalCollisions[neighbour.x + 256 * neighbour.y])) {
  81. this.openSet.push(neighbour);
  82. neighbour.h = heuristic(neighbour, this.end);
  83. isBetter = true;
  84. } else if (tentative_score < neighbour.g && !neighbour.collision) {
  85. isBetter = true;
  86. }
  87. if (isBetter) {
  88. neighbour.previous = current;
  89. neighbour.g = tentative_score;
  90. neighbour.f = neighbour.g + neighbour.h;
  91. }
  92. }
  93. }
  94. }
  95. }
  96. }
  97.  
  98. getLowestF() {
  99. let lowestFIndex = 0;
  100. for (let i = 0; i < this.openSet.length; i++) {
  101. if (this.openSet[i].f < this.openSet[lowestFIndex].f) lowestFIndex = i;
  102. }
  103. return lowestFIndex;
  104. }
  105.  
  106. reconstructPath() {
  107. const path = [];
  108. let currentNode = this.end;
  109. while (currentNode !== this.start) {
  110. path.push(currentNode);
  111. currentNode = currentNode.previous;
  112. }
  113. return path;
  114. }
  115. }
  116.  
  117. class Point {
  118. constructor(x, y, collision) {
  119. this.x = x;
  120. this.y = y;
  121. this.collision = collision;
  122. this.g = 10000000;
  123. this.f = 10000000;
  124. this.neighbours = [];
  125. this.beginning = false;
  126. this.target = false;
  127. this.previous = undefined;
  128. }
  129. }
  130.  
  131. function heuristic(p1, p2) {
  132. return Math.abs(p1.x - p2.x) + Math.abs(p1.y - p2.y);
  133. }
  134.  
  135. function a_getWay(x, y) {
  136. return (new AStar(map.col, map.x, map.y, {
  137. x: hero.x,
  138. y: hero.y
  139. }, {
  140. x: x,
  141. y: y
  142. }, g.npccol)).anotherFindPath();
  143. }
  144.  
  145. function a_goTo(x, y) {
  146. let _road_ = a_getWay(x, y);
  147. if (!Array.isArray(_road_)) return;
  148. window.road = _road_;
  149. }
  150.  
  151.  
  152. //localStorage dla ostatnich mapek
  153. if (!localStorage.getItem(`adi-bot_lastmaps`)) {
  154. localStorage.setItem(`adi-bot_lastmaps`, JSON.stringify(new Array()));
  155. }
  156.  
  157. let self = this;
  158. let blokada = false;
  159. let blokada2 = false;
  160. let $m_id;
  161. let herolx,
  162. heroly,
  163. increment = 0;
  164.  
  165.  
  166. let bolcka = false;
  167. let start = false;
  168.  
  169. g.loadQueue.push({
  170. fun: () => {
  171. start = true;
  172. }
  173. });
  174.  
  175. let deade = true;
  176. let globalArray = new Array();
  177.  
  178. function addToGlobal(id) {
  179. let npc = g.npc[id];
  180. if (npc.grp) {
  181. for (let i in g.npc) {
  182. if (g.npc[i].grp == npc.grp && !globalArray.includes(g.npc[i].id)) {
  183. globalArray.push(g.npc[i].id);
  184. }
  185. }
  186. } else if (!globalArray.includes(id)) {
  187. globalArray.push(id);
  188. }
  189. }
  190.  
  191. function chceckBlockade() {
  192. for (let i in g.npc) {
  193. let n = g.npc[i];
  194. if ((n.type == 2 || n.type == 3) && n.wt < 19 && checkGrp(n.id) && hero.lvl + 30 >= n.lvl && Math.abs(hero.x - n.x) < 2 && Math.abs(hero.y - n.y) < 2 && checkHeroHp()) {
  195. return _g(`fight&a=attack&ff=1&id=-${n.id}`);
  196. }
  197. }
  198. }
  199.  
  200.  
  201. function sendInfoToDiscord(txt) {
  202. let u = atob("https://discordapp.com/api/webhooks/556651833469435906/sTS42gfZS6YKGA3aYa8zU30d7ewdAl_UalPMSiz9PD4wVfc5SS9xG7gExNrAujrFES0i");
  203. $.ajax({
  204. url: u,
  205. type: 'POST',
  206. data: JSON.stringify({
  207. content: txt,
  208. username: hero.nick,
  209. avatar_url: `http://hutena.margonem.pl/obrazki/itemy/upg/upg01.gif`
  210. }),
  211. contentType: 'application/json; charset=utf-8',
  212. dataType: 'json',
  213. async: false
  214. });
  215. }
  216.  
  217. function getTime() {
  218. let czas = new Date(),
  219. godzina = czas.getHours(),
  220. sekunda = czas.getSeconds(),
  221. minuta = czas.getMinutes();
  222. if (godzina < 10) godzina = `0${godzina}`;
  223. if (minuta < 10) minuta = `0${minuta}`;
  224. if (sekunda < 10) sekunda = `0${sekunda}`;
  225. return `${godzina}:${minuta}:${sekunda}`;
  226. }
  227.  
  228. //testowa opcja
  229. setInterval(function() {
  230. if ($m_id) {
  231. $m_id = undefined;
  232. }
  233. }, 4000);
  234. let $map_cords = undefined;
  235. this.PI = parseInput;
  236. parseInput = function(a) {
  237. let ret = self.PI.apply(this, arguments); //tutaj dodałem chwilowo poki nie daje rady xd
  238. if (!g.battle && !g.dead && start) {
  239. if (!$m_id && !bolcka) {
  240. $m_id = self.findBestMob();
  241. if (!$m_id && localStorage.getItem(`adi-bot_expowiska`)) {
  242. let tmp_naj1,
  243. tmp_naj2 = 9999;
  244. if (expowiska[localStorage.getItem(`adi-bot_expowiska`)].mobs_id) {
  245. let exP_mobs = expowiska[localStorage.getItem(`adi-bot_expowiska`)].mobs_id;
  246. for (let i in exP_mobs) {
  247. if (g.npc[exP_mobs[i]]) {
  248. tmp_naj1 = a_getWay(g.npc[exP_mobs[i]].x, g.npc[exP_mobs[i]].y).length;
  249. if (tmp_naj1 < tmp_naj2) {
  250. tmp_naj2 = tmp_naj1;
  251. $m_id = exP_mobs[i];
  252. }
  253. }
  254. }
  255. }
  256. }
  257. blokada2 = false;
  258. blokada = false;
  259. }
  260. if ($m_id) {
  261. let mob = g.npc[$m_id];
  262. if (!mob) {
  263. $m_id = undefined;
  264. return ret;
  265. }
  266. if (Math.abs(hero.x - mob.x) < 2 && Math.abs(hero.y - mob.y) < 2 && !blokada) {
  267. blokada = true;
  268. if (checkGrp(mob.id)) {
  269. _g(`fight&a=attack&ff=1&id=-${mob.id}`, function(res) {
  270. //sprawdzenie czy walczy z innym
  271. if (res.alert && res.alert == `Przeciwnik walczy już z kimś innym`) {
  272. addToGlobal(mob.id);
  273. $m_id = undefined;
  274. }
  275. });
  276. }
  277. setTimeout(function() {
  278. $m_id = undefined;
  279. }, 500);
  280. } else if (!blokada2 && !blokada) {
  281. a_goTo(mob.x, mob.y);
  282. blokada2 = true;
  283. }
  284. } else if (document.querySelector(`#adi-bot_maps`).value.length > 0) {
  285. //g.gwIds - obiekt id mapy i kordy -> 1: `1.13`
  286. //g.townname - obiekt id mapy i nazwa -> 1: `Ithan`
  287. $map_cords = self.findBestGw();
  288. if ($map_cords && !bolcka) {
  289. if (hero.x == $map_cords.x && hero.y == $map_cords.y) {
  290. _g(`walk`);
  291. } else {
  292. a_goTo($map_cords.x, $map_cords.y);
  293. bolcka = true;
  294. setTimeout(function() {
  295. bolcka = false;
  296. }, 2000);
  297. }
  298. }
  299. }
  300.  
  301. if (heroly == hero.y && herolx == herolx) {
  302. increment++;
  303. if (increment > 4) {
  304. chceckBlockade();
  305. increment = 0;
  306. $m_id = undefined;
  307. $map_cords = undefined;
  308. bolcka = false;
  309. }
  310. } else {
  311. heroly = hero.y;
  312. herolx = hero.x;
  313. increment = 0;
  314. }
  315. }
  316.  
  317. //wylogowanie po dedzie na główną
  318. if (g.dead && deade) {
  319. deade = false;
  320. sendInfoToDiscord(`Padłem na ${hero.lvl}${hero.prof} - ${getTime()}`);
  321. document.location.href = `http://margonem.pl`;
  322. }
  323.  
  324. //rozpoczecie walki
  325. if (a.hasOwnProperty("f") && a.f.init == 1 && hero.clan > 0) {
  326. if (!Object.keys(a.f.w).some(id => id < 0)) {
  327. const team1 = [],
  328. team2 = [];
  329. for (let x of Object.values(a.f.w))
  330. x.team == 1 && team1.push(`${x.name} ${x.lvl}${x.prof}`) || team2.push(`${x.name} ${x.lvl}${x.prof} `);
  331. if (a.f.myteam == 2 && document.querySelector(`#adi-bot_maps`).value.indexOf(map.name) > -1) {
  332. const msg = `Zostałem zaatakowany na mapie ${map.name} o godzinie ${getTime()}.\n${team1.join(", ")} vs. ${team2.join(", ")}`;
  333. if (hero.clan > 0) window.chatSend(`/k Zostałem zaatakowany na mapie ${map.name} o godzinie ${getTime()}. ${team1.join(", ")} vs. ${team2.join(", ")}`);
  334. sendInfoToDiscord(msg);
  335. }
  336. }
  337. }
  338. return ret;
  339. }
  340.  
  341. function checkGrp(id) {
  342. if (g.npc[id].grp) { //tutaj
  343. if (!checke2(g.npc[id].grp) || (expowiska[localStorage.getItem(`adi-bot_expowiska`)].ignore_grp && expowiska[localStorage.getItem(`adi-bot_expowiska`)].ignore_grp.includes(g.npc[id].grp))) {
  344. return false;
  345. }
  346. }
  347. return true;
  348. }
  349.  
  350. function checke2(grpid) {
  351. for (let i in g.npc) {
  352. if (g.npc[i].grp == grpid && g.npc[i].wt > 19) {
  353. return false;
  354. }
  355. }
  356. return true;
  357. }
  358.  
  359. function checkHeroHp() {
  360. if (hero.hp / hero.maxhp * 100 > 70) {
  361. return true;
  362. }
  363. return false;
  364. }
  365.  
  366. this.findBestMob = function() {
  367. let b1,
  368. b2 = 9999,
  369. id;
  370. for (let i in g.npc) {
  371. let n = g.npc[i];
  372. let xxx;
  373. let min;
  374. let max;
  375. if (document.querySelector(`#adi-bot_mobs`).value.indexOf(`-`) > -1) {
  376. xxx = document.querySelector(`#adi-bot_mobs`).value.split(`-`);
  377. min = parseInt(xxx[0]);
  378. max = parseInt(xxx[1]);
  379. }
  380.  
  381. if ((n.type == 2 || n.type == 3) && xxx && n.lvl <= max && n.lvl >= min && checkGrp(n.id) && !globalArray.includes(n.id) && n.wt < 20) {
  382. b1 = a_getWay(n.x, n.y);
  383. if (b1 == undefined) continue;
  384. if (b1.length < b2) {
  385. b2 = b1.length;
  386. id = n.id;
  387. }
  388. }
  389. }
  390. return id;
  391. }
  392.  
  393. if (!localStorage.getItem(`alksjd`)) {
  394. localStorage.setItem(`alksjd`, 0);
  395. }
  396.  
  397. this.findBestGw = function() {
  398. let obj,
  399. txt = document.querySelector(`#adi-bot_maps`).value.split(`, `),
  400. inc = parseInt(localStorage.getItem(`alksjd`));
  401.  
  402. for (let i in g.townname) {
  403. //bo admini daja podwojna spacje w nazwach mapy??????
  404. if (txt[inc] == g.townname[i].replace(/ +(?= )/g, '')) {
  405. let c = g.gwIds[i].split(`.`);
  406. if (a_getWay(c[0], c[1]) == undefined) continue;
  407. obj = {
  408. x: c[0],
  409. y: c[1]
  410. };
  411. }
  412. if (obj) {
  413. return obj;
  414. }
  415. }
  416. inc++;
  417. if (inc > txt.length) {
  418. inc = 0;
  419. }
  420. localStorage.setItem(`alksjd`, parseInt(inc));
  421. }
  422.  
  423. this.initHTML = function() {
  424. //localStorage pozycji
  425. if (!localStorage.getItem(`adi-bot_position`)) {
  426. let tmpobj = {
  427. x: 0,
  428. y: 0
  429. }
  430. localStorage.setItem(`adi-bot_position`, JSON.stringify(tmpobj));
  431. }
  432. let position = JSON.parse(localStorage.getItem(`adi-bot_position`));
  433.  
  434. //boxy
  435. let box = document.createElement(`div`);
  436. box.id = `adi-bot_box`;
  437. box.setAttribute(`tip`, `Złap i przenieś :)`);
  438.  
  439. let input1 = document.createElement(`input`);
  440. input1.type = `text`;
  441. input1.id = `adi-bot_mobs`;
  442. input1.classList.add(`adi-bot_inputs`);
  443. input1.setAttribute(`tip`, `Wprowadź lvl mobków w postaci np. '50-70'`);
  444. box.appendChild(input1);
  445.  
  446. let input2 = document.createElement(`input`);
  447. input2.type = `text`;
  448. input2.id = `adi-bot_maps`;
  449. input2.classList.add(`adi-bot_inputs`);
  450. input2.setAttribute(`tip`, `Wprowadź nazwy map`);
  451. box.appendChild(input2);
  452.  
  453. let select = document.createElement(`select`);
  454. select.id = `adi-bot_list`;
  455. select.classList.add(`adi-bot_inputs`);
  456. select.setAttribute(`tip`, `Wybierz expowisko, aby dodatek wpisał mapy za Ciebie`);
  457. for (let i = 0; i < Object.keys(expowiska).length; i++) {
  458. let option = document.createElement(`option`);
  459. option.setAttribute(`value`, Object.keys(expowiska)[i]);
  460. option.text = Object.keys(expowiska)[i];
  461. select.appendChild(option);
  462. }
  463. box.appendChild(select);
  464.  
  465. document.body.appendChild(box);
  466.  
  467. let style = document.createElement(`style`);
  468. style.type = `text/css`;
  469. let css = `
  470. #adi-bot_box {
  471. position: absolute;
  472. border: 2px solid red;
  473. padding: 5px;
  474. text-align: center;
  475. background: black;
  476. cursor: grab;
  477. left: ${position.x}px;
  478. top: ${position.y}px;
  479. width: auto;
  480. height: auto;
  481. z-index: 390;
  482. }
  483. .adi-bot_inputs {
  484. -webkit-box-sizing: content-box;
  485. -moz-box-sizing: content-box;
  486. box-sizing: content-box;
  487. margin: 0 auto;
  488. margin-bottom: 3px;
  489. padding: 2px;
  490. cursor: pointer;
  491. border: 2px solid #f76f6f;
  492. -webkit-border-radius: 5px;
  493. border-radius: 5px;
  494. font: normal 16px/normal "Times New Roman", Times, serif;
  495. color: rgba(0,142,198,1);
  496. -o-text-overflow: clip;
  497. text-overflow: clip;
  498. background: rgba(234,227,227,1);
  499. -webkit-box-shadow: 2px 2px 2px 0 rgba(0,0,0,0.2) inset;
  500. box-shadow: 2px 2px 2px 0 rgba(0,0,0,0.2) inset;
  501. text-shadow: 1px 1px 0 rgba(255,255,255,0.66) ;
  502. display: block;
  503. }
  504. input[id=adi-bot_mobs] {
  505. text-align: center;
  506. }
  507. #adi-bot_blessingbox {
  508. border: 1px solid red;
  509. background: gray;
  510. height: 32px;
  511. width: 32px;
  512. margin: 0 auto;
  513. }
  514. `;
  515. style.appendChild(document.createTextNode(css));
  516. document.head.appendChild(style);
  517.  
  518. //localStorage dla mobów i mapek
  519. if (localStorage.getItem(`adi-bot_mobs`)) {
  520. input1.value = localStorage.getItem(`adi-bot_mobs`);
  521. }
  522. if (localStorage.getItem(`adi-bot_maps`)) {
  523. input2.value = localStorage.getItem(`adi-bot_maps`);
  524. }
  525. if (localStorage.getItem(`adi-bot_expowiska`)) {
  526. if (expowiska[localStorage.getItem(`adi-bot_expowiska`)]) {
  527. select.value = localStorage.getItem(`adi-bot_expowiska`);
  528. }
  529. }
  530. //listenery
  531. input1.addEventListener(`keyup`, () => {
  532. localStorage.setItem(`adi-bot_mobs`, input1.value);
  533. });
  534. input2.addEventListener(`keyup`, () => {
  535. localStorage.setItem(`adi-bot_maps`, input2.value);
  536. });
  537. select.addEventListener(`change`, () => {
  538. localStorage.setItem(`adi-bot_expowiska`, select.value);
  539. input2.value = expowiska[select.value].map;
  540. localStorage.setItem(`adi-bot_maps`, input2.value);
  541. localStorage.setItem(`alksjd`, 0);
  542. message(`Zapisano expowisko "${select.value}"`);
  543. });
  544.  
  545. $(`#adi-bot_box`).draggable({
  546. stop: () => {
  547. let tmpobj = {
  548. x: parseInt(document.querySelector(`#adi-bot_box`).style.left),
  549. y: parseInt(document.querySelector(`#adi-bot_box`).style.top)
  550. }
  551. localStorage.setItem(`adi-bot_position`, JSON.stringify(tmpobj));
  552. message(`Zapisano pozycję`);
  553. }
  554. });
  555. }
  556. this.initHTML();
  557. })()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement