mota-js/libs/core.min.js
2017-12-08 14:57:13 +08:00

1 line
59 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

function core(){this.dom={};this.statusBar={};this.canvas={};this.images=[];this.sounds={};this.floorIds=[];this.floors={};this.firstData={};this.material={images:{},sounds:{},ground:null,items:{},enemys:{},icons:{},events:{}};this.timeout={getItemTipTimeout:null};this.interval={twoAnimate:null,fourAnimate:null,boxAnimate:null,heroMoveTriggerInterval:null,heroMoveInterval:null,heroAutoMoveScan:null,tipAnimate:null,openDoorAnimate:null};this.musicStatus={isIOS:false,loaded:false,bgmStatus:false,soundStatus:true,playedSound:null,playedBgm:null,};this.position={gameGroup:{},canvas:{},statusBar:{},toolBar:{},items:{},scale:1,screenMode:"bigScreen",};this.initStatus={played:false,hero:{},floorId:null,thisMap:null,maps:null,heroMoving:false,heroStop:true,lockControl:false,autoHeroMove:false,automaticRouting:false,automaticRouted:false,autoStep:0,movedStep:0,destStep:0,automaticRoutingTemp:{destX:0,destY:0,moveStep:[]},autoStepRoutes:[],holdingPath:0,stepPostfix:[],mouseOutCheck:1,moveStepBeforeStop:[],savePage:null,shops:{},event:{id:null,data:null},openingDoor:null,twoAnimateObjs:[],fourAnimateObjs:[],boxAnimateObjs:[],};this.status={};this.flags={}}core.prototype.init=function(c,i,a,f,h,d,e,b){core.dom=c;core.statusBar=i;core.canvas=a;core.images=f;core.sounds=h;core.floorIds=d;core.floors=e;for(var g in b){core[g]=b[g]}core.flags=core.data.flags;core.values=core.clone(core.data.values);core.firstData=core.data.getFirstData();core.initStatus.shops=core.firstData.shops;core.dom.versionLabel.innerHTML=core.firstData.version;core.dom.logoLabel.innerHTML=core.firstData.title;core.material.items=core.items.getItems();core.initStatus.maps=core.maps.initMaps(d);core.material.enemys=core.clone(core.enemys.getEnemys());core.material.icons=core.icons.getIcons();core.material.events=core.events.getEvents();core.musicStatus.soundStatus=core.getLocalStorage("soundStatus",true);var j=navigator.userAgent;if(j.indexOf("iPhone")>-1||j.indexOf("iPad")>-1){console.log("你的设备为iphone不自动播放音乐");core.musicStatus.isIOS=true;core.musicStatus.soundStatus=false}core.material.ground=new Image();core.material.ground.src="images/ground.png";core.loader(function(){console.log(core.material);core.showStartAnimate()})};core.prototype.showStartAnimate=function(a){core.dom.startPanel.style.opacity=1;core.dom.startPanel.style.display="block";core.dom.startTop.style.opacity=1;core.dom.startTop.style.display="block";core.dom.startButtonGroup.style.display="none";core.dom.startButtons.style.display="block";core.dom.levelChooseButtons.style.display="none";core.status.played=false;core.clearStatus();core.clearMap("all");var b=1;var c=window.setInterval(function(){b-=0.03;if(b<0){clearInterval(c);core.dom.startTop.style.display="none";core.dom.startButtonGroup.style.display="block";if(core.isset(a)){a()}}core.dom.startTop.style.opacity=b},20)};core.prototype.hideStartAnimate=function(a){var b=1;var c=window.setInterval(function(){b-=0.03;if(b<0){clearInterval(c);core.dom.startPanel.style.display="none";if(core.isset(a)){a()}}core.dom.startPanel.style.opacity=b},20)};core.prototype.setStartProgressVal=function(a){core.dom.startTopProgress.style.width=a+"%"};core.prototype.setStartLoadTipText=function(a){core.dom.startTopLoadTips.innerHTML=a};core.prototype.loader=function(c){var f=0,a=0,b=0;a=core.images.length;for(var e in core.sounds){b+=core.sounds[e].length}for(var d=0;d<core.images.length;d++){core.loadImage(core.images[d],function(j,h){core.setStartLoadTipText("正在加载图片 "+j+"...");j=j.split("-");j=j[0];core.material.images[j]=h;f++;core.setStartLoadTipText(j+" 加载完毕...");core.setStartProgressVal(f*(100/a));if(f==a){for(var k in core.sounds){for(var g=0;g<core.sounds[k].length;g++){var m=core.sounds[k][g];m=m.split("-");var l=new Audio();l.preload="none";l.src="sounds/"+m[0]+"."+k;if(m[1]=="loop"){l.loop="loop"}if(!core.isset(core.material.sounds[k])){core.material.sounds[k]={}}core.material.sounds[k][m[0]]=l}}c()}})}};core.prototype.loadImage=function(d,a){try{core.setStartLoadTipText("加载图片 "+d+" 中...");var c=new Image();c.src="images/"+d+".png";if(c.complete){a(d,c);return}c.onload=function(){a(d,c)}}catch(b){alert(b)}};core.prototype.loadSound=function(){if(!core.isset(core.material.sounds.mp3)){return}if(core.musicStatus.isIOS){return}if(core.musicStatus.loaded){return}core.musicStatus.loaded=true;console.log("加载音乐");var c=[];for(var a in core.material.sounds){for(var b in core.material.sounds[a]){c.push(core.material.sounds[a][b])}}core.loadSoundItem(c)};core.prototype.loadSoundItem=function(b){if(b.length==0){if(core.musicStatus.bgmStatus>0){return}core.musicStatus.bgmStatus=1;if(core.musicStatus.soundStatus){core.playBgm("bgm","mp3")}return}var a=b.shift();a.oncanplay=function(){core.loadSoundItem(b)};a.load()};core.prototype.isPlaying=function(){if(core.isset(core.status.played)&&core.status.played){return true}return false};core.prototype.clearStatus=function(){for(var a in core.interval){clearInterval(core.interval[a])}core.status={};core.clearStatusBar();core.resize(main.dom.body.clientWidth,main.dom.body.clientHeight)};core.prototype.resetStatus=function(c,b,a,e){for(var d in core.interval){clearInterval(core.interval[d])}core.status=core.clone(core.initStatus);core.status.played=true;core.status.floorId=a;core.status.maps=core.clone(e);core.material.enemys=core.clone(core.enemys.getEnemys());core.status.hero=core.clone(c);core.status.hard=b;core.status.savePage=core.getLocalStorage("savePage",0);core.resize(main.dom.body.clientWidth,main.dom.body.clientHeight)};core.prototype.startGame=function(b,a){console.log("开始游戏");core.resetStatus(core.firstData.hero,b,core.firstData.floorId,core.initStatus.maps);core.changeFloor(core.status.floorId,null,core.firstData.hero.loc,null,function(){core.setHeroMoveTriggerInterval();if(core.isset(a)){a()}})};core.prototype.restart=function(){core.showStartAnimate()};core.prototype.onkeyDown=function(a){if(!core.isset(core.status.holdingKeys)){core.status.holdingKeys=[]}var c={37:true,38:true,39:true,40:true}[a.keyCode];if(c){for(var b=0;b<core.status.holdingKeys.length;b++){if(core.status.holdingKeys[b]===a.keyCode){return}}core.status.holdingKeys.push(a.keyCode);core.pressKey(a.keyCode)}else{core.keyDown(a.keyCode)}};core.prototype.onkeyUp=function(a){var c={37:true,38:true,39:true,40:true}[a.keyCode];if(c){for(var b=0;b<core.status.holdingKeys.length;b++){if(core.status.holdingKeys[b]===a.keyCode){core.status.holdingKeys=core.status.holdingKeys.slice(0,b).concat(core.status.holdingKeys.slice(b+1));if(b===core.status.holdingKeys.length&&core.status.holdingKeys.length!==0){core.pressKey(core.status.holdingKeys.slice(-1)[0])}break}}core.stopHero()}else{core.keyUp(a.keyCode)}};core.prototype.pressKey=function(a){if(a===core.status.holdingKeys.slice(-1)[0]){core.keyDown(a);window.setTimeout(function(){core.pressKey(a)},30)}};core.prototype.keyDown=function(a){if(!core.status.played){return}if(core.status.automaticRouting||core.status.automaticRouted){core.stopAutomaticRoute()}if(core.status.lockControl){if(core.status.event.id=="book"){if(a==37){core.ui.drawEnemyBook(core.status.event.data-1)}else{if(a==39){core.ui.drawEnemyBook(core.status.event.data+1)}}return}if(core.status.event.id=="fly"){if(a==38){core.ui.drawFly(core.status.event.data+1)}else{if(a==40){core.ui.drawFly(core.status.event.data-1)}}return}if(core.status.event.id=="save"||core.status.event.id=="load"){if(a==37){core.ui.drawSLPanel(core.status.event.data-1)}else{if(a==39){core.ui.drawSLPanel(core.status.event.data+1)}}return}return}switch(a){case 37:core.moveHero("left");break;case 38:core.moveHero("up");break;case 39:core.moveHero("right");break;case 40:core.moveHero("down");break}};core.prototype.keyUp=function(c){if(!core.status.played){return}if(core.status.lockControl){if(core.status.event.id=="book"&&(c==27||c==88)){core.ui.closePanel(true)}if(core.status.event.id=="fly"&&(c==71||c==27)){core.ui.closePanel()}if(core.status.event.id=="fly"&&c==13){var b=core.status.hero.flyRange.indexOf(core.status.floorId);var d=core.status.event.data<b?"upFloor":"downFloor";var a=core.status.event.data;core.ui.closePanel();core.changeFloor(core.status.hero.flyRange[a],d)}if(core.status.event.id=="save"&&(c==83||c==27)){core.ui.closePanel()}if(core.status.event.id=="load"&&(c==76||c==27)){core.ui.closePanel()}if((core.status.event.id=="settings"||core.status.event.id=="selectShop")&&c==27){core.ui.closePanel()}if(core.status.event.id=="selectShop"&&c==75){core.ui.closePanel()}if(core.status.event.id=="shop"&&c==27){core.status.boxAnimateObjs=[];core.setBoxAnimate();if(core.status.event.data.fromList){core.ui.drawQuickShop()}else{core.ui.closePanel()}}if(core.status.event.id=="toolbox"&&(c==84||c==27)){core.ui.closePanel()}if(core.status.event.id=="about"&&(c==13||c==32)){core.ui.closePanel()}if(core.status.event.id=="text"&&(c==13||c==32)){core.drawText()}if(core.status.event.id=="action"&&core.isset(core.status.event.data.current)&&core.status.event.data.type=="text"&&(c==13||c==32)){core.events.doAction()}return}switch(c){case 27:core.ui.drawSettings(true);break;case 71:core.useFly(true);break;case 88:core.openBook(true);break;case 83:core.save(true);break;case 76:core.load(true);break;case 84:core.openToolbox(true);break;case 90:core.turnHero();break;case 75:core.ui.drawQuickShop(true);break;case 37:break;case 38:break;case 39:break;case 40:break}core.stopHero()};core.prototype.ondown=function(b,c){if(!core.status.played||core.status.lockControl){core.onclick(b,c,[]);return}core.status.holdingPath=1;core.status.mouseOutCheck=1;window.setTimeout(core.clearStepPostfix);core.saveCanvas("ui");core.clearMap("ui",0,0,416,416);var a={x:b,y:c};core.status.stepPostfix=[];core.status.stepPostfix.push(a);core.fillPosWithPoint(a)};core.prototype.onmove=function(g,h){if(core.status.holdingPath==0){return}core.status.mouseOutCheck=1;var e={x:g,y:h};var f=core.status.stepPostfix[core.status.stepPostfix.length-1];var a=[e.y-f.y,f.x-e.x,f.y-e.y,e.x-f.x];var d=0,c=4;for(var b=0;b<4;b++){if(a[b]>d){c=b;d=a[b]}}e=[{x:0,y:1},{x:-1,y:0},{x:0,y:-1},{x:1,y:0},false][c];if(e){e.x+=f.x;e.y+=f.y;core.status.stepPostfix.push(e);core.fillPosWithPoint(e)}};core.prototype.onup=function(){core.status.holdingPath=0;if(core.status.stepPostfix.length>0){var g=[];var a={"0":{"1":"down","-1":"up"},"-1":{"0":"left"},"1":{"0":"right"}};for(var b=1;b<core.status.stepPostfix.length;b++){var d=core.status.stepPostfix[b-1];var c=core.status.stepPostfix[b];g.push({direction:a[c.x-d.x][c.y-d.y],x:c.x,y:c.y})}var e=core.status.stepPostfix[0].x;var f=core.status.stepPostfix[0].y;core.status.stepPostfix=[];core.canvas.ui.clearRect(0,0,416,416);core.canvas.ui.restore();core.onclick(e,f,g)}};core.prototype.getClickLoc=function(f,g){if(!core.isset(core.position.canvas.top)){return null}var d={x:0,y:0};var c=32;c=c*core.position.scale;switch(core.position.screenMode){case"vertical":d.x=0;d.y=core.position.statusBar.height+3;break;case"horizontal":d.x=core.position.statusBar.width+3;console.log(core.position.statusBar.width);d.y=0;break;case"bigScreen":d.x=core.position.statusBar.width+3;d.y=0;break}var a=core.dom.gameGroup.offsetLeft+d.x;var e=core.dom.gameGroup.offsetTop+d.y;var b={x:f-a,y:g-e,size:c};return b};core.prototype.onclick=function(b,c,a){if(b<0||c<0||b>12||c>12){return}if(!core.status.lockControl){core.setAutomaticRoute(b,c,a);return}if(core.status.event.id=="book"){core.events.clickBook(b,c);return}if(core.status.event.id=="fly"){core.events.clickFly(b,c);return}if(core.status.event.id=="settings"){core.events.clickSettings(b,c);return}if(core.status.event.id=="shop"){core.events.clickShop(b,c);return}if(core.status.event.id=="selectShop"){core.events.clickSelectShop(b,c);return}if(core.status.event.id=="toolbox"){core.events.clickToolbox(b,c);return}if(core.status.event.id=="save"||core.status.event.id=="load"){core.events.clickSL(b,c);return}if(core.status.event.id=="confirmBox"){if((b==4||b==5)&&c==7&&core.isset(core.status.event.data.yes)){core.status.event.data.yes()}if((b==7||b==8)&&c==7&&core.isset(core.status.event.data.no)){core.status.event.data.no()}return}if(core.status.event.id=="about"){if(core.isPlaying()){core.ui.closePanel(false)}else{core.showStartAnimate()}return}if(core.status.event.id=="action"){core.events.clickAction(b,c);return}if(core.status.event.id=="text"){core.drawText();return}if(core.status.event.id=="syncSave"){if(b>=4&&b<=8){if(c==5){core.ui.drawConfirmBox("你确定要将本地存档同步到服务器吗?",function(){core.ui.drawWaiting("正在同步,请稍后...");var e=new FormData();e.append("type","save");e.append("name",core.firstData.name);var h=[];for(var f=1;f<=180;f++){var d=core.getLocalStorage("save"+f,null);if(core.isset(d)){h.push(d)}}var g=JSON.stringify(h);e.append("data",g);var j=new XMLHttpRequest();j.open("POST","../sync.php");j.timeout=1000;j.onload=function(i){if(j.status==200){var k=JSON.parse(j.response);if(k.code<0){core.drawText("出错啦!\n无法同步存档到服务器。")}else{core.drawText("同步成功!\n\n您的存档编号 "+k.code+"\n您的存档密码 "+k.msg+"\n\n请牢记以上两个信息如截图等在从服务器\n同步存档时使用。")}}else{core.drawText("出错啦!\n无法同步存档到服务器。")}};j.ontimeout=function(i){console.log(i);core.drawText("出错啦!\n无法同步存档到服务器。")};j.onerror=function(i){console.log(i);core.drawText("出错啦!\n无法同步存档到服务器。")};j.send(e)},function(){core.ui.drawSyncSave()})}if(c==6){core.ui.drawConfirmBox("你确定要从服务器加载存档吗?\n该操作将覆盖所有本地存档且不可逆",function(){var e=prompt("请输入存档编号:");if(e==null||e==""){core.ui.drawSyncSave();return}var f=prompt("请输入存档密码:");if(f==null||f==""){core.ui.drawSyncSave();return}core.ui.drawWaiting("正在同步,请稍后...");var d=new FormData();d.append("type","load");d.append("name",core.firstData.name);d.append("id",e);d.append("password",f);var g=new XMLHttpRequest();g.open("POST","../sync.php");g.timeout=1000;g.onload=function(j){if(g.status==200){var l=JSON.parse(g.response);switch(l.code){case 0:var h=JSON.parse(l.msg);for(var k=1;k<=180;k++){if(k<=h.length){core.setLocalStorage("save"+k,h[k-1])}else{core.removeLocalStorage("save"+k)}}core.drawText("同步成功!\n你的本地所有存档均已被覆盖。");break;case -1:core.drawText("出错啦!\n存档编号"+e+"不存在!");break;case -2:core.drawText("出错啦!\n存档密码错误");break;default:core.drawText("出错啦!\n无法从服务器同步存档。");break}}else{core.drawText("出错啦!\n无法从服务器同步存档。")}};g.ontimeout=function(h){console.log(h);core.drawText("出错啦!\n无法从服务器同步存档。")};g.onerror=function(h){console.log(h);core.drawText("出错啦!\n无法从服务器同步存档。")};g.send(d)},function(){core.ui.drawSyncSave()})}}if(b>=5&&b<=7&&c==7){core.ui.drawSettings(false)}}};core.prototype.onmousewheel=function(a){if(core.status.lockControl&&core.status.event.id=="fly"){if(a==-1){core.ui.drawFly(core.status.event.data-1)}if(a==1){core.ui.drawFly(core.status.event.data+1)}return}};core.prototype.clearAutomaticRouteNode=function(a,b){core.canvas.ui.clearRect(a*32+5,b*32+5,27,27)};core.prototype.stopAutomaticRoute=function(){if(!core.status.played){return}core.stopAutoHeroMove();core.status.automaticRouting=false;core.status.automaticRouted=false;core.status.autoStepRoutes=[];core.status.automaticRoutingTemp={destX:0,destY:0,moveStep:[]};if(core.status.moveStepBeforeStop.length==0){core.canvas.ui.clearRect(0,0,416,416)}};core.prototype.continueAutomaticRoute=function(){var a=core.status.moveStepBeforeStop;core.status.moveStepBeforeStop=[];if(a.length===0){return}if(a.length===1&&a[0].step===1){return}core.status.automaticRouting=true;core.setAutoHeroMove(a)};core.prototype.clearContinueAutomaticRoute=function(){core.canvas.ui.clearRect(0,0,416,416);core.status.moveStepBeforeStop=[]};core.prototype.setAutomaticRoute=function(a,b,f){if(!core.status.played||core.status.lockControl){return}else{if(core.status.automaticRouting){core.stopAutomaticRoute();return}}if(a==core.status.hero.loc.x&&b==core.status.hero.loc.y&&f.length==0){core.turnHero();return}var e=0;var g=null;var d;core.status.automaticRoutingTemp={destX:0,destY:0,moveStep:[]};if(!(d=core.automaticRoute(a,b))){if(a==core.status.hero.loc.x&&b==core.status.hero.loc.y){d=[]}else{core.canvas.ui.clearRect(0,0,416,416);return}}d=d.concat(f);core.status.automaticRoutingTemp.destX=a;core.status.automaticRoutingTemp.destY=b;core.canvas.ui.save();core.canvas.ui.clearRect(0,0,416,416);core.canvas.ui.fillStyle="#bfbfbf";core.canvas.ui.strokeStyle="#bfbfbf";core.canvas.ui.lineWidth=8;for(var c=0;c<d.length;c++){if(g==null){e++;g=d[c].direction}else{if(g==d[c].direction){e++}else{core.status.automaticRoutingTemp.moveStep.push({direction:g,step:e});e=1;g=d[c].direction}}if(c==d.length-1){core.status.automaticRoutingTemp.moveStep.push({direction:g,step:e});core.canvas.ui.fillRect(d[c].x*32+10,d[c].y*32+10,12,12)}else{core.canvas.ui.beginPath();if(core.isset(d[c+1])&&g!=d[c+1].direction){if(g=="up"&&d[c+1].direction=="left"||g=="right"&&d[c+1].direction=="down"){core.canvas.ui.moveTo(d[c].x*32+5,d[c].y*32+16);core.canvas.ui.lineTo(d[c].x*32+16,d[c].y*32+16);core.canvas.ui.lineTo(d[c].x*32+16,d[c].y*32+27)}else{if(g=="up"&&d[c+1].direction=="right"||g=="left"&&d[c+1].direction=="down"){core.canvas.ui.moveTo(d[c].x*32+27,d[c].y*32+16);core.canvas.ui.lineTo(d[c].x*32+16,d[c].y*32+16);core.canvas.ui.lineTo(d[c].x*32+16,d[c].y*32+27)}else{if(g=="left"&&d[c+1].direction=="up"||g=="down"&&d[c+1].direction=="right"){core.canvas.ui.moveTo(d[c].x*32+27,d[c].y*32+16);core.canvas.ui.lineTo(d[c].x*32+16,d[c].y*32+16);core.canvas.ui.lineTo(d[c].x*32+16,d[c].y*32+5)}else{if(g=="right"&&d[c+1].direction=="up"||g=="down"&&d[c+1].direction=="left"){core.canvas.ui.moveTo(d[c].x*32+5,d[c].y*32+16);core.canvas.ui.lineTo(d[c].x*32+16,d[c].y*32+16);core.canvas.ui.lineTo(d[c].x*32+16,d[c].y*32+5)}}}}core.canvas.ui.stroke();continue}switch(g){case"up":case"down":core.canvas.ui.beginPath();core.canvas.ui.moveTo(d[c].x*32+16,d[c].y*32+5);core.canvas.ui.lineTo(d[c].x*32+16,d[c].y*32+27);core.canvas.ui.stroke();break;case"left":case"right":core.canvas.ui.beginPath();core.canvas.ui.moveTo(d[c].x*32+5,d[c].y*32+16);core.canvas.ui.lineTo(d[c].x*32+27,d[c].y*32+16);core.canvas.ui.stroke();break}}}core.canvas.ui.restore();core.status.automaticRouted=true;core.status.automaticRouting=true;core.setAutoHeroMove(core.status.automaticRoutingTemp.moveStep);core.status.automaticRoutingTemp={destX:0,destY:0,moveStep:[]}};core.prototype.automaticRoute=function(e,g){var u=core.getHeroLoc("x");var v=core.getHeroLoc("y");var t={up:{x:0,y:-1},left:{x:-1,y:0},down:{x:0,y:1},right:{x:1,y:0}};var r=[];var m=0;var s=[];var a=[];if(e==u&&g==v){return false}r.push(13*u+v);r.push(-1);s[13*u+v]="";while(r.length!=1){var j=r.shift();if(j===-1){m+=1;r.push(-1);continue}var c=~~(j/169);if(c!==m){r.push(j);continue}j=j%169;var n=parseInt(j/13),o=j%13;for(var i in t){var p=n+t[i].x;var q=o+t[i].y;if(p<0||p>12||q<0||q>12){continue}var l=13*p+q;if(core.isset(s[l])){continue}if(p==e&&q==g){s[l]=i;break}if(core.noPassExists(p,q)){continue}var d=1;var b=core.getBlock(p,q);if(b!=null){var k=b.block.event.id;if(k.substring(k.length-3)=="Net"){d=100}if(!core.flags.potionWhileRouting&&k.substring(k.length-6)=="Potion"){d=20}if(b.block.event.trigger=="checkBlock"){d=200}}s[l]=i;r.push(169*(m+d)+l)}if(core.isset(s[13*e+g])){break}}if(!core.isset(s[13*e+g])){return false}var n=e,o=g;while(n!=u||o!=v){var h=s[13*n+o];a.push({direction:h,x:n,y:o});n-=t[h].x;o-=t[h].y}a.reverse();return a};core.prototype.fillPosWithPoint=function(a){core.fillRect("ui",a.x*32+12,a.y*32+12,8,8,"#bfbfbf")};core.prototype.clearStepPostfix=function(){if(core.status.mouseOutCheck>0){core.status.mouseOutCheck--;window.setTimeout(core.clearStepPostfix,1000);return}core.status.holdingPath=0;if(core.status.stepPostfix.length>0){core.status.stepPostfix=[];core.canvas.ui.clearRect(0,0,416,416);core.canvas.ui.restore()}};core.prototype.stopAutoHeroMove=function(){core.status.autoHeroMove=false;core.status.automaticRouting=false;core.status.automaticRouted=false;core.status.autoStep=0;core.status.destStep=0;core.status.movedStep=0;core.status.autoStepRoutes=[];core.stopHero();clearInterval(core.interval.heroAutoMoveScan)};core.prototype.setAutoHeroMove=function(b,a){if(b.length==0){return}core.status.autoStepRoutes=b;core.status.autoStep=0;clearInterval(core.interval.heroAutoMoveScan);core.interval.heroAutoMoveScan=window.setInterval(function(){if(!core.status.autoHeroMove){if(core.status.autoStep==core.status.autoStepRoutes.length){core.stopAutoHeroMove();return}core.autoHeroMove(core.status.autoStepRoutes[core.status.autoStep].direction,core.status.autoStepRoutes[core.status.autoStep].step);core.status.autoStep++}},80)};core.prototype.autoHeroMove=function(a,b){core.status.autoHeroMove=true;core.status.destStep=b;core.moveHero(a)};core.prototype.setHeroMoveInterval=function(b,d,e,a){if(core.status.heroMoving){return}core.status.heroMoving=true;var c=0;core.interval.heroMoveInterval=window.setInterval(function(){switch(b){case"up":c-=4;if(c==-4||c==-8||c==-12||c==-16){core.drawHero(b,d,e,"leftFoot",0,c)}else{if(c==-20||c==-24||c==-28||c==-32){core.drawHero(b,d,e,"rightFoot",0,c)}}if(c==-32){core.setHeroLoc("y","--");core.moveOneStep();if(core.status.heroStop){core.drawHero(b,d,e-1,"stop")}if(core.isset(a)){a()}}break;case"left":c-=4;if(c==-4||c==-8||c==-12||c==-16){core.drawHero(b,d,e,"leftFoot",c)}else{if(c==-20||c==-24||c==-28||c==-32){core.drawHero(b,d,e,"rightFoot",c)}}if(c==-32){core.setHeroLoc("x","--");core.moveOneStep();if(core.status.heroStop){core.drawHero(b,d-1,e,"stop")}if(core.isset(a)){a()}}break;case"down":c+=4;if(c==4||c==8||c==12||c==16){core.drawHero(b,d,e,"leftFoot",0,c)}else{if(c==20||c==24||c==28||c==32){core.drawHero(b,d,e,"rightFoot",0,c)}}if(c==32){core.setHeroLoc("y","++");core.moveOneStep();if(core.status.heroStop){core.drawHero(b,d,e+1,"stop")}if(core.isset(a)){a()}}break;case"right":c+=4;if(c==4||c==8||c==12||c==16){core.drawHero(b,d,e,"leftFoot",c)}else{if(c==20||c==24||c==28||c==32){core.drawHero(b,d,e,"rightFoot",c)}}if(c==32){core.setHeroLoc("x","++");core.moveOneStep();if(core.status.heroStop){core.drawHero(b,d+1,e,"stop")}if(core.isset(a)){a()}}break}},10)};core.prototype.setHeroMoveTriggerInterval=function(){var a,c,d;var b={up:{x:0,y:-1},left:{x:-1,y:0},down:{x:0,y:1},right:{x:1,y:0}};core.interval.heroMoveTriggerInterval=window.setInterval(function(){if(!core.status.heroStop){a=core.getHeroLoc("direction");c=core.getHeroLoc("x");d=core.getHeroLoc("y");var e;e=core.noPass(c+b[a].x,d+b[a].y);if(e){core.trigger(c+b[a].x,d+b[a].y);core.drawHero(a,c,d,"stop");if(core.status.autoHeroMove){core.status.movedStep++;if(core.status.destStep==core.status.movedStep){core.status.autoHeroMove=false;core.status.destStep=0;core.status.movedStep=0;core.status.moveStepBeforeStop=[];core.stopAutomaticRoute()}}else{core.status.heroStop=true}return}core.setHeroMoveInterval(a,c,d,function(){if(core.status.autoHeroMove){core.status.movedStep++;if(core.status.destStep==core.status.movedStep){core.status.autoHeroMove=false;core.status.destStep=0;core.status.movedStep=0;core.stopHero();core.drawHero(core.getHeroLoc("direction"),core.getHeroLoc("x"),core.getHeroLoc("y"),"stop")}}else{if(core.status.heroStop){core.drawHero(core.getHeroLoc("direction"),core.getHeroLoc("x"),core.getHeroLoc("y"),"stop")}}core.trigger(core.getHeroLoc("x"),core.getHeroLoc("y"));clearInterval(core.interval.heroMoveInterval);core.status.heroMoving=false})}},50)};core.prototype.turnHero=function(a){if(core.isset(a)){core.status.hero.loc.direction=a}else{if(core.status.hero.loc.direction=="up"){core.status.hero.loc.direction="right"}else{if(core.status.hero.loc.direction=="right"){core.status.hero.loc.direction="down"}else{if(core.status.hero.loc.direction=="down"){core.status.hero.loc.direction="left"}else{if(core.status.hero.loc.direction=="left"){core.status.hero.loc.direction="up"}}}}}core.drawHero(core.status.hero.loc.direction,core.status.hero.loc.x,core.status.hero.loc.y,"stop",0,0);core.status.automaticRoutingTemp={destX:0,destY:0,moveStep:[]};core.canvas.ui.clearRect(0,0,416,416)};core.prototype.moveHero=function(a){core.setHeroLoc("direction",a);core.status.heroStop=false};core.prototype.moveOneStep=function(){if(core.hasFlag("poison")){core.status.hero.hp-=core.values.poisonDamage;if(core.status.hero.hp<=0){core.status.hero.hp=0;core.updateStatusBar();core.events.lose("poison");return}core.updateStatusBar()}};core.prototype.waitHeroToStop=function(a){core.stopAutomaticRoute();core.clearContinueAutomaticRoute();if(core.isset(a)){core.lockControl();setTimeout(function(){core.drawHero(core.getHeroLoc("direction"),core.getHeroLoc("x"),core.getHeroLoc("y"),"stop");a()},30)}};core.prototype.stopHero=function(){core.status.heroStop=true};core.prototype.drawHero=function(a,f,g,e,c,d){c=c||0;d=d||0;core.clearAutomaticRouteNode(f,g);var b=core.material.icons.heros[core.status.hero.id][a];f=f*32;g=g*32;core.canvas.hero.clearRect(f-32,g-32,96,96);core.canvas.hero.drawImage(core.material.images.heros,b[e]*32,b.loc*32,32,32,f+c,g+d,32,32)};core.prototype.openDoor=function(d,i,j,f,a){if(!core.terrainExists(i,j,d)){if(core.isset(a)){a()}return}if(core.status.moveStepBeforeStop.length==0){core.status.moveStepBeforeStop=core.status.autoStepRoutes.slice(core.status.autoStep-1,core.status.autoStepRoutes.length);if(core.status.moveStepBeforeStop.length>=1){core.status.moveStepBeforeStop[0].step-=core.status.movedStep}}core.stopHero();core.stopAutomaticRoute();var g=30;if(f){var e=d.replace("Door","Key");if(!core.rmItem(e)){if(e!="specialKey"){core.drawTip("你没有"+core.material.items[e].name)}else{core.drawTip("无法开启此门")}core.clearContinueAutomaticRoute();if(core.isset(a)){a()}return}}core.playSound("door","ogg");var h=0;var c=d;if(!(c.substring(c.length-4)=="Door")){c=c+"Door";g=100}var b=core.material.icons.animates[c];core.interval.openDoorAnimate=window.setInterval(function(){h++;if(h==4){clearInterval(core.interval.openDoorAnimate);core.removeBlock(i,j);core.events.afterOpenDoor(d,i,j,a);return}core.canvas.event.clearRect(32*i,32*j,32,32);core.canvas.event.drawImage(core.material.images.animates,32*h,32*b,32,32,32*i,32*j,32,32)},g)};core.prototype.battle=function(f,h,i,d,a){if(core.status.moveStepBeforeStop.length==0){core.status.moveStepBeforeStop=core.status.autoStepRoutes.slice(core.status.autoStep-1,core.status.autoStepRoutes.length);if(core.status.moveStepBeforeStop.length>=1){core.status.moveStepBeforeStop[0].step-=core.status.movedStep}}core.stopHero();core.stopAutomaticRoute();var b=core.enemys.getDamage(f);if(b>=core.status.hero.hp&&!d){core.drawTip("你打不过此怪物!");core.clearContinueAutomaticRoute();return}core.playSound("attack","ogg");core.status.hero.hp-=b;if(core.status.hero.hp<=0){core.status.hero.hp=0;core.updateStatusBar();core.events.lose("battle");return}var g=core.material.enemys[f].money;if(core.hasItem("coin")){g*=2}if(core.hasFlag("curse")){g=0}core.status.hero.money+=g;var c=core.material.enemys[f].experience;if(core.hasFlag("curse")){c=0}core.status.hero.experience+=c;core.updateStatusBar();if(core.isset(h)&&core.isset(i)){core.removeBlock(h,i);core.canvas.event.clearRect(32*h,32*i,32,32)}core.updateFg();var e="打败 "+core.material.enemys[f].name+",金币+"+g;if(core.flags.enableExperience){e+=",经验+"+core.material.enemys[f].experience}core.drawTip(e);core.events.afterBattle(f,h,i,a)};core.prototype.changeFloor=function(c,f,d,g,b){g=g||50;core.lockControl();core.stopHero();core.stopAutomaticRoute();core.clearContinueAutomaticRoute();core.dom.floorNameLabel.innerHTML=core.status.maps[c].title;if(core.isset(f)){d=core.status.hero.loc;var a=core.status.maps[c].blocks;for(var e in a){if(core.isset(a[e].event)&&!(core.isset(a[e].enable)&&!a[e].enable)&&a[e].event.id===f){d.x=a[e].x;d.y=a[e].y}}}if(core.status.maps[c].canFlyTo&&core.status.hero.flyRange.indexOf(c)<0){if(core.floorIds.indexOf(c)>core.floorIds.indexOf(core.status.floorId)){core.status.hero.flyRange.push(c)}else{core.status.hero.flyRange.unshift(c)}}window.setTimeout(function(){core.playSound("floor","mp3");core.mapChangeAnimate("show",g/2,function(){core.statusBar.floor.innerHTML=core.status.maps[c].name;core.updateStatusBar();core.drawMap(c,function(){setTimeout(function(){core.mapChangeAnimate("hide",g/4,function(){core.unLockControl();core.events.afterChangeFloor(c);if(core.isset(b)){b()}});if(core.isset(d.direction)){core.setHeroLoc("direction",d.direction)}core.setHeroLoc("x",d.x);core.setHeroLoc("y",d.y);core.drawHero(core.getHeroLoc("direction"),core.getHeroLoc("x"),core.getHeroLoc("y"),"stop");core.updateFg()},15)})})},50)};core.prototype.mapChangeAnimate=function(b,c,a){if(b=="show"){core.show(core.dom.floorMsgGroup,c,function(){a()})}else{core.hide(core.dom.floorMsgGroup,c,function(){a()})}};core.prototype.clearMap=function(c,e,f,d,a){if(c=="all"){for(var b in core.canvas){core.canvas[b].clearRect(0,0,416,416)}}else{core.canvas[c].clearRect(e,f,d,a)}};core.prototype.fillText=function(b,d,e,f,c,a){if(core.isset(c)){core.setFillStyle(b,c)}if(core.isset(a)){core.setFont(b,a)}core.canvas[b].fillText(d,e,f)};core.prototype.fillRect=function(b,e,f,d,a,c){if(core.isset(c)){core.setFillStyle(b,c)}core.canvas[b].fillRect(e,f,d,a)};core.prototype.strokeRect=function(c,f,g,e,a,d,b){if(core.isset(d)){core.setStrokeStyle(c,d)}if(core.isset(b)){core.setLineWidth(c,b)}core.canvas[c].strokeRect(f,g,e,a)};core.prototype.setFont=function(b,a){core.canvas[b].font=a};core.prototype.setLineWidth=function(c,a){if(c=="all"){for(var b in core.canvas){core.canvas[b].lineWidth=a}}core.canvas[c].lineWidth=a};core.prototype.saveCanvas=function(a){core.canvas[a].save()};core.prototype.loadCanvas=function(a){core.canvas[a].restore()};core.prototype.setAlpha=function(c,a){if(c=="all"){for(var b in core.canvas){core.canvas[b].globalAlpha=a}}core.canvas[c].globalAlpha=a};core.prototype.setStrokeStyle=function(b,c){if(b=="all"){for(var a in core.canvas){core.canvas[a].strokeStyle=c}}else{core.canvas[b].strokeStyle=c}};core.prototype.setAlpha=function(c,a){if(c=="all"){for(var b in core.canvas){core.canvas[b].globalAlpha=a}}else{core.canvas[c].globalAlpha=a}};core.prototype.setOpacity=function(b,c){if(b=="all"){for(var a in core.canvas){core.canvas[a].canvas.style.opacity=c}}else{core.canvas[b].canvas.style.opacity=c}};core.prototype.setFillStyle=function(b,c){if(b=="all"){for(var a in core.canvas){core.canvas[a].fillStyle=c}}else{core.canvas[b].fillStyle=c}};core.prototype.drawMap=function(h,e){var g=core.status.maps[h];var f=g.blocks;core.status.floorId=h;core.status.thisMap=g;var c,d;core.clearMap("all");core.rmGlobalAnimate(null,null,true);for(var i=0;i<13;i++){for(var j=0;j<13;j++){c=core.material.icons.terrains.ground;d=core.material.images.terrains;core.canvas.bg.drawImage(d,0,c*32,32,32,i*32,j*32,32,32)}}for(var a=0;a<f.length;a++){if(core.isset(f[a].event)&&!(core.isset(f[a].enable)&&!f[a].enable)){c=core.material.icons[f[a].event.cls][f[a].event.id];d=core.material.images[f[a].event.cls];core.canvas.event.drawImage(core.material.images[f[a].event.cls],0,c*32,32,32,f[a].x*32,f[a].y*32,32,32);core.addGlobalAnimate(f[a].event.animate,f[a].x*32,f[a].y*32,c,d)}}core.setGlobalAnimate(core.values.animateSpeed);if(core.isset(e)){e()}};core.prototype.noPassExists=function(c,d,b){var a=core.getBlock(c,d,b);if(a==null){return false}return core.isset(a.block.event.noPass)&&a.block.event.noPass};core.prototype.npcExists=function(c,d,b){var a=core.getBlock(c,d,b);if(a==null){return false}return a.block.event.cls=="npcs"};core.prototype.terrainExists=function(d,e,c,b){var a=core.getBlock(d,e,b);if(a==null){return false}return a.block.event.cls=="terrains"&&a.block.event.id==c};core.prototype.stairExists=function(c,d,b){var a=core.getBlock(c,d,b);if(a==null){return false}return a.block.event.cls=="terrains"&&(a.block.event.id=="upFloor"||a.block.event.id=="downFloor")};core.prototype.nearStair=function(){var a=core.getHeroLoc("x"),b=core.getHeroLoc("y");return core.stairExists(a,b)||core.stairExists(a-1,b)||core.stairExists(a,b-1)||core.stairExists(a+1,b)||core.stairExists(a,b+1)};core.prototype.enemyExists=function(d,e,c,b){var a=core.getBlock(d,e,b);if(a==null){return false}return a.block.event.cls=="enemys"&&a.block.event.id==c};core.prototype.getBlock=function(e,f,b,d){if(!core.isset(b)){b=core.status.floorId}if(!core.isset(d)){d=true}var a=core.status.maps[b].blocks;for(var c=0;c<a.length;c++){if(a[c].x==e&&a[c].y==f&&core.isset(a[c].event)){if(d&&core.isset(a[c].enable)&&!a[c].enable){return null}return{index:c,block:a[c]}}}return null};core.prototype.removeBlockById=function(d,c){var a=core.status.maps[c].blocks;var e=a[d].x,f=a[d].y;if(core.floors[c].checkBlock.indexOf(e+","+f)>=0){a[d]={x:e,y:f,event:{cls:"terrains",id:"ground",noPass:false,trigger:"checkBlock"}};return}var b=core.floors[c].events[e+","+f];if(!core.isset(b)){b=core.floors[c].changeFloor[e+","+f]}if(!core.isset(b)){a.splice(d,1);return}a[d].enable=false};core.prototype.moveBlock=function(m,n,k,l,d,c){l=l||500;clearInterval(core.interval.tipAnimate);core.saveCanvas("data");core.clearMap("data",0,0,416,416);var b=core.getBlock(m,n,core.status.floorId,false);if(b==null){if(core.isset(c)){c()}return}core.removeBlock(m,n);core.clearMap("ui",0,0,416,416);core.setAlpha("ui",1);b=b.block;blockIcon=core.material.icons[b.event.cls][b.event.id];blockImage=core.material.images[b.event.cls];var h=1;core.setOpacity("data",h);core.canvas.data.drawImage(blockImage,0,blockIcon*32,32,32,b.x*32,b.y*32,32,32);var e=[];k.forEach(function(o){if(typeof o=="string"){e.push(o)}else{if(!core.isset(o.value)){e.push(o.direction)}else{for(var p=0;p<o.value;p++){e.push(o.direction)}}}});var f=32*m,g=32*n,j=0;var i={up:{x:0,y:-1},left:{x:-1,y:0},down:{x:0,y:1},right:{x:1,y:0}};var a=window.setInterval(function(){if(e.length==0){if(d){h=0}else{h-=0.06}core.setOpacity("data",h);core.clearMap("data",f,g,32,32);core.canvas.data.drawImage(blockImage,0,blockIcon*32,32,32,f,g,32,32);if(h<=0){clearInterval(a);core.loadCanvas("data");core.clearMap("data",0,0,416,416);core.setOpacity("data",1);if(core.isset(c)){c()}}}else{j++;f+=i[e[0]].x*2;g+=i[e[0]].y*2;core.clearMap("data",f-32,g-32,96,96);core.canvas.data.drawImage(blockImage,0,blockIcon*32,32,32,f,g,32,32);if(j==16){j=0;e.shift()}}},l/16)};core.prototype.animateBlock=function(g,h,f,e,c){if(f!="hide"){f="show"}clearInterval(core.interval.tipAnimate);core.saveCanvas("data");core.clearMap("data",0,0,416,416);var b=core.getBlock(g,h,core.status.floorId,false);if(b==null){if(core.isset(c)){c()}return}core.clearMap("ui",0,0,416,416);core.setAlpha("ui",1);b=b.block;blockIcon=core.material.icons[b.event.cls][b.event.id];blockImage=core.material.images[b.event.cls];var d=0;if(f=="hide"){d=1}core.setOpacity("data",d);core.canvas.data.drawImage(blockImage,0,blockIcon*32,32,32,b.x*32,b.y*32,32,32);var a=window.setInterval(function(){if(f=="show"){d+=0.1}else{d-=0.1}core.setOpacity("data",d);core.clearMap("data",b.x*32,b.y*32,32,32);core.canvas.data.drawImage(blockImage,0,blockIcon*32,32,32,b.x*32,b.y*32,32,32);if(d>=1||d<=0){clearInterval(a);core.loadCanvas("data");core.clearMap("data",0,0,416,416);core.setOpacity("data",1);if(core.isset(c)){c()}}},e/10)};core.prototype.addBlock=function(c,d,b){b=b||core.status.floorId;var a=core.getBlock(c,d,b,false);if(a==null){return}a=a.block;if(core.isset(a.enable)&&!a.enable){a.enable=true;if(b==core.status.floorId&&core.isset(a.event)){blockIcon=core.material.icons[a.event.cls][a.event.id];blockImage=core.material.images[a.event.cls];core.canvas.event.drawImage(core.material.images[a.event.cls],0,blockIcon*32,32,32,a.x*32,a.y*32,32,32);core.addGlobalAnimate(a.event.animate,a.x*32,a.y*32,blockIcon,blockImage);core.setGlobalAnimate(core.values.animateSpeed)}}};core.prototype.removeBlock=function(d,e,b){b=b||core.status.floorId;var a=core.getBlock(d,e,b,false);if(a==null){return}var c=a.index;if(b==core.status.floorId){core.rmGlobalAnimate(d,e);core.canvas.event.clearRect(d*32,e*32,32,32)}core.removeBlockById(c,b);core.updateFg()};core.prototype.removeBlockByIds=function(a,b){b.sort(function(c,d){return d-c}).forEach(function(c){core.removeBlockById(c,a)})};core.prototype.noPass=function(a,b){return a<0||a>12||b<0||b>12||core.noPassExists(a,b)};core.prototype.trigger=function(g,h){var d=core.status.thisMap.blocks;var e;for(var a=0;a<d.length;a++){if(d[a].x==g&&d[a].y==h&&!(core.isset(d[a].enable)&&!d[a].enable)){e=d[a].event&&d[a].event.noPass;if(e){core.clearAutomaticRouteNode(g,h)}if(core.isset(d[a].event)&&core.isset(d[a].event.trigger)){var f=d[a].event.trigger;if(f=="changeFloor"&&(core.status.autoHeroMove||core.status.autoStep<core.status.autoStepRoutes.length)){var c=core.flags.portalWithoutTrigger;if(core.isset(d[a].event.data)&&core.isset(d[a].event.data.portalWithoutTrigger)){c=d[a].event.data.portalWithoutTrigger}if(c){continue}}core.material.events[f](d[a],core,function(b){})}}}};core.prototype.addGlobalAnimate=function(a,d,e,c,b){if(a==2){core.status.twoAnimateObjs.push({x:d,y:e,status:0,loc:c,image:b})}else{if(a==4){core.status.fourAnimateObjs.push({x:d,y:e,status:0,loc:c,image:b})}}};core.prototype.rmGlobalAnimate=function(d,e,a){if(a==true){core.status.twoAnimateObjs=[];core.status.fourAnimateObjs=[]}for(var c=0;c<core.status.twoAnimateObjs.length;c++){if(core.status.twoAnimateObjs[c].x==d*32&&core.status.twoAnimateObjs[c].y==e*32){core.status.twoAnimateObjs.splice(c,1);return}}for(var b=0;b<core.status.fourAnimateObjs.length;b++){if(core.status.fourAnimateObjs[b].x==d*32&&core.status.fourAnimateObjs[b].y==e*32){core.status.fourAnimateObjs.splice(b,1);return}}};core.prototype.setGlobalAnimate=function(b){clearInterval(core.interval.twoAnimate);clearInterval(core.interval.fourAnimate);var a=false;core.interval.twoAnimate=window.setInterval(function(){for(var c=0;c<core.status.twoAnimateObjs.length;c++){var d=core.status.twoAnimateObjs[c];d.status=(d.status+1)%2;core.canvas.event.clearRect(d.x,d.y,32,32);if(!a){core.canvas.event.drawImage(d.image,d.status*32,d.loc*32,32,32,d.x,d.y,32,32)}a=false}},b);core.interval.fourAnimate=window.setInterval(function(){for(var c=0;c<core.status.fourAnimateObjs.length;c++){var d=core.status.fourAnimateObjs[c];d.status=(d.status+1)%4;core.canvas.event.clearRect(d.x,d.y,32,32);if(!a){core.canvas.event.drawImage(d.image,d.status*32,d.loc*32,32,32,d.x,d.y,32,32)}a=false}},b/2)};core.prototype.setBoxAnimate=function(){clearInterval(core.interval.boxAnimate);if(core.status.boxAnimateObjs.length>0){var a=core.canvas.ui.createPattern(core.material.ground,"repeat");core.drawBoxAnimate(a);core.interval.boxAnimate=setInterval(function(){core.drawBoxAnimate(a)},core.values.animateSpeed)}};core.prototype.drawBoxAnimate=function(c){for(var b=0;b<core.status.boxAnimateObjs.length;b++){var d=core.status.boxAnimateObjs[b];d.status=d.status==0?1:0;core.clearMap("ui",d.bgx,d.bgy,d.bgsize,d.bgsize);core.fillRect("ui",d.bgx,d.bgy,d.bgsize,d.bgsize,c);core.canvas.ui.drawImage(d.image,d.status*32,d.icon*32,32,32,d.x,d.y,32,32)}};core.prototype.setHeroLoc=function(a,b){if(b=="++"){core.status.hero.loc[a]++;return}else{if(b=="--"){core.status.hero.loc[a]--;return}}core.status.hero.loc[a]=b};core.prototype.getHeroLoc=function(a){return core.status.hero.loc[a]};core.prototype.nextX=function(){var a={up:{x:0,y:-1},left:{x:-1,y:0},down:{x:0,y:1},right:{x:1,y:0}};return core.getHeroLoc("x")+a[core.getHeroLoc("direction")].x};core.prototype.nextY=function(){var a={up:{x:0,y:-1},left:{x:-1,y:0},down:{x:0,y:1},right:{x:1,y:0}};return core.getHeroLoc("y")+a[core.getHeroLoc("direction")].y};core.prototype.updateFg=function(){if(!core.isset(core.status.thisMap)||!core.isset(core.status.thisMap.blocks)){return}var g=core.status.thisMap.blocks;core.clearMap("fg",0,0,416,416);if(!core.hasItem("book")){return}core.setFont("fg","bold 11px Arial");var e=core.status.hero.hp;for(var a=0;a<g.length;a++){var h=g[a].x,i=g[a].y;if(core.isset(g[a].event)&&g[a].event.cls=="enemys"&&g[a].event.trigger=="battle"&&!(core.isset(g[a].enable)&&!g[a].enable)){var f=g[a].event.id;var d=core.enemys.getDamage(f);var c="#000000";if(d<=0){c="#00FF00"}else{if(d<e/3){c="#FFFFFF"}else{if(d<e*2/3){c="#FFFF00"}else{if(d<e){c="#FF7F00"}else{c="#FF0000"}}}}if(d>=999999999){d="???"}else{if(d>100000){d=(d/10000).toFixed(1)+"w"}}core.setFillStyle("fg","#000000");core.canvas.fg.fillText(d,32*h+2,32*(i+1)-2);core.canvas.fg.fillText(d,32*h,32*(i+1)-2);core.canvas.fg.fillText(d,32*h+2,32*(i+1));core.canvas.fg.fillText(d,32*h,32*(i+1));core.setFillStyle("fg",c);core.canvas.fg.fillText(d,32*h+1,32*(i+1)-1)}}};core.prototype.itemCount=function(b){if(!core.isset(b)||!core.isset(core.material.items[b])){return 0}var a=core.material.items[b].cls;if(a=="items"){return 0}return core.isset(core.status.hero.items[a][b])?core.status.hero.items[a][b]:0};core.prototype.hasItem=function(a){return core.itemCount(a)>0};core.prototype.setItem=function(b,c){var a=core.material.items[b].cls;if(a=="items"){return}if(!core.isset(core.status.hero.items[a])){core.status.hero.items[a]={}}core.status.hero.items[a][b]=c};core.prototype.rmItem=function(b){if(!core.hasItem(b)){return false}var a=core.material.items[b].cls;core.status.hero.items[a][b]--;core.updateStatusBar();if(a=="tools"&&core.status.hero.items[a][b]==0){delete core.status.hero.items[a][b]}return true};core.prototype.useItem=function(a){core.items.useItem(a);return};core.prototype.canUseItem=function(a){return core.items.canUseItem(a)};core.prototype.addItem=function(c,d){var b=core.material.items[c];var a=b.cls;if(a=="items"){return}if(!core.isset(core.status.hero.items[a])){core.status.hero.items[a]={};core.status.hero.items[a][c]=0}else{if(!core.isset(core.status.hero.items[a][c])){core.status.hero.items[a][c]=0}}core.status.hero.items[a][c]+=d};core.prototype.getItem=function(d,e,f,g,a){core.playSound("item","ogg");var c=core.material.items[d].cls;core.items.getItemEffect(d,e);core.removeBlock(f,g);var h="获得 "+core.material.items[d].name;if(e>1){h+="x"+e}if(c==="items"){h+=core.items.getItemEffectTip(d)}core.drawTip(h,core.material.icons.items[d]);core.canvas.event.clearRect(f*32,g*32,32,32);core.updateStatusBar();var b=core.floors[core.status.floorId].afterGetItem[f+","+g];if(core.isset(b)){core.events.doEvents(b,f,g,a)}else{if(core.isset(a)){a()}}};core.prototype.drawTip=function(e,c){var f,g,h,a,b=false,d=0;clearInterval(core.interval.tipAnimate);core.setFont("data","16px Arial");core.saveCanvas("data");core.setOpacity("data",0);if(!core.isset(c)){f=16;g=18;h=f+core.canvas.data.measureText(e).width+16;a=42}else{f=44;g=18;h=f+core.canvas.data.measureText(e).width+8;a=42}core.interval.tipAnimate=window.setInterval(function(){if(b){d-=0.1}else{d+=0.1}core.setOpacity("data",d);core.clearMap("data",5,5,400,a);core.fillRect("data",5,5,h,a,"#000");if(core.isset(c)){core.canvas.data.drawImage(core.material.images.items,0,c*32,32,32,10,8,32,32)}core.fillText("data",e,f+5,g+15,"#fff");if(d>0.6||d<0){if(b){core.loadCanvas("data");core.clearMap("data",5,5,400,a);core.setOpacity("data",1);clearInterval(core.interval.tipAnimate);return}else{if(!core.timeout.getItemTipTimeout){core.timeout.getItemTipTimeout=window.setTimeout(function(){b=true;core.timeout.getItemTipTimeout=null},750)}d=0.6;core.setOpacity("data",d)}}},30)};core.prototype.drawText=function(b,a){if(core.isset(b)){if(typeof b=="string"){b=[{content:b}]}else{if(b instanceof Object&&core.isset(b.content)){b=[b]}else{if(!(b instanceof Array)){core.drawTip("出错了");console.log(b);return}}}core.status.event={id:"text",data:{list:b,callback:a}};core.lockControl();core.stopAutomaticRoute();setTimeout(function(){core.drawText()},30);return}if(core.status.event.data.list.length==0){var a=core.status.event.data.callback;core.ui.closePanel(false);if(core.isset(a)){a()}return}var c=core.status.event.data.list.shift();if(typeof c=="string"){core.ui.drawTextBox(c)}else{core.ui.drawTextBox(c.content,c.id)}};core.prototype.replaceText=function(a){return a.replace(/\${([^}]+)}/g,function(c,b){return core.calValue(b)})};core.prototype.calValue=function(value){value=value.replace(/status:([\w\d_]+)/g,"core.getStatus('$1')");value=value.replace(/item:([\w\d_]+)/g,"core.itemCount('$1')");value=value.replace(/flag:([\w\d_]+)/g,"core.getFlag('$1', false)");return eval(value)};core.prototype.unshift=function(c,d){if(!(c instanceof Array)||!core.isset(d)){return}if(d instanceof Array){core.clone(d).reverse().forEach(function(a){c.unshift(a)})}else{c.unshift(d)}return c};core.prototype.setLocalStorage=function(b,c){try{localStorage.setItem(core.firstData.name+"_"+b,JSON.stringify(c));return true}catch(a){console.log(a);return false}};core.prototype.getLocalStorage=function(b,a){var c=localStorage.getItem(core.firstData.name+"_"+b);if(core.isset(c)){return JSON.parse(c)}return a};core.prototype.removeLocalStorage=function(a){localStorage.removeItem(core.firstData.name+"_"+a)};core.prototype.clone=function(b){if(!core.isset(b)){return b}if(b instanceof Date){var a=new Date();a.setTime(b.getTime());return a}if(b instanceof Array){var a=[];for(var c in b){a[c]=core.clone(b[c])}return a}if(b instanceof Function){return b}if(b instanceof Object){var a={};for(var c in b){if(b.hasOwnProperty(c)){a[c]=core.clone(b[c])}}return a}return b};core.prototype.formatDate=function(a){if(!core.isset(a)){return""}return a.getFullYear()+"-"+core.setTwoDigits(a.getMonth()+1)+"-"+core.setTwoDigits(a.getDate())+" "+core.setTwoDigits(a.getHours())+":"+core.setTwoDigits(a.getMinutes())+":"+core.setTwoDigits(a.getSeconds())};core.prototype.setTwoDigits=function(a){return parseInt(a)<10?"0"+a:a};core.prototype.lose=function(){core.stopAutomaticRoute();if(!core.status.heroStop){setTimeout(function(){core.lose()},30);return}core.events.lose()};core.prototype.debug=function(){core.setStatus("hp",999999);core.setStatus("atk",10000);core.setStatus("def",10000);core.setStatus("mdef",10000);core.setStatus("money",10000);core.setStatus("experience",10000);core.setItem("yellowKey",50);core.setItem("blueKey",50);core.setItem("redKey",50);core.setItem("book",1);core.setItem("fly",1);for(var a in core.status.maps){if(core.status.maps[a].canFlyTo&&core.status.hero.flyRange.indexOf(a)<0){core.status.hero.flyRange.push(a)}}core.updateStatusBar();core.drawTip("作弊成功")};core.prototype.checkStatus=function(c,d,b,a){if(d&&core.status.event.id==c){core.ui.closePanel(a);return false}if(d&&core.status.lockControl){return false}if(core.isset(b)&&b&&!core.hasItem(c)){core.drawTip("你没有"+core.material.items[c].name);return false}if(!core.status.heroStop){core.drawTip("请先停止勇士行动");return false}core.lockControl();core.status.automaticRoutingTemp={destX:0,destY:0,moveStep:[]};core.status.event.id=c;return true};core.prototype.openBook=function(a){if(!core.checkStatus("book",a,true,true)){return}core.useItem("book")};core.prototype.useFly=function(a){if(!core.checkStatus("fly",a,true)){return}if(core.flags.flyNearStair&&!core.nearStair()){core.drawTip("只有在楼梯边才能使用传送器");core.unLockControl();core.status.event.data=null;core.status.event.id=null;return}if(!core.canUseItem("fly")){core.drawTip("楼层传送器好像失效了");core.unLockControl();core.status.event.data=null;core.status.event.id=null;return}core.useItem("fly");return};core.prototype.openToolbox=function(a){if(!core.checkStatus("toolbox",a)){return}core.ui.drawToolbox()};core.prototype.save=function(a){if(!core.checkStatus("save",a)){return}core.ui.drawSLPanel(core.status.savePage)};core.prototype.load=function(a){if(!core.isPlaying()){core.status.event={id:"load",data:null};core.status.lockControl=true;core.dom.startPanel.style.display="none";var b=core.getLocalStorage("savePage",0);core.ui.drawSLPanel(b);return}if(!core.checkStatus("load",a)){return}core.ui.drawSLPanel(core.status.savePage)};core.prototype.doSL=function(b,c){if(c=="save"){if(core.saveData("save"+b)){core.ui.closePanel();core.drawTip("存档成功!");core.setLocalStorage("savePage",core.status.savePage)}else{core.drawTip("存储空间不足,请覆盖已有的存档或在菜单栏中进行清理")}return}else{if(c=="load"){var a=core.getLocalStorage("save"+b,null);if(!core.isset(a)){core.drawTip("无效的存档");return}if(a.version!=core.firstData.version){core.drawTip("存档版本不匹配");return}core.ui.closePanel();core.loadData(a,function(){core.setLocalStorage("savePage",core.status.savePage);core.drawTip("读档成功")});return}}};core.prototype.saveData=function(b){var a={floorId:core.status.floorId,hero:core.clone(core.status.hero),hard:core.status.hard,maps:core.maps.save(core.status.maps),shops:{},version:core.firstData.version,time:new Date().getTime()};for(var c in core.status.shops){a.shops[c]={times:core.status.shops[c].times||0,visited:core.status.shops[c].visited||false}}core.events.beforeSaveData(a);return core.setLocalStorage(b,a)};core.prototype.loadData=function(b,a){core.resetStatus(b.hero,b.hard,b.floorId,core.maps.load(b.maps));for(var c in core.status.shops){core.status.shops[c].times=b.shops[c].times;core.status.shops[c].visited=b.shops[c].visited}core.events.afterLoadData(b);core.changeFloor(b.floorId,null,b.hero.loc,null,function(){core.setHeroMoveTriggerInterval();if(core.isset(a)){a()}})};core.prototype.setStatus=function(a,b){core.status.hero[a]=b};core.prototype.getStatus=function(a){return core.status.hero[a]};core.prototype.setFlag=function(a,b){if(!core.isset(core.status.hero)){return}core.status.hero.flags[a]=b};core.prototype.getFlag=function(b,a){if(!core.isset(core.status.hero)){return a}var c=core.status.hero.flags[b];if(core.isset(c)){return c}return a};core.prototype.hasFlag=function(a){if(core.getFlag(a)){return true}return false};core.prototype.lockControl=function(){core.status.lockControl=true};core.prototype.unLockControl=function(){core.status.lockControl=false};core.prototype.isset=function(a){if(a==undefined||a==null){return false}return true};core.prototype.playSound=function(a,b){if(!core.musicStatus.soundStatus||!core.musicStatus.loaded){return}if(!core.isset(core.material.sounds[b][a])){return}core.musicStatus.playedSound=core.material.sounds[b][a];core.musicStatus.playedSound.play()};core.prototype.playBgm=function(a,b){if(core.musicStatus.isIOS||!core.musicStatus.loaded){return}if(core.isset(core.musicStatus.playedBgm)){core.musicStatus.playedBgm.pause()}core.musicStatus.playedBgm=core.material.sounds[b][a];if(core.musicStatus.soundStatus){core.musicStatus.playedBgm.play()}};core.prototype.changeSoundStatus=function(){if(core.musicStatus.soundStatus){main.core.disabledSound()}else{main.core.enabledSound()}};core.prototype.enabledSound=function(){core.musicStatus.soundStatus=true;core.playBgm("bgm","mp3");core.setLocalStorage("soundStatus",true)};core.prototype.disabledSound=function(){core.musicStatus.playedBgm.pause();core.musicStatus.soundStatus=false;core.setLocalStorage("soundStatus",false)};core.prototype.show=function(b,e,a){if(!core.isset(e)){b.style.display="block";return}b.style.display="block";b.style.opacity=0;var c=0;var d=window.setInterval(function(){c+=0.03;b.style.opacity=c;if(c>1){clearInterval(d);if(core.isset(a)){a()}}},e)};core.prototype.hide=function(c,e,a){if(!core.isset(e)){c.style.display="none";return}var d=1;var b=window.setInterval(function(){d-=0.03;c.style.opacity=d;if(d<0){c.style.display="none";clearInterval(b);if(core.isset(a)){a()}}},e)};core.prototype.clearStatusBar=function(){var a=["floor","hp","atk","def","mdef","money","experience","yellowKey","blueKey","redKey","poison","weak","curse","hard"];a.forEach(function(b){core.statusBar[b].innerHTML=""});core.statusBar.image.book.style.opacity=0.3;core.statusBar.image.fly.style.opacity=0.3};core.prototype.updateStatusBar=function(){if(core.values.HPMAX>0){core.setStatus("hp",Math.min(core.values.HPMAX,core.getStatus("hp")))}var b=["hp","atk","def","mdef","money","experience"];b.forEach(function(c){core.statusBar[c].innerHTML=core.getStatus(c)});var a=["yellowKey","blueKey","redKey"];a.forEach(function(c){core.statusBar[c].innerHTML=core.setTwoDigits(core.status.hero.items.keys[c])});core.statusBar.poison.innerHTML=core.hasFlag("poison")?"毒":"";core.statusBar.weak.innerHTML=core.hasFlag("weak")?"衰":"";core.statusBar.curse.innerHTML=core.hasFlag("curse")?"咒":"";core.statusBar.hard.innerHTML=core.status.hard;if(core.hasItem("book")){core.statusBar.image.book.style.opacity=1}else{core.statusBar.image.book.style.opacity=0.3}if(core.hasItem("fly")){core.statusBar.image.fly.style.opacity=1}else{core.statusBar.image.fly.style.opacity=0.3}core.updateFg()};core.prototype.resize=function(d,c){var b=416;var k=83;var q=49;var l=132;var a=b+6;var s=d;var i=false;if(d>c&&c<422){i=true;s=c}if(s<a){var t=(a-s)/4.22;var j=1-t/100;core.position.scale=j;b=s-6;if(!i){core.position.screenMode="vertical";k*=j;q*=j;core.position.gameGroup={width:b,height:s+k+q,top:(c-s-k-q)/2,left:3};core.position.statusBar={width:b,height:k,top:0,left:0,fontSize:16*j};core.position.canvas={width:b,height:b,top:k,left:0,borderLeft:"",borderTop:"3px #fff solid",borderBottom:"3px #fff solid"};core.position.toolBar={display:"block",width:b,height:q,top:k+3+b,};var e=8*j,f=44*j;var g=core.position.toolBar.top+13*j;var h=46*j;var m=14*j,n=50*j,o=75*j;var p=core.position.toolBar.top+18*j;if(core.flags.enableMDef&&core.flags.enableExperience){core.position.items={image:{size:32*j,floor:{top:0,left:0,display:"none"},hp:{top:e,left:8*j},atk:{top:e,left:126*j},def:{top:e,left:226*j},mdef:{top:f,left:8*j,display:"block"},money:{top:f,left:108*j},experience:{top:f,left:208*j,display:"block"},book:{top:g,left:8*j},fly:{top:g,left:8*j+h},toolbox:{top:g,left:8*j+h*2},shop:{top:g,left:8*j+h*3,display:"block"},save:{top:g,left:8*j+h*4},load:{top:g,left:8*j+h*5},settings:{top:g,left:8*j+h*6}},floor:{top:0,left:0,display:"none"},hp:{top:m,left:42*j},atk:{top:m,left:160*j},def:{top:m,left:260*j},mdef:{top:n,left:42*j,display:"block"},money:{top:n,left:144*j},experience:{top:n,left:242*j,display:"block"},yellowKey:{top:n,left:308*j},blueKey:{top:n,left:342*j},redKey:{top:n,left:376*j},poison:{top:m,left:330*j},weak:{top:m,left:355*j},curse:{top:m,left:380*j},hard:{top:p,left:320*j}}}else{core.position.items={image:{size:32*j,floor:{top:e,left:8*j,display:"block"},hp:{top:e,left:90*j},atk:{top:e,left:208*j},def:{top:e,left:308*j},mdef:{top:f,left:8*j,display:core.flags.enableMDef?"block":"none"},money:{top:f,left:(core.flags.enableMDef?108:8)*j},experience:{top:f,left:108*j,display:core.flags.enableExperience?"block":"none"},book:{top:g,left:8*j},fly:{top:g,left:8*j+h},toolbox:{top:g,left:8*j+h*2},shop:{top:g,left:8*j+h*3,display:"block"},save:{top:g,left:8*j+h*4},load:{top:g,left:8*j+h*5},settings:{top:g,left:8*j+h*6}},floor:{top:m,left:44*j},hp:{top:m,left:124*j},atk:{top:m,left:242*j},def:{top:m,left:342*j},mdef:{top:n,left:44*j,display:core.flags.enableMDef?"block":"none"},money:{top:n,left:(core.flags.enableMDef?144:44)*j},experience:{top:n,left:142*j,display:core.flags.enableExperience?"block":"none"},yellowKey:{top:n,left:216*j},blueKey:{top:n,left:250*j},redKey:{top:n,left:284*j},poison:{top:n,left:330*j},weak:{top:n,left:355*j},curse:{top:n,left:380*j},hard:{top:p,left:320*j}}}}else{core.position.screenMode="horizontal";l*=j;core.position.gameGroup={width:l+b+3,height:b,top:3,left:(d-s-l)/2,};core.position.statusBar={top:0,left:0,width:l,height:b,fontSize:16*j};core.position.canvas={borderTop:"",borderLeft:"3px #fff solid",borderBottom:"",top:0,left:l,width:b,height:b};core.position.toolBar={display:"none",top:0,left:0,width:0,height:0};core.resizeIconHorizontal(j)}}else{core.position.scale=1;core.position.screenMode="bigScreen";var r=l+3+b;core.position.gameGroup={top:(c-b)/2,left:(s-r)/2,width:r,height:b};core.position.statusBar={top:0,left:0,width:l,height:b,fontSize:16};core.position.canvas={borderTop:"",borderBottom:"",borderLeft:"3px #fff solid",top:0,left:l,width:b,height:b};core.position.toolBar={display:"none",top:0,left:0,width:0,height:0};core.resizeIconHorizontal(1)}core.resetSize()};core.prototype.resizeIconHorizontal=function(f){var a=8*f,g=50*f,h=92*f;var b=20*f,c=28*f,d=303*f;var e=36*f,i=40*f;if(core.flags.enableMDef&&core.flags.enableExperience){core.position.items={image:{size:32*f,floor:{top:0,left:0,display:"none"},hp:{top:b,left:a},atk:{top:b+e,left:a},def:{top:b+e*2,left:a},mdef:{top:b+e*3,left:a,display:"block"},money:{top:b+e*4,left:a},experience:{top:b+e*5,left:a,display:"block"},book:{top:d,left:a},fly:{top:d,left:g},toolbox:{top:d,left:h},shop:{top:0,left:0,display:"none"},save:{top:d+i,left:a},load:{top:d+i,left:g},settings:{top:d+i,left:h}},floor:{top:0,left:0,display:"none"},hp:{top:c,left:g},atk:{top:c+e,left:g},def:{top:c+e*2,left:g},mdef:{top:c+e*3,left:g,display:"block"},money:{top:c+e*4,left:g},experience:{top:c+e*5,left:g,display:"block"},yellowKey:{top:c+e*6,left:a},blueKey:{top:c+e*6,left:g},redKey:{top:c+e*6,left:h},poison:{top:c+e*6.75,left:a+10*f},weak:{top:c+e*6.75,left:a+35*f},curse:{top:c+e*6.75,left:a+60*f},hard:{top:383*f,left:0}}}else{core.position.items={image:{size:32*f,floor:{top:b,left:a,display:"block"},hp:{top:b+e,left:a},atk:{top:b+e*2,left:a},def:{top:b+e*3,left:a},mdef:{top:b+e*4,left:a,display:core.flags.enableMDef?"block":"none"},money:{top:b+e*(core.flags.enableMDef?5:4),left:a},experience:{top:b+e*5,left:a,display:core.flags.enableExperience?"block":"none"},book:{top:d,left:a},fly:{top:d,left:g},toolbox:{top:d,left:h},shop:{top:0,left:0,display:"none"},save:{top:d+i,left:a},load:{top:d+i,left:g},settings:{top:d+i,left:h}},floor:{top:c,left:g,display:"block"},hp:{top:c+e,left:g},atk:{top:c+e*2,left:g},def:{top:c+e*3,left:g},mdef:{top:c+e*4,left:g,display:core.flags.enableMDef?"block":"none"},money:{top:c+e*(core.flags.enableMDef?5:4),left:g},experience:{top:c+e*5,left:g,display:core.flags.enableExperience?"block":"none"},yellowKey:{top:c+e*6,left:a},blueKey:{top:c+e*6,left:g},redKey:{top:c+e*6,left:h},poison:{top:c+e*6.75,left:a+10*f},weak:{top:c+e*6.75,left:a+35*f},curse:{top:c+e*6.75,left:a+60*f},hard:{top:383*f,left:0}}}};core.prototype.resetSize=function(){core.dom.gameGroup.style.left=core.position.gameGroup.left+"px";core.dom.gameGroup.style.top=core.position.gameGroup.top+"px";core.dom.gameGroup.style.width=core.position.gameGroup.width+"px";core.dom.gameGroup.style.height=core.position.gameGroup.height+"px";core.dom.statusBar.style.width=core.position.statusBar.width+"px";core.dom.statusBar.style.height=core.position.statusBar.height+"px";core.dom.statusBar.style.fontSize=core.position.statusBar.fontSize+"px";core.dom.toolBar.style.top=core.position.toolBar.top+"px";core.dom.toolBar.style.width=core.position.toolBar.width+"px";core.dom.toolBar.style.height=core.position.toolBar.height+"px";core.dom.toolBar.style.display=core.position.toolBar.display;core.dom.floorMsgGroup.style.width=core.position.canvas.width+"px";for(var a=0;a<core.dom.gameCanvas.length;a++){core.dom.gameCanvas[a].style.borderTop=core.position.canvas.borderTop;core.dom.gameCanvas[a].style.borderLeft=core.position.canvas.borderLeft;core.dom.gameCanvas[a].style.top=core.position.canvas.top+"px";core.dom.gameCanvas[a].style.left=core.position.canvas.left+"px";core.dom.gameCanvas[a].style.width=core.position.canvas.width+"px";core.dom.gameCanvas[a].style.height=core.position.canvas.height+"px"}for(var b in core.statusBar.image){if(core.isset(core.position.items.image[b].display)){core.statusBar.image[b].style.display=core.position.items.image[b].display}else{core.statusBar.image[b].style.display="block"}core.statusBar.image[b].style.width=core.position.items.image.size+"px";core.statusBar.image[b].style.height=core.position.items.image.size+"px";core.statusBar.image[b].style.top=core.position.items.image[b].top+"px";core.statusBar.image[b].style.left=core.position.items.image[b].left+"px"}for(var b in core.statusBar){if(b=="image"){continue}if(core.isset(core.position.items[b].display)){core.statusBar[b].style.display=core.position.items[b].display}else{core.statusBar[b].style.display="block"}core.statusBar[b].style.top=core.position.items[b].top+"px";core.statusBar[b].style.left=core.position.items[b].left+"px"}};var core=new core();main.instance.core=core;