// ==UserScript==
// @name każdy kuba to frajer
// @version 0.1
// @description chuj
// @author Adi Wilk
// @match http://*.margonem.pl/
// @grant none
// ==/UserScript==
(() => {
new class oooooooooooooooooooo {
constructor() {
this.interface = typeof window.Engine === "object" ? "ni" : "si";
this.npcsOutOfView = new Array();
this.initAjaxParser();
}
get hero() {
return this.interface === "ni" ? window.Engine.hero.d : window.hero;
}
get map() {
return this.interface === "ni" ? window.Engine.map.d : window.map;
}
get npcs() {
return this.interface === "ni" ? this.npcsOnNewInterface : window.g.npc;
}
get npcsOnNewInterface() {
const newNpcs = new Object();
for (const [id, npc] of Object.entries(window.Engine.npcs.check())) {
newNpcs[id] = npc.d;
}
return newNpcs;
}
npcInOutOfRange({x:hx, y:hy}, {x, y}) {
return Math.abs(x - hx) > this.map.visibility || Math.abs(y - hy) > this.map.visibility;
}
initAjaxParser() {
const self = this;
const _ajax = window.$.ajax;
window.$.ajax = (...args) => {
if (args[0].url.indexOf("/engine?t=") > -1) {
const oldsucc = args[0].success;
args[0].success = (...arg) => {
const canEmit = typeof arg[0] === "object" && arg[0] !== null && arg[0].e === "ok";
if (canEmit) {
arg[0] = self.parseInput(arg[0]);
}
return oldsucc.apply(this, arg);
};
}
return _ajax.apply(this, args);
}
}
parseInput(data) {
if (this.map.visibility !== 0) {
if (data.hasOwnProperty("npc") && data.npc !== undefined) {
for (const [id, npc] of Object.entries(data.npc)) {
if (npc.hasOwnProperty("del") && npc.del === 1 && this.npcs[id] !== undefined) {
if ([2, 3].includes(this.npcs[id].type) && this.npcInOutOfRange(this.hero, this.npcs[id])) {
this.npcsOutOfView.push(id);
delete data.npc[id];
}
}
}
}
}
if (data.hasOwnProperty("h") && data.h.hasOwnProperty("x") && data.h.hasOwnProperty("y")) {
const npcsToRemove = new Array();
for (const [id, npc] of Object.entries(this.npcs)) {
if (this.npcsOutOfView.includes(id) && !this.npcInOutOfRange(data.h, npc)) {
this.npcsOutOfView.splice(this.npcsOutOfView.indexOf(id), 1);
if ((data.hasOwnProperty("npc") && data.npc[id] === undefined) || !data.hasOwnProperty("npc")) {
npcsToRemove.push(id);
}
}
}
if (npcsToRemove.length > 0) {
if (!data.hasOwnProperty("npc")) {
data.npc = new Object();
}
for (const id of npcsToRemove) {
data.npc[id] = {
del: 2
}
}
}
}
return data;
}
}
})()
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}