Advertisement
Guest User

Untitled

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