mota-js/libs/core.min.js
2017-12-04 01:35:38 +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.firstData={};this.material={images:{},sounds:{},ground:null,items:{},enemys:{},icons:{},events:{},npcs:{}};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:{id:"",name:"",hp:0,atk:0,def:0,mdef:0,money:0,experience:0,loc:{direction:"down",x:0,y:0},flyRange:[],items:[]},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:{},npcs:{},event:{id:null,data:null},openingDoor:null,twoAnimateObjs:[],fourAnimateObjs:[],boxAnimateObjs:[]};this.status={};this.flags={}}core.prototype.init=function(h,c,d,b,a,f){core.dom=h;core.statusBar=c;core.canvas=d;core.images=b;core.sounds=a;for(var e in f){core[e]=f[e]}core.firstData=core.data.getFirstData();core.initStatus.shops=core.firstData.shops;core.initStatus.npcs=core.firstData.npcs;core.dom.versionLabel.innerHTML=core.firstData.version;core.material.items=core.items.getItems();core.initStatus.maps=core.maps.getMaps();core.material.enemys=core.clone(core.enemys.getEnemys());core.material.icons=core.icons.getIcons();core.material.events=core.events.getEvents();core.material.npcs=core.npcs.getNpcs();core.flags=core.data.flags;core.musicStatus.soundStatus=core.getLocalStorage("soundStatus",true);var g=navigator.userAgent;if(g.indexOf("iPhone")>-1||g.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(function(){})})};core.prototype.showStartAnimate=function(c){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 a=window.setInterval(function(){b-=0.03;if(b<0){clearInterval(a);core.dom.startTop.style.display="none";core.dom.startButtonGroup.style.display="block";if(core.isset(c)){c()}}core.dom.startTop.style.opacity=b},20)};core.prototype.hideStartAnimate=function(c){var b=1;var a=window.setInterval(function(){b-=0.03;if(b<0){clearInterval(a);core.dom.startPanel.style.display="none";c()}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(g){var e=0,a=0,f=0,d=0;a=core.images.length;for(var c in core.sounds){d+=core.sounds[c].length}for(var b=0;b<core.images.length;b++){core.loadImage(core.images[b],function(k,m){core.setStartLoadTipText("正在加载图片 "+k+"...");k=k.split("-");k=k[0];core.material.images[k]=m;e++;core.setStartLoadTipText(k+" 加载完毕...");core.setStartProgressVal(e*(100/a));if(e==a){for(var j in core.sounds){for(var h=0;h<core.sounds[j].length;h++){var n=core.sounds[j][h];n=n.split("-");var l=new Audio();l.preload="none";l.src="sounds/"+n[0]+"."+j;if(n[1]=="loop"){l.loop="loop"}if(!core.isset(core.material.sounds[j])){core.material.sounds[j]={}}core.material.sounds[j][n[0]]=l}}g()}})}};core.prototype.loadImage=function(a,d){try{core.setStartLoadTipText("加载图片 "+a+" 中...");var c=new Image();c.src="images/"+a+".png";if(c.complete){d(a,c);return}c.onload=function(){d(a,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 b in core.material.sounds){for(var a in core.material.sounds[b]){c.push(core.material.sounds[b][a])}}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,e,b,d){for(var a in core.interval){clearInterval(core.interval[a])}core.status=core.clone(core.initStatus);core.status.played=true;core.status.floorId=b;core.status.maps=core.clone(d);core.material.enemys=core.clone(core.enemys.getEnemys());core.status.hero=core.clone(c);core.status.hard=e;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,function(){core.setHeroMoveTriggerInterval();if(core.isset(a)){a()}})};core.prototype.restart=function(){core.showStartAnimate()};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.keyCode==37){core.ui.drawEnemyBook(core.status.event.data-1)}else{if(a.keyCode==39){core.ui.drawEnemyBook(core.status.event.data+1)}}return}if(core.status.event.id=="fly"){if(a.keyCode==38){core.ui.drawFly(core.status.event.data+1)}else{if(a.keyCode==40){core.ui.drawFly(core.status.event.data-1)}}return}if(core.status.event.id=="save"||core.status.event.id=="load"){if(a.keyCode==37){core.ui.drawSLPanel(core.status.event.data-1)}else{if(a.keyCode==39){core.ui.drawSLPanel(core.status.event.data+1)}}return}return}switch(a.keyCode){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(d){if(!core.status.played){return}if(core.status.lockControl){if(core.status.event.id=="book"&&(d.keyCode==27||d.keyCode==88)){core.ui.closePanel(true)}if(core.status.event.id=="fly"&&(d.keyCode==71||d.keyCode==27)){core.ui.closePanel()}if(core.status.event.id=="fly"&&d.keyCode==13){var a=core.status.hero.flyRange.indexOf(core.status.floorId);var c=core.status.event.data<a?"upFloor":"downFloor";var b=core.status.event.data;core.ui.closePanel();core.changeFloor(core.status.hero.flyRange[b],c)}if(core.status.event.id=="save"&&(d.keyCode==83||d.keyCode==27)){core.ui.closePanel()}if(core.status.event.id=="load"&&(d.keyCode==76||d.keyCode==27)){core.ui.closePanel()}if((core.status.event.id=="shop"||core.status.event.id=="settings"||core.status.event.id=="selectShop")&&d.keyCode==27){core.ui.closePanel()}if(core.status.event.id=="selectShop"&&d.keyCode==75){core.ui.closePanel()}if(core.status.event.id=="toolbox"&&(d.keyCode==84||d.keyCode==27)){core.ui.closePanel()}if(core.status.event.id=="about"&&(d.keyCode==13||d.keyCode==32)){core.ui.closePanel()}if(core.status.event.id=="text"&&(d.keyCode==13||d.keyCode==32)){core.drawText()}if(core.status.event.id=="npc"&&core.isset(core.status.event.data.current)&&core.status.event.data.current.action=="text"&&(d.keyCode==13||d.keyCode==32)){core.npcAction()}return}switch(d.keyCode){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.drawSelectShop(true);break;case 37:break;case 38:break;case 39:break;case 40:break}core.stopHero()};core.prototype.ondown=function(a,c){if(!core.status.played||core.status.lockControl){core.onclick(a,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 b={x:a,y:c};core.status.stepPostfix=[];core.status.stepPostfix.push(b);core.fillPosWithPoint(b)};core.prototype.onmove=function(b,h){if(core.status.holdingPath==0){return}core.status.mouseOutCheck=1;var g={x:b,y:h};var e=core.status.stepPostfix[core.status.stepPostfix.length-1];var f=[g.y-e.y,e.x-g.x,e.y-g.y,g.x-e.x];var a=0,c=4;for(var d=0;d<4;d++){if(f[d]>a){c=d;a=f[d]}}g=[{x:0,y:1},{x:-1,y:0},{x:0,y:-1},{x:1,y:0},false][c];if(g){g.x+=e.x;g.y+=e.y;core.status.stepPostfix.push(g);core.fillPosWithPoint(g)}};core.prototype.onup=function(){core.status.holdingPath=0;if(core.status.stepPostfix.length>0){var b=[];var e={"0":{"1":"down","-1":"up"},"-1":{"0":"left"},"1":{"0":"right"}};for(var c=1;c<core.status.stepPostfix.length;c++){var d=core.status.stepPostfix[c-1];var g=core.status.stepPostfix[c];b.push({direction:e[g.x-d.x][g.y-d.y],x:g.x,y:g.y})}var a=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(a,f,b)}};core.prototype.getClickLoc=function(a,g){if(!core.isset(core.position.canvas.top)){return null}var b={x:0,y:0};var c=32;c=c*core.position.scale;switch(core.position.screenMode){case"vertical":b.x=0;b.y=core.position.statusBar.height+3;break;case"horizontal":b.x=core.position.statusBar.width+3;console.log(core.position.statusBar.width);b.y=0;break;case"bigScreen":b.x=core.position.statusBar.width+3;b.y=0;break}var e=core.dom.gameGroup.offsetLeft+b.x;var d=core.dom.gameGroup.offsetTop+b.y;var f={x:a-e,y:g-d,size:c};return f};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=="text"){core.drawText();return}if(core.status.event.id=="npc"){core.events.clickNPC(b,c);return}if(core.status.event.id=="syncSave"){if(b>=4&&b<=8){if(c==5){core.showConfirmBox("你确定要将本地存档同步到服务器吗?",function(){core.waiting("正在同步,请稍后...");var h=new FormData();h.append("type","save");var d=[];for(var e=1;e<=180;e++){var g=core.getLocalStorage("save"+e,null);if(core.isset(g)){d.push(g)}}var f=JSON.stringify(d);h.append("data",f);var j=new XMLHttpRequest();j.open("POST","../sync.php");j.timeout=1000;j.onload=function(k){if(j.status==200){var i=JSON.parse(j.response);if(i.code<0){core.drawText("出错啦!\n无法同步存档到服务器。")}else{core.drawText("同步成功!\n\n您的存档编号 "+i.code+"\n您的存档密码 "+i.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(h)},function(){core.syncSave()})}if(c==6){core.showConfirmBox("你确定要从服务器加载存档吗?\n该操作将覆盖所有本地存档且不可逆",function(){var g=prompt("请输入存档编号:");if(g==null||g==""){core.syncSave();return}var d=prompt("请输入存档密码:");if(d==null||d==""){core.syncSave();return}core.waiting("正在同步,请稍后...");var e=new FormData();e.append("type","load");e.append("id",g);e.append("password",d);var f=new XMLHttpRequest();f.open("POST","../sync.php");f.timeout=1000;f.onload=function(l){if(f.status==200){var h=JSON.parse(f.response);switch(h.code){case 0:var k=JSON.parse(h.msg);for(var j=1;j<=180;j++){if(j<=k.length){core.setLocalStorage("save"+j,k[j-1])}else{core.removeLocalStorage("save"+j)}}core.drawText("同步成功!\n你的本地所有存档均已被覆盖。");break;case -1:core.drawText("出错啦!\n存档编号"+g+"不存在!");break;case -2:core.drawText("出错啦!\n存档密码错误");break;default:core.drawText("出错啦!\n无法从服务器同步存档。");break}}else{core.drawText("出错啦!\n无法从服务器同步存档。")}};f.ontimeout=function(h){console.log(h);core.drawText("出错啦!\n无法从服务器同步存档。")};f.onerror=function(h){console.log(h);core.drawText("出错啦!\n无法从服务器同步存档。")};f.send(e)},function(){core.syncSave()})}}if(b>=5&&b<=7&&c==7){core.ui.openSettings(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(d,c,b){if(!core.status.played||core.status.lockControl){return}else{if(core.status.automaticRouting){core.stopAutomaticRoute();return}}if(d==core.status.hero.loc.x&&c==core.status.hero.loc.y){core.turnHero();return}var f=0;var g=null;var e;core.status.automaticRoutingTemp={destX:0,destY:0,moveStep:[]};if(!(e=core.automaticRoute(d,c))){core.canvas.ui.clearRect(0,0,416,416);return false}e=e.concat(b);core.status.automaticRoutingTemp.destX=d;core.status.automaticRoutingTemp.destY=c;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 a=0;a<e.length;a++){if(g==null){f++;g=e[a].direction}else{if(g==e[a].direction){f++}else{core.status.automaticRoutingTemp.moveStep.push({direction:g,step:f});f=1;g=e[a].direction}}if(a==e.length-1){core.status.automaticRoutingTemp.moveStep.push({direction:g,step:f});core.canvas.ui.fillRect(e[a].x*32+10,e[a].y*32+10,12,12)}else{core.canvas.ui.beginPath();if(core.isset(e[a+1])&&g!=e[a+1].direction){if(g=="up"&&e[a+1].direction=="left"||g=="right"&&e[a+1].direction=="down"){core.canvas.ui.moveTo(e[a].x*32+5,e[a].y*32+16);core.canvas.ui.lineTo(e[a].x*32+16,e[a].y*32+16);core.canvas.ui.lineTo(e[a].x*32+16,e[a].y*32+27)}else{if(g=="up"&&e[a+1].direction=="right"||g=="left"&&e[a+1].direction=="down"){core.canvas.ui.moveTo(e[a].x*32+27,e[a].y*32+16);core.canvas.ui.lineTo(e[a].x*32+16,e[a].y*32+16);core.canvas.ui.lineTo(e[a].x*32+16,e[a].y*32+27)}else{if(g=="left"&&e[a+1].direction=="up"||g=="down"&&e[a+1].direction=="right"){core.canvas.ui.moveTo(e[a].x*32+27,e[a].y*32+16);core.canvas.ui.lineTo(e[a].x*32+16,e[a].y*32+16);core.canvas.ui.lineTo(e[a].x*32+16,e[a].y*32+5)}else{if(g=="right"&&e[a+1].direction=="up"||g=="down"&&e[a+1].direction=="left"){core.canvas.ui.moveTo(e[a].x*32+5,e[a].y*32+16);core.canvas.ui.lineTo(e[a].x*32+16,e[a].y*32+16);core.canvas.ui.lineTo(e[a].x*32+16,e[a].y*32+5)}}}}core.canvas.ui.stroke();continue}switch(g){case"up":case"down":core.canvas.ui.beginPath();core.canvas.ui.moveTo(e[a].x*32+16,e[a].y*32+5);core.canvas.ui.lineTo(e[a].x*32+16,e[a].y*32+27);core.canvas.ui.stroke();break;case"left":case"right":core.canvas.ui.beginPath();core.canvas.ui.moveTo(e[a].x*32+5,e[a].y*32+16);core.canvas.ui.lineTo(e[a].x*32+27,e[a].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(u,t){var o=core.getHeroLoc("x");var m=core.getHeroLoc("y");var d=o;var c=m;var b={x:0,y:0};var h={up:{x:0,y:-1},left:{x:-1,y:0},down:{x:0,y:1},right:{x:1,y:0}};var k=[];var g=0;var s=[];var j=[];if(u==o&&t==m){return false}k.push(13*o+m);k.push(-1);s[13*o+m]="";while(k.length!=1){var n=k.shift();if(n===-1){g+=1;k.push(-1);continue}var l=~~(n/169);if(l!==g){k.push(n);continue}n=n%169;var d=parseInt(n/13),c=n%13;for(var r in h){var q=d+h[r].x;var p=c+h[r].y;if(q<0||q>12||p<0||p>12){continue}var e=13*q+p;if(core.isset(s[e])){continue}if(q==u&&p==t){s[e]=r;break}if(core.noPassExists(q,p)){continue}var a=1;if(core.idEndWith(q,p,"lavaNet")){a=100}if(!core.flags.potionWhileRouting&&core.idEndWith(q,p,"Potion")){a=20}s[e]=r;k.push(169*(g+a)+e)}if(core.isset(s[13*u+t])){break}}if(!core.isset(s[13*u+t])){return false}var d=u,c=t;while(d!=o||c!=m){var i=s[13*d+c];j.push({direction:i,x:d,y:c});d-=h[i].x;c-=h[i].y}j.reverse();return j};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(a,b){if(a.length==0){return}core.status.autoStepRoutes=a;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(b,a){core.status.autoHeroMove=true;core.status.destStep=a;core.moveHero(b)};core.prototype.setHeroMoveInterval=function(c,a,e,d){if(core.status.heroMoving){return}core.status.heroMoving=true;var b=0;core.interval.heroMoveInterval=window.setInterval(function(){switch(c){case"up":b-=4;if(b==-4||b==-8||b==-12||b==-16){core.drawHero(c,a,e,"leftFoot",0,b)}else{if(b==-20||b==-24||b==-28||b==-32){core.drawHero(c,a,e,"rightFoot",0,b)}}if(b==-32){core.setHeroLoc("y","--");core.moveOneStep();if(core.status.heroStop){core.drawHero(c,a,e-1,"stop")}if(core.isset(d)){d()}}break;case"left":b-=4;if(b==-4||b==-8||b==-12||b==-16){core.drawHero(c,a,e,"leftFoot",b)}else{if(b==-20||b==-24||b==-28||b==-32){core.drawHero(c,a,e,"rightFoot",b)}}if(b==-32){core.setHeroLoc("x","--");core.moveOneStep();if(core.status.heroStop){core.drawHero(c,a-1,e,"stop")}if(core.isset(d)){d()}}break;case"down":b+=4;if(b==4||b==8||b==12||b==16){core.drawHero(c,a,e,"leftFoot",0,b)}else{if(b==20||b==24||b==28||b==32){core.drawHero(c,a,e,"rightFoot",0,b)}}if(b==32){core.setHeroLoc("y","++");core.moveOneStep();if(core.status.heroStop){core.drawHero(c,a,e+1,"stop")}if(core.isset(d)){d()}}break;case"right":b+=4;if(b==4||b==8||b==12||b==16){core.drawHero(c,a,e,"leftFoot",b)}else{if(b==20||b==24||b==28||b==32){core.drawHero(c,a,e,"rightFoot",b)}}if(b==32){core.setHeroLoc("x","++");core.moveOneStep();if(core.status.heroStop){core.drawHero(c,a+1,e,"stop")}if(core.isset(d)){d()}}break}},10)};core.prototype.setHeroMoveTriggerInterval=function(){var c,a,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){c=core.getHeroLoc("direction");a=core.getHeroLoc("x");d=core.getHeroLoc("y");var e;e=core.noPass(a+b[c].x,d+b[c].y);if(e){core.trigger(a+b[c].x,d+b[c].y);core.drawHero(c,a,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(c,a,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(){core.status.hero.steps++};core.prototype.waitHeroToStop=function(a){core.stopAutomaticRoute();if(core.isset(a)){core.lockControl();setTimeout(function(){a()},30)}};core.prototype.stopHero=function(){core.status.heroStop=true};core.prototype.drawHero=function(d,b,g,c,a,f){a=a||0;f=f||0;core.clearAutomaticRouteNode(b,g);var e=core.material.icons.heros[core.status.hero.id][d];b=b*e.size;g=g*e.size;core.canvas.hero.clearRect(b-32,g-32,96,96);core.canvas.hero.drawImage(core.material.images.heros,e.loc[c]*e.size,e.loc.iconLoc*e.size,e.size,e.size,b+a,g+f,e.size,e.size)};core.prototype.openDoor=function(h,b,g,a,f){if(!core.terrainExists(b,g,h)){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();if(a){var d=h.replace("Door","Key");if(!core.useKey(d)){if(d!="specialKey"){core.drawTip("你没有"+core.material.items[d].name+"","normal")}else{core.drawTip("无法开启此门。")}core.clearContinueAutomaticRoute();return}}core.playSound("door","ogg");var e=0;var c=core.material.icons.animates[h];core.interval.openDoorAnimate=window.setInterval(function(){e++;if(e==4){clearInterval(core.interval.openDoorAnimate);core.removeBlock("event",b,g);core.events.afterOpenDoor(h);if(core.isset(f)){f()}return}core.canvas.event.clearRect(32*b,32*g,32,32);core.canvas.event.drawImage(core.material.images.animates,32*e,32*c.loc,32,32,32*b,32*g,32,32)},30)};core.prototype.battle=function(g,a,f,e){if(typeof(core.status.moveStepBeforeStop)=="undefined"||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 c=core.enemys.getDamage(g);if(c>=core.status.hero.hp){core.drawTip("你打不过此怪物!");core.clearContinueAutomaticRoute();return}core.playSound("attack","ogg");core.status.hero.hp-=c;var b=core.material.enemys[g].money;if(core.hasItem("coin")){core.status.hero.money+=core.material.enemys[g].money}core.status.hero.money+=b;core.status.hero.experience+=core.material.enemys[g].experience;core.updateStatusBar();core.removeBlock("event",a,f);core.canvas.event.clearRect(32*a,32*f,32,32);core.updateFg();var d="打败 "+core.material.enemys[g].name+",金币+"+b;if(core.flags.enableExperience){d+=",经验+"+core.material.enemys[g].experience}core.drawTip(d);core.events.afterBattle(g);if(core.isset(e)){e()}};core.prototype.changeFloor=function(d,c,a,f){core.lockControl();core.stopHero();core.stopAutomaticRoute();core.dom.floorNameLabel.innerHTML=core.status.maps[d].title;if(core.isset(c)){a=core.status.hero.loc;var e=core.status.maps[d].blocks;for(var b in e){if(core.isset(e[b].event)&&e[b].event.id===c){a.x=e[b].x;a.y=e[b].y}}if(core.status.maps[d].canFlyTo&&core.status.hero.flyRange.indexOf(d)<0){if(c=="upFloor"){core.status.hero.flyRange.unshift(d)}if(c=="downFloor"){core.status.hero.flyRange.push(d)}}}window.setTimeout(function(){core.playSound("floor","mp3");core.mapChangeAnimate("show",function(){core.statusBar.floor.innerHTML=core.status.maps[d].name;core.updateStatusBar();core.drawMap(d,function(){core.hide(core.dom.floorMsgGroup,10,function(){core.unLockControl();core.events.afterChangeFloor(d);if(core.isset(f)){f()}});core.setHeroLoc("direction",a.direction);core.setHeroLoc("x",a.x);core.setHeroLoc("y",a.y);core.drawHero(core.getHeroLoc("direction"),core.getHeroLoc("x"),core.getHeroLoc("y"),"stop");core.updateFg()})})},50)};core.prototype.mapChangeAnimate=function(a,b){if(a=="show"){core.show(core.dom.floorMsgGroup,15,function(){b()})}else{core.hide(core.dom.floorMsgGroup,20,function(){b()})}};core.prototype.clearMap=function(e,c,f,d,b){if(e=="all"){for(var a in core.canvas){core.canvas[a].clearRect(0,0,416,416)}}else{core.canvas[e].clearRect(c,f,d,b)}};core.prototype.fillText=function(d,e,a,f,c,b){if(core.isset(c)){core.setFillStyle(d,c)}if(core.isset(b)){core.setFont(d,b)}core.canvas[d].fillText(e,a,f)};core.prototype.fillRect=function(e,b,f,d,a,c){if(core.isset(c)){core.setFillStyle(e,c)}core.canvas[e].fillRect(b,f,d,a)};core.prototype.strokeRect=function(f,c,g,e,b,d,a){if(core.isset(d)){core.setStrokeStyle(f,d)}if(core.isset(a)){core.setLineWidth(f,a)}core.canvas[f].strokeRect(c,g,e,b)};core.prototype.drawBlock=function(a,b,d,c,g,f,i,h,e){h=h||1;if(core.isset(e)&&e==true){core.canvas[a].clearRect(g*i,f*i,i,i)}core.canvas[a].drawImage(core.material.images[b],d*i,c*i,i,i,g*i,f*i,i*h,i*h)};core.prototype.setFont=function(b,a){core.canvas[b].font=a};core.prototype.setLineWidth=function(c,b){if(c=="all"){for(var a in core.canvas){core.canvas[a].lineWidth=b}}core.canvas[c].lineWidth=b};core.prototype.saveCanvas=function(a){core.canvas[a].save()};core.prototype.loadCanvas=function(a){core.canvas[a].restore()};core.prototype.setOpacity=function(c,b){if(c=="all"){for(var a in core.canvas){core.canvas[a].globalAlpha=b}}core.canvas[c].globalAlpha=b};core.prototype.setStrokeStyle=function(c,b){if(c=="all"){for(var a in core.canvas){core.canvas[a].strokeStyle=b}}else{core.canvas[c].strokeStyle=b}};core.prototype.setAlpha=function(c,b){if(c=="all"){for(var a in core.canvas){core.canvas[a].globalAlpha=b}}else{core.canvas[c].globalAlpha=b}};core.prototype.setOpacity=function(c,b){if(c=="all"){for(var a in core.canvas){core.canvas[a].canvas.style.opacity=b}}else{core.canvas[c].canvas.style.opacity=b}};core.prototype.setFillStyle=function(c,b){if(c=="all"){for(var a in core.canvas){core.canvas[a].fillStyle=b}}else{core.canvas[c].fillStyle=b}};core.prototype.drawMap=function(c,i){var j=core.status.maps[c];var g=j.blocks;core.status.floorId=c;core.status.thisMap=j;var h,f,a,d;core.clearMap("all");core.rmGlobalAnimate(null,null,true);core.enabledAllTrigger();for(h=0;h<13;h++){for(f=0;f<13;f++){a=core.material.icons.terrains.ground;d=core.material.images.terrains;core.canvas.bg.drawImage(d,0,a.loc*a.size,a.size,a.size,h*a.size,f*a.size,a.size,a.size)}}h=0;f=0;for(var e=0;e<g.length;e++){if(core.isset(g[e].bg)){a=core.material.icons[g[e].bg.cls][g[e].bg.id];d=core.material.images[g[e].bg.cls];h=g[e].x*a.size;f=g[e].y*a.size;if(g[e].bg.cls!="empty"){core.canvas.bg.drawImage(d,0,a.loc*a.size,a.size,a.size,h,f,a.size,a.size);core.addGlobalAnimate(g[e].bg.animate,h,f,"bg",a.loc,a.size,d)}else{core.canvas.bg.clearRect(h,f,a.size,a.size)}}else{a=core.material.icons.terrains.ground;d=core.material.images.terrains;h=g[e].x*a.size;f=g[e].y*a.size;core.canvas.bg.drawImage(d,0,a.loc*a.size,a.size,a.size,h,f,a.size,a.size)}if(core.isset(g[e].event)){a=core.material.icons[g[e].event.cls][g[e].event.id];d=core.material.images[g[e].event.cls];core.canvas.event.drawImage(core.material.images[g[e].event.cls],0,a.loc*a.size,a.size,a.size,h,f,a.size,a.size);core.addGlobalAnimate(g[e].event.animate,h,f,"event",a.loc,a.size,d)}}core.setGlobalAnimate(core.firstData.animateSpeed);if(core.isset(i)){i()}};core.prototype.noPassExists=function(a,d){var b=core.status.thisMap.blocks;for(var c=0;c<b.length;c++){if(b[c].x==a&&b[c].y==d&&core.isset(b[c].event)&&core.isset(b[c].event.noPass)&&b[c].event.noPass){return true}}return false};core.prototype.npcExists=function(a,d){var b=core.status.thisMap.blocks;for(var c=0;c<b.length;c++){if(b[c].x==a&&b[c].y==d&&core.isset(b[c].event)&&b[c].event.cls=="npcs"){return true}}return false};core.prototype.terrainExists=function(a,f,e){if(a>12||f>12||a<0||f<0){return true}if(core.stairExists(a,f)){return false}var d=core.status.thisMap.blocks;for(var b=0;b<d.length;b++){if(d[b].x==a&&d[b].y==f){for(var c in core.canvas){if(core.isset(d[b][c])&&(d[b][c].cls=="terrains"||(d[b][c].cls=="animates"&&core.isset(d[b][c].noPass)&&d[b][c].noPass==true))&&((core.isset(e)&&core.isset(d[b][c].id))?d[b][c].id==e:true)){return true}}}}return false};core.prototype.stairExists=function(a,d){var c=core.status.thisMap.blocks;for(var b=0;b<c.length;b++){if(c[b].x==a&&c[b].y==d&&core.isset(c[b].event)&&c[b].event.cls=="terrains"&&core.isset(c[b].event.id)&&(c[b].event.id=="upFloor"||c[b].event.id=="downFloor")){return true}}return false};core.prototype.enemyExists=function(a,f,d){var c=core.status.thisMap.blocks;for(var b=0;b<c.length;b++){if(c[b].x==a&&c[b].y==f&&core.isset(c[b].event)&&c[b].event.cls=="enemys"&&((core.isset(d)&&core.isset(c[b].event.id))?c[b].event.id==d:true)){return true}}return false};core.prototype.idEndWith=function(a,f,b){var c=core.status.thisMap.blocks;for(var e=0;e<c.length;e++){if(c[e].x==a&&c[e].y==f&&core.isset(c[e].event)){var d=c[e].event.id;return d.substring(d.length-b.length)==b}}return false};core.prototype.removeBlock=function(g,d,h){var g=g.split(",");var e=core.status.thisMap.blocks;var f;for(var c=0;c<e.length;c++){if(e[c].x==d&&e[c].y==h){core.rmGlobalAnimate(d,h);for(var a=0;a<g.length;a++){if(!core.isset(e[c][g[a]])){continue}f=core.material.icons[e[c][g[a]].cls][e[c][g[a]].id];core.canvas[g[a]].clearRect(d*f.size,h*f.size,f.size,f.size)}core.status.thisMap.blocks.splice(c,1);break}}};core.prototype.removeBlockByIds=function(b,a){a.sort(function(d,c){return c-d}).forEach(function(c){core.status.maps[b].blocks.splice(c,1)})};core.prototype.noPass=function(d,f){if(d>12||f>12||d<0||f<0){return true}var e=core.status.thisMap.blocks;var c;for(var a=0;a<e.length;a++){if(e[a].x==d&&e[a].y==f){return c=(e[a].event&&e[a].event.noPass)||(e[a].bg&&e[a].bg.noPass)}}};core.prototype.trigger=function(d,f){var e=core.status.thisMap.blocks;var c;for(var a=0;a<e.length;a++){if(e[a].x==d&&e[a].y==f){c=(e[a].event&&e[a].event.noPass)||(e[a].bg&&e[a].bg.noPass);if(c){core.clearAutomaticRouteNode(d,f)}if(core.isset(e[a].event)&&core.isset(e[a].event.trigger)&&(core.isset(e[a].event.disabledTrigger)?e[a].event.disabledTrigger==false:true)&&!(core.isset(e[a].event.noTriggerCross)&&e[a].event.noTriggerCross&&(core.status.autoHeroMove||core.status.autoStep<core.status.autoStepRoutes.length))){core.material.events[e[a].event.trigger](e[a],core,function(b){})}else{if(core.isset(e[a].bg)&&core.isset(e[a].bg.trigger)&&(core.isset(e[a].bg.disabledTrigger)?e[a].bg.disabledTrigger==false:true)){core.material.events[e[a].bg.trigger](e[a],core,function(b){})}}}}};core.prototype.setTrigger=function(c,g,f,d){var e=core.status.thisMap.blocks;for(var a=0;a<e.length;a++){if(e[a].x==c&&e[a].y==g&&core.isset(e[a][f])){e[a][f].trigger=d}}};core.prototype.enabledTrigger=function(c,f,e){var d=core.status.thisMap.blocks;for(var a=0;a<d.length;a++){if(d[a].x==c&&d[a].y==f&&core.isset(d[a][e])&&core.isset(d[a][e].trigger)){d[a][e].disabledTrigger=false}}};core.prototype.enabledAllTrigger=function(){var c=core.status.thisMap.blocks;for(var a=0;a<c.length;a++){for(var d in core.canvas){if(core.isset(c[a][d])&&core.isset(c[a][d].trigger)){c[a][d].disabledTrigger=false}}}};core.prototype.disabledTrigger=function(c,f,e){var d=core.status.thisMap.blocks;for(var a=0;a<d.length;a++){if(d[a].x==c&&d[a].y==f&&core.isset(d[a][e])&&core.isset(d[a][e].trigger)){d[a][e].disabledTrigger=true}}};core.prototype.rmTrigger=function(c,f,e){var d=core.status.thisMap.blocks;for(var a=0;a<d.length;a++){if(d[a].x==c&&d[a].y==f&&core.isset(d[a][e])&&core.isset(d[a][e].trigger)){delete d[a][e].trigger}}};core.prototype.addGlobalAnimate=function(b,a,g,e,f,c,d){if(b==2){core.status.twoAnimateObjs.push({x:a,y:g,map:e,status:0,loc:f,size:c,image:d})}else{if(b==4){core.status.fourAnimateObjs.push({x:a,y:g,map:e,status:0,loc:f,size:c,image:d})}}};core.prototype.rmGlobalAnimate=function(a,e,c){if(c==true){core.status.twoAnimateObjs=[];core.status.fourAnimateObjs=[]}for(var b=0;b<core.status.twoAnimateObjs.length;b++){if(core.status.twoAnimateObjs[b].x==a*core.status.twoAnimateObjs[b].size&&core.status.twoAnimateObjs[b].y==e*core.status.twoAnimateObjs[b].size){core.status.twoAnimateObjs.splice(b,1);return}}for(var d=0;d<core.status.fourAnimateObjs.length;d++){if(core.status.fourAnimateObjs[d].x==a*core.status.fourAnimateObjs[d].size&&core.status.fourAnimateObjs[d].y==e*core.status.fourAnimateObjs[d].size){core.status.fourAnimateObjs.splice(d,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 d=0;d<core.status.twoAnimateObjs.length;d++){core.status.twoAnimateObjs[d].status=core.status.twoAnimateObjs[d].status==0?1:0;core.canvas[core.status.twoAnimateObjs[d].map].clearRect(core.status.twoAnimateObjs[d].x,core.status.twoAnimateObjs[d].y,core.status.twoAnimateObjs[d].size,core.status.twoAnimateObjs[d].size);for(var c=0;c<core.status.thisMap.blocks.length;c++){if(core.status.thisMap.blocks[c].x*32==core.status.twoAnimateObjs[d].x&&core.status.thisMap.blocks[c].y*32==core.status.twoAnimateObjs[d].y&&(!core.isset(core.status.thisMap.blocks[c][core.status.twoAnimateObjs[d].map])||core.status.thisMap.blocks[c][core.status.twoAnimateObjs[d].map].animate==0)){a=true}}if(!a){core.canvas[core.status.twoAnimateObjs[d].map].drawImage(core.status.twoAnimateObjs[d].image,core.status.twoAnimateObjs[d].status*32,core.status.twoAnimateObjs[d].loc*core.status.twoAnimateObjs[d].size,core.status.twoAnimateObjs[d].size,core.status.twoAnimateObjs[d].size,core.status.twoAnimateObjs[d].x,core.status.twoAnimateObjs[d].y,core.status.twoAnimateObjs[d].size,core.status.twoAnimateObjs[d].size)}a=false}},b);core.interval.fourAnimate=window.setInterval(function(){for(var d=0;d<core.status.fourAnimateObjs.length;d++){core.status.fourAnimateObjs[d].status=(core.status.fourAnimateObjs[d].status==0?1:(core.status.fourAnimateObjs[d].status==1?2:(core.status.fourAnimateObjs[d].status==2?3:0)));core.canvas[core.status.fourAnimateObjs[d].map].clearRect(core.status.fourAnimateObjs[d].x,core.status.fourAnimateObjs[d].y,core.status.fourAnimateObjs[d].size,core.status.fourAnimateObjs[d].size);for(var c=0;c<core.status.thisMap.blocks.length;c++){if(core.status.thisMap.blocks[c].x*32==core.status.fourAnimateObjs[d].x&&core.status.thisMap.blocks[c].y*32==core.status.fourAnimateObjs[d].y&&(!core.isset(core.status.thisMap.blocks[c][core.status.fourAnimateObjs[d].map])||core.status.thisMap.blocks[c][core.status.fourAnimateObjs[d].map].animate==0)){a=true}}if(!a){core.canvas[core.status.fourAnimateObjs[d].map].drawImage(core.status.fourAnimateObjs[d].image,core.status.fourAnimateObjs[d].status*32,core.status.fourAnimateObjs[d].loc*core.status.fourAnimateObjs[d].size,core.status.fourAnimateObjs[d].size,core.status.fourAnimateObjs[d].size,core.status.fourAnimateObjs[d].x,core.status.fourAnimateObjs[d].y,core.status.fourAnimateObjs[d].size,core.status.fourAnimateObjs[d].size)}a=false}},b/2)};core.prototype.setBoxAnimate=function(b){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)},b)}};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*d.icon.size,d.icon.loc*d.icon.size,d.icon.size,d.icon.size,d.x,d.y,d.icon.size,d.icon.size)}};core.prototype.setHeroLoc=function(b,a){if(a=="++"){core.status.hero.loc[b]++;return}else{if(a=="--"){core.status.hero.loc[b]--;return}}core.status.hero.loc[b]=a};core.prototype.getHeroLoc=function(a){return core.status.hero.loc[a]};core.prototype.updateFg=function(){if(!core.isset(core.status.thisMap)||!core.isset(core.status.thisMap.blocks)){return}var e=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;for(var c=0;c<e.length;c++){var a=e[c].x,i=e[c].y;if(core.isset(e[c].event)&&e[c].event.cls=="enemys"){var h=e[c].event.id;var f=core.enemys.getDamage(h);var d="#000000";if(f<=0){d="#00FF00"}else{if(f<g/3){d="#FFFFFF"}else{if(f<g*2/3){d="#FFFF00"}else{if(f<g){d="#FF7F00"}else{d="#FF0000"}}}}if(f>=999999999){f="???"}else{if(f>100000){f=(f/10000).toFixed(1)+"w"}}core.setFillStyle("fg","#000000");core.canvas.fg.fillText(f,32*a+2,32*(i+1)-2);core.canvas.fg.fillText(f,32*a,32*(i+1)-2);core.canvas.fg.fillText(f,32*a+2,32*(i+1));core.canvas.fg.fillText(f,32*a,32*(i+1));core.setFillStyle("fg",d);core.canvas.fg.fillText(f,32*a+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;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(c,b){var a=core.material.items[c].cls;if(a=="item"){return}if(!core.isset(core.status.hero.items[a])){core.status.hero.items[a]={}}core.status.hero.items[a][c]=b};core.prototype.useKey=function(b){if(!core.hasItem(b)){return false}var a=core.material.items[b].cls;core.status.hero.items[a][b]--;core.updateStatusBar();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(d,c){var a=core.material.items[d];var b=a.cls;if(b=="item"){return}if(!core.isset(core.status.hero.items[b])){core.status.hero.items[b]={};core.status.hero.items[b][d]=0}else{if(!core.isset(core.status.hero.items[b][d])){core.status.hero.items[b][d]=0}}core.status.hero.items[b][d]+=c};core.prototype.getItemEffect=function(b,a){core.items.getItemEffect(b,a)};core.prototype.getItemEffectTip=function(a){return core.items.getItemEffectTip(a)};core.prototype.getItem=function(f,e,c,a,g){core.playSound("item","ogg");var b=core.material.items[f].cls;core.getItemEffect(f,e);core.removeBlock("event",c,a);var d="获得 "+core.material.items[f].name;if(e>1){d+="x"+e}if(b==="items"){d+=core.getItemEffectTip(f)}core.drawTip(d,"image",core.material.icons.items[f]);core.canvas.event.clearRect(c*32,a*32,32,32);core.updateStatusBar();if(core.isset(g)){g()}};core.prototype.drawTip=function(h,g,f){g=g||"normal";var d,c,b,i,e=false,a=0;clearInterval(core.interval.tipAnimate);core.setFont("data","16px Arial");core.saveCanvas("data");core.setOpacity("data",0);if(g=="normal"){d=16;c=18;b=d+core.canvas.data.measureText(h).width+16;i=42}else{if(g=="image"&&core.isset(f)){d=44;c=18;b=d+core.canvas.data.measureText(h).width+8;i=42}else{core.loadCanvas("data");return}}core.interval.tipAnimate=window.setInterval(function(){if(e){a-=0.1}else{a+=0.1}core.setOpacity("data",a);core.clearMap("data",5,5,400,i);core.fillRect("data",5,5,b,i,"#000");if(core.isset(f)){core.canvas.data.drawImage(core.material.images.items,0,f.loc*f.size,f.size,f.size,10,8,f.size,f.size)}core.fillText("data",h,d+5,c+15,"#fff");if(a>0.6||a<0){if(e){core.loadCanvas("data");core.clearMap("data",5,5,400,i);core.setOpacity("data",1);clearInterval(core.interval.tipAnimate);return}else{if(!core.timeout.getItemTipTimeout){core.timeout.getItemTipTimeout=window.setTimeout(function(){e=true;core.timeout.getItemTipTimeout=null},1000)}a=0.6;core.setOpacity("data",a)}}},30)};core.prototype.drawText=function(a,c){if(core.isset(a)){if(typeof a=="string"){a=[{content:a}]}else{if(a instanceof Object&&core.isset(a.content)){a=[a]}else{if(!(a instanceof Array)){core.drawTip("出错了");console.log(a);return}}}core.status.event={id:"text",data:{list:a,callback:c}};core.lockControl();core.stopAutomaticRoute();setTimeout(function(){core.drawText()},30);return}if(core.status.event.data.list.length==0){var c=core.status.event.data.callback;core.ui.closePanel(false);if(core.isset(c)){c()}return}var b=core.status.event.data.list.shift();if(typeof b=="string"){core.ui.drawTextBox(b)}else{core.ui.drawTextBox(b.content,b.id)}};core.prototype.visitNpc=function(b,a,f,e){if(!core.status.heroStop){setTimeout(function(){core.visitNpc(b,a,f,e)},30);return}if(!core.isset(core.status.npcs[b])){core.status.npcs[b]=0}var d=core.status.npcs[b];var c=core.npcs.getEffect(b,d);if(c.length==0){return}core.status.event.data={x:a,y:f,id:b,list:c,callback:e};core.status.event.id="npc";core.lockControl();core.npcAction()};core.prototype.npcAction=function(){if(core.status.event.data.list.length==0){if(core.isset(core.status.event.data.callback)){core.status.event.data.callback()}core.ui.closePanel(false);return}var g=core.status.event.data.list.shift();core.status.event.data.current=g;var c=core.status.event.data.id,l=core.status.event.data.x,j=core.status.event.data.y;if(g.action=="text"){core.ui.drawTextBox(g.content,core.isset(g.isHero)&&g.isHero?"hero":g.id);return}if(g.action=="choices"){var h=core.material.npcs[g.id];var b=core.canvas.ui.createPattern(core.material.ground,"repeat");clearInterval(core.interval.tipAnimate);core.clearMap("data",0,0,416,416);core.setOpacity("data",1);core.clearMap("ui",0,0,416,416);core.setAlpha("ui",1);core.setFillStyle("ui",b);var e=97,k=64,m=416-2*e,a=416-2*k;core.fillRect("ui",e,k,m,a,b);core.strokeRect("ui",e-1,k-1,m+1,a+1,"#FFFFFF",2);core.canvas.ui.textAlign="center";core.fillText("ui",h.name,e+135,k+34,"#FFFFFF","bold 19px Verdana");core.strokeRect("ui",e+15-1,k+30-1,34,34,"#DDDDDD",2);core.status.boxAnimateObjs=[];core.status.boxAnimateObjs.push({bgx:e+15,bgy:k+30,bgsize:32,image:core.material.images.npcs,x:e+15,y:k+30,icon:core.material.icons.npcs[h.icon]});core.setBoxAnimate(core.firstData.animateSpeed);core.canvas.ui.textAlign="left";var d=g.hint.split("\n");for(var f=0;f<d.length;f++){core.fillText("ui",d[f],e+60,k+65+18*f,"#FFFFFF","bold 14px Verdana")}core.canvas.ui.textAlign="center";for(var f=0;f<g.choices.length;f++){core.fillText("ui",g.choices[f].text,208,k+120+32*f,"#FFFFFF","bold 17px Verdana")}if(!(core.isset(g.cancel)&&!g.cancel)){core.fillText("ui","返回",208,k+248)}return}if(g.action=="addtimes"){core.status.npcs[c]++;core.npcAction();return}if(g.action=="settimes"){core.status.npcs[c]=g.times;core.npcAction();return}if(g.action=="disappear"){core.removeBlock("event",l,j);core.npcAction();return}if(g.action=="revisit"){core.ui.closePanel(false);core.visitNpc(c,l,j);return}if(g.action=="custom"){core.events.npcCustomAction(g);return}return};core.prototype.npcEffect=function(b,a){if(b.indexOf("custom:")==0){core.events.npcCustomEffect(b.substr(7),a);return}effects=b.split(";");effects.forEach(function(h){var f=h.split(",");var d=f[0],c=f[1],g=f[2];if(d=="status"){core.setStatus(c,core.getStatus(c)+parseInt(g))}else{if(d=="item"){core.setItem(c,core.itemCount(c)+parseInt(g))}}});core.updateStatusBar()};core.prototype.setLocalStorage=function(a,b){try{localStorage.setItem(core.firstData.name+"_"+a,JSON.stringify(b));return true}catch(c){console.log(c);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 c=new Date();c.setTime(b.getTime());return c}if(b instanceof Array){var c=[];for(var a in b){c[a]=core.clone(b[a])}return c}if(b instanceof Object){var c={};for(var a in b){if(b.hasOwnProperty(a)){c[a]=core.clone(b[a])}}return c}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 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.win=function(){if(!core.status.heroStop){setTimeout(function(){core.win()},30);return}core.events.win()};core.prototype.updateTime=function(){var a=new Date();core.status.hero.time.playtime+=(a.getTime()-core.status.hero.time.lasttime.getTime())/1000;core.status.hero.time.totaltime+=(a.getTime()-core.status.hero.time.lasttime.getTime())/1000;core.status.hero.time.lasttime=a};core.prototype.upload=function(a){};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(b,c,d,a){if(c&&core.status.event.id==b){core.ui.closePanel(a);return false}if(c&&core.status.lockControl){return false}if(core.isset(d)&&d&&!core.hasItem(b)){core.drawTip("你没有"+core.material.items[b].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=b;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.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(c,a){if(a=="save"){if(core.saveData("save"+c)){core.ui.closePanel();core.drawTip("存档成功!");core.setLocalStorage("savePage",core.status.savePage)}else{core.drawTip("存储空间不足,请覆盖已有的存档或在菜单栏中进行清理")}return}else{if(a=="load"){var b=core.getLocalStorage("save"+c,null);if(!core.isset(b)){core.drawTip("无效的存档");return}core.ui.closePanel();core.loadData(b,function(){core.setLocalStorage("savePage",core.status.savePage);core.drawTip("读档成功")});return}}};core.prototype.saveData=function(a){core.updateTime();var b={floorId:core.status.floorId,hero:core.clone(core.status.hero),hard:core.status.hard,maps:core.maps.save(core.status.maps),npcs:{},shops:{},version:core.firstData.version,time:new Date().getTime()};b.hero.time.starttime=core.status.hero.time.starttime.getTime();for(var c in core.status.shops){b.shops[c]={times:core.status.shops[c].times,visited:core.status.shops[c].visited}}core.events.beforeSaveData(b);return core.setLocalStorage(a,b)};core.prototype.loadData=function(b,e){core.upload();var d=null,a=null;if(core.isPlaying()){core.updateTime();var d=core.status.hero.time.totaltime;var a=core.clone(core.status.hero.time.lasttime)}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.status.hero.time.starttime=new Date(core.status.hero.time.starttime);if(core.isset(d)&&d>core.status.hero.time.totaltime){core.status.hero.time.totaltime=d}if(core.isset(a)){core.status.hero.time.lasttime=a}else{core.status.hero.time.lasttime=new Date()}core.events.afterLoadData(b);core.changeFloor(b.floorId,null,b.hero.loc,function(){core.setHeroMoveTriggerInterval();if(core.isset(e)){e()}});core.upload(1500)};core.prototype.setStatus=function(a,b){if(core.isset(core.status.hero[a])){core.status.hero[a]=b}};core.prototype.getStatus=function(a){if(core.isset(core.status.hero[a])){return core.status.hero[a]}};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(b,a){if(!core.musicStatus.soundStatus||!core.musicStatus.loaded){return}core.musicStatus.playedSound=core.material.sounds[a][b];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(d,b,e){if(!core.isset(b)){d.style.display="block";return}d.style.display="block";d.style.opacity=0;var c=0;var a=window.setInterval(function(){c+=0.03;d.style.opacity=c;if(c>1){clearInterval(a);if(core.isset(e)){e()}}},b)};core.prototype.hide=function(d,b,e){if(!core.isset(b)){d.style.display="none";return}var c=1;var a=window.setInterval(function(){c-=0.03;d.style.opacity=c;if(c<0){d.style.display="none";clearInterval(a);if(core.isset(e)){e()}}},b)};core.prototype.clearStatusBar=function(){var a=["floor","hp","atk","def","money","experience","yellowKey","blueKey","redKey","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.flags.HPMAX>0){core.setStatus("hp",Math.min(core.flags.HPMAX,core.getStatus("hp")))}var b=["hp","atk","def","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.hard.innerHTML="Lv"+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(t,j){var v=416;var k=83;var x=49;var A=129;var m=v+6;var s=t;var n=false;if(t>j&&j<422){n=true;s=j}if(s<m){var b=(m-s)/4.22;var z=1-b/100;core.position.scale=z;v=s-6;if(!n){core.position.screenMode="vertical";k*=z;x*=z;core.position.gameGroup={width:v,height:s+k+x,top:(j-s-k-x)/2,left:3};core.position.statusBar={width:v,height:k,top:0,left:0,fontSize:16*z};core.position.canvas={width:v,height:v,top:k,left:0,borderLeft:"",borderTop:"3px #fff solid",borderBottom:"3px #fff solid"};core.position.toolBar={display:"block",width:v,height:x,top:k+3+v};var r=8*z,l=44*z;var f=core.position.toolBar.top+13*z;var d=46*z;var q=16*z,e=52*z,u=75*z;var a=core.position.toolBar.top+18*z;core.position.items={image:{size:32*z,floor:{top:r,left:8*z},hp:{top:r,left:90*z},atk:{top:r,left:210*z},def:{top:r,left:316*z},mdef:{top:0,left:0},money:{top:l,left:8*z},experience:{top:l,left:138*z},book:{top:f,left:8*z},fly:{top:f,left:8*z+d},toolbox:{top:f,left:8*z+d*2},shop:{top:f,left:8*z+d*3,display:"block"},save:{top:f,left:8*z+d*4},load:{top:f,left:8*z+d*5},settings:{top:f,left:8*z+d*6}},floor:{top:q,left:48*z},hp:{top:q,left:130*z},atk:{top:q,left:246*z},def:{top:q,left:352*z},mdef:{top:0,left:0},money:{top:e,left:48*z},experience:{top:e,left:178*z},yellowKey:{top:e,left:268*z},blueKey:{top:e,left:308*z},redKey:{top:e,left:348*z},hard:{top:a,left:340*z}}}else{core.position.screenMode="horizontal";A*=z;core.position.gameGroup={width:A+v+3,height:v,top:3,left:(t-s-A)/2};core.position.statusBar={top:0,left:0,width:A,height:v,fontSize:16*z};core.position.canvas={borderTop:"",borderLeft:"3px #fff solid",borderBottom:"",top:0,left:A,width:v,height:v};core.position.toolBar={display:"none",top:0,left:0,width:0,height:0};var h=8*z,y=50*z,c=92*z;var p=20*z,i=28*z,o=303*z,w=40*z;core.position.items={image:{size:32*z,floor:{top:p,left:h},hp:{top:p+w,left:h},atk:{top:p+w*2,left:h},def:{top:p+w*3,left:h},mdef:{top:0,left:0},money:{top:p+w*4,left:h},experience:{top:p+w*5,left:h},book:{top:o,left:h},fly:{top:o,left:y},toolbox:{top:o,left:c},shop:{top:0,left:0,display:"none"},save:{top:o+w,left:h},load:{top:o+w,left:y},settings:{top:o+w,left:c}},floor:{top:i,left:y},hp:{top:i+w,left:y},atk:{top:i+w*2,left:y},def:{top:i+w*3,left:y},mdef:{top:0,left:0},money:{top:i+w*4,left:y},experience:{top:i+w*5,left:y},yellowKey:{top:i+w*6,left:h},blueKey:{top:i+w*6,left:y},redKey:{top:i+w*6,left:c},hard:{top:383*z,left:43*z}}}}else{core.position.scale=1;core.position.screenMode="bigScreen";var g=A+3+v;core.position.gameGroup={top:(j-v)/2,left:(s-g)/2,width:g,height:v};core.position.statusBar={top:0,left:0,width:A,height:v,fontSize:16};core.position.canvas={borderTop:"",borderBottom:"",borderLeft:"3px #fff solid",top:0,left:A,width:v,height:v};core.position.toolBar={display:"none",top:0,left:0,width:0,height:0};var h=8,y=50,c=92;var p=20,i=28,o=303,w=40;core.position.items={image:{size:32,floor:{top:p,left:h},hp:{top:p+w,left:h},atk:{top:p+w*2,left:h},def:{top:p+w*3,left:h},mdef:{top:0,left:0},money:{top:p+w*4,left:h},experience:{top:p+w*5,left:h},book:{top:o,left:h},fly:{top:o,left:y},toolbox:{top:o,left:c},shop:{top:0,left:0,display:"none"},save:{top:o+w,left:h},load:{top:o+w,left:y},settings:{top:o+w,left:c}},floor:{top:i,left:y},hp:{top:i+w,left:y},atk:{top:i+w*2,left:y},def:{top:i+w*3,left:y},mdef:{top:0,left:0},money:{top:i+w*4,left:y},experience:{top:i+w*5,left:y},yellowKey:{top:i+w*6,left:h},blueKey:{top:i+w*6,left:y},redKey:{top:i+w*6,left:c},hard:{top:383,left:43}}}core.resetSize()};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}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;