mota-js/libs/control.min.js
2018-05-27 23:17:10 +08:00

1 line
52 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 control(){this.init()}control.prototype.init=function(){};control.prototype.setRequestAnimationFrame=function(){(function(){var c=0;var d=["webkit","moz"];for(var e=0;e<d.length&&!window.requestAnimationFrame;++e){window.requestAnimationFrame=window[d[e]+"RequestAnimationFrame"];window.cancelAnimationFrame=window[d[e]+"CancelAnimationFrame"]||window[d[e]+"CancelRequestAnimationFrame"]}if(!window.requestAnimationFrame){window.requestAnimationFrame=function(f,h){var g=new Date().getTime();var j=Math.max(0,16.7-(g-c));var i=window.setTimeout(function(){f(g+j)},j);c=g+j;return i}}if(!window.cancelAnimationFrame){window.cancelAnimationFrame=function(f){clearTimeout(f)}}}());core.animateFrame.speed=core.values.animateSpeed;core.animateFrame.background=core.canvas.ui.createPattern(core.material.ground,"repeat");var b={up:{x:0,y:-1},left:{x:-1,y:0},down:{x:0,y:1},right:{x:1,y:0}};var a=function(g){core.animateFrame.globalTime=core.animateFrame.globalTime||g;core.animateFrame.boxTime=core.animateFrame.boxTime||g;core.animateFrame.moveTime=core.animateFrame.moveTime||g;core.animateFrame.weather.time=core.animateFrame.weather.time||g;if(core.isPlaying()&&core.isset(core.status)&&core.isset(core.status.hero)&&core.isset(core.status.hero.statistics)){core.status.hero.statistics.totalTime+=g-(core.status.hero.statistics.start||g);core.status.hero.statistics.currTime+=g-(core.status.hero.statistics.start||g);core.status.hero.statistics.start=g}if(core.animateFrame.globalAnimate&&core.isPlaying()){if(g-core.animateFrame.globalTime>core.animateFrame.speed&&core.isset(core.status.globalAnimateObjs)){for(var c=0;c<core.status.globalAnimateObjs.length;c++){var f=core.status.globalAnimateObjs[c];f.status=(f.status+1)%(f.event.animate||1);core.drawBlock(f,f.status)}core.animateFrame.globalTime=g}}if(g-core.animateFrame.boxTime>core.animateFrame.speed&&core.isset(core.status.boxAnimateObjs)&&core.status.boxAnimateObjs.length>0){core.drawBoxAnimate();core.animateFrame.boxTime=g}if(g-core.animateFrame.moveTime>16&&core.isset(core.status.heroMoving)&&core.status.heroMoving>0){var h=core.getHeroLoc("x"),i=core.getHeroLoc("y"),e=core.getHeroLoc("direction");if(core.status.heroMoving<=4){core.drawHero(e,h,i,"leftFoot",4*core.status.heroMoving*b[e].x,4*core.status.heroMoving*b[e].y)}else{if(core.status.heroMoving<=8){core.drawHero(e,h,i,"rightFoot",4*core.status.heroMoving*b[e].x,4*core.status.heroMoving*b[e].y)}}core.animateFrame.moveTime=g}if(core.isPlaying()&&g-core.animateFrame.weather.time>30){if(core.animateFrame.weather.type=="rain"&&core.animateFrame.weather.level>0){core.clearMap("weather",0,0,416,416);core.canvas.weather.strokeStyle="rgba(174,194,224,0.8)";core.canvas.weather.lineWidth=1;core.canvas.weather.lineCap="round";core.animateFrame.weather.nodes.forEach(function(j){core.canvas.weather.beginPath();core.canvas.weather.moveTo(j.x,j.y);core.canvas.weather.lineTo(j.x+j.l*j.xs,j.y+j.l*j.ys);core.canvas.weather.stroke();j.x+=j.xs;j.y+=j.ys;if(j.x>416||j.y>416){j.x=Math.random()*416;j.y=-10}});core.canvas.weather.fill()}else{if(core.animateFrame.weather.type=="snow"&&core.animateFrame.weather.level>0){core.clearMap("weather",0,0,416,416);core.canvas.weather.fillStyle="rgba(255, 255, 255, 0.8)";core.canvas.weather.beginPath();if(!core.isset(core.animateFrame.weather.data)){core.animateFrame.weather.data=0}core.animateFrame.weather.data+=0.01;var d=core.animateFrame.weather.data;core.animateFrame.weather.nodes.forEach(function(j){core.canvas.weather.moveTo(j.x,j.y);core.canvas.weather.arc(j.x,j.y,j.r,0,Math.PI*2,true);j.x+=Math.sin(d)*2;j.y+=Math.cos(d+j.d)+1+j.r/2;if(j.x>416+5||j.x<-5||j.y>416){if(Math.random()>1/3){j.x=Math.random()*416;j.y=-10}else{if(Math.sin(d)>0){j.x=-5;j.y=Math.random()*416}else{j.x=416+5;j.y=Math.random()*416}}}});core.canvas.weather.fill()}}core.animateFrame.weather.time=g}window.requestAnimationFrame(a)};window.requestAnimationFrame(a)};control.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.dom.curtain.style.background="#000000";core.dom.curtain.style.opacity=0;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)};control.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)};control.prototype.isPlaying=function(){return core.isset(core.status.played)&&core.status.played};control.prototype.clearStatus=function(){for(var a in core.timeout){clearTimeout(core.timeout[a]);core.timeout[a]=null}for(var a in core.interval){clearInterval(core.interval[a]);core.interval[a]=null}core.status={};core.clearStatusBar();core.resize(main.dom.body.clientWidth,main.dom.body.clientHeight)};control.prototype.resetStatus=function(c,b,a,e,d){var f=0;if(core.isset(core.status)&&core.isset(core.status.hero)&&core.isset(core.status.hero.statistics)&&core.isset(e)){f=core.status.hero.statistics.totalTime}this.clearStatus();core.status=core.clone(core.initStatus);core.status.played=true;core.status.floorId=a;core.status.maps=core.clone(d);core.material.enemys=core.clone(core.enemys.getEnemys());core.status.hero=core.clone(c);if(!core.isset(core.status.hero.statistics)){core.status.hero.statistics={totalTime:f,currTime:0,hp:0,battleDamage:0,poisonDamage:0,extraDamage:0,moveDirectly:0,ignoreSteps:0,}}core.status.hero.statistics.totalTime=Math.max(core.status.hero.statistics.totalTime,f);core.status.hero.statistics.start=null;core.status.hard=b;if(core.isset(e)){core.status.route=e}core.status.saveIndex=core.getLocalStorage("saveIndex2",1)};control.prototype.startGame=function(b,a){console.log("开始游戏");this.resetStatus(core.firstData.hero,b,core.firstData.floorId,null,core.initStatus.maps);core.changeFloor(core.status.floorId,null,core.firstData.hero.loc,null,function(){if(core.isset(a)){a()}},true);setTimeout(function(){var c=new FormData();c.append("type","people");c.append("name",core.firstData.name);c.append("version",core.firstData.version);c.append("platform",core.platform.isPC?"PC":core.platform.isAndroid?"Android":core.platform.isIOS?"iOS":"");c.append("hard",b);c.append("hardCode",core.getFlag("hard",0));core.utils.http("POST","/games/upload.php",c)})};control.prototype.restart=function(){this.showStartAnimate();if(core.bgms.length>0){core.playBgm(core.bgms[0])}};control.prototype.clearAutomaticRouteNode=function(a,b){if(core.status.event.id==null){core.canvas.ui.clearRect(a*32+5,b*32+5,27,27)}};control.prototype.stopAutomaticRoute=function(){if(!core.status.played){return}core.status.automaticRoute.autoHeroMove=false;core.status.automaticRoute.autoStep=0;core.status.automaticRoute.destStep=0;core.status.automaticRoute.movedStep=0;core.status.automaticRoute.autoStepRoutes=[];core.status.automaticRoute.destX=null;core.status.automaticRoute.destY=null;core.status.automaticRoute.lastDirection=null;core.stopHero();if(core.status.automaticRoute.moveStepBeforeStop.length==0){core.canvas.ui.clearRect(0,0,416,416)}};control.prototype.continueAutomaticRoute=function(){var a=core.status.automaticRoute.moveStepBeforeStop;if(a.length===0||(a.length===1&&a[0].step===1)){core.status.automaticRoute.moveStepBeforeStop=[]}else{core.setAutoHeroMove(a)}};control.prototype.clearContinueAutomaticRoute=function(){core.canvas.ui.clearRect(0,0,416,416);core.status.automaticRoute.moveStepBeforeStop=[]};control.prototype.setAutomaticRoute=function(a,b,h){if(!core.status.played||core.status.lockControl){return}if(core.status.automaticRoute.autoHeroMove){var c=core.status.automaticRoute.destX,d=core.status.automaticRoute.destY;core.stopAutomaticRoute();if(c==a&&d==b){core.status.automaticRoute.moveDirectly=true;setTimeout(function(){if(core.status.automaticRoute.moveDirectly&&core.status.heroMoving==0){var j=core.canMoveDirectly(a,b);if(j>0){core.clearMap("hero",0,0,416,416);core.setHeroLoc("x",a);core.setHeroLoc("y",b);core.drawHero();core.status.route.push("move:"+a+":"+b);core.status.hero.statistics.moveDirectly++;core.status.hero.statistics.ignoreSteps+=j}}core.status.automaticRoute.moveDirectly=false},100)}return}if(a==core.status.hero.loc.x&&b==core.status.hero.loc.y&&h.length==0){if(core.timeout.turnHeroTimeout==null){core.timeout.turnHeroTimeout=setTimeout(function(){core.turnHero();clearTimeout(core.timeout.turnHeroTimeout);core.timeout.turnHeroTimeout=null},250)}else{clearTimeout(core.timeout.turnHeroTimeout);core.timeout.turnHeroTimeout=null;core.getNextItem()}return}var g=0;var i=null;var f;if(!(f=core.automaticRoute(a,b))){if(a==core.status.hero.loc.x&&b==core.status.hero.loc.y){f=[]}else{core.canvas.ui.clearRect(0,0,416,416);return}}f=f.concat(h);core.status.automaticRoute.destX=a;core.status.automaticRoute.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 e=0;e<f.length;e++){if(i==null){g++;i=f[e].direction}else{if(i==f[e].direction){g++}else{core.status.automaticRoute.autoStepRoutes.push({direction:i,step:g});g=1;i=f[e].direction}}if(e==f.length-1){core.status.automaticRoute.autoStepRoutes.push({direction:i,step:g});core.canvas.ui.fillRect(f[e].x*32+10,f[e].y*32+10,12,12)}else{core.canvas.ui.beginPath();if(core.isset(f[e+1])&&i!=f[e+1].direction){if(i=="up"&&f[e+1].direction=="left"||i=="right"&&f[e+1].direction=="down"){core.canvas.ui.moveTo(f[e].x*32+5,f[e].y*32+16);core.canvas.ui.lineTo(f[e].x*32+16,f[e].y*32+16);core.canvas.ui.lineTo(f[e].x*32+16,f[e].y*32+27)}else{if(i=="up"&&f[e+1].direction=="right"||i=="left"&&f[e+1].direction=="down"){core.canvas.ui.moveTo(f[e].x*32+27,f[e].y*32+16);core.canvas.ui.lineTo(f[e].x*32+16,f[e].y*32+16);core.canvas.ui.lineTo(f[e].x*32+16,f[e].y*32+27)}else{if(i=="left"&&f[e+1].direction=="up"||i=="down"&&f[e+1].direction=="right"){core.canvas.ui.moveTo(f[e].x*32+27,f[e].y*32+16);core.canvas.ui.lineTo(f[e].x*32+16,f[e].y*32+16);core.canvas.ui.lineTo(f[e].x*32+16,f[e].y*32+5)}else{if(i=="right"&&f[e+1].direction=="up"||i=="down"&&f[e+1].direction=="left"){core.canvas.ui.moveTo(f[e].x*32+5,f[e].y*32+16);core.canvas.ui.lineTo(f[e].x*32+16,f[e].y*32+16);core.canvas.ui.lineTo(f[e].x*32+16,f[e].y*32+5)}}}}core.canvas.ui.stroke();continue}switch(i){case"up":case"down":core.canvas.ui.beginPath();core.canvas.ui.moveTo(f[e].x*32+16,f[e].y*32+5);core.canvas.ui.lineTo(f[e].x*32+16,f[e].y*32+27);core.canvas.ui.stroke();break;case"left":case"right":core.canvas.ui.beginPath();core.canvas.ui.moveTo(f[e].x*32+5,f[e].y*32+16);core.canvas.ui.lineTo(f[e].x*32+27,f[e].y*32+16);core.canvas.ui.stroke();break}}}core.canvas.ui.restore();core.setAutoHeroMove()};control.prototype.automaticRoute=function(d,e){var x=core.getHeroLoc("x");var y=core.getHeroLoc("y");var w={up:{x:0,y:-1},left:{x:-1,y:0},down:{x:0,y:1},right:{x:1,y:0}};var u=[];var n=0;var v=[];var a=[];if(d==x&&e==y){return false}u.push(13*x+y);u.push(-1);v[13*x+y]="";while(u.length!=1){var i=u.shift();if(i===-1){n+=1;u.push(-1);continue}var b=~~(i/169);if(b!==n){u.push(i);continue}i=i%169;var q=parseInt(i/13),r=i%13;var p=false,o,m=core.getBlock(q,r);for(var h in w){if(!core.canMoveHero(q,r,h)){continue}var s=q+w[h].x;var t=r+w[h].y;if(s<0||s>12||t<0||t>12){continue}var l=13*s+t;if(core.isset(v[l])){continue}var c=1;var k,j=core.getBlock(s,t);if(j!=null){k=j.block.event.id;if(k=="light"){c=100}if(k.substring(k.length-3)=="Net"){c=core.values.lavaDamage}if(!core.flags.potionWhileRouting&&k.substring(k.length-6)=="Potion"){c=20}if(j.block.event.trigger=="changeFloor"){c=10}}if(core.status.checkBlock.damage[l]>0){c=core.status.checkBlock.damage[l]}if(s==d&&t==e){v[l]=h;break}if(core.noPassExists(s,t)){continue}v[l]=h;u.push(169*(n+c)+l)}if(core.isset(v[13*d+e])){break}}if(!core.isset(v[13*d+e])){return false}var q=d,r=e;while(q!=x||r!=y){var g=v[13*q+r];a.push({direction:g,x:q,y:r});q-=w[g].x;r-=w[g].y}a.reverse();return a};control.prototype.fillPosWithPoint=function(a){core.fillRect("ui",a.x*32+12,a.y*32+12,8,8,"#bfbfbf")};control.prototype.setAutoHeroMove=function(a){a=a||core.status.automaticRoute.autoStepRoutes;if(a.length==0){return}core.status.automaticRoute.autoStepRoutes=a;core.status.automaticRoute.autoHeroMove=true;core.status.automaticRoute.autoStep=1;core.status.automaticRoute.destStep=a[0].step;core.moveHero(a[0].direction)};control.prototype.setHeroMoveInterval=function(b,e,f,a){if(core.status.heroMoving>0){return}core.status.heroMoving=1;var c={up:{x:0,y:-1},left:{x:-1,y:0},down:{x:0,y:1},right:{x:1,y:0}};var d=1;if(core.status.replay.speed>3){d=2}core.interval.heroMoveInterval=window.setInterval(function(){core.status.heroMoving+=d;if(core.status.heroMoving>=8){core.setHeroLoc("x",e+c[b].x);core.setHeroLoc("y",f+c[b].y);core.moveOneStep();core.clearMap("hero",0,0,416,416);core.drawHero(b);clearInterval(core.interval.heroMoveInterval);core.status.heroMoving=0;if(core.isset(a)){a()}}},12.5*d/core.status.replay.speed)};control.prototype.moveAction=function(a){if(core.interval.openDoorAnimate!=null){return}if(core.status.heroMoving>0){return}var e={up:{x:0,y:-1},left:{x:-1,y:0},down:{x:0,y:1},right:{x:1,y:0}};var c=core.getHeroLoc("direction");var f=core.getHeroLoc("x");var g=core.getHeroLoc("y");var d=core.noPass(f+e[c].x,g+e[c].y),b=core.canMoveHero();if(d||!b){if(core.status.event.id!="ski"){core.status.route.push(c)}core.status.automaticRoute.moveStepBeforeStop=[];core.status.automaticRoute.lastDirection=core.getHeroLoc("direction");if(b){core.trigger(f+e[c].x,g+e[c].y)}core.drawHero(c,f,g);if(core.status.automaticRoute.moveStepBeforeStop.length==0){core.clearContinueAutomaticRoute();core.stopAutomaticRoute()}if(core.isset(a)){a()}}else{core.setHeroMoveInterval(c,f,g,function(){if(core.status.automaticRoute.autoHeroMove){core.status.automaticRoute.movedStep++;core.status.automaticRoute.lastDirection=core.getHeroLoc("direction");if(core.status.automaticRoute.destStep==core.status.automaticRoute.movedStep){if(core.status.automaticRoute.autoStep==core.status.automaticRoute.autoStepRoutes.length){core.clearContinueAutomaticRoute();core.stopAutomaticRoute()}else{core.status.automaticRoute.movedStep=0;core.status.automaticRoute.destStep=core.status.automaticRoute.autoStepRoutes[core.status.automaticRoute.autoStep].step;core.setHeroLoc("direction",core.status.automaticRoute.autoStepRoutes[core.status.automaticRoute.autoStep].direction);core.status.automaticRoute.autoStep++}}}else{if(core.status.heroStop){core.drawHero()}}if(core.status.event.id!="ski"){core.status.route.push(c)}core.trigger(core.getHeroLoc("x"),core.getHeroLoc("y"));core.checkBlock();if(core.isset(a)){a()}})}};control.prototype.turnHero=function(){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.canvas.ui.clearRect(0,0,416,416);core.status.route.push("turn")};control.prototype.moveHero=function(b,a){if(core.status.heroMoving!=0){return}if(core.isset(b)){core.setHeroLoc("direction",b)}if(!core.isset(a)){core.status.heroStop=false;core.status.automaticRoute.moveDirectly=false;var c=function(){if(!core.status.heroStop){if(core.hasFlag("debug")&&core.status.ctrlDown){if(core.status.heroMoving!=0){return}core.status.heroMoving=-1;core.eventMoveHero([core.getHeroLoc("direction")],100,function(){core.status.heroMoving=0;c()})}else{core.moveAction();setTimeout(c,50)}}else{core.stopHero()}};c()}else{core.moveAction(function(){a()})}};control.prototype.eventMoveHero=function(f,g,b){g=g||100;core.clearMap("ui",0,0,416,416);core.setAlpha("ui",1);var c=[];f.forEach(function(h){if(typeof h=="string"){c.push(h)}else{if(!core.isset(h.value)){c.push(h.direction)}else{for(var j=0;j<h.value;j++){c.push(h.direction)}}}});var e=0;var d={up:{x:0,y:-1},left:{x:-1,y:0},down:{x:0,y:1},right:{x:1,y:0}};core.status.replay.animate=true;var a=window.setInterval(function(){var i=core.getHeroLoc("x"),j=core.getHeroLoc("y");if(c.length==0){clearInterval(a);core.drawHero(null,i,j);core.status.replay.animate=false;if(core.isset(b)){b()}}else{var h=c[0];core.setHeroLoc("direction",h);e++;if(e<=4){core.drawHero(h,i,j,"leftFoot",4*e*d[h].x,4*e*d[h].y)}else{if(e<=8){core.drawHero(h,i,j,"rightFoot",4*e*d[h].x,4*e*d[h].y)}}if(e==8){e=0;core.setHeroLoc("x",i+d[h].x);core.setHeroLoc("y",j+d[h].y);c.shift()}}},g/8/core.status.replay.speed)};control.prototype.moveOneStep=function(){core.status.hero.steps++;if(core.hasFlag("poison")){core.status.hero.statistics.poisonDamage+=core.values.poisonDamage;core.status.hero.hp-=core.values.poisonDamage;if(core.status.hero.hp<=0){core.status.hero.hp=0;core.updateStatusBar();core.events.lose();return}core.updateStatusBar()}};control.prototype.waitHeroToStop=function(a){var b=core.status.automaticRoute.lastDirection;core.stopAutomaticRoute();core.clearContinueAutomaticRoute();if(core.isset(a)){core.status.replay.animate=true;core.lockControl();core.status.automaticRoute.moveDirectly=false;setTimeout(function(){core.status.replay.animate=false;if(core.isset(b)){core.setHeroLoc("direction",b)}core.drawHero();a()},30)}};control.prototype.stopHero=function(){core.status.heroStop=true};control.prototype.drawHero=function(a,i,j,h,f,g){f=f||0;g=g||0;var b=f==0?0:f/Math.abs(f),c=g==0?0:g/Math.abs(g);if(!core.isset(i)){i=core.getHeroLoc("x")}if(!core.isset(j)){j=core.getHeroLoc("y")}core.clearAutomaticRouteNode(i+b,j+c);i=i*32;j=j*32;h=h||"stop";var e=core.material.icons.hero[a||core.getHeroLoc("direction")];core.canvas.hero.clearRect(i-32,j-32,96,96);var d=core.material.icons.hero.height;core.canvas.hero.drawImage(core.material.images.hero,e[h]*32,e.loc*d,32,d,i+f,j+g+32-d,32,d)};control.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};control.prototype.getHeroLoc=function(a){if(!core.isset(a)){return core.status.hero.loc}return core.status.hero.loc[a]};control.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};control.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};control.prototype.updateCheckBlock=function(){core.status.checkBlock={};if(!core.isset(core.status.thisMap)){return}var b=core.status.thisMap.blocks;core.status.checkBlock.map=[];for(var k=0;k<b.length;k++){var a=b[k];if(core.isset(a.event)&&!(core.isset(a.enable)&&!a.enable)&&a.event.cls.indexOf("enemy")==0){var g=a.event.id,e=core.material.enemys[g];if(core.isset(e)){core.status.checkBlock.map[13*a.x+a.y]=g}}if(core.isset(a.event)&&!(core.isset(a.enable)&&!a.enable)&&a.event.id=="lavaNet"&&a.event.trigger=="passNet"&&!core.hasItem("shoes")){core.status.checkBlock.map[13*a.x+a.y]="lavaNet"}}core.status.checkBlock.damage=[];for(var p=0;p<13*13;p++){core.status.checkBlock.damage[p]=0}for(var p=0;p<13;p++){for(var q=0;q<13;q++){var g=core.status.checkBlock.map[13*p+q];if(core.isset(g)){if(g=="lavaNet"){core.status.checkBlock.damage[13*p+q]+=core.values.lavaDamage;continue}var e=core.material.enemys[g];if(core.enemys.hasSpecial(e.special,15)){var o=e.range||1;var r=false;if(core.isset(e.zoneSquare)){r=e.zoneSquare}for(var c=-o;c<=o;c++){for(var d=-o;d<=o;d++){if(c==0&&d==0){continue}var l=p+c,m=q+d;if(l<0||l>12||m<0||m>12){continue}if(!r&&Math.abs(c)+Math.abs(d)>o){continue}core.status.checkBlock.damage[13*l+m]+=e.value}}}if(core.enemys.hasSpecial(e.special,18)){for(var c=-1;c<=1;c++){for(var d=-1;d<=1;d++){if(c==0&&d==0){continue}var l=p+c,m=q+d;if(l<0||l>12||m<0||m>12||Math.abs(c)+Math.abs(d)>1){continue}core.status.checkBlock.damage[13*l+m]+=e.value}}}}}}core.status.checkBlock.betweenAttack=[];for(var p=0;p<13;p++){for(var q=0;q<13;q++){var f=false;if(p>0&&p<12){var h=core.status.checkBlock.map[13*(p-1)+q],i=core.status.checkBlock.map[13*(p+1)+q];if(core.isset(h)&&core.isset(i)&&h==i){var e=core.material.enemys[h];if(core.isset(e)&&core.enemys.hasSpecial(e.special,16)){f=true}}}if(q>0&&q<12){var h=core.status.checkBlock.map[13*p+q-1],i=core.status.checkBlock.map[13*p+q+1];if(core.isset(h)&&core.isset(i)&&h==i){var e=core.material.enemys[h];if(core.isset(e)&&core.enemys.hasSpecial(e.special,16)){f=true}}}if(f){core.status.checkBlock.betweenAttack[13*p+q]=true;var j=core.status.hero.hp-core.status.checkBlock.damage[13*p+q];if(j>1){core.status.checkBlock.damage[13*p+q]+=Math.floor((j+(core.flags.betweenAttackCeil?0:1))/2)}}}}};control.prototype.checkBlock=function(){var i=core.getHeroLoc("x"),j=core.getHeroLoc("y");var a=core.status.checkBlock.damage[13*i+j];if(a>0){core.status.hero.hp-=a;var h=[];var g={up:{x:0,y:-1},left:{x:-1,y:0},down:{x:0,y:1},right:{x:1,y:0}};for(var b in g){var e=i+g[b].x,f=j+g[b].y;if(e<0||e>12||f<0||f>12){continue}var d=core.status.checkBlock.map[13*e+f];if(core.isset(d)){var c=core.material.enemys[d];if(core.isset(c)&&core.enemys.hasSpecial(c.special,18)){h.push({direction:b,x:e,y:f})}}}if(core.status.checkBlock.betweenAttack[13*i+j]&&a>0){core.drawTip("受到夹击,生命变成一半")}else{if(core.status.checkBlock.map[13*i+j]=="lavaNet"){core.drawTip("受到血网伤害"+a+"点")}else{if(h.length>0&&a>0){core.drawTip("受到阻击伤害"+a+"点")}else{if(a>0){core.drawTip("受到领域伤害"+a+"点")}}}}if(a>0){core.playSound("zone.mp3");core.drawAnimate("zone",i,j)}core.status.hero.statistics.extraDamage+=a;if(core.status.hero.hp<=0){core.status.hero.hp=0;core.updateStatusBar();core.events.lose();return}h=h.filter(function(n){var o=n.x,p=n.y,k=n.direction;var l=o+g[k].x,m=p+g[k].y;return l>=0&&l<=12&&m>=0&&m<=12&&core.getBlock(l,m,core.status.floorId,false)==null});core.updateStatusBar();if(h.length>0){core.snipe(h)}}};control.prototype.snipe=function(c){var b={up:{x:0,y:-1},left:{x:-1,y:0},down:{x:0,y:1},right:{x:1,y:0}};c.forEach(function(j){var k=j.x,l=j.y,h=j.direction;j.nx=k+b[j.direction].x;j.ny=l+b[j.direction].y;core.removeGlobalAnimate(k,l);var d=core.getBlock(k,l).block;var e=d.event.cls;var i=d.event.height||32;j.animate=d.event.animate||1;j.blockIcon=core.material.icons[e][d.event.id];j.blockImage=core.material.images[e];j.height=i;var g=core.enemys.getDamage(d.event.id);var f="#000000";if(g==null){g="???";f="#FF0000"}else{if(g<=0){f="#00FF00"}else{if(g<core.status.hero.hp/3){f="#FFFFFF"}else{if(g<core.status.hero.hp*2/3){f="#FFFF00"}else{if(g<core.status.hero.hp){f="#FF7F00"}else{f="#FF0000"}}}}g=core.formatBigNumber(g)}j.damage=g;j.color=f;j.block=core.clone(d)});var a=function(){c.forEach(function(e){core.removeBlock(e.x,e.y);var d=core.clone(e.block);d.x=e.nx;d.y=e.ny;core.status.thisMap.blocks.push(d);core.drawBlock(d);core.addGlobalAnimate(d)});core.syncGlobalAnimate();core.updateStatusBar();return};if(core.status.replay.replaying){a()}else{core.waitHeroToStop(function(){core.lockControl();var h=500,g=0;var e=0;var f=0;core.canvas.fg.textAlign="left";var d=window.setInterval(function(){g++;f+=h/16;if(f>=core.values.animateSpeed){e++;f=0}c.forEach(function(n){var o=n.x,p=n.y,i=n.direction;var j=b[i].x*2*g,k=b[i].y*2*g;var l=32*o+j,m=32*p+k;core.clearMap("fg",l-2*b[i].x,m-2*b[i].y,32,32);core.canvas.event.clearRect(l-2*b[i].x,m-2*b[i].y,32,32);core.canvas.event2.clearRect(l-2*b[i].x,m-2*b[i].y-32,32,32);core.drawBlock(n.block,e,j,k);if(core.hasItem("book")){core.setFillStyle("fg","#000000");core.canvas.fg.fillText(n.damage,l+2,m+30);core.canvas.fg.fillText(n.damage,l,m+30);core.canvas.fg.fillText(n.damage,l+2,m+32);core.canvas.fg.fillText(n.damage,l,m+32);core.setFillStyle("fg",n.color);core.canvas.fg.fillText(n.damage,l+1,m+31)}});if(g==16){clearInterval(d);a();if(core.status.event.id==null){core.unLockControl()}}},h/16)})}};control.prototype.setWeather=function(d,c){if(d!="rain"&&d!="snow"){core.clearMap("weather",0,0,416,416);core.animateFrame.weather.type=null;core.animateFrame.weather.level=0;core.animateFrame.weather.nodes=[];return}c=parseInt(c);if(d==core.animateFrame.weather.type&&(!core.isset(c)||20*c==core.animateFrame.weather.level)){return}if(!core.isset(c)){c=5}if(c<1){c=1}if(c>10){c=10}c*=20;core.clearMap("weather",0,0,416,416);core.animateFrame.weather.type=d;core.animateFrame.weather.level=c;core.animateFrame.weather.nodes=[];if(d=="rain"){for(var b=0;b<c;b++){core.animateFrame.weather.nodes.push({x:Math.random()*416,y:Math.random()*416,l:Math.random()*2.5,xs:-4+Math.random()*4+2,ys:Math.random()*10+10})}}else{if(d=="snow"){for(var b=0;b<c;b++){core.animateFrame.weather.nodes.push({x:Math.random()*416,y:Math.random()*416,r:Math.random()*5+1,d:Math.random()*c,})}}}};control.prototype.setFg=function(c,f,a){if(!core.isset(f)){f=750}if(f<=0){f=0}if(!core.isset(core.status.curtainColor)){core.status.curtainColor=[0,0,0,0]}var d=core.status.curtainColor;if(!core.isset(c)){c=[0,0,0,0]}if(c.length==3){c.push(1)}if(c[3]<0){c[3]=0}if(c[3]>1){c[3]=1}if(f==0){core.dom.curtain.style.background=core.arrayToRGB(c);core.dom.curtain.style.opacity=c[3];core.status.curtainColor=c;if(core.isset(a)){a()}return}var e=0;core.status.replay.animate=true;var b=setInterval(function(){e++;var g=d[3]+(c[3]-d[3])*e/25;var j=parseInt(d[0]+(c[0]-d[0])*e/25);var i=parseInt(d[1]+(c[1]-d[1])*e/25);var h=parseInt(d[2]+(c[2]-d[2])*e/25);core.dom.curtain.style.background=core.arrayToRGB([j,i,h]);core.dom.curtain.style.opacity=g;if(e>=25){clearInterval(b);core.status.curtainColor=c;core.status.replay.animate=false;if(core.isset(a)){a()}}},f/25)};control.prototype.updateFg=function(){if(!core.isset(core.status.thisMap)||!core.isset(core.status.thisMap.blocks)){return}var i=core.status.thisMap.blocks;core.clearMap("fg",0,0,416,416);if(!core.hasItem("book")){return}core.setFont("fg","bold 11px Arial");var g=core.status.hero.hp;if(core.flags.displayEnemyDamage||core.flags.displayCritical){core.canvas.fg.textAlign="left";for(var a=0;a<i.length;a++){var j=i[a].x,k=i[a].y;if(core.isset(i[a].event)&&i[a].event.cls.indexOf("enemy")==0&&!(core.isset(i[a].enable)&&!i[a].enable)){if(i[a].event.trigger!="battle"){var f=core.floors[core.status.floorId].events[j+","+k];if(core.isset(f)&&!(f instanceof Array)){if(core.isset(f.displayDamage)&&!f.displayDamage){continue}}}var h=i[a].event.id;if(core.flags.displayEnemyDamage){var e=core.enemys.getDamage(h);var c="#000000";if(e==null){e="???";c="#FF0000"}else{if(e<=0){c="#00FF00"}else{if(e<g/3){c="#FFFFFF"}else{if(e<g*2/3){c="#FFFF00"}else{if(e<g){c="#FF7F00"}else{c="#FF0000"}}}}e=core.formatBigNumber(e)}core.setFillStyle("fg","#000000");core.canvas.fg.fillText(e,32*j+2,32*(k+1)-2);core.canvas.fg.fillText(e,32*j,32*(k+1)-2);core.canvas.fg.fillText(e,32*j+2,32*(k+1));core.canvas.fg.fillText(e,32*j,32*(k+1));core.setFillStyle("fg",c);core.canvas.fg.fillText(e,32*j+1,32*(k+1)-1)}if(core.flags.displayCritical){var d=core.enemys.nextCriticals(h);if(d.length>0){d=d[0]}d=core.formatBigNumber(d[0]);if(d=="???"){d="?"}core.setFillStyle("fg","#000000");core.canvas.fg.fillText(d,32*j+2,32*(k+1)-2-10);core.canvas.fg.fillText(d,32*j,32*(k+1)-2-10);core.canvas.fg.fillText(d,32*j+2,32*(k+1)-10);core.canvas.fg.fillText(d,32*j,32*(k+1)-10);core.setFillStyle("fg","#FFFFFF");core.canvas.fg.fillText(d,32*j+1,32*(k+1)-1-10)}}}}if(core.flags.displayExtraDamage){core.canvas.fg.textAlign="center";for(var j=0;j<13;j++){for(var k=0;k<13;k++){var e=core.status.checkBlock.damage[13*j+k];if(e>0){e=core.formatBigNumber(e);core.setFillStyle("fg","#000000");core.canvas.fg.fillText(e,32*j+17,32*(k+1)-13);core.canvas.fg.fillText(e,32*j+15,32*(k+1)-15);core.canvas.fg.fillText(e,32*j+17,32*(k+1)-15);core.canvas.fg.fillText(e,32*j+15,32*(k+1)-13);core.setFillStyle("fg","#FF7F00");core.canvas.fg.fillText(e,32*j+16,32*(k+1)-14)}}}}};control.prototype.doEffect=function(b){var a=b.split("+=");if(a.length!=2){return}var d=a[0],f=core.calValue(a[1]);if(d.indexOf("status:")==0){var e=d.substring(7);core.setStatus(e,core.getStatus(e)+f)}else{if(d.indexOf("item:")==0){var c=d.substring(5);core.setItem(c,core.itemCount(c)+f)}}};control.prototype.debug=function(){core.setFlag("debug",true);core.insertAction(["\t[调试模式开启]此模式下按住Ctrl键可以穿墙并忽略一切事件。\n同时录像将失效也无法上传成绩。"])};control.prototype.startReplay=function(a){core.status.replay.replaying=true;core.status.replay.pausing=false;core.status.replay.speed=1;core.status.replay.toReplay=core.clone(a);core.status.replay.totalList=core.clone(a);core.status.replay.steps=0;core.status.replay.save=[];core.updateStatusBar();core.drawTip("开始播放");this.replay();return};control.prototype.triggerReplay=function(){if(core.status.event.id=="save"){return}if(core.status.replay.pausing){this.resumeReplay()}else{this.pauseReplay()}};control.prototype.pauseReplay=function(){if(core.status.event.id=="save"){return}if(!core.status.replay.replaying){return}core.status.replay.pausing=true;core.updateStatusBar();core.drawTip("暂停播放")};control.prototype.resumeReplay=function(){if(core.status.event.id=="save"){return}if(!core.status.replay.replaying){return}core.status.replay.pausing=false;core.updateStatusBar();core.drawTip("恢复播放");core.replay()};control.prototype.speedUpReplay=function(){if(core.status.event.id=="save"){return}if(!core.status.replay.replaying){return}var a=core.status.replay.speed>=3?3:core.status.replay.speed>=2?2:1;core.status.replay.speed=parseInt(10*core.status.replay.speed+a)/10;if(core.status.replay.speed>6){core.status.replay.speed=6}core.drawTip("x"+core.status.replay.speed+"倍")};control.prototype.speedDownReplay=function(){if(core.status.event.id=="save"){return}if(!core.status.replay.replaying){return}var a=core.status.replay.speed>3?3:core.status.replay.speed>2?2:1;core.status.replay.speed=parseInt(10*core.status.replay.speed-a)/10;if(core.status.replay.speed<0.3){core.status.replay.speed=0.3}core.drawTip("x"+core.status.replay.speed+"倍")};control.prototype.stopReplay=function(){if(core.status.event.id=="save"){return}if(!core.status.replay.replaying){return}core.status.replay.toReplay=[];core.status.replay.totalList=[];core.status.replay.replaying=false;core.status.replay.pausing=false;core.status.replay.speed=1;core.status.replay.steps=0;core.status.replay.save=[];core.updateStatusBar();core.drawTip("停止播放并恢复游戏")};control.prototype.rewindReplay=function(){if(core.status.event.id=="save"){return}if(!core.status.replay.replaying){return}if(!core.status.replay.pausing){core.drawTip("请先暂停录像");return}if(core.status.replay.animate){core.drawTip("请等待当前事件的处理结束");return}if(core.status.replay.save.length==0){core.drawTip("无法再回到上一个节点");return}var b=core.status.replay.save;var a=b.pop();core.loadData(a.data,function(){core.status.replay={replaying:true,pausing:true,animate:false,toReplay:a.replay.toReplay,totalList:a.replay.totalList,speed:a.replay.speed,steps:a.replay.steps,save:b};core.updateStatusBar();core.drawTip("成功回退到上一个节点")})};control.prototype.saveReplay=function(){if(!core.status.replay.replaying){return}if(!core.status.replay.pausing){core.drawTip("请先暂停录像");return}if(core.status.replay.animate||core.isset(core.status.event.id)){core.drawTip("请等待当前事件的处理结束");return}core.lockControl();core.status.event.id="save";var c=core.status.saveIndex;var b=parseInt((c-1)/5),a=c-5*b;core.ui.drawSLPanel(10*b+a)};control.prototype.bookReplay=function(){if(!core.status.replay.replaying){return}if(!core.status.replay.pausing){core.drawTip("请先暂停录像");return}if(core.status.replay.animate||core.isset(core.status.event.id)){core.drawTip("请等待当前事件的处理结束");return}core.lockControl();core.status.event.id="book";core.useItem("book")};control.prototype.replay=function(){if(!core.status.replay.replaying){return}if(core.status.replay.pausing){return}if(core.status.replay.animate){return}if(core.status.replay.toReplay.length==0){core.stopReplay();core.insertAction("录像回放完毕!");return}core.status.replay.steps++;if(core.status.replay.steps%50==0){core.status.replay.save.push({data:core.saveData(),replay:{totalList:core.clone(core.status.replay.totalList),toReplay:core.clone(core.status.replay.toReplay),speed:core.status.replay.speed,steps:core.status.replay.steps}})}var a=core.status.replay.toReplay.shift();if(a=="up"||a=="down"||a=="left"||a=="right"){core.moveHero(a,function(){setTimeout(function(){core.replay()})});return}else{if(a.indexOf("item:")==0){var h=a.substring(5);if(core.canUseItem(h)){var s=Object.keys(core.status.hero.items.tools).sort();var d=Object.keys(core.status.hero.items.constants).sort();var g;if((g=s.indexOf(h))>=0||(g=d.indexOf(h)+100)>=100){core.ui.drawToolbox(g);setTimeout(function(){core.ui.closePanel();core.useItem(h,function(){core.replay()})},750/core.status.replay.speed)}return}}else{if(a.indexOf("fly:")==0){var e=a.substring(4);var r=core.status.hero.flyRange.indexOf(e);var k=core.status.hero.flyRange.indexOf(core.status.floorId);if(core.hasItem("fly")&&r>=0&&k>=0){core.ui.drawFly(r);setTimeout(function(){core.ui.closePanel();var w=r<k?"upFloor":"downFloor";core.status.route.push("fly:"+e);core.changeFloor(e,w,null,null,function(){core.replay()})},750/core.status.replay.speed);return}}else{if(a.indexOf("shop:")==0){var q=a.substring(5).split(":");var o=q[0],m=q[1].split("");if(m.length>0){var n=core.status.shops[o];if(core.isset(n)&&n.visited){var c=n.choices;var t=6-parseInt(c.length/2);core.status.event.selection=parseInt(m.shift());core.events.openShop(o,false);var p=setInterval(function(){if(!core.actions.clickShop(6,t+core.status.event.selection)){clearInterval(p);core.stopReplay();core.drawTip("录像文件出错");return}if(m.length==0){clearInterval(p);core.actions.clickShop(6,t+c.length);core.replay();return}core.status.event.selection=parseInt(m.shift());core.events.openShop(o,false)},750/core.status.replay.speed);return}}}else{if(a=="turn"){core.turnHero();core.replay();return}else{if(a=="getNext"){if(core.flags.enableGentleClick&&core.getBlock(core.nextX(),core.nextY())!=null){var i=core.nextX(),j=core.nextY();var b=core.getBlock(i,j);if(b!=null&&b.block.event.trigger=="getItem"){core.getItem(b.block.event.id,1,i,j);core.status.route.push("getNext");core.replay();return}}}else{if(a.indexOf("move:")==0){var l=a.substring(5).split(":");var u=parseInt(l[0]),v=parseInt(l[1]);var f=core.canMoveDirectly(u,v);if(f>0){core.clearMap("hero",0,0,416,416);core.setHeroLoc("x",u);core.setHeroLoc("y",v);core.drawHero();core.status.route.push("move:"+u+":"+v);core.status.hero.statistics.moveDirectly++;core.status.hero.statistics.ignoreSteps+=f;core.replay();return}}else{if(a.indexOf("key:")==0){core.actions.keyUp(parseInt(a.substring(4)),true);core.replay();return}}}}}}}}core.stopReplay();core.insertAction("录像文件出错")};control.prototype.checkStatus=function(b,c,a){if(c&&core.status.event.id==b){core.ui.closePanel();return false}if(c&&core.status.lockControl){return false}if(core.isset(a)&&a&&!core.hasItem(b)){core.drawTip("你没有"+core.material.items[b].name);return false}if(!core.status.heroStop){core.drawTip("请先停止勇士行动");return false}core.lockControl();core.status.event.id=b;return true};control.prototype.openBook=function(a){if(core.isset(core.status.replay)&&core.status.replay.replaying){return}if(core.status.event.id=="book"&&core.isset(core.status.event.selection)){core.status.boxAnimateObjs=[];core.ui.drawMaps(core.status.event.selection);return}if(core.status.event.id=="viewMaps"){a=false;core.status.event.selection=core.status.event.data}if(!core.checkStatus("book",a,true)){return}core.useItem("book")};control.prototype.useFly=function(a){if(core.isset(core.status.replay)&&core.status.replay.replaying){return}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};control.prototype.openToolbox=function(a){if(core.isset(core.status.replay)&&core.status.replay.replaying){return}if(!core.checkStatus("toolbox",a)){return}core.ui.drawToolbox()};control.prototype.openQuickShop=function(a){if(core.isset(core.status.replay)&&core.status.replay.replaying){return}if(!core.checkStatus("selectShop",a)){return}core.ui.drawQuickShop()};control.prototype.save=function(a){if(core.isset(core.status.replay)&&core.status.replay.replaying){return}if(!core.checkStatus("save",a)){return}var d=core.status.saveIndex;var c=parseInt((d-1)/5),b=d-5*c;core.ui.drawSLPanel(10*c+b)};control.prototype.load=function(a){if(core.isset(core.status.replay)&&core.status.replay.replaying){return}var d=core.getLocalStorage("saveIndex2",1);var c=parseInt((d-1)/5),b=d-5*c;if(!core.isPlaying()){core.status.event={id:"load",data:null};core.status.lockControl=true;core.dom.startPanel.style.display="none";core.ui.drawSLPanel(10*c+b);return}if(!core.checkStatus("load",a)){return}core.ui.drawSLPanel(10*c+b)};control.prototype.openSettings=function(a){if(core.isset(core.status.replay)&&core.status.replay.replaying){return}if(!core.checkStatus("settings",a)){return}core.ui.drawSettings()};control.prototype.autosave=function(a){if(core.status.event.id!=null){return}var b=null;if(a){b=core.status.route.pop()}core.setLocalStorage("autoSave",core.saveData());if(a&&core.isset(b)){core.status.route.push(b)}};control.prototype.doSL=function(b,e){if(e=="save"){if(b=="autoSave"){core.drawTip("不能覆盖自动存档!");return}if(core.setLocalStorage("save"+b,core.saveData())){core.ui.closePanel();core.drawTip("存档成功!");if(b!="autoSave"){core.status.saveIndex=b;core.setLocalStorage("saveIndex2",core.status.saveIndex)}}else{core.drawTip("存储空间不足,请覆盖已有的存档或在菜单栏中进行清理")}return}else{if(e=="load"){var a=core.getLocalStorage(b=="autoSave"?b:"save"+b,null);if(!core.isset(a)){core.drawTip("无效的存档");return}if(a.version!=core.firstData.version){if(confirm("存档版本不匹配!\n你想回放此存档的录像吗")){core.dom.startPanel.style.display="none";var d=a.hero.flags.seed;core.resetStatus(core.firstData.hero,a.hard,core.firstData.floorId,null,core.initStatus.maps);core.events.setInitData(a.hard);core.setFlag("seed",d);core.setFlag("rand",d);core.changeFloor(core.status.floorId,null,core.firstData.hero.loc,null,function(){core.startReplay(core.decodeRoute(a.route))},true)}return}core.ui.closePanel();core.loadData(a,function(){core.drawTip("读档成功");if(b!="autoSave"){core.status.saveIndex=b;core.setLocalStorage("saveIndex2",core.status.saveIndex)}});return}else{if(e=="replayLoad"){var a=core.getLocalStorage(b=="autoSave"?b:"save"+b,null);if(!core.isset(a)){core.drawTip("无效的存档");return}if(a.version!=core.firstData.version){core.drawTip("存档版本不匹配");return}if(a.hard!=core.status.hard){core.drawTip("游戏难度不匹配!");return}var c=core.subarray(core.status.route,core.decodeRoute(a.route));if(!core.isset(c)||a.hero.flags.seed!=core.getFlag("seed")){core.drawTip("无法从此存档回放录像");return}core.loadData(a,function(){core.startReplay(c);core.drawTip("回退到存档节点")})}}}};control.prototype.syncSave=function(f){var e=null;if(f=="all"){e=[];for(var c=1;c<=5*(main.savePages||30);c++){var a=core.getLocalStorage("save"+c,null);if(core.isset(a)){e.push(a)}}}else{for(var c=5*(main.savePages||30);c>=1;c--){e=core.getLocalStorage("save"+c,null);if(core.isset(e)){break}}}if(!core.isset(e)){core.drawText("没有要同步的存档");return}core.ui.drawWaiting("正在同步,请稍后...");var b=new FormData();b.append("type","save");b.append("name",core.firstData.name);var d=JSON.stringify(e);b.append("data",d);core.http("POST","/games/sync.php",b,function(g){var h=JSON.parse(g);if(h.code<0){core.drawText("出错啦!\n无法同步存档到服务器。\n错误原因"+h.msg)}else{core.drawText("同步成功!\n\n您的存档编号 "+h.code+"\n您的存档密码 "+h.msg+"\n\n请牢记以上两个信息如截图等在从服务器\n同步存档时使用。")}},function(g){core.drawText("出错啦!\n无法同步存档到服务器。\n错误原因"+g)})};control.prototype.syncLoad=function(){var b=prompt("请输入存档编号:");if(b==null||b==""){core.ui.drawSyncSave();return}var c=prompt("请输入存档密码:");if(c==null||c==""){core.ui.drawSyncSave();return}core.ui.drawWaiting("正在同步,请稍后...");var a=new FormData();a.append("type","load");a.append("name",core.firstData.name);a.append("id",b);a.append("password",c);core.http("POST","/games/sync.php",a,function(d){var g=JSON.parse(d);switch(g.code){case 0:var d=JSON.parse(g.msg);if(d instanceof Array){core.status.event.selection=1;core.ui.drawConfirmBox("所有本地存档都将被覆盖,确认?",function(){for(var h=1;h<=5*(main.savePages||30);h++){if(h<=d.length){core.setLocalStorage("save"+h,d[h-1])}else{core.removeLocalStorage("save"+h)}}core.drawText("同步成功!\n你的本地所有存档均已被覆盖。")},function(){core.status.event.selection=0;core.ui.drawSyncSave()})}else{var f=5*(main.savePages||30);for(var e=5*(main.savePages||30);e>=1;e--){if(core.getLocalStorage("save"+e,null)==null){f=e}else{break}}core.setLocalStorage("save"+f,d);core.drawText("同步成功!\n单存档已覆盖至存档"+f)}break;case -1:core.drawText("出错啦!\n存档编号"+b+"不存在!");break;case -2:core.drawText("出错啦!\n存档密码错误");break;default:core.drawText("出错啦!\n无法从服务器同步存档。\n错误原因"+g.msg);break}},function(d){core.drawText("出错啦!\n无法从服务器同步存档。\n错误原因"+d)})};control.prototype.saveData=function(){var a={floorId:core.status.floorId,hero:core.clone(core.status.hero),hard:core.status.hard,maps:core.maps.save(core.status.maps),route:core.encodeRoute(core.status.route),shops:{},version:core.firstData.version,time:new Date().getTime()};for(var b in core.status.shops){a.shops[b]={times:core.status.shops[b].times||0,visited:core.status.shops[b].visited||false}}core.events.beforeSaveData(a);return a};control.prototype.loadData=function(b,a){core.resetStatus(b.hero,b.hard,b.floorId,core.decodeRoute(b.route),core.maps.load(b.maps));for(var d in core.status.shops){if(core.isset(b.shops[d])){core.status.shops[d].times=b.shops[d].times;core.status.shops[d].visited=b.shops[d].visited}}var c=core.getFlag("heroIcon","hero.png");if(core.isset(core.material.images.images[c])){core.material.images.hero.src=core.material.images.images[c].src;core.material.icons.hero.height=core.material.images.images[c].height/4}core.events.afterLoadData(b);core.changeFloor(b.floorId,null,b.hero.loc,0,function(){if(core.isset(a)){a()}},true)};control.prototype.setStatus=function(a,b){if(core.isset(core.status.hero.loc[a])){core.status.hero.loc[a]=b}else{core.status.hero[a]=b}};control.prototype.getStatus=function(a){if(core.isset(core.status.hero.loc[a])){return core.status.hero.loc[a]}return core.status.hero[a]};control.prototype.getLvName=function(){if(core.status.hero.lv>core.firstData.levelUp.length){return core.status.hero.lv}return core.firstData.levelUp[core.status.hero.lv-1].name||core.status.hero.lv};control.prototype.setFlag=function(a,b){if(!core.isset(core.status.hero)){return}core.status.hero.flags[a]=b};control.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};control.prototype.hasFlag=function(a){if(core.getFlag(a)){return true}return false};control.prototype.lockControl=function(){core.status.lockControl=true};control.prototype.unLockControl=function(){core.status.lockControl=false};control.prototype.playBgm=function(a){if(main.mode!="play"){return}if(!core.musicStatus.bgmStatus){return}if(!core.isset(core.material.bgms[a])){return}if(core.material.bgms[a]=="loading"){core.material.bgms[a]="starting";return}try{if(core.musicStatus.playingBgm==a&&core.musicStatus.isPlaying){return}if(core.isset(core.musicStatus.playingBgm)&&core.musicStatus.isPlaying){core.material.bgms[core.musicStatus.playingBgm].pause()}core.material.bgms[a].volume=core.musicStatus.volume;core.material.bgms[a].play();core.musicStatus.playingBgm=a;core.musicStatus.isPlaying=true}catch(b){console.log("无法播放BGM "+a);console.log(b);core.musicStatus.playingBgm=null}};control.prototype.pauseBgm=function(){try{if(core.isset(core.musicStatus.playingBgm)){core.material.bgms[core.musicStatus.playingBgm].pause()}core.musicStatus.isPlaying=false}catch(a){console.log("无法暂停BGM "+bgm);console.log(a)}};control.prototype.resumeBgm=function(){if(main.mode!="play"){return}if(!core.musicStatus.bgmStatus){return}try{if(core.isset(core.musicStatus.playingBgm)){core.material.bgms[core.musicStatus.playingBgm].play();core.musicStatus.isPlaying=true}else{if(core.bgms.length>0){if(core.isset(core.floors[core.status.floorId].bgm)){core.playBgm(core.floors[core.status.floorId].bgm)}else{core.playBgm(core.bgms[0])}core.musicStatus.isPlaying=true}}}catch(a){console.log("无法恢复BGM "+bgm);console.log(a)}};control.prototype.playSound=function(d){if(main.mode!="play"){return}if(!core.musicStatus.soundStatus){return}if(!core.isset(core.material.sounds[d])){return}try{if(core.musicStatus.audioContext!=null){var f=core.musicStatus.audioContext.createBufferSource();f.buffer=core.material.sounds[d];f.connect(core.musicStatus.gainNode);try{f.start(0)}catch(a){try{f.noteOn(0)}catch(b){}}}else{core.material.sounds[d].volume=core.musicStatus.volume;core.material.sounds[d].play()}}catch(c){console.log("无法播放SE "+d);console.log(c)}};control.prototype.clearStatusBar=function(){var a=["floor","lv","hp","atk","def","mdef","money","experience","up","yellowKey","blueKey","redKey","poison","weak","curse","hard"];a.forEach(function(b){core.statusBar[b].innerHTML="&nbsp;"});core.statusBar.image.book.style.opacity=0.3;core.statusBar.image.fly.style.opacity=0.3};control.prototype.updateStatusBar=function(){core.events.checkLvUp();if(core.flags.enableHPMax){core.setStatus("hp",Math.min(core.getStatus("hpmax"),core.getStatus("hp")))}core.updateCheckBlock();var b=core.getLvName();core.statusBar.lv.innerHTML=b;if(/^[+-]?\d+$/.test(b)){core.statusBar.lv.style.fontStyle="italic"}else{core.statusBar.lv.style.fontStyle="normal"}var c=["hpmax","hp","atk","def","mdef","money","experience"];c.forEach(function(d){if(core.isset(core.status.hero[d])){core.status.hero[d]=Math.floor(core.status.hero[d])}core.statusBar[d].innerHTML=core.formatBigNumber(core.getStatus(d))});if(core.flags.enableLevelUp&&core.status.hero.lv<core.firstData.levelUp.length){core.statusBar.up.innerHTML=core.firstData.levelUp[core.status.hero.lv].need||"&nbsp;"}else{core.statusBar.up.innerHTML="&nbsp;"}var a=["yellowKey","blueKey","redKey"];a.forEach(function(d){core.statusBar[d].innerHTML=core.setTwoDigits(core.status.hero.items.keys[d])});if(core.flags.enableDebuff){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.status.replay.replaying){core.statusBar.image.book.src=core.status.replay.pausing?core.statusBar.icons.play.src:core.statusBar.icons.pause.src;core.statusBar.image.book.style.opacity=1;core.statusBar.image.fly.src=core.statusBar.icons.stop.src;core.statusBar.image.fly.style.opacity=1;core.statusBar.image.toolbox.src=core.statusBar.icons.rewind.src;core.statusBar.image.shop.src=core.statusBar.icons.book.src;core.statusBar.image.save.src=core.statusBar.icons.speedDown.src;core.statusBar.image.load.src=core.statusBar.icons.speedUp.src;core.statusBar.image.settings.src=core.statusBar.icons.save.src}else{core.statusBar.image.book.src=core.statusBar.icons.book.src;core.statusBar.image.book.style.opacity=core.hasItem("book")?1:0.3;core.statusBar.image.fly.src=core.statusBar.icons.fly.src;core.statusBar.image.fly.style.opacity=core.hasItem("fly")?1:0.3;core.statusBar.image.toolbox.src=core.statusBar.icons.toolbox.src;core.statusBar.image.shop.src=core.statusBar.icons.shop.src;core.statusBar.image.save.src=core.statusBar.icons.save.src;core.statusBar.image.load.src=core.statusBar.icons.load.src;core.statusBar.image.settings.src=core.statusBar.icons.settings.src}core.updateFg()};control.prototype.resize=function(i,h){if(main.mode=="editor"){return}var m=422;var l=132;var c=32;var v=3;var n=16;var a=m;var g=m+l;var U=i;var r=false;if(i>h&&h<a){r=true;U=h}var q,p,d,f,e,z,y,x,F,A,E,B,N,L,M,J,S,P,Q,R,o,K,s,w,O;var k=core.dom.statusBar.children.length;if(!core.flags.enableFloor){k--}if(!core.flags.enableLv){k--}if(!core.flags.enableHPMax){k--}if(!core.flags.enableMDef){k--}if(!core.flags.enableMoney){k--}if(!core.flags.enableExperience){k--}if(!core.flags.enableLevelUp){k--}if(!core.flags.enableDebuff){k--}if(core.isset(core.flags.enableKeys)&&!core.flags.enableKeys){k--}var D=c*9/k;var C=n;if(k>9){C=C*9/k}var u;x="3px #fff solid";J="3px #fff solid";var V=(a-U)/4.22;var b=1-V/100;if(U<g){if(U<a){core.domStyle.scale=b;f=U}else{f=m;core.domStyle.scale=1}var t=core.domStyle.scale;var I=m*t;if(!r){core.domStyle.screenMode="vertical";u="block";var j=parseInt((k-1)/3)+1;var H=t*(c*j+v*2)+6;var G=t*(c+v*4)+6;p=I+H+G;q=I;e=H;N=z=f;y=H;x="3px #fff solid";A=t*c*0.8;B=0.8*c*t;E=t*l*0.95;w=main.statusTopBackground;L=G;M=y+f;J="3px #fff solid";P=t*c;R=t*l*0.4;O=main.toolsBackground;d="3px #fff solid";s=t*v*2;Q=t*v*4;o=n*t;K=n*t}else{core.domStyle.screenMode="horizontal";u="none";q=I+l*t;p=I;e=0;N=z=l*t;y=p-v;x="3px #fff solid";w=main.statusLeftBackground;A=t*D*0.8;B=0.8*D*t;M=t*D*k+v*2;L=f-M;J="3px #fff solid";P=t*c;O="transparent";o=C*t;K=n*t;d="";E=t*l;R=t*l;s=t*v*2;Q=2*v*t}}else{core.domStyle.scale=1;core.domStyle.screenMode="bigScreen";u="none";q=m+l;p=m;f=m;e=0;N=z=l;w=main.statusLeftBackground;y=p-v;A=D*0.8;B=0.8*D;M=D*k+v*2;L=m-M;O="transparent";P=c;d="";o=C;K=n;E=l;R=l*0.9;s=v*2;Q=2*v}var T="px";core.domStyle.styles=[{id:"gameGroup",rules:{width:q+T,height:p+T,top:(h-p)/2+T,left:(i-q)/2+T,}},{className:"gameCanvas",rules:{width:f+T,height:f+T,top:e+T,right:0,border:"3px #fff solid",}},{id:"gif",rules:{width:(f-v*2)+T,height:(f-v*2)+T,top:(e+v)+T,right:v+T,}},{id:"gif2",rules:{width:(f-v*2)+T,height:(f-v*2)+T,top:(e+v)+T,right:v+T,}},{id:"curtain",rules:{width:(f-v*2)+T,height:(f-v*2)+T,top:(e+v)+T,right:v+T,}},{id:"floorMsgGroup",rules:{width:(f-v*2)+T,height:(p-v*2)+T,top:v+T,right:v+T,}},{id:"statusBar",rules:{width:z+T,height:y+T,top:0,left:0,padding:v+T,borderTop:x,borderLeft:x,borderRight:d,fontSize:o+T,background:w,}},{className:"status",rules:{width:"100%",maxWidth:E+T,height:A+T,margin:s/2+T}},{className:"statusLabels",rules:{marginLeft:s+T,lineHeight:B+T,}},{id:"toolBar",rules:{width:N+T,height:L+T,top:M+T,left:0,padding:v+T,borderBottom:J,borderLeft:J,borderRight:d,fontSize:K+T,background:O,}},{className:"tools",rules:{height:P+T,maxWidth:R+T,marginLeft:Q+T,marginTop:s+T,}},{imgId:"shop",rules:{display:u}},{id:"floorCol",rules:{display:core.flags.enableFloor?"block":"none"}},{id:"lvCol",rules:{display:core.flags.enableLv?"block":"none"}},{id:"hpmaxCol",rules:{display:core.flags.enableHPMax?"block":"none"}},{id:"mdefCol",rules:{display:core.flags.enableMDef?"block":"none"}},{id:"moneyCol",rules:{display:core.flags.enableMoney?"block":"none"}},{id:"expCol",rules:{display:core.flags.enableExperience?"block":"none"}},{id:"upCol",rules:{display:core.flags.enableLevelUp?"block":"none"}},{id:"keyCol",rules:{display:!core.isset(core.flags.enableKeys)||core.flags.enableKeys?"block":"none"}},{id:"debuffCol",rules:{display:core.flags.enableDebuff?"block":"none"}},{id:"hard",rules:{lineHeight:P+T}}];core.domRenderer()};control.prototype.domRenderer=function(){core.dom.statusBar.style.display="block";core.dom.toolBar.style.display="block";var l=core.domStyle.styles;for(var b=0;b<l.length;b++){if(l[b].hasOwnProperty("rules")){var g=l[b].rules;var h=Object.keys(g);if(l[b].hasOwnProperty("className")){var a=l[b].className;for(var e=0;e<core.dom[a].length;e++){for(var f=0;f<h.length;f++){core.dom[a][e].style[h[f]]=g[h[f]]}}}if(l[b].hasOwnProperty("id")){var c=l[b].id;for(var e=0;e<h.length;e++){core.dom[c].style[h[e]]=g[h[e]]}}if(l[b].hasOwnProperty("imgId")){var d=l[b].imgId;for(var e=0;e<h.length;e++){core.statusBar.image[d].style[h[e]]=g[h[e]]}}}}};