Created
March 5, 2019 20:20
-
-
Save d0peCode/32dd1752000b6dc65ed6fa5bb7eabb0d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function goTo(x, y) { | |
let coords = { x, y } | |
searchPath.call(window.hero, coords.x, coords.y); | |
} | |
function searchPath(a,t){ | |
for(var h=[],i=128&hero.opt?8:20,r=Math.max(0,Math.min(a,this.x)-i),s=Math.min(map.x-1,Math.max(a,this.x)+i),o=Math.max(0,Math.min(t,this.y)-i),e=Math.min(map.y-1,Math.max(t,this.y)+i),d=r-1;s+1>=d;d++){h[d]=[];for(var x=o-1;e+1>=x;x++)h[d][x]=!(d>=r&&s>=d&&x>=o&&e>=x)||isset(g.npccol[d+256*x])||map.col&&"0"!=map.col.charAt(d+x*map.x)?-2:-1}h[this.x][this.y]=0,b=-1,road=[];for(var c={x:-1,y:-1,dist:99},y=1;s-r+e-o+3>y;y++)for(var d=r;s>=d;d++)for(var x=o;e>=x;x++){if(-1!=h[d][x]||h[d][x-1]!=y-1&&h[d][x+1]!=y-1&&h[d-1][x]!=y-1&&h[d+1][x]!=y-1||(h[d][x]=y),h[a][t]>0){d=s+1;break}c.dist2=Math.abs(a-d)+Math.abs(t-x),h[d][x]==y&&c.dist2<c.dist&&(c.x=d,c.y=x,c.dist=c.dist2)}if(c.hdist=Math.abs(a-hero.x)+Math.abs(t-hero.y),h[a][t]>0||c.dist<c.hdist){h[a][t]<0&&(a>c.x?b=2:a<c.x?b=1:t>c.y?b=0:t<c.y&&(b=3),a=c.x,t=c.y),road[0]={x:a,y:t};for(var f=h[a][t]-1,l=a,m=t;f>0;f--)h[l][m-1]==f?m--:h[l][m+1]==f?m++:h[l-1][m]==f?l--:h[l+1][m]==f?l++:f=0,f&&(road[h[a][t]-f]={x:l,y:m})}road.length>1&&null==g.playerCatcher.follow&&$("#target").stop().css({left:32*a,top:32*t,display:"block",opacity:1}).fadeOut(1e3) | |
}; | |
goTo(7, 25); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment