// ==UserScript== // @name AKiller Wodzu // @version 1.4.0 // @author Wodzu // @match https://*.margonem.pl/ // @grant none // ==/UserScript== const addon = () => { const isNI = typeof Engine == 'object' ? !0 : !1; const hero = isNI ? Engine.hero.d : window.hero; const saveLS = () => localStorage.setItem('AK1LL3R', JSON.stringify(ls)); if (!JSON.parse(localStorage.getItem('AK1LL3R'))) localStorage.setItem('AK1LL3R', JSON.stringify({ pos: { x: 0, y: 0 }, settings: {} })); const ls = JSON.parse(localStorage.getItem('AK1LL3R')); if (!ls.settings[window.getCookie('mchar_id')]) { ls.settings[window.getCookie('mchar_id')] = { enabled: false, enabledBack: false, lvl: { min: 0, max: 500 }, posBack: { x: 0, y: 0 } } }; saveLS(); const s = ls.settings[window.getCookie('mchar_id')]; const getTargets = () => { const checkEmo = o => isNI ? Engine.others.getById(o.id).getOnSelfEmoList()[0] ? 'battle' != Engine.others.getById(o.id).getOnSelfEmoList()[0].type : true : !document.querySelector(`#other${o.id}`).querySelector('.emo-cointainer > .emo.emo-battle'); return (isNI ? Engine.others.getDrawableList().filter(o => o.d).map(o => o.d) : Object.keys(g.other).map(id => g.other[id])) .filter(o => [1, 3, 6].includes(o.relation)) .filter(o => s.lvl.max >= o.lvl && o.lvl >= s.lvl.min) .filter(checkEmo); } const checkCol = p => isNI ? Engine.map.col.check(p.x, p.y) === 0 : !parseInt(map.col[map.x * p.y + p.x]) ? !Object.keys(g.npc).map(i => g.npc[i]).find(n => n.x == p.x && n.y == p.y) : false; const getEnds = () => { return [].concat(...getTargets().map(t => { return [{ x: t.x + 1, y: t.y + 1 }, { x: t.x + 1, y: t.y - 1 }, { x: t.x - 1, y: t.y + 1 }, { x: t.x - 1, y: t.y - 1 }, { x: t.x + 1, y: t.y }, { x: t.x - 1, y: t.y }, { x: t.x, y: t.y + 1 }, { x: t.x, y: t.y - 1 }, { x: t.x, y: t.y }].filter(checkCol) })); }; const attack = target => { if ((new Date() / 1000) - lastAttackReq < 0.3) return; window._g(`fight&a=attack&id=${target.id}`); lastAttackReq = new Date() / 1000; } let lastAttackReq = (new Date / 1000) - 10; const track = () => { const notInBattle = isNI ? Engine.battle ? Engine.battle.endBattle : true : !g.battle; const mapMode = isNI ? Engine.map.d.pvp : map.pvp; const targets = getTargets(); if (!s.enabled || mapMode != 2) { return; } else { if (targets.length == 0) { if (notInBattle && s.enabledBack) { } } else { if (notInBattle) setRoad(new path(...getEnds())); else setRoad([]); const target = targets.find(t => Math.abs(t.x - hero.x) <= 2 && Math.abs(t.y - hero.y) <= 2); if (target) attack(target); } } }; setInterval(track, 50); const setRoad = path => { } class path { constructor(...ends) { this.ends = [...ends]; this.done = []; this.path = []; this.queue = [{ x: hero.x, y: hero.y }]; this.explore(); this.draw(); return this.path; }; getNeighbours(pos) { return [ { x: pos.x + 1, y: pos.y, f: { x: pos.x, y: pos.y } }, { x: pos.x - 1, y: pos.y, f: { x: pos.x, y: pos.y } }, { x: pos.x, y: pos.y + 1, f: { x: pos.x, y: pos.y } }, { x: pos.x, y: pos.y - 1, f: { x: pos.x, y: pos.y } } ].filter(n => { return checkCol(n) && this.done.filter(d => d.x == n.x && d.y == n.y).length == 0 && this.queue.filter(d => d.x == n.x && d.y == n.y).length == 0 }); }; endFound(pos) { if (typeof pos === "undefined") return false; for (let i = 0; i < this.ends.length; i++) { if (this.ends[i].x === pos.x && this.ends[i].y === pos.y) return true; }; return false; }; explore() { let notFound = false; let pos; while (this.queue.length > 0 && !this.endFound(pos)) { pos = this.queue.shift(); this.getNeighbours(pos).forEach(n => this.queue.push(n)); this.done.push(pos); }; }; draw() { let pos = this.done[this.done.length - 1]; while (typeof pos.f === "object") { this.path.push({ x: pos.x, y: pos.y }); pos = this.done.find(d => d.x === pos.f.x && d.y === pos.f.y); } }; }; const turn = () => { const button = document.getElementById('AK1LL3R-button'); if (s.enabled) { s.enabled = false; button.classList.add('AK1LL3R-OFF'); button.classList.remove('AK1LL3R-ON'); } else { s.enabled = true; button.classList.add('AK1LL3R-ON'); button.classList.remove('AK1LL3R-OFF'); } saveLS(); } const turnBack = () => { const button = document.getElementById('AK1LL3R-button-back'); if (s.enabledBack) { s.enabledBack = false; button.classList.add('AK1LL3R-OFF'); button.classList.remove('AK1LL3R-ON'); } else { s.enabledBack = true; button.classList.add('AK1LL3R-ON'); button.classList.remove('AK1LL3R-OFF'); } saveLS(); } const main = document.createElement('div'); main.setAttribute('id', 'AK1LL3R'); document.body.appendChild(main); const button = document.createElement('button'); button.setAttribute('id', 'AK1LL3R-button'); if (s.enabled) button.classList.add('AK1LL3R-ON'); else button.classList.add('AK1LL3R-OFF'); button.addEventListener('click', turn); main.appendChild(button); const buttonBack = document.createElement('button'); buttonBack.setAttribute('id', 'AK1LL3R-button-back'); if (s.enabledBack) buttonBack.classList.add('AK1LL3R-ON'); else buttonBack.classList.add('AK1LL3R-OFF'); buttonBack.addEventListener('click', turnBack); main.appendChild(buttonBack); const input = document.createElement('input'); input.setAttribute('id', 'AK1LL3R-lvl'); input.setAttribute('type', 'text'); input.setAttribute('value', `${s.lvl.min}-${s.lvl.max}`); input.addEventListener('keyup', () => { const [min, max] = input.value.split('-'); s.lvl.min = min; s.lvl.max = max; saveLS(); }); main.appendChild(input); const inputBack = document.createElement('input'); inputBack.setAttribute('id', 'AK1LL3R-pos-back'); inputBack.setAttribute('type', 'text'); inputBack.setAttribute('value', `${s.posBack.x}-${s.posBack.y}`); inputBack.addEventListener('keyup', () => { const [xx, yy] = inputBack.value.split('-'); s.posBack.x = xx; s.posBack.y = yy; saveLS(); }); main.appendChild(inputBack); const style = document.createElement('style'); style.innerHTML = ` #AK1LL3R { position: absolute; width: 105px; height: 50px; top:${ls.pos.y}px; left:${ls.pos.x}px; border:grey solid 1px; background:#000; z-index:100 } #AK1LL3R-button { position: relative; top: 7px; left: 6px; height: 16px; width: 16px; } #AK1LL3R-button-back { position: relative; top: 28px; left: -10px; height: 16px; width: 16px; } #AK1LL3R-lvl { position: relative; top: 5px; left: -4px; height: 12px; width: 60px; text-align: center } #AK1LL3R-pos-back { position: relative; top: 8px; left: 28px; height: 12px; width: 60px; text-align: center } .AK1LL3R-ON { background: red } .AK1LL3R-OFF { background: #add8e6 } `; document.head.appendChild(style); $('#AK1LL3R').draggable({ stop: () => { ls.pos.x = parseInt(main.style.left); ls.pos.y = parseInt(main.style.top); saveLS() } }); } const init = () => { console.log(0); if (window.Engine) { if (window.Engine.npcs) { return addon(); } } if (window.g) { if (window.g.item) { if (window.g.item.length > 0) { return addon(); } } } setTimeout(init, 500); } window.addEventListener('load', init);