Facebook
From Aqua Shama, 4 Years ago, written in Plain Text.
This paste is a reply to e2 from Michał Zawadka - go back
Embed
Viewing differences between e2 and Re: e2
// ==UserScript==
// @name         Bot na e2 test!!!
// @version      1.4
// @description  bot na e2 w trakcie rozbudowy, dziala na NI i SI
// @author       Adi Wilk
// @match        http://*.margonem.pl/
// @match        https://*.margonem.pl/
// @grant        none
// ==/UserScript==

(()=>{class a{constructor(a,b,c,d,e,f){this.width=b,this.height=c,this.collisions=this.parseCollisions(a,b,c),this.additionalCollisions=f||{},this.start=this.collisions[d.x][d.y],this.end=this.collisions[e.x][e.y],this.start.beginning=!0,this.start.g=0,this.start.f=this.heuristic(this.start,this.end),this.end.target=!0,this.end.g=0,this.addNeighbours(),this.openSet=[],this.closedSet=[],this.openSet.push(this.start)}parseCollisions(a,c,d){const e=Array(c);for(let f=0;fgetItem("adi-bot-lootfilterSettings"))||{stat:{gold:{translation:"Z\u0142oto",active:!0},quest:{translation:"Questowe",active:!0},runes:{translation:"Runy",active:!0},unique:{translation:"Unikaty",active:!0},heroic:{translation:"Heroiki",active:!0},legendary:{translation:"Legendy",active:!0}},names:[]},this.getItem("adi-bot-lootfilterSettings"))||{stat:{gold:{translation:"Zu0142oto",active:!0},quest:{translation:"Questowe",active:!0},runes:{translation:"Runy",active:!0},unique:{translation:"Unikaty",active:!0},heroic:{translation:"Heroiki",active:!0},legendary:{translation:"Legendy",active:!0}},names:[]},this.QuickGroupSettings=JSON.parse(localStorage.getItem("adi-bot-QuickGroupSettings12"))||{adding:{translation:"Automatycznie dodawaj do grupy znaj/klan",active:!0},accepting:{translation:"Automatycznie przyjmuj zaproszenia do grupy",active:!0},reSendingMessage:{translation:"Automatycznie odpisuj innym graczom",active:!0}},this.npcToKillId=void 0,this.lastAttackTimestamp=this.timeStamp,this.timerData=JSON.parse(this.getCookie("adi-bot-timer"))||{},this.refreshTime=[3,6],this.delayToRelog=35,this.waitForNpcRespawn=120,this.randomAnswers=["nie interesuje mnie to","kiedy\u015B to","kiedyu015B to by\u0142o, byu0142o, nie to co tera","to fajnie","nom","super","co ?","interesuj\u0105ce","bombowo","Bardzo si\u0119 ciesz\u0119.?","interesuju0105ce","bombowo","Bardzo siu0119 cieszu0119.","Xd","co","co.?","co?","xD","xd","ehhhhhh","heh","fajnie fajnie :]"],this.answersBeforeAddingToEnemies=["dobra, do wrog\xF3w wrogxF3w cie daje :)","papapappapapapap","nara.","w ty\u0142ku tyu0142ku cie mam gosciu, nara","papapapp","nara kole\u017Cko","lecisz koleu017Cko","lecisz do wrogow :P","narka ;)","hehehehhe, narq","ej jeste\u015B?","haha.jesteu015B?","haha. ;)"],this.messagesInc=JSON.parse(localStorage.getItem("adi-bot-messages"))||{},this.isHealing=!1,this.isActuallySendingMessage=!1,this.startInctementingLagRefresher=!1,this.incrementValue=0,this.init()}get collisions(){return"ni"===this.interface?this.updateCollisions():window.map.col}get npccol(){return"ni"===this.interface?this.getNpcColsNI():window.g.npccol}get timeStamp(){return Math.floor(new Date().getTime()/1e3)}get hero(){return"ni"===this.interface?window.Engine.hero.d:window.hero}get map(){return"ni"===this.interface?window.Engine.map.size:window.map}get mapName(){return"ni"===this.interface?window.Engine.map.d.name:window.map.name}get npcs(){return"ni"===this.interface?this.npcsOnNewInterface:window.g.npc}get others(){return"ni"===this.interface?this.othersOnNewInterface:window.g.other}get world(){return"ni"===this.interface?window.Engine.worldName:window.g.worldname}get serverTimerSpeed(){return"none"!==this.interface&&["aldous","berufs","brutal","classic","gefion","hutena","jaruna","katahha","lelwani","majuna","nomada","perkun","tarhuna","telawel","tempest","zemyna","zorza"].includes(this.world.toLowerCase())?1:"none"!==this.interface&&"syberia"===this.world.toLowerCase()?2:3}get battle(){return"ni"===this.interface?!!window.Engine.battle&&!window.Engine.battle.endBattle:window.g.battle}get dead(){return"ni"===this.interface?window.Engine.dead:window.g.dead}get party(){return"ni"===this.interface?Engine.party:window.g.party}get loots(){return"ni"===this.interface?window.Engine.loots!==void 0&&!!(0this.storage.name.toLowerCase().includes(a.nick.toLowerCase()))}get items(){return"ni"===this.interface?window.Engine.items.fetchLocationItems("g"):Object.values(window.g.item)}get npcsOnNewInterface(){const a=window.Engine.npcs.check(),b={};for(const[c,d]of Object.entries(a))b[c]=d.d;return b}get othersOnNewInterface(){const a=window.Engine.others.check(),b={};for(const[c,d]of Object.entries(a))b[c]=d.d;return b}getNpcColsNI(){const a={};for(const{x:b,y:c}of Object.values(this.npcs))a[b+256*c]=!0;return a}chatParser(){"ni"===this.interface&&window.API.addCallbackToEvent("newMsg",([a,b])=>{this.chatFilter(b)}),"si"===this.interface&&window.g.chat.parsers.push(a=>{this.chatFilter(a)})}chatFilter(a){const{n:b,t:c,ts:d,k:e}=a;if(""!==b&&b!==this.hero.nick&&"System"!==b&&!1!==this.QuickGroupSettings.reSendingMessage.active&&1>=window.unix_time()-d&&!this.isActuallySendingMessage){if(void 0!==this.messagesInc[b+this.world]&&3{window._g("chat",{c:d}),!0===c&&this.addToEnemy(a),this.isActuallySendingMessage=!1})}Sleep(a){return new Promise(b=>{setTimeout(()=>{b(null)},a)})}saveMessages(){localStorage.setItem("adi-bot-messages",JSON.stringify(this.messagesInc))}addToEnemy(a){window._g(`friends&a=eadd&nick=${a}`)}getWay(b,c){return new a(this.collisions,this.map.x,this.map.y,{x:this.hero.x,y:this.hero.y},{x:b,y:c},this.npccol).anotherFindPath()}goTo(a,b){const c=this.getWay(a,b);Array.isArray(c)&&("ni"===this.interface?window.Engine.hero.autoPath=c:window.road=c)}getDistanceToNpc(a,b){const c=this.getWay(a,b);return Array.isArray(c)?c.length:void 0}updateCollisions(){const a=[],{x:b,y:c}=this.map;for(let d=0;dappendText(a,"Wprowad\u017A appendText(a,"Wprowadu017A nazwy elit II:");const b=document.createElement("input");b.type="text",b.classList.add("adi-bot-input-text"),b.value=this.storage.name,b.addEventListener("keyup",()=>{this.storage.name=b.value,this.saveStorage()}),a.appendChild(b),this.appendText(a,"Lootfilter:");for(const[b,{translation:c,active:d}]of Object.entries(this.lootfilterSettings.stat))this.createCheckBox(a,c,d,a=>{this.lootfilterSettings.stat[b].active=a,localStorage.setItem("adi-bot-lootfilterSettings",JSON.stringify(this.lootfilterSettings))});this.appendText(a,"\u0141ap appendText(a,"u0141ap itemki po nazwie:");const c=document.createElement("input");c.classList.add("adi-bot-input-text"),c.tip="Oddzielaj przecinkiem!",c.type="text",c.value=this.lootfilterSettings.names.join(", "),c.addEventListener("keyup",()=>{const a=c.value.split(",");for(let b=0;b{this.QuickGroupSettings[b].active=a,localStorage.setItem("adi-bot-QuickGroupSettings12",JSON.stringify(this.QuickGroupSettings))});this.makeBoxDraggable(a,()=>{this.storage.x=parseInt(a.style.left),this.storage.y=parseInt(a.style.top),this.saveStorage(),window.message(`Zapisano pozycję okienka :)`)}),this.storage.hasOwnProperty("minimalized")||(this.storage.minimalized=!1,this.saveStorage()),a.addEventListener("dblclick",({x:b,y:c})=>{!1===this.storage.minimalized?(a.style.width="10px",a.style.height="10px",this.storage.minimalized=!0,this.changeVisibility(a,!0)):(a.style.width="360px",a.style.height="272px",this.storage.minimalized=!1,this.changeVisibility(a,!1)),a.style.left=b-parseInt(a.style.width)/2+"px",a.style.top=c-parseInt(a.style.height)/2+"px",this.storage.x=parseInt(a.style.left),this.storage.y=parseInt(a.style.top),this.saveStorage()}),"ni"===this.interface?document.querySelector(".game-window-positioner").appendChild(a):document.body.appendChild(a),this.initStyle(),!0===this.storage.minimalized&&(a.style.width="10px",a.style.height="10px",this.changeVisibility(a,!0))}changeVisibility(a,b){for(const c of a.childNodes)c.style.display=!0===b?"none":""}appendText(a,b){const c=document.createElement("div");c.appendChild(document.createTextNode(b)),a.appendChild(c)}createCheckBox(a,b,c,d){const e=document.createElement("div"),f=document.createElement("input");f.type="checkbox",f.name=b+"adi-bot",f.id=b+"adi-bot",f.checked=c,e.appendChild(f);const g=document.createElement("label");g.setAttribute("for",b+"adi-bot"),g.innerHTML=b,f.addEventListener("change",()=>{d(f.checked)}),e.appendChild(g),a.appendChild(e)}makeBoxDraggable(a,b){$(a).draggable({containment:"window",stop:b})}saveStorage(){localStorage.setItem("adi-bot-storage",JSON.stringify(this.storage))}initStyle(){const a=document.createElement("style"),b=`
            .adi-bot-box {
                position: absolute;
                text-align: center;
                padding: 10px;
                height: 272px;
                width: 360px;
                left: ${this.storage.x}px;
                top: ${this.storage.y}px;
                background: #975b83;
                border: 2px solid white;
                border-radius: 8px;
                color: black;
                z-index: 999;
            }
            .adi-bot-input-text {
                text-align: center;
                border: 2px solid lightblue;
                border-radius: 3px;
                color: black;
                cursor: text;
            }
            `;a.type="text/css",a.appendChild(document.createTextNode(b)),document.head.appendChild(a)}initNewNpc(){if("ni"===this.interface&&(window.API.addCallbackToEvent("newNpc",a=>{void 0!==a&&this.addNpcs(a.d)}),window.API.addCallbackToEvent("removeNpc",a=>{void 0!==a&&this.removeNpcs(a.d)})),"si"===this.interface){const a=window.newNpc;window.newNpc=b=>{if(void 0!==b)for(const[a,c]of Object.entries(b))void 0!==c.del&&void 0!==window.g.npc[a]?this.removeNpcs(window.g.npc[a],a):void 0!==c&&this.addNpcs(c,a);a(b)}}}initNewOther(){if("ni"===this.interface&&(this.makeParty(),window.API.addCallbackToEvent("newOther",a=>{this.filterOther(a.d)})),"si"===this.interface){this.makeParty();const a=window.newOther;window.newOther=b=>{if(a(b),void 0!==b)for(const a of Object.values(b))this.filterOther(a)}}}filterOther(a){if(a!==void 0){const{relation:b,id:c}=a;!0===this.canHeroTryToAttack()&&["cl","fr"].includes(b)&&!0===this.QuickGroupSettings.adding.active&&this.sendInviteToParty(c)}}makeParty(){if("object"!=typeof this.party)return this.sendInvites();const a="ni"===this.interface?this.party.getLeaderId()===this.hero.id:1===this.party[this.hero.id].r;!0==a&&this.sendInvites()}sendInvites(){if(this.others!==void 0)for(const a of Object.values(this.others))this.filterOther(a)}sendInviteToParty(a){window._g(`party&a=inv&id=${a}`)}initChecker(){if(setTimeout(()=>{this.initChecker()},500),!0===this.dead&&(this.removeNpcsFromThisCharId(this.hero.id),this.logout()),!0===this.canHeroTryToAttack())try{if(void 0!==this.npcToKillId){const{x:a,y:b}=this.npcs[this.npcToKillId];1>=Math.abs(this.hero.x-a)&&1>=Math.abs(this.hero.y-b)?0a.hasOwnProperty("alert")&&a.alert.includes("Przeciwnik walczy ju\u017C juu017C kim\u015B kimu015B innym")?void(this.lastAttackTimestamp=this.timeStamp+2):void(this.lastAttackTimestamp=this.timeStamp+1)):this.goTo(a,b)}else this.reFindNpcs()}catch(a){this.npcToKillId=void 0}}canHeroTryToAttack(){return!(this.battle||this.dead)}removeNpcs(a){const{x:b,y:c,nick:d,lvl:e}=a;"ni"===this.interface?window.Engine.map.col.unset(b,c,window.Engine.map.col.check(b,c)):window.map.nodes.changeCollision(b,c,0),this.storage.name.toLowerCase().includes(d.toLowerCase())&&(this.addNpcToTimer(d,e),this.npcToKillId=void 0,this.reFindNpcs())}findEilteIIName(a){for(const b of Object.values(this.npcs)){const{nick:c,lvl:d,grp:e,wt:f}=b;if(e===a&&19{const a=d.getImageData(Math.floor(d.width/2),0,1,d.height).data;for(let c=3;cf||void 0===c)&&void 0===this.npcToKillId&&this.storage.name.toLowerCase().includes(c.toLowerCase())&&""!==this.storage.name){const a=d.includes("/obrazki/npc/")?d:`/obrazki/npc/${d}`;this.isNpcFake(a,a=>{!1===a&&(this.npcToKillId=0===g?parseInt(b):parseInt(this.findBestNpcFromGrp(g)),this.makeParty())})}}findBestNpcFromGrp(a){let b,c=999999;for(const[d,e]of Object.entries(this.npcs)){const{x:f,y:g,grp:h}=e;if(a===h){const a=this.getDistanceToNpc(f,g);ab.nick==this.timerData[a].name)||this.timerData[a].charId!==this.hero.id)){for(;this.timeStamp>this.timerData[a].nextRespawn;)this.timerData[a].nextRespawn+=this.getNewRespawnTime(this.timerData[a].lvl);this.saveTimersCookies()}}isThisHeroIssetInTimer(b){return void 0!==b&&Object.values(this.timerData).some(c=>c.charId==b)}isntTimersInRange(){return Object.values(this.timerData).every(b=>b.nextRespawn-this.timeStamp>this.delayToRelog)}checkHeroOnGoodMap(a){for(const[b,c]of Object.entries(this.timerData)){const{mapName:d,charId:e}=c;e==a&&this.mapName!==void 0&&d!==void 0&&d!==this.mapName&&this.deleteNpcFromTimer(b)}}initTimer(){if(0b.nextRespawn-this.timeStamp<=this.delayToRelog)){const{world:a,charId:b}=Object.values(this.timerData).reduce((c,a)=>c.nextRespawn<=a.nextRespawn?c:a);void 0!==b&&this.logIn(b,a)}}else if(this.isntTimersInRange()&&this.isThisHeroIssetInTimer(this.hero.id))this.logout();else{this.checkHeroOnGoodMap(this.hero.id);const a=Object.values(this.timerData).filter(b=>b.nextRespawn-this.timeStamp<=this.delayToRelog);if(0c.nextRespawn<=a.nextRespawn?c:a);void 0!==this.hero.id&&parseInt(b)!==this.hero.id&&this.logIn(b,c)}}this.checkTimers(),setTimeout(()=>{this.initTimer()},500)}saveTimersCookies(){const a=new Date;a.setMonth(a.getMonth()+1),this.setCookie("adi-bot-timer",JSON.stringify(this.timerData),a,"/","margonem.pl")}randomSeconds(a,b){return a*=60,b*=60,Math.floor(Math.random()*(b-a+1))+a}randomRefresh(){const[a,b]=this.refreshTime;setTimeout(()=>{window.location.reload()},1e3*this.randomSeconds(a,b))}getCookie(a){const b=document.cookie,c=a+"=";let d=b.indexOf("; "+c);if(-1!=d)d+=2;else if(d=b.indexOf(c),0!=d)return null;let e=document.cookie.indexOf(";",d);return-1==e&&(e=b.length),unescape(b.substring(d+c.length,e))}setCookie(a,b,c,d,e,f){const g=a+"="+escape(b)+(c?"; expires="+c.toGMTString():"")+(d?"; path="+d:"")+(e?"; domain="+e:"")+(f?"; secure":"");document.cookie=g}createTimerOnMainPage(){if(0===Object.keys(this.timerData).length)return;const a=document.createElement("div");a.classList.add("adi-bot-minutnik-strona-glowna"),document.querySelector(".rmenu").appendChild(a);const b=document.createElement("style");b.type="text/css",b.appendChild(document.createTextNode(`
            .adi-bot-minutnik-strona-glowna {
                color: white;
                font-size: 14px;
                text-align: left;
            }

            .timer_data {
                font-weight: bold;
                float: right;
                cursor: pointer;
            }

            .timer_data:hover {
                color: gray;
            }

            .adi-bot-konfiguracja {

            }
        `)),document.head.appendChild(b),this.addNpcsToTimerBox(a),document.addEventListener("click",a=>{try{if("timer_data"===a.target.className){const[b,c]=a.target.getAttribute("timer-data").split("|");c!==void 0&&b!==void 0&&(this.deleteNpcFromTimer(b+c),window.showMsg(`Usunięto ${b} ze świata ${c.charAt(0).toUpperCase()+c.slice(1)}.`))}}catch(a){}})}addNpcsToTimerBox(a){const b={};for(const c of Object.values(this.timerData)){const{name:a,nextRespawn:d,world:e}=c;b[e]===void 0?b[e]=[{name:a,nextRespawn:d}]:b[e].push({name:a,nextRespawn:d})}let c="";for(const[d,e]of Object.entries(b)){c+=`
${this.capitalizeWorld(d)}
`,e.sort((a,b)=>a.nextRespawn-b.nextRespawn);const a=[];a.push("");for(const b of e){const{name:c,nextRespawn:e}=b;a.push(`${this.getTimeToRespawn(c,e)}---`)}a.push(""),c+=a.join("
")}a.innerHTML=c,setTimeout(()=>{this.addNpcsToTimerBox(a)},1e3)}capitalizeWorld(a){return a.charAt(0).toUpperCase()+a.slice(1)+":"}getTimeToRespawn(a,b){const c=b-this.timeStamp,d=10>parseInt(c/60)?`0${parseInt(c/60)}`:parseInt(c/60),e=10>c%60?`0${c%60}`:c%60;return`${a}: ${d}:${e}`}removeLockAdding(){"ni"===this.interface&&(window.Engine.lock.add=Function.prototype),"si"===this.interface&&(window.g.lock.add=Function.prototype),window.mAlert=Function.prototype}initLagRefresher(){!1===this.startInctementingLagRefresher&&(this.startInctementingLagRefresher=!0,setInterval(()=>{this.incrementValue++,8{if(c[0].url.includes("engine?t=")){const b=c[0].success;c[0].success=(...c)=>{const d="object"==typeof c[0]&&null!==c[0]&&"ok"===c[0].e,e=b.apply(this,c);return d&&a.parseAjaxData(c[0]),e}}return b.apply(this,c)}}parseAjaxData(a){if((a.hasOwnProperty("d")&&"stop"===a.d||a.hasOwnProperty("t")&&"stop"===a.t)&&this.Sleep(2500).then(()=>{window.location.reload()}),this.incrementValue=0,a.hasOwnProperty("loot")&&a.hasOwnProperty("item")&&a.loot.hasOwnProperty("init")&&a.loot.hasOwnProperty("source")&&1===a.loot.init&&"fight"===a.loot.source){const b=[],c=[];for(const[d,e]of Object.entries(a.item)){const{stat:a,name:f}=e;!0==this.isGoodItem(a,f)?b.push(d):c.push(d)}this.sendLoots(b,c)}a.hasOwnProperty("f")&&a.f.hasOwnProperty("move")&&a.f.hasOwnProperty("current")&&0===a.f.current&&-1===a.f.move&&(this.closeBattle(),a.f.hasOwnProperty("w")&&this.autoHeal()),a.hasOwnProperty("event_done")&&this.autoHeal(),a.hasOwnProperty("ask")&&a.ask.hasOwnProperty("re")&&"party&a=accept&answer="===a.ask.re&&!0===this.QuickGroupSettings.accepting.active&&window._g("party&a=accept&answer=1")}isGoodItem(a,b){const c=[];for(const[d,{active:e}]of Object.entries(this.lootfilterSettings.stat))!0===e&&c.push(d);const d=this.lootfilterSettings.names;for(const d of c)if(a.includes(d))return!0;for(const c of d)if(b.toLowerCase()===c.toLowerCase())return!0;return!1}sendLoots(a,b){window._g(`loot¬=${b._g(`loot¬=${b.join(",")}&want=&must=${a.join(",")}&final=1`),"si"===this.interface&&(document.querySelector("#loots").style.display="none")}closeBattle(){window._g("fight&a=quit"),"si"===this.interface&&(document.querySelector("#battle").style.display="none")}autoHeal(){if(this.dead)return;const a="ni"===this.interface?window.Engine.hero.d.warrior_stats:window.hero;if(a.hp===a.maxhp)return this.isHealing=!1;this.isHealing=!0;const b=[],c=[];let d=!1;for(const e of this.items){const{stat:f,loc:g,name:h}=e;if("g"===g){const{timelimit:g,lvl:i,leczy:j,fullheal:k}=this.parseItemStat(f);if(g!==void 0&&g.includes(","))continue;if(void 0!==i&&i>a.lvl)continue;j!==void 0&&(j<=a.maxhp-a.hp?c.push(e):d=!0),"Czarna per\u0142a \u017Cycia"===h&&(16e3<=a.peru0142a u017Cycia"===h&&(16e3<=a.maxhp-a.hp?c.push(e):d=!0),k!==void 0&&b.push(e)}}if(0this.parseItemStat(b.stat).leczy-this.parseItemStat(a.stat).leczy);this.useItem(a[0].id,()=>{this.Sleep(100).then(()=>{this.autoHeal()})})}else 0{this.Sleep(100).then(()=>{this.autoHeal()})}):!1==d&&window.message(`Brakuje Ci potek!`);this.isHealing=!1}parseItemStat(a){const b={},c=a.split(";");for(const d of c){const[a,c]=d.split("=");b[a]=c}return b}useItem(a,b){window._g(`moveitem&id=${a}&st=1`,b)}init(){if(this.initTimer(),"none"===this.interface)return this.createTimerOnMainPage();if("ni"===this.interface){const a=window.Storage.prototype.setItem;window.Storage.prototype.setItem=function(b,c){if("Margonem"===b){const a=JSON.parse(c);a.f=0,c=JSON.stringify(a)}a.apply(this,[b,c])}}else window.bB=Function.prototype;this.initBox(),this.initNewNpc(),this.initNewOther(),this.removeLockAdding(),this.initChecker(),this.randomRefresh(),this.initLagRefresher(),this.chatParser()}}})();