Advertisement
Guest User

Untitled

a guest
Mar 25th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. const names = ["Gvar Hamryd", "Rozlewisko Kai"];
  2.  
  3. const _newNpc = window.newNpc;
  4. window.newNpc = function (npcs) {
  5. if (npcs !== undefined) {
  6. for (const npc of Object.values(npcs)) {
  7. if (names.includes(npc.nick)) {
  8. createFakeGateways(npc);
  9. }
  10. }
  11. }
  12.  
  13. _newNpc.apply(this, arguments);
  14. }
  15.  
  16. const _send = window._g;
  17. window._g = function (url) {
  18. if (url === "walk") {
  19. const {x, y} = window.hero;
  20. if (isFakeGatewayAtPosition(x, y)) {
  21. window.hero.autoWalkLock = true;
  22. url = `talk&id=${getFakeGatewayId(x, y)}`;
  23. }
  24. }
  25.  
  26. _send.apply(this, arguments);
  27. }
  28.  
  29.  
  30. function createFakeGateways(npc) {
  31. const nearbyNodes = getNearbyNodes(npc.x, npc.y);
  32. for (const [x, y] of nearbyNodes) {
  33. craeteElementAtPosition(npc.nick, npc.id, x, y);
  34. setFakeGateway(npc.nick, npc.id, x, y);
  35. }
  36. }
  37.  
  38. function getNearbyNodes(x, y) {
  39. const nodes = [];
  40. for (let i = y - 1; i <= y + 1; i++) {
  41. for (let j = x - 1; j <= x + 1; j++) {
  42. if (!isNodeBlockedAtPosition(j, i)) {
  43. nodes.push([j, i]);
  44. }
  45. }
  46. }
  47.  
  48. return nodes;
  49. }
  50.  
  51. function isNodeBlockedAtPosition(x, y) {
  52. if (x === undefined || y === undefined) return true;
  53. if (x < 0 || x > window.map.x || y < 0 || y > window.map.y) return true;
  54.  
  55. return window.map.col[y * window.map.x + x] !== "0";
  56. }
  57.  
  58. function craeteElementAtPosition(name, id, x, y) {
  59. const gw = document.createElement("div");
  60. gw.classList.add("gw");
  61. gw.classList.add("gwmap");
  62. gw.id = "gw" + id;
  63. gw.style.left = `${x * 32}px`;
  64. gw.style.top = `${y * 32}px`;
  65. gw.tip = name + "1";
  66. gw.addEventListener("click", e => window.hero.mClick(e));
  67. document.querySelector("#base").appendChild(gw);
  68. }
  69.  
  70. function setFakeGateway(name, id, x, y) {
  71. const position = `${x}.${y}`;
  72. window.g.gwIds[id] = position;
  73. window.g.townname[id] = name + "1";
  74. window.g.gw[position] = 69;
  75. }
  76.  
  77. function isFakeGatewayAtPosition(x, y) {
  78. const position = `${x}.${y}`;
  79. if (window.g.gw[position] && window.g.gw[position] === 69) return true;
  80. return false;
  81. }
  82.  
  83. function getFakeGatewayId(x, y){
  84. const position = `${x}.${y}`;
  85. for(const [id, pos] of Object.entries(window.g.gwIds)){
  86. if(pos === position) return id;
  87. }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement