Advertisement
Guest User

Untitled

a guest
Nov 16th, 2019
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.68 KB | None | 0 0
  1. // ==UserScript==
  2. // @name VISIBILITY - ON
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @author You
  6. // @match http://telawel.margonem.pl/
  7. // @match http://hypnos.margonem.pl/
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (() => {
  12. new class oooooooooooooooooooo {
  13. constructor() {
  14. this.interface = typeof window.Engine === "object" ? "ni" : "si";
  15. this.npcsOutOfView = new Array();
  16. this.initAjaxParser();
  17. }
  18.  
  19. get hero() {
  20. return this.interface === "ni" ? window.Engine.hero.d : window.hero;
  21. }
  22.  
  23. get map() {
  24. return this.interface === "ni" ? window.Engine.map.d : window.map;
  25. }
  26.  
  27. get npcs() {
  28. return this.interface === "ni" ? this.npcsOnNewInterface : window.g.npc;
  29. }
  30.  
  31. get npcsOnNewInterface() {
  32. const newNpcs = new Object();
  33.  
  34. for (const [id, npc] of Object.entries(window.Engine.npcs.check())) {
  35. newNpcs[id] = npc.d;
  36. }
  37.  
  38. return newNpcs;
  39. }
  40.  
  41. npcInOutOfRange({x:hx, y:hy}, {x, y}) {
  42. return Math.abs(x - hx) > this.map.visibility || Math.abs(y - hy) > this.map.visibility;
  43. }
  44.  
  45. initAjaxParser() {
  46. const self = this;
  47. const _ajax = window.$.ajax;
  48.  
  49. window.$.ajax = (...args) => {
  50. if (args[0].url.indexOf("/engine?t=") > -1) {
  51. const oldsucc = args[0].success;
  52. args[0].success = (...arg) => {
  53. const canEmit = typeof arg[0] === "object" && arg[0] !== null && arg[0].e === "ok";
  54.  
  55. if (canEmit) {
  56. arg[0] = self.parseInput(arg[0]);
  57. }
  58.  
  59. return oldsucc.apply(this, arg);
  60. };
  61. }
  62.  
  63. return _ajax.apply(this, args);
  64. }
  65. }
  66.  
  67. parseInput(data) {
  68. if (this.map.visibility !== 0) {
  69. if (data.hasOwnProperty("npc") && data.npc !== undefined) {
  70. for (const [id, npc] of Object.entries(data.npc)) {
  71. if (npc.hasOwnProperty("del") && npc.del === 1 && this.npcs[id] !== undefined) {
  72. if ([2, 3].includes(this.npcs[id].type) && this.npcInOutOfRange(this.hero, this.npcs[id])) {
  73. this.npcsOutOfView.push(id);
  74. delete data.npc[id];
  75. }
  76. }
  77. }
  78. }
  79. }
  80.  
  81. if (data.hasOwnProperty("h")) {
  82. const npcsToRemove = new Array();
  83.  
  84. for (const [id, npc] of Object.entries(this.npcs)) {
  85. if (this.npcsOutOfView.includes(id) && !this.npcInOutOfRange(data.h, npc)) {
  86. this.npcsOutOfView.splice(this.npcsOutOfView.indexOf(id), 1);
  87.  
  88. if ((data.hasOwnProperty("npc") && data.npc[id] === undefined) || !data.hasOwnProperty("npc")) {
  89. npcsToRemove.push(id);
  90. }
  91. }
  92. }
  93.  
  94. if (npcsToRemove.length > 0) {
  95. if (!data.hasOwnProperty("npc")) {
  96. data.npc = new Object();
  97. }
  98.  
  99. for (const id of npcsToRemove) {
  100. data.npc[id] = {
  101. del: 2
  102. }
  103. }
  104. }
  105. }
  106.  
  107. return data;
  108. }
  109. }
  110. })()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement