From 543f86642bdf847f0575521c290f74c4462f84fd Mon Sep 17 00:00:00 2001 From: oc Date: Fri, 1 Jun 2018 23:17:36 +0800 Subject: [PATCH] clear status bar --- libs/actions.min.js | 1 - libs/control.js | 5533 ++++++++++++++++++++++--------------------- libs/control.min.js | 1 - libs/data.min.js | 1 - libs/enemys.min.js | 1 - libs/events.min.js | 1 - libs/icons.min.js | 1 - libs/items.min.js | 1 - libs/loader.min.js | 1 - libs/maps.min.js | 1 - libs/ui.min.js | 1 - libs/utils.min.js | 1 - main.js | 1070 ++++----- project/data.js | 334 +-- 14 files changed, 3469 insertions(+), 3479 deletions(-) delete mode 100644 libs/actions.min.js delete mode 100644 libs/control.min.js delete mode 100644 libs/data.min.js delete mode 100644 libs/enemys.min.js delete mode 100644 libs/events.min.js delete mode 100644 libs/icons.min.js delete mode 100644 libs/items.min.js delete mode 100644 libs/loader.min.js delete mode 100644 libs/maps.min.js delete mode 100644 libs/ui.min.js delete mode 100644 libs/utils.min.js diff --git a/libs/actions.min.js b/libs/actions.min.js deleted file mode 100644 index 43e59332..00000000 --- a/libs/actions.min.js +++ /dev/null @@ -1 +0,0 @@ -function actions(){this.init()}actions.prototype.init=function(){};actions.prototype.onkeyDown=function(a){if(core.isset(core.status.replay)&&core.status.replay.replaying&&core.status.event.id!="save"&&(core.status.event.id||"").indexOf("book")!=0){return}if(!core.isset(core.status.holdingKeys)){core.status.holdingKeys=[]}var c={37:true,38:true,39:true,40:true}[a.keyCode];if(c&&!core.status.lockControl){for(var b=0;bd){c=b;d=a[b]}}e=[{x:0,y:1},{x:-1,y:0},{x:0,y:-1},{x:1,y:0},false][c];if(e){e.x+=f.x;e.y+=f.y;core.status.stepPostfix.push(e);core.fillPosWithPoint(e)}};actions.prototype.onup=function(){if(core.isset(core.status.replay)&&core.status.replay.replaying&&core.status.event.id!="save"&&(core.status.event.id||"").indexOf("book")!=0){return}clearTimeout(core.timeout.onDownTimeout);core.timeout.onDownTimeout=null;clearInterval(core.interval.onDownInterval);core.interval.onDownInterval=null;if(core.status.stepPostfix.length>0){var g=[];var a={"0":{"1":"down","-1":"up"},"-1":{"0":"left"},"1":{"0":"right"}};for(var b=1;b=1000){this.longClick(e,f)}else{this.onclick(e,f,g)}core.status.downTime=null}};actions.prototype.getClickLoc=function(f,g){var d={x:0,y:0};var c=32;c=c*core.domStyle.scale;switch(core.domStyle.screenMode){case"vertical":d.x=0;d.y=core.dom.statusBar.offsetHeight+3;break;case"horizontal":case"bigScreen":d.x=core.dom.statusBar.offsetWidth+3;d.y=0;break}var a=core.dom.gameGroup.offsetLeft+d.x;var e=core.dom.gameGroup.offsetTop+d.y;var b={x:f-a,y:g-e,size:c};return b};actions.prototype.onclick=function(b,c,a){if(core.isset(core.status.replay)&&core.status.replay.replaying&&core.status.event.id!="save"&&(core.status.event.id||"").indexOf("book")!=0){return}a=a||[];if(b<0||c<0||b>12||c>12){return}if(core.status.usingCenterFly){if(b!=12-core.getHeroLoc("x")||c!=12-core.getHeroLoc("y")){core.clearMap("ui",(12-core.getHeroLoc("x"))*32,(12-core.getHeroLoc("y"))*32,32,32)}else{if(core.canUseItem("centerFly")){core.useItem("centerFly");core.clearMap("ui",core.getHeroLoc("x")*32,core.getHeroLoc("y")*32,32,32);return}else{core.drawTip("当前不能使用中心对称飞行器");core.clearMap("ui",(12-core.getHeroLoc("x"))*32,(12-core.getHeroLoc("y"))*32,32,32)}}core.status.usingCenterFly=false}if(!core.status.lockControl){core.setAutomaticRoute(b,c,a);return}if(core.status.event.id=="book"){this.clickBook(b,c);return}if(core.status.event.id=="book-detail"){this.clickBookDetail(b,c);return}if(core.status.event.id=="fly"){this.clickFly(b,c);return}if(core.status.event.id=="viewMaps"){this.clickViewMaps(b,c);return}if(core.status.event.id=="switchs"){this.clickSwitchs(b,c);return}if(core.status.event.id=="settings"){this.clickSettings(b,c);return}if(core.status.event.id=="shop"){this.clickShop(b,c);return}if(core.status.event.id=="selectShop"){this.clickQuickShop(b,c);return}if(core.status.event.id=="toolbox"){this.clickToolbox(b,c);return}if(core.status.event.id=="save"||core.status.event.id=="load"||core.status.event.id=="replayLoad"){this.clickSL(b,c);return}if(core.status.event.id=="confirmBox"){this.clickConfirmBox(b,c);return}if(core.status.event.id=="keyBoard"){this.clickKeyBoard(b,c);return}if(core.status.event.id=="about"){this.clickAbout(b,c);return}if(core.status.event.id=="action"){this.clickAction(b,c);return}if(core.status.event.id=="text"){core.drawText();return}if(core.status.event.id=="syncSave"){this.clickSyncSave(b,c);return}if(core.status.event.id=="syncSelect"){this.clickSyncSelect(b,c);return}if(core.status.event.id=="localSaveSelect"){this.clickLocalSaveSelect(b,c);return}if(core.status.event.id=="storageRemove"){this.clickStorageRemove(b,c);return}if(core.status.event.id=="cursor"){this.clickCursor(b,c);return}if(core.status.event.id=="replay"){this.clickReplay(b,c);return}};actions.prototype.onmousewheel=function(a){if(core.isset(core.status.replay)&&core.status.replay.replaying&&core.status.event.id!="save"&&(core.status.event.id||"").indexOf("book")!=0){return}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}if(core.status.lockControl&&core.status.event.id=="book"){if(a==1){core.ui.drawBook(core.status.event.data-6)}if(a==-1){core.ui.drawBook(core.status.event.data+6)}return}if(core.status.lockControl&&(core.status.event.id=="save"||core.status.event.id=="load")){if(a==1){core.ui.drawSLPanel(core.status.event.data-10)}if(a==-1){core.ui.drawSLPanel(core.status.event.data+10)}return}if(core.status.lockControl&&core.status.event.id=="viewMaps"){if(a==1){this.clickViewMaps(6,2)}if(a==-1){this.clickViewMaps(6,10)}return}};actions.prototype.longClick=function(b,c,a){if(!core.isPlaying()){return false}if(core.status.lockControl){if(core.status.event.id=="text"){core.drawText();return true}if(core.status.event.id=="action"&&core.status.event.data.type=="text"){core.doAction();return true}}else{if(!a){core.waitHeroToStop(function(){core.ui.drawKeyBoard()})}}return false};actions.prototype.keyDownCtrl=function(){if(core.status.event.id=="text"){core.drawText();return}if(core.status.event.id=="action"&&core.status.event.data.type=="text"){core.doAction();return}};actions.prototype.clickConfirmBox=function(a,b){if((a==4||a==5)&&b==7&&core.isset(core.status.event.data.yes)){core.status.event.data.yes()}if((a==7||a==8)&&b==7&&core.isset(core.status.event.data.no)){core.status.event.data.no()}};actions.prototype.keyUpConfirmBox=function(a){if(a==37){core.status.event.selection=0;core.ui.drawConfirmBox(core.status.event.ui,core.status.event.data.yes,core.status.event.data.no)}if(a==39){core.status.event.selection=1;core.ui.drawConfirmBox(core.status.event.ui,core.status.event.data.yes,core.status.event.data.no)}if(a==13||a==32||a==67){if(core.status.event.selection==0&&core.isset(core.status.event.data.yes)){core.status.event.selection=null;core.status.event.data.yes()}if(core.status.event.selection==1&&core.isset(core.status.event.data.no)){core.status.event.selection=null;core.status.event.data.no()}}};actions.prototype.clickAction=function(d,e){if(core.status.event.data.type=="text"){core.doAction();return}if(core.status.event.data.type=="wait"){core.setFlag("type",1);core.setFlag("x",d);core.setFlag("y",e);core.status.route.push("input:"+(10000+100*d+e));core.doAction();return}if(core.status.event.data.type=="choices"){var b=core.status.event.data.current;var a=b.choices;if(a.length==0){return}if(d>=5&&d<=7){var c=6-parseInt((a.length-1)/2);if(e>=c&&e0){if(c==38){core.status.event.selection--;core.ui.drawChoices(core.status.event.ui.text,core.status.event.ui.choices)}if(c==40){core.status.event.selection++;core.ui.drawChoices(core.status.event.ui.text,core.status.event.ui.choices)}}}};actions.prototype.keyUpAction=function(c){if(core.status.event.data.type=="text"&&(c==13||c==32||c==67)){core.doAction();return}if(core.status.event.data.type=="wait"){core.setFlag("type",0);core.setFlag("keycode",c);core.status.route.push("input:"+c);core.doAction();return}if(core.status.event.data.type=="choices"){var b=core.status.event.data.current;var a=b.choices;if(a.length>0){if(c==13||c==32||c==67){core.status.route.push("choices:"+core.status.event.selection);core.insertAction(a[core.status.event.selection].action);core.doAction()}}}};actions.prototype.clickBook=function(d,e){if((d==3||d==4)&&e==12){core.ui.drawBook(core.status.event.data-6);return}if((d==8||d==9)&&e==12){core.ui.drawBook(core.status.event.data+6);return}if(d>=10&&d<=12&&e==12){if(core.status.event.selection==null){core.ui.closePanel()}else{core.status.boxAnimateObjs=[];core.ui.drawMaps(core.status.event.selection)}return}var a=core.status.event.data;if(core.isset(a)&&e<12){var c=parseInt(a/6);var b=6*c+parseInt(e/2);core.ui.drawBook(b);core.ui.drawBookDetail(b)}return};actions.prototype.keyDownBook=function(a){if(a==37){core.ui.drawBook(core.status.event.data-6)}if(a==38){core.ui.drawBook(core.status.event.data-1)}if(a==39){core.ui.drawBook(core.status.event.data+6)}if(a==40){core.ui.drawBook(core.status.event.data+1)}if(a==33){core.ui.drawBook(core.status.event.data-6)}if(a==34){core.ui.drawBook(core.status.event.data+6)}return};actions.prototype.keyUpBook=function(b){if(b==27||b==88){if(core.status.event.selection==null){core.ui.closePanel()}else{core.status.boxAnimateObjs=[];core.ui.drawMaps(core.status.event.selection)}return}if(b==13||b==32||b==67){var a=core.status.event.data;if(core.isset(a)){this.clickBook(6,2*(a%6))}return}};actions.prototype.clickBookDetail=function(){core.clearMap("data",0,0,416,416);core.status.event.id="book"};actions.prototype.clickFly=function(e,f){if((e==10||e==11)&&f==9){core.ui.drawFly(core.status.event.data-1)}if((e==10||e==11)&&f==5){core.ui.drawFly(core.status.event.data+1)}if(e>=5&&e<=7&&f==12){core.ui.closePanel()}if(e>=0&&e<=9&&f>=3&&f<=11){var b=core.status.hero.flyRange.indexOf(core.status.floorId);var c=core.status.event.data=8){a--;while(a>=0&&a!=b&&core.floors[core.floorIds[a]].cannotViewMap){a--}if(a>=0){core.ui.drawMaps(a)}}else{core.clearMap("data",0,0,416,416);core.setOpacity("data",1);core.ui.closePanel()}}};actions.prototype.keyDownViewMaps=function(a){if(a==37||a==38||a==33){this.clickViewMaps(6,2)}else{if(a==39||a==40||a==34){this.clickViewMaps(6,10)}}return};actions.prototype.keyUpViewMaps=function(a){if(a==27||a==13||a==32||a==67){core.clearMap("data",0,0,416,416);core.setOpacity("data",1);core.ui.closePanel()}if(a==88){core.openBook(false)}return};actions.prototype.clickShop=function(x,y){var shop=core.status.event.data.shop;var choices=shop.choices;if(x>=5&&x<=7){var topIndex=6-parseInt(choices.length/2);if(y>=topIndex&&yeval(use)){core.drawTip("你的"+use_text+"不足");return false}core.status.event.data.actions.push(y-topIndex);eval(use+"-="+need);core.setStatus("money",money);core.setStatus("experience",experience);choice.effect.split(";").forEach(function(t){core.doEffect(t)});core.updateStatusBar();shop.times++;core.events.openShop(core.status.event.data.id)}else{if(y==topIndex+choices.length){if(core.status.event.data.actions.length>0){core.status.route.push("shop:"+core.status.event.data.id+":"+core.status.event.data.actions.join(""))}core.status.event.data.actions=[];core.status.boxAnimateObjs=[];if(core.status.event.data.fromList){core.ui.drawQuickShop()}else{core.ui.closePanel()}}else{return false}}}return true};actions.prototype.keyDownShop=function(a){if(a==38){core.status.event.selection--;core.ui.drawChoices(core.status.event.ui.text,core.status.event.ui.choices)}if(a==40){core.status.event.selection++;core.ui.drawChoices(core.status.event.ui.text,core.status.event.ui.choices)}};actions.prototype.keyUpShop=function(b){if(b==27||b==88){if(core.status.event.data.actions.length>0){core.status.route.push("shop:"+core.status.event.data.id+":"+core.status.event.data.actions.join(""))}core.status.event.data.actions=[];core.status.boxAnimateObjs=[];if(core.status.event.data.fromList){core.ui.drawQuickShop()}else{core.ui.closePanel()}return}var c=core.status.event.data.shop;var a=c.choices;if(b==13||b==32||b==67){var d=6-parseInt(a.length/2);this.clickShop(6,d+core.status.event.selection)}return};actions.prototype.clickQuickShop=function(e,f){var c=core.status.shops,a=Object.keys(c);if(e>=5&&e<=7){var d=6-parseInt(a.length/2);if(f>=d&&f=10&&b<=12&&c==12){core.ui.closePanel();return}if(b>=10&&b<=12&&c<=1){if(!core.isset(core.status.event.data)){return}if(!core.flags.enableDeleteItem){core.drawTip("不支持删除道具!");return}core.removeItem(core.status.event.data);core.status.event.data=null;core.ui.drawToolbox();return}var a=0;if(c==4||c==5||c==9||c==10){a=parseInt(b/2)}else{a=6+parseInt(b/2)}if(c>=9){a+=100}this.clickToolboxIndex(a)};actions.prototype.clickToolboxIndex=function(b){var d=null;var a=b;if(a<100){d=Object.keys(core.status.hero.items.tools).sort()}else{a-=100;d=Object.keys(core.status.hero.items.constants).sort()}if(d==null){return}if(a>=d.length){return}var c=d[a];if(c==core.status.event.data){core.events.useItem(c)}else{core.ui.drawToolbox(b)}};actions.prototype.keyDownToolbox=function(c){if(!core.isset(core.status.event.data)){return}var d=Object.keys(core.status.hero.items.tools).sort();var a=Object.keys(core.status.hero.items.constants).sort();var b=core.status.event.selection;if(c==37){if((b>0&&b<100)||b>100){this.clickToolboxIndex(b-1);return}if(b==100&&d.length>0){this.clickToolboxIndex(d.length-1);return}}if(c==38){if((b>5&&b<100)||b>105){this.clickToolboxIndex(b-6);return}if(b>=100&&b<=105){if(d.length>6){this.clickToolboxIndex(Math.min(d.length-1,b-100+6))}else{if(d.length>0){this.clickToolboxIndex(Math.min(d.length-1,b-100))}}return}}if(c==39){if((b=100&&b0){this.clickToolboxIndex(100);return}}if(c==40){if(b<=5){if(d.length>6){this.clickToolboxIndex(Math.min(d.length-1,b+6))}else{if(a.length>0){this.clickToolboxIndex(100+Math.min(a.length-1,b))}}return}if(b>5&&b<100&&a.length>0){this.clickToolboxIndex(100+Math.min(a.length-1,b-6));return}if(b>=100&&b<=105&&a.length>6){this.clickToolboxIndex(Math.min(100+a.length-1,b+6));return}}};actions.prototype.keyUpToolbox=function(a){if(a==84||a==27||a==88){core.ui.closePanel();return}if(!core.isset(core.status.event.data)){return}if(a==13||a==32||a==67){this.clickToolboxIndex(core.status.event.selection);return}if(a==46){if(!core.isset(core.status.event.data)){return}if(!core.flags.enableDeleteItem){core.drawTip("不支持删除道具!");return}core.removeItem(core.status.event.data);core.status.event.data=null;core.ui.drawToolbox();return}};actions.prototype.clickSL=function(e,f){var b=core.status.event.data;var d=parseInt(b/10),c=b%10;if((e==3||e==4)&&f==12){core.ui.drawSLPanel(10*(d-1)+c);return}if((e==8||e==9)&&f==12){core.ui.drawSLPanel(10*(d+1)+c);return}if(e>=10&&e<=12&&f==12){core.ui.closePanel();if(!core.isPlaying()){core.showStartAnimate()}return}if(e>=0&&e<=2&&f==12){core.status.event.selection=!core.status.event.selection;core.ui.drawSLPanel(b);return}var a=null;if(f>=1&&f<=4){if(e>=1&&e<=3){a="autoSave"}if(e>=5&&e<=7){a=5*d+1}if(e>=9&&e<=11){a=5*d+2}}if(f>=7&&f<=10){if(e>=1&&e<=3){a=5*d+3}if(e>=5&&e<=7){a=5*d+4}if(e>=9&&e<=11){a=5*d+5}}if(a!=null){if(core.status.event.selection){if(a=="autoSave"){core.drawTip("无法删除自动存档!")}else{core.removeLocalStorage("save"+a);core.ui.drawSLPanel(b)}}else{core.doSL(a,core.status.event.id)}}};actions.prototype.keyDownSL=function(b){var a=core.status.event.data;var d=parseInt(a/10),c=a%10;if(b==37){if(c==0){core.ui.drawSLPanel(10*(d-1)+5)}else{core.ui.drawSLPanel(a-1)}return}if(b==38){if(c<3){core.ui.drawSLPanel(10*(d-1)+c+3)}else{core.ui.drawSLPanel(a-3)}return}if(b==39){if(c==5){core.ui.drawSLPanel(10*(d+1)+1)}else{core.ui.drawSLPanel(a+1)}return}if(b==40){if(c>=3){core.ui.drawSLPanel(10*(d+1)+c-3)}else{core.ui.drawSLPanel(a+3)}return}if(b==33){core.ui.drawSLPanel(10*(d-1)+c);return}if(b==34){core.ui.drawSLPanel(10*(d+1)+c);return}};actions.prototype.keyUpSL=function(b){var a=core.status.event.data;var d=parseInt(a/10),c=a%10;if(b==27||b==88||(core.status.event.id=="save"&&b==83)||(core.status.event.id=="load"&&b==68)){core.ui.closePanel();if(!core.isPlaying()){core.showStartAnimate()}return}if(b==13||b==32||b==67){if(c==0){core.doSL("autoSave",core.status.event.id)}else{core.doSL(5*d+c,core.status.event.id)}return}if(b==46){if(c==0){core.drawTip("无法删除自动存档!")}else{core.removeLocalStorage("save"+(5*d+c));core.ui.drawSLPanel(a)}}};actions.prototype.clickSwitchs=function(d,e){if(d<5||d>7){return}var a=core.status.event.ui.choices;var c=6-parseInt((a.length-1)/2);if(e>=c&&e7){return}var a=core.status.event.ui.choices;var c=6-parseInt((a.length-1)/2);if(e>=c&&e7){return}var a=core.status.event.ui.choices;var c=6-parseInt((a.length-1)/2);if(e>=c&&e=1;g--){if(core.getLocalStorage("save"+g,null)==null){h=g}else{break}}core.setLocalStorage("save"+h,f);core.drawText("同步成功!\n单存档已覆盖至存档"+h)}},function(){});break;case 4:if(core.hasFlag("debug")){core.drawText("\t[系统提示]调试模式下无法下载录像");break}core.download(core.firstData.name+"_"+core.formatDate2(new Date())+".h5route",JSON.stringify({name:core.firstData.name,hard:core.status.hard,seed:core.getFlag("seed"),route:core.encodeRoute(core.status.route)}));break;case 5:core.status.event.selection=0;core.ui.drawStorageRemove();break;case 6:core.status.event.selection=3;core.ui.drawSettings();break}}return};actions.prototype.keyDownSyncSave=function(a){if(a==38){core.status.event.selection--;core.ui.drawChoices(core.status.event.ui.text,core.status.event.ui.choices)}if(a==40){core.status.event.selection++;core.ui.drawChoices(core.status.event.ui.text,core.status.event.ui.choices)}};actions.prototype.keyUpSyncSave=function(b){if(b==27||b==88){core.status.event.selection=2;core.ui.drawSettings();return}var a=core.status.event.ui.choices;if(b==13||b==32||b==67){var c=6-parseInt((a.length-1)/2);this.clickSyncSave(6,c+core.status.event.selection)}};actions.prototype.clickSyncSelect=function(d,e){if(d<5||d>7){return}var a=core.status.event.ui.choices;var c=6-parseInt((a.length-1)/2);if(e>=c&&e7){return}var a=core.status.event.ui.choices;var g=6-parseInt((a.length-1)/2);var e=null;if(j>=g&&j=1;d--){e=core.getLocalStorage("save"+d,null);if(core.isset(e)){break}}break;case 2:break}}if(core.isset(e)){var b={name:core.firstData.name,version:core.firstData.version,data:e};core.download(core.firstData.name+"_"+core.formatDate2(new Date())+".h5save",JSON.stringify(b))}core.status.event.selection=2;core.ui.drawSyncSave()};actions.prototype.keyDownLocalSaveSelect=function(a){if(a==38){core.status.event.selection--;core.ui.drawChoices(core.status.event.ui.text,core.status.event.ui.choices)}if(a==40){core.status.event.selection++;core.ui.drawChoices(core.status.event.ui.text,core.status.event.ui.choices)}};actions.prototype.keyUpLocalSaveSelect=function(b){if(b==27||b==88){core.status.event.selection=0;core.ui.drawSettings();return}var a=core.status.event.ui.choices;if(b==13||b==32||b==67){var c=6-parseInt((a.length-1)/2);this.clickLocalSaveSelect(6,c+core.status.event.selection)}};actions.prototype.clickStorageRemove=function(e,f){if(e<5||e>7){return}var a=core.status.event.ui.choices;var d=6-parseInt((a.length-1)/2);if(f>=d&&f7){return}var a=core.status.event.ui.choices;var i=6-parseInt((a.length-1)/2);if(k>=i&&k=1&&b<=11){core.ui.closePanel();core.keyUp(112+b-1)}if(c==4&&b>=1&&b<=10){core.ui.closePanel();core.keyUp(b==10?48:48+b)}var a=[["Q","W","E","R","T","Y","U","I","O","P"],["A","S","D","F","G","H","J","K","L"],["Z","X","C","V","B","N","M"],];if(c==5&&b>=1&&b<=10){core.ui.closePanel();core.keyUp(a[0][b-1].charCodeAt(0))}if(c==6&&b>=1&&b<=9){core.ui.closePanel();core.keyUp(a[1][b-1].charCodeAt(0))}if(c==7&&b>=1&&b<=7){core.ui.closePanel();core.keyUp(a[2][b-1].charCodeAt(0))}if(c==8&&b>=1&&b<=11){core.ui.closePanel();if(b==1){core.keyUp(189)}if(b==2){core.keyUp(187)}if(b==3){core.keyUp(219)}if(b==4){core.keyUp(221)}if(b==5){core.keyUp(220)}if(b==6){core.keyUp(186)}if(b==7){core.keyUp(222)}if(b==8){core.keyUp(188)}if(b==9){core.keyUp(190)}if(b==10){core.keyUp(191)}if(b==11){core.keyUp(192)}}if(c==9&&b>=1&&b<=10){core.ui.closePanel();if(b==1){core.keyUp(27)}if(b==2){core.keyUp(9)}if(b==3){core.keyUp(20)}if(b==4){core.keyUp(16)}if(b==5){core.keyUp(17)}if(b==6){core.keyUp(18)}if(b==7){core.keyUp(32)}if(b==8){core.keyUp(8)}if(b==9){core.keyUp(13)}if(b==10){core.keyUp(46)}}if(c==10&&b>=9&&b<=11){core.ui.closePanel()}};actions.prototype.clickCursor=function(a,b){if(a==core.status.automaticRoute.cursorX&&b==core.status.automaticRoute.cursorY){core.ui.closePanel();core.onclick(a,b,[]);return}core.status.automaticRoute.cursorX=a;core.status.automaticRoute.cursorY=b;core.ui.drawCursor()};actions.prototype.keyDownCursor=function(a){if(a==37){core.status.automaticRoute.cursorX--;core.ui.drawCursor();return}if(a==38){core.status.automaticRoute.cursorY--;core.ui.drawCursor();return}if(a==39){core.status.automaticRoute.cursorX++;core.ui.drawCursor();return}if(a==40){core.status.automaticRoute.cursorY++;core.ui.drawCursor();return}};actions.prototype.keyUpCursor=function(a){if(a==27||a==88){core.ui.closePanel();return}if(a==13||a==32||a==67||a==69){core.ui.closePanel();core.onclick(core.status.automaticRoute.cursorX,core.status.automaticRoute.cursorY,[]);return}};actions.prototype.clickAbout=function(){if(core.isPlaying()){core.ui.closePanel()}else{core.restart()}}; \ No newline at end of file diff --git a/libs/control.js b/libs/control.js index 8253b5e7..7b562801 100644 --- a/libs/control.js +++ b/libs/control.js @@ -1,2767 +1,2768 @@ -/* -control.js:游戏主要逻辑控制 -主要负责status相关内容,以及各种变量获取/存储 -寻路算法和人物行走也在此文件内 - */ - -function control() { - this.init(); -} - -control.prototype.init = function () { - -} - -////// 设置requestAnimationFrame ////// -control.prototype.setRequestAnimationFrame = function () { - - (function() { - var lastTime = 0; - var vendors = ['webkit', 'moz']; - for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) { - window.requestAnimationFrame = window[vendors[x] + 'RequestAnimationFrame']; - window.cancelAnimationFrame = window[vendors[x] + 'CancelAnimationFrame'] || // Webkit中此取消方法的名字变了 - window[vendors[x] + 'CancelRequestAnimationFrame']; - } - - if (!window.requestAnimationFrame) { - window.requestAnimationFrame = function(callback, element) { - var currTime = new Date().getTime(); - var timeToCall = Math.max(0, 16.7 - (currTime - lastTime)); - var id = window.setTimeout(function() { - callback(currTime + timeToCall); - }, timeToCall); - lastTime = currTime + timeToCall; - return id; - }; - } - if (!window.cancelAnimationFrame) { - window.cancelAnimationFrame = function(id) { - clearTimeout(id); - }; - } - }()); - - core.animateFrame.speed = core.values.animateSpeed; - core.animateFrame.background = core.canvas.ui.createPattern(core.material.ground, "repeat"); - - var scan = { - 'up': {'x': 0, 'y': -1}, - 'left': {'x': -1, 'y': 0}, - 'down': {'x': 0, 'y': 1}, - 'right': {'x': 1, 'y': 0} - }; - - var draw = function(timestamp) { - - core.animateFrame.globalTime = core.animateFrame.globalTime||timestamp; - core.animateFrame.boxTime = core.animateFrame.boxTime||timestamp; - core.animateFrame.moveTime = core.animateFrame.moveTime||timestamp; - core.animateFrame.weather.time = core.animateFrame.weather.time||timestamp; - - // move time - if (core.isPlaying() && core.isset(core.status) && core.isset(core.status.hero) - && core.isset(core.status.hero.statistics)) { - core.status.hero.statistics.totalTime += timestamp-(core.status.hero.statistics.start||timestamp); - core.status.hero.statistics.currTime += timestamp-(core.status.hero.statistics.start||timestamp); - core.status.hero.statistics.start=timestamp; - } - - // Global Animate - if (core.animateFrame.globalAnimate && core.isPlaying()) { - - if (timestamp-core.animateFrame.globalTime>core.animateFrame.speed && core.isset(core.status.globalAnimateObjs)) { - - for (var a = 0; a < core.status.globalAnimateObjs.length; a++) { - var obj = core.status.globalAnimateObjs[a]; - obj.status = (obj.status+1)%(obj.event.animate||1); - core.drawBlock(obj, obj.status); - } - - core.animateFrame.globalTime = timestamp; - } - } - - // Box - if (timestamp-core.animateFrame.boxTime>core.animateFrame.speed && core.isset(core.status.boxAnimateObjs) && core.status.boxAnimateObjs.length>0) { - core.drawBoxAnimate(); - core.animateFrame.boxTime = timestamp; - } - - // Hero move - if (timestamp-core.animateFrame.moveTime>16 && core.isset(core.status.heroMoving) && core.status.heroMoving>0) { - var x=core.getHeroLoc('x'), y=core.getHeroLoc('y'), direction = core.getHeroLoc('direction'); - if (core.status.heroMoving<=4) { - core.drawHero(direction, x, y, 'leftFoot', 4*core.status.heroMoving*scan[direction].x, 4*core.status.heroMoving*scan[direction].y); - } - else if (core.status.heroMoving<=8) { - core.drawHero(direction, x, y, 'rightFoot', 4*core.status.heroMoving*scan[direction].x, 4*core.status.heroMoving*scan[direction].y); - } - core.animateFrame.moveTime = timestamp; - } - - // weather - if (core.isPlaying() && timestamp-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 (p) { - core.canvas.weather.beginPath(); - core.canvas.weather.moveTo(p.x, p.y); - core.canvas.weather.lineTo(p.x + p.l * p.xs, p.y + p.l * p.ys); - core.canvas.weather.stroke(); - - p.x += p.xs; - p.y += p.ys; - if (p.x > 416 || p.y > 416) { - p.x = Math.random() * 416; - p.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 angle = core.animateFrame.weather.data; - core.animateFrame.weather.nodes.forEach(function (p) { - core.canvas.weather.moveTo(p.x, p.y); - core.canvas.weather.arc(p.x, p.y, p.r, 0, Math.PI * 2, true); - - // update - p.x += Math.sin(angle) * 2; - p.y += Math.cos(angle + p.d) + 1 + p.r / 2; - - if (p.x > 416 + 5 || p.x < -5 || p.y > 416) { - if (Math.random() > 1 / 3) { - p.x = Math.random() * 416; - p.y = -10; - } - else { - if (Math.sin(angle) > 0) { - p.x = -5; - p.y = Math.random() * 416; - } - else { - p.x = 416 + 5; - p.y = Math.random() * 416; - } - } - } - - }) - - core.canvas.weather.fill(); - - } - core.animateFrame.weather.time = timestamp; - - } - window.requestAnimationFrame(draw); - } - window.requestAnimationFrame(draw); -} - -////// 显示游戏开始界面 ////// -control.prototype.showStartAnimate = function (callback) { - 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 opacityVal = 1; - var startAnimate = window.setInterval(function () { - opacityVal -= 0.03; - if (opacityVal < 0) { - clearInterval(startAnimate); - core.dom.startTop.style.display = 'none'; - // core.playGame(); - core.dom.startButtonGroup.style.display = 'block'; - if (core.isset(callback)) callback(); - } - core.dom.startTop.style.opacity = opacityVal; - }, 20); -} - -////// 隐藏游戏开始界面 ////// -control.prototype.hideStartAnimate = function (callback) { - var opacityVal = 1; - var startAnimate = window.setInterval(function () { - opacityVal -= 0.03; - if (opacityVal < 0) { - clearInterval(startAnimate); - core.dom.startPanel.style.display = 'none'; - if (core.isset(callback)) callback(); - } - core.dom.startPanel.style.opacity = opacityVal; - }, 20); -} - -////// 游戏是否已经开始 ////// -control.prototype.isPlaying = function() { - return core.isset(core.status.played) && core.status.played; -} - -////// 清除游戏状态和数据 ////// -control.prototype.clearStatus = function() { - // 停止各个Timeout和Interval - for (var i in core.timeout) { - clearTimeout(core.timeout[i]); - core.timeout[i] = null; - } - for (var i in core.interval) { - clearInterval(core.interval[i]); - core.interval[i] = null; - } - core.status = {}; - core.clearStatusBar(); - core.resize(main.dom.body.clientWidth, main.dom.body.clientHeight); -} - -////// 重置游戏状态和初始数据 ////// -control.prototype.resetStatus = function(hero, hard, floorId, route, maps) { - - var totalTime=0; - if (core.isset(core.status) && core.isset(core.status.hero) - && core.isset(core.status.hero.statistics) && core.isset(route)) { - totalTime=core.status.hero.statistics.totalTime; - } - - this.clearStatus(); - - // 初始化status - core.status = core.clone(core.initStatus); - core.status.played = true; - // 初始化maps - core.status.floorId = floorId; - core.status.maps = core.clone(maps); - // 初始化怪物 - core.material.enemys = core.clone(core.enemys.getEnemys()); - // 初始化人物属性 - core.status.hero = core.clone(hero); - // 统计数据 - if (!core.isset(core.status.hero.statistics)) - core.status.hero.statistics = { - 'totalTime': totalTime, - '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, totalTime); - core.status.hero.statistics.start = null; - - core.status.hard = hard; - // 初始化路线 - if (core.isset(route)) - core.status.route = route; - // 保存的Index - core.status.saveIndex = core.getLocalStorage('saveIndex2', 1); - -} - -////// 开始游戏 ////// -control.prototype.startGame = function (hard, callback) { - console.log('开始游戏'); - - this.resetStatus(core.firstData.hero, hard, core.firstData.floorId, null, core.initStatus.maps); - - core.changeFloor(core.status.floorId, null, core.firstData.hero.loc, null, function() { - if (core.isset(callback)) callback(); - }, true); - - setTimeout(function () { - // Upload - var formData = new FormData(); - formData.append('type', 'people'); - formData.append('name', core.firstData.name); - formData.append('version', core.firstData.version); - formData.append('platform', core.platform.isPC?"PC":core.platform.isAndroid?"Android":core.platform.isIOS?"iOS":""); - formData.append('hard', hard); - formData.append('hardCode', core.getFlag('hard', 0)); - - core.utils.http("POST", "/games/upload.php", formData); - }) - -} - -////// 重新开始游戏;此函数将回到标题页面 ////// -control.prototype.restart = function() { - this.showStartAnimate(); - if (core.bgms.length>0) - core.playBgm(core.bgms[0]); -} - - -/////////////////////// 寻路算法 & 人物行走控制 /////////////////////// - -////// 清除自动寻路路线 ////// -control.prototype.clearAutomaticRouteNode = function (x, y) { - if (core.status.event.id==null) - core.canvas.ui.clearRect(x * 32 + 5, y * 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 () { - // 此函数只应由events.afterOpenDoor和events.afterBattle调用 - var moveStep = core.status.automaticRoute.moveStepBeforeStop; - //core.status.automaticRoute.moveStepBeforeStop = []; - if(moveStep.length===0 || (moveStep.length===1 && moveStep[0].step===1)) { - core.status.automaticRoute.moveStepBeforeStop = []; - } - else { - core.setAutoHeroMove(moveStep); - } -} - -////// 清空剩下的自动寻路列表 ////// -control.prototype.clearContinueAutomaticRoute = function () { - core.canvas.ui.clearRect(0, 0, 416, 416); - core.status.automaticRoute.moveStepBeforeStop=[]; -} - -////// 设置自动寻路路线 ////// -control.prototype.setAutomaticRoute = function (destX, destY, stepPostfix) { - if (!core.status.played || core.status.lockControl) { - return; - } - // 正在寻路中 - if (core.status.automaticRoute.autoHeroMove) { - var lastX = core.status.automaticRoute.destX, lastY=core.status.automaticRoute.destY; - core.stopAutomaticRoute(); - if (lastX==destX && lastY==destY) { - core.status.automaticRoute.moveDirectly = true; - setTimeout(function () { - if (core.status.automaticRoute.moveDirectly && core.status.heroMoving==0) { - var ignoreSteps = core.canMoveDirectly(destX, destY); - if (ignoreSteps>0) { - core.clearMap('hero', 0, 0, 416, 416); - core.setHeroLoc('x', destX); - core.setHeroLoc('y', destY); - core.drawHero(); - core.status.route.push("move:"+destX+":"+destY); - core.status.hero.statistics.moveDirectly++; - core.status.hero.statistics.ignoreSteps+=ignoreSteps; - } - } - core.status.automaticRoute.moveDirectly = false; - }, 100); - } - return; - } - if (destX == core.status.hero.loc.x && destY == core.status.hero.loc.y && stepPostfix.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 step = 0; - var tempStep = null; - var moveStep; - if (!(moveStep = core.automaticRoute(destX, destY))) { - if (destX == core.status.hero.loc.x && destY == core.status.hero.loc.y){ - moveStep=[]; - } else { - core.canvas.ui.clearRect(0, 0, 416, 416); - return; - } - } - moveStep=moveStep.concat(stepPostfix); - core.status.automaticRoute.destX=destX; - core.status.automaticRoute.destY=destY; - 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 m = 0; m < moveStep.length; m++) { - if (tempStep == null) { - step++; - tempStep = moveStep[m].direction; - } - else if (tempStep == moveStep[m].direction) { - step++; - } - else { - //core.status.automaticRoutingTemp.moveStep.push({'direction': tempStep, 'step': step}); - core.status.automaticRoute.autoStepRoutes.push({'direction': tempStep, 'step': step}); - step = 1; - tempStep = moveStep[m].direction; - } - if (m == moveStep.length - 1) { - // core.status.automaticRoutingTemp.moveStep.push({'direction': tempStep, 'step': step}); - core.status.automaticRoute.autoStepRoutes.push({'direction': tempStep, 'step': step}); - core.canvas.ui.fillRect(moveStep[m].x * 32 + 10, moveStep[m].y * 32 + 10, 12, 12); - } - else { - core.canvas.ui.beginPath(); - if (core.isset(moveStep[m + 1]) && tempStep != moveStep[m + 1].direction) { - if (tempStep == 'up' && moveStep[m + 1].direction == 'left' || tempStep == 'right' && moveStep[m + 1].direction == 'down') { - core.canvas.ui.moveTo(moveStep[m].x * 32 + 5, moveStep[m].y * 32 + 16); - core.canvas.ui.lineTo(moveStep[m].x * 32 + 16, moveStep[m].y * 32 + 16); - core.canvas.ui.lineTo(moveStep[m].x * 32 + 16, moveStep[m].y * 32 + 27); - } - else if (tempStep == 'up' && moveStep[m + 1].direction == 'right' || tempStep == 'left' && moveStep[m + 1].direction == 'down') { - core.canvas.ui.moveTo(moveStep[m].x * 32 + 27, moveStep[m].y * 32 + 16); - core.canvas.ui.lineTo(moveStep[m].x * 32 + 16, moveStep[m].y * 32 + 16); - core.canvas.ui.lineTo(moveStep[m].x * 32 + 16, moveStep[m].y * 32 + 27); - } - else if (tempStep == 'left' && moveStep[m + 1].direction == 'up' || tempStep == 'down' && moveStep[m + 1].direction == 'right') { - core.canvas.ui.moveTo(moveStep[m].x * 32 + 27, moveStep[m].y * 32 + 16); - core.canvas.ui.lineTo(moveStep[m].x * 32 + 16, moveStep[m].y * 32 + 16); - core.canvas.ui.lineTo(moveStep[m].x * 32 + 16, moveStep[m].y * 32 + 5); - } - else if (tempStep == 'right' && moveStep[m + 1].direction == 'up' || tempStep == 'down' && moveStep[m + 1].direction == 'left') { - core.canvas.ui.moveTo(moveStep[m].x * 32 + 5, moveStep[m].y * 32 + 16); - core.canvas.ui.lineTo(moveStep[m].x * 32 + 16, moveStep[m].y * 32 + 16); - core.canvas.ui.lineTo(moveStep[m].x * 32 + 16, moveStep[m].y * 32 + 5); - } - core.canvas.ui.stroke(); - continue; - } - switch (tempStep) { - case 'up': - case 'down': - core.canvas.ui.beginPath(); - core.canvas.ui.moveTo(moveStep[m].x * 32 + 16, moveStep[m].y * 32 + 5); - core.canvas.ui.lineTo(moveStep[m].x * 32 + 16, moveStep[m].y * 32 + 27); - core.canvas.ui.stroke(); - break; - case 'left': - case 'right': - core.canvas.ui.beginPath(); - core.canvas.ui.moveTo(moveStep[m].x * 32 + 5, moveStep[m].y * 32 + 16); - core.canvas.ui.lineTo(moveStep[m].x * 32 + 27, moveStep[m].y * 32 + 16); - core.canvas.ui.stroke(); - break; - } - } - } - core.canvas.ui.restore(); - - // 立刻移动 - core.setAutoHeroMove(); - -} - -////// 自动寻路算法,找寻最优路径 ////// -control.prototype.automaticRoute = function (destX, destY) { - var startX = core.getHeroLoc('x'); - var startY = core.getHeroLoc('y'); - var scan = { - 'up': {'x': 0, 'y': -1}, - 'left': {'x': -1, 'y': 0}, - 'down': {'x': 0, 'y': 1}, - 'right': {'x': 1, 'y': 0} - }; - var queue = []; - var nowDeep = 0; - var route = []; - var ans = [] - - if (destX == startX && destY == startY) return false; - queue.push(13 * startX + startY); - queue.push(-1); - route[13 * startX + startY] = ''; - - while (queue.length != 1) { - var f = queue.shift(); - if (f===-1) {nowDeep+=1;queue.push(-1);continue;} - var deep = ~~(f/169); - if (deep!==nowDeep) {queue.push(f);continue;} - f=f%169; - var nowX = parseInt(f / 13), nowY = f % 13; - var nowIsArrow = false, nowId, nowBlock = core.getBlock(nowX,nowY); - for (var direction in scan) { - if (!core.canMoveHero(nowX, nowY, direction)) - continue; - - var nx = nowX + scan[direction].x; - var ny = nowY + scan[direction].y; - - if (nx<0 || nx>12 || ny<0 || ny>12) continue; - - var nid = 13 * nx + ny; - - if (core.isset(route[nid])) continue; - - var deepAdd=1; - - var nextId, nextBlock = core.getBlock(nx,ny); - if (nextBlock!=null){ - nextId = nextBlock.block.event.id; - // 绕过亮灯(因为只有一次通行机会很宝贵) - if(nextId == "light") deepAdd=100; - // 绕过路障 - if (nextId.substring(nextId.length-3)=="Net") deepAdd=core.values.lavaDamage; - // 绕过血瓶 - if (!core.flags.potionWhileRouting && nextId.substring(nextId.length-6)=="Potion") deepAdd=20; - // 绕过传送点 - if (nextBlock.block.event.trigger == 'changeFloor') deepAdd = 10; - } - if (core.status.checkBlock.damage[nid]>0) - deepAdd = core.status.checkBlock.damage[nid]; - - if (nx == destX && ny == destY) { - route[nid] = direction; - break; - } - if (core.noPassExists(nx, ny)) - continue; - - route[nid] = direction; - queue.push(169*(nowDeep+deepAdd)+nid); - } - if (core.isset(route[13 * destX + destY])) break; - } - - if (!core.isset(route[13 * destX + destY])) { - return false; - } - - var nowX = destX, nowY = destY; - while (nowX != startX || nowY != startY) { - var dir = route[13 * nowX + nowY]; - ans.push({'direction': dir, 'x': nowX, 'y': nowY}); - nowX -= scan[dir].x; - nowY -= scan[dir].y; - } - - ans.reverse(); - return ans; -} - -////// 显示离散的寻路点 ////// -control.prototype.fillPosWithPoint = function (pos) { - core.fillRect('ui', pos.x*32+12,pos.y*32+12,8,8, '#bfbfbf'); -} - -////// 设置勇士的自动行走路线 ////// -control.prototype.setAutoHeroMove = function (steps) { - steps=steps||core.status.automaticRoute.autoStepRoutes; - if (steps.length == 0) { - return; - } - core.status.automaticRoute.autoStepRoutes=steps; - core.status.automaticRoute.autoHeroMove = true; - core.status.automaticRoute.autoStep = 1; - core.status.automaticRoute.destStep = steps[0].step; - core.moveHero(steps[0].direction); -} - -////// 设置行走的效果动画 ////// -control.prototype.setHeroMoveInterval = function (direction, x, y, callback) { - if (core.status.heroMoving>0) { - return; - } - core.status.heroMoving=1; - var scan = { - 'up': {'x': 0, 'y': -1}, - 'left': {'x': -1, 'y': 0}, - 'down': {'x': 0, 'y': 1}, - 'right': {'x': 1, 'y': 0} - }; - - var toAdd = 1; - if (core.status.replay.speed>3) - toAdd = 2; - - core.interval.heroMoveInterval = window.setInterval(function () { - core.status.heroMoving+=toAdd; - if (core.status.heroMoving>=8) { - core.setHeroLoc('x', x+scan[direction].x); - core.setHeroLoc('y', y+scan[direction].y); - core.moveOneStep(); - core.clearMap('hero', 0, 0, 416, 416); - core.drawHero(direction); - clearInterval(core.interval.heroMoveInterval); - core.status.heroMoving = 0; - if (core.isset(callback)) callback(); - } - }, 12.5 * toAdd / core.status.replay.speed); -} - -////// 实际每一步的行走过程 ////// -control.prototype.moveAction = function (callback) { - if (core.interval.openDoorAnimate!=null) return; // 开门判断 - if (core.status.heroMoving>0) return; - var scan = { - 'up': {'x': 0, 'y': -1}, - 'left': {'x': -1, 'y': 0}, - 'down': {'x': 0, 'y': 1}, - 'right': {'x': 1, 'y': 0} - }; - var direction = core.getHeroLoc('direction'); - var x = core.getHeroLoc('x'); - var y = core.getHeroLoc('y'); - var noPass = core.noPass(x + scan[direction].x, y + scan[direction].y), canMove = core.canMoveHero(); - if (noPass || !canMove) { - if (core.status.event.id!='ski') - core.status.route.push(direction); - core.status.automaticRoute.moveStepBeforeStop = []; - core.status.automaticRoute.lastDirection = core.getHeroLoc('direction'); - if (canMove) // 非箭头:触发 - core.trigger(x + scan[direction].x, y + scan[direction].y); - core.drawHero(direction, x, y); - - if (core.status.automaticRoute.moveStepBeforeStop.length==0) { - core.clearContinueAutomaticRoute(); - core.stopAutomaticRoute(); - } - if (core.isset(callback)) - callback(); - } - else { - core.setHeroMoveInterval(direction, x, y, 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(direction); - core.trigger(core.getHeroLoc('x'), core.getHeroLoc('y')); - core.checkBlock(); - if (core.isset(callback)) callback(); - }); - } -} - -////// 转向 ////// -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 (direction, callback) { - // 如果正在移动,直接return - if (core.status.heroMoving!=0) return; - if (core.isset(direction)) - core.setHeroLoc('direction', direction); - if (!core.isset(callback)) { // 如果不存在回调函数,则使用heroMoveTrigger - core.status.heroStop = false; - core.status.automaticRoute.moveDirectly = false; - - var doAction = 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; - doAction(); - }); - } - else { - core.moveAction(); - setTimeout(doAction, 50); - } - } - else { - core.stopHero(); - } - } - doAction(); - } - else { // 否则,只向某个方向移动一步,然后调用callback - core.moveAction(function () { - callback(); - }) - } -} - -/////// 使用事件让勇士移动。这个函数将不会触发任何事件 ////// -control.prototype.eventMoveHero = function(steps, time, callback) { - - time = time || 100; - - core.clearMap('ui', 0, 0, 416, 416); - core.setAlpha('ui', 1.0); - - // 要运行的轨迹:将steps展开 - var moveSteps=[]; - steps.forEach(function (e) { - if (typeof e=="string") { - moveSteps.push(e); - } - else { - if (!core.isset(e.value)) { - moveSteps.push(e.direction) - } - else { - for (var i=0;i12 || ny<0 || ny>12) continue; - if (!zoneSquare && Math.abs(dx)+Math.abs(dy)>range) continue; - core.status.checkBlock.damage[13*nx+ny]+=enemy.value; - } - } - } - // 存在阻击 - if (core.enemys.hasSpecial(enemy.special, 18)) { - for (var dx=-1;dx<=1;dx++) { - for (var dy=-1;dy<=1;dy++) { - if (dx==0 && dy==0) continue; - var nx=x+dx, ny=y+dy; - if (nx<0 || nx>12 || ny<0 || ny>12 || Math.abs(dx)+Math.abs(dy)>1) continue; - core.status.checkBlock.damage[13*nx+ny]+=enemy.value; - } - } - } - } - } - } - - - // Step3: 更新夹击点坐标,并将夹击伤害加入到damage中 - core.status.checkBlock.betweenAttack = []; // 记录(x,y)点是否有夹击 - for (var x=0;x<13;x++) { - for (var y=0;y<13;y++) { - var has=false; - if (x>0 && x<12) { - var id1=core.status.checkBlock.map[13*(x-1)+y], - id2=core.status.checkBlock.map[13*(x+1)+y]; - if (core.isset(id1) && core.isset(id2) && id1==id2) { - var enemy = core.material.enemys[id1]; - if (core.isset(enemy) && core.enemys.hasSpecial(enemy.special, 16)) { - has = true; - } - } - } - if (y>0 && y<12) { - var id1=core.status.checkBlock.map[13*x+y-1], - id2=core.status.checkBlock.map[13*x+y+1]; - if (core.isset(id1) && core.isset(id2) && id1==id2) { - var enemy = core.material.enemys[id1]; - if (core.isset(enemy) && core.enemys.hasSpecial(enemy.special, 16)) { - has = true; - } - } - } - // 存在夹击 - if (has) { - core.status.checkBlock.betweenAttack[13*x+y]=true; - var leftHp = core.status.hero.hp - core.status.checkBlock.damage[13*x+y]; - if (leftHp>1) - core.status.checkBlock.damage[13*x+y] += Math.floor((leftHp+(core.flags.betweenAttackCeil?0:1))/2); - } - } - } -} - -////// 检查并执行领域、夹击、阻击事件 ////// -control.prototype.checkBlock = function () { - var x=core.getHeroLoc('x'), y=core.getHeroLoc('y'); - var damage = core.status.checkBlock.damage[13*x+y]; - if (damage>0) { - core.status.hero.hp -= damage; - - // 检查阻击事件 - var snipe = []; - var scan = { - 'up': {'x': 0, 'y': -1}, - 'left': {'x': -1, 'y': 0}, - 'down': {'x': 0, 'y': 1}, - 'right': {'x': 1, 'y': 0} - } - for (var direction in scan) { - var nx = x+scan[direction].x, ny=y+scan[direction].y; - if (nx<0 || nx>12 || ny<0 || ny>12) continue; - var id=core.status.checkBlock.map[13*nx+ny]; - if (core.isset(id)) { - var enemy = core.material.enemys[id]; - if (core.isset(enemy) && core.enemys.hasSpecial(enemy.special, 18)) { - snipe.push({'direction': direction, 'x': nx, 'y': ny}); - } - } - } - - if (core.status.checkBlock.betweenAttack[13*x+y] && damage>0) { - core.drawTip('受到夹击,生命变成一半'); - } - else if (core.status.checkBlock.map[13*x+y]=='lavaNet') { - core.drawTip('受到血网伤害'+damage+'点'); - } - // 阻击 - else if (snipe.length>0 && damage>0) { - core.drawTip('受到阻击伤害'+damage+'点'); - } - else if (damage>0) { - core.drawTip('受到领域伤害'+damage+'点'); - } - - if (damage>0) { - core.playSound('zone.mp3'); - core.drawAnimate("zone", x, y); - } - core.status.hero.statistics.extraDamage += damage; - - if (core.status.hero.hp<=0) { - core.status.hero.hp=0; - core.updateStatusBar(); - core.events.lose(); - return; - } - snipe = snipe.filter(function (t) { - var x=t.x, y=t.y, direction = t.direction; - var nx = x+scan[direction].x, ny=y+scan[direction].y; - - return nx>=0 && nx<=12 && ny>=0 && ny<=12 && core.getBlock(nx, ny, core.status.floorId, false)==null; - }); - core.updateStatusBar(); - if (snipe.length>0) - core.snipe(snipe); - } -} - -////// 阻击事件(动画效果) ////// -control.prototype.snipe = function (snipes) { - - var scan = { - 'up': {'x': 0, 'y': -1}, - 'left': {'x': -1, 'y': 0}, - 'down': {'x': 0, 'y': 1}, - 'right': {'x': 1, 'y': 0} - }; - - snipes.forEach(function (snipe) { - var x=snipe.x, y=snipe.y, direction = snipe.direction; - snipe.nx = x+scan[snipe.direction].x; - snipe.ny = y+scan[snipe.direction].y; - - core.removeGlobalAnimate(x, y); - - var block = core.getBlock(x,y).block; - - var cls = block.event.cls; - var height = block.event.height || 32; - - snipe.animate = block.event.animate || 1; - snipe.blockIcon = core.material.icons[cls][block.event.id]; - snipe.blockImage = core.material.images[cls]; - snipe.height = height; - - var damage = core.enemys.getDamage(block.event.id); - var color = '#000000'; - - if (damage == null) { - damage = "???"; - color = '#FF0000'; - } - else { - if (damage <= 0) color = '#00FF00'; - else if (damage < core.status.hero.hp / 3) color = '#FFFFFF'; - else if (damage < core.status.hero.hp * 2 / 3) color = '#FFFF00'; - else if (damage < core.status.hero.hp) color = '#FF7F00'; - else color = '#FF0000'; - - damage = core.formatBigNumber(damage); - } - - snipe.damage = damage; - snipe.color = color; - snipe.block = core.clone(block); - - }) - - var finishSnipe = function () { - snipes.forEach(function (t) { - core.removeBlock(t.x, t.y); - var nBlock = core.clone(t.block); - nBlock.x = t.nx; nBlock.y = t.ny; - core.status.thisMap.blocks.push(nBlock); - core.drawBlock(nBlock); - core.addGlobalAnimate(nBlock); - }); - core.syncGlobalAnimate(); - core.updateStatusBar(); - return; - } - - if (core.status.replay.replaying) { - finishSnipe(); - } - else { - core.waitHeroToStop(function() { - - core.lockControl(); - - var time = 500, step = 0; - - var animateCurrent = 0; - var animateTime = 0; - - core.canvas.fg.textAlign = 'left'; - - var animate=window.setInterval(function() { - - step++; - animateTime += time / 16; - if (animateTime >= core.values.animateSpeed) { - animateCurrent++; - animateTime = 0; - } - - snipes.forEach(function (snipe) { - var x=snipe.x, y=snipe.y, direction = snipe.direction; - - var dx = scan[direction].x*2*step, dy = scan[direction].y*2*step; - var nowX = 32*x+dx, nowY = 32*y+dy; - - // 清空上一次 - core.clearMap('fg', nowX-2*scan[direction].x, nowY-2*scan[direction].y, 32, 32); - core.canvas.event.clearRect(nowX-2*scan[direction].x, nowY-2*scan[direction].y, 32, 32); - core.canvas.event2.clearRect(nowX-2*scan[direction].x, nowY-2*scan[direction].y-32, 32, 32) - - core.drawBlock(snipe.block, animateCurrent, dx, dy); - - if (core.hasItem('book')) { - // drawFG - core.setFillStyle('fg', '#000000'); - core.canvas.fg.fillText(snipe.damage, nowX + 2, nowY + 30); - core.canvas.fg.fillText(snipe.damage, nowX, nowY + 30); - core.canvas.fg.fillText(snipe.damage, nowX + 2, nowY + 32); - core.canvas.fg.fillText(snipe.damage, nowX, nowY + 32); - - core.setFillStyle('fg', snipe.color); - core.canvas.fg.fillText(snipe.damage, nowX + 1, nowY + 31); - } - - }) - - if (step==16) { // 移动完毕 - clearInterval(animate); - finishSnipe(); - // 不存在自定义事件 - if (core.status.event.id==null) - core.unLockControl(); - } - }, time/16); - }); - } -} - -////// 更改天气效果 ////// -control.prototype.setWeather = function (type, level) { - - // 非雨雪 - if (type!='rain' && type!='snow') { - core.clearMap('weather', 0, 0, 416, 416) - core.animateFrame.weather.type = null; - core.animateFrame.weather.level = 0; - core.animateFrame.weather.nodes = []; - return; - } - - level = parseInt(level); - - // 当前天气:则忽略 - if (type==core.animateFrame.weather.type && - (!core.isset(level) || 20*level==core.animateFrame.weather.level)) { - return; - } - - if (!core.isset(level)) level=5; - if (level<1) level=1; if (level>10) level=10; - level *= 20; - - core.clearMap('weather', 0, 0, 416, 416) - core.animateFrame.weather.type = type; - core.animateFrame.weather.level = level; - - core.animateFrame.weather.nodes = []; - - if (type == 'rain') { - for (var a=0;a1) color[3]=1; - - if (time==0) { - // 直接变色 - core.dom.curtain.style.background = core.arrayToRGB(color); - core.dom.curtain.style.opacity = color[3]; - core.status.curtainColor = color; - if (core.isset(callback)) callback(); - return; - } - - var step=0; - core.status.replay.animate=true; - var changeAnimate = setInterval(function() { - step++; - - var nowAlpha = fromColor[3]+(color[3]-fromColor[3])*step/25; - var nowR = parseInt(fromColor[0]+(color[0]-fromColor[0])*step/25); - var nowG = parseInt(fromColor[1]+(color[1]-fromColor[1])*step/25); - var nowB = parseInt(fromColor[2]+(color[2]-fromColor[2])*step/25); - core.dom.curtain.style.background = core.arrayToRGB([nowR,nowG,nowB]); - core.dom.curtain.style.opacity = nowAlpha; - - if (step>=25) { - clearInterval(changeAnimate); - core.status.curtainColor = color; - core.status.replay.animate=false; - if (core.isset(callback)) callback(); - } - }, time/25); -} - -////// 更新全地图显伤 ////// -control.prototype.updateFg = function () { - - if (!core.isset(core.status.thisMap) || !core.isset(core.status.thisMap.blocks)) return; - // 更新显伤 - var mapBlocks = core.status.thisMap.blocks; - core.clearMap('fg', 0, 0, 416, 416); - // 没有怪物手册 - if (!core.hasItem('book')) return; - core.setFont('fg', "bold 11px Arial"); - var hero_hp = core.status.hero.hp; - if (core.flags.displayEnemyDamage || core.flags.displayCritical) { - core.canvas.fg.textAlign = 'left'; - for (var b = 0; b < mapBlocks.length; b++) { - var x = mapBlocks[b].x, y = mapBlocks[b].y; - if (core.isset(mapBlocks[b].event) && mapBlocks[b].event.cls.indexOf('enemy')==0 - && !(core.isset(mapBlocks[b].enable) && !mapBlocks[b].enable)) { - - // 非系统默认的战斗事件(被覆盖) - if (mapBlocks[b].event.trigger != 'battle') { - // 判断显伤 - var event = core.floors[core.status.floorId].events[x+","+y]; - if (core.isset(event) && !(event instanceof Array)) { - if (core.isset(event.displayDamage) && !event.displayDamage) - continue; - } - } - - var id = mapBlocks[b].event.id; - - if (core.flags.displayEnemyDamage) { - var damage = core.enemys.getDamage(id); - var color = '#000000'; - - if (damage == null) { - damage = "???"; - color = '#FF0000'; - } - else { - if (damage <= 0) color = '#00FF00'; - else if (damage < hero_hp / 3) color = '#FFFFFF'; - else if (damage < hero_hp * 2 / 3) color = '#FFFF00'; - else if (damage < hero_hp) color = '#FF7F00'; - else color = '#FF0000'; - - damage = core.formatBigNumber(damage); - } - - core.setFillStyle('fg', '#000000'); - core.canvas.fg.fillText(damage, 32 * x + 2, 32 * (y + 1) - 2); - core.canvas.fg.fillText(damage, 32 * x, 32 * (y + 1) - 2); - core.canvas.fg.fillText(damage, 32 * x + 2, 32 * (y + 1)); - core.canvas.fg.fillText(damage, 32 * x, 32 * (y + 1)); - - core.setFillStyle('fg', color); - core.canvas.fg.fillText(damage, 32 * x + 1, 32 * (y + 1) - 1); - } - - // 临界显伤 - if (core.flags.displayCritical) { - var critical = core.enemys.nextCriticals(id); - if (critical.length>0) critical=critical[0]; - critical = core.formatBigNumber(critical[0]); - if (critical == '???') critical = '?'; - core.setFillStyle('fg', '#000000'); - core.canvas.fg.fillText(critical, 32 * x + 2, 32 * (y + 1) - 2 - 10); - core.canvas.fg.fillText(critical, 32 * x, 32 * (y + 1) - 2 - 10); - core.canvas.fg.fillText(critical, 32 * x + 2, 32 * (y + 1) - 10); - core.canvas.fg.fillText(critical, 32 * x, 32 * (y + 1) - 10); - core.setFillStyle('fg', '#FFFFFF'); - core.canvas.fg.fillText(critical, 32 * x + 1, 32 * (y + 1) - 1 - 10); - } - - } - } - } - // 如果是领域&夹击 - if (core.flags.displayExtraDamage) { - core.canvas.fg.textAlign = 'center'; - for (var x=0;x<13;x++) { - for (var y=0;y<13;y++) { - var damage = core.status.checkBlock.damage[13*x+y]; - if (damage>0) { - damage = core.formatBigNumber(damage); - core.setFillStyle('fg', '#000000'); - core.canvas.fg.fillText(damage, 32 * x + 17, 32 * (y + 1) - 13); - core.canvas.fg.fillText(damage, 32 * x + 15, 32 * (y + 1) - 15); - core.canvas.fg.fillText(damage, 32 * x + 17, 32 * (y + 1) - 15); - core.canvas.fg.fillText(damage, 32 * x + 15, 32 * (y + 1) - 13); - - core.setFillStyle('fg', '#FF7F00'); - core.canvas.fg.fillText(damage, 32 * x + 16, 32 * (y + 1) - 14); - } - } - } - } -} - -////// 执行一个表达式的effect操作 ////// -control.prototype.doEffect = function (expression) { - // 必须使用"+=" - var arr = expression.split("+="); - if (arr.length!=2) return; - var name=arr[0], value=core.calValue(arr[1]); - if (name.indexOf("status:")==0) { - var status=name.substring(7); - core.setStatus(status, core.getStatus(status)+value); - } - else if (name.indexOf("item:")==0) { - var itemId=name.substring(5); - core.setItem(itemId, core.itemCount(itemId)+value); - } -} - -////// 开启debug模式 ////// -control.prototype.debug = function() { - core.setFlag('debug', true); - core.insertAction(["\t[调试模式开启]此模式下按住Ctrl键可以穿墙并忽略一切事件。\n同时,录像将失效,也无法上传成绩。"]); - /* - 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 i in core.status.maps) - if (core.status.maps[i].canFlyTo && core.status.hero.flyRange.indexOf(i)<0) - core.status.hero.flyRange.push(i); - core.updateStatusBar(); - core.drawTip("作弊成功"); - */ -} - -////// 开始播放 ////// -control.prototype.startReplay = function (list) { - core.status.replay.replaying=true; - core.status.replay.pausing=false; - core.status.replay.speed=1.0; - core.status.replay.toReplay = core.clone(list); - core.status.replay.totalList = core.clone(list); - 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 toAdd = core.status.replay.speed>=3?3:core.status.replay.speed>=2?2:1; - core.status.replay.speed = parseInt(10*core.status.replay.speed + toAdd)/10; - if (core.status.replay.speed>6.0) core.status.replay.speed=6.0; - 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 toAdd = core.status.replay.speed>3?3:core.status.replay.speed>2?2:1; - core.status.replay.speed = parseInt(10*core.status.replay.speed - toAdd)/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.0; - 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 save = core.status.replay.save; - var data = save.pop(); - core.loadData(data.data, function () { - core.status.replay = { - "replaying": true, - "pausing": true, - "animate": false, - "toReplay": data.replay.toReplay, - "totalList": data.replay.totalList, - "speed": data.replay.speed, - "steps": data.replay.steps, - "save": save - } - 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 saveIndex = core.status.saveIndex; - var page=parseInt((saveIndex-1)/5), offset=saveIndex-5*page; - - core.ui.drawSLPanel(10*page+offset); -} - -////// 回放时查看怪物手册 ////// -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) { - //if (core.status.replay.save.length == 30) - // core.status.replay.save.shift(); - 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 action=core.status.replay.toReplay.shift(); - - if (action=='up' || action=='down' || action=='left' || action=='right') { - core.moveHero(action, function () { - setTimeout(function() { - core.replay(); - }); - }); - return; - } - else if (action.indexOf("item:")==0) { - var itemId = action.substring(5); - if (core.canUseItem(itemId)) { - var tools = Object.keys(core.status.hero.items.tools).sort(); - var constants = Object.keys(core.status.hero.items.constants).sort(); - var index; - if ((index=tools.indexOf(itemId))>=0 || (index=constants.indexOf(itemId)+100)>=100) { - core.ui.drawToolbox(index); - setTimeout(function () { - core.ui.closePanel(); - core.useItem(itemId, function () { - core.replay(); - }); - }, 750 / core.status.replay.speed); - } - return; - } - } - else if (action.indexOf("fly:")==0) { - var floorId=action.substring(4); - var toIndex=core.status.hero.flyRange.indexOf(floorId); - var nowIndex=core.status.hero.flyRange.indexOf(core.status.floorId); - if (core.hasItem('fly') && toIndex>=0 && nowIndex>=0) { - core.ui.drawFly(toIndex); - setTimeout(function () { - core.ui.closePanel(); - var stair=toIndex0) { - var shop=core.status.shops[shopId]; - if (core.isset(shop) && shop.visited) { // 商店可用 - var choices = shop.choices; - var topIndex = 6 - parseInt(choices.length / 2); - - core.status.event.selection = parseInt(selections.shift()); - - core.events.openShop(shopId, false); - var shopInterval = setInterval(function () { - if (!core.actions.clickShop(6, topIndex+core.status.event.selection)) { - clearInterval(shopInterval); - core.stopReplay(); - core.drawTip("录像文件出错"); - return; - } - if (selections.length==0) { - clearInterval(shopInterval); - core.actions.clickShop(6, topIndex+choices.length); - core.replay(); - return; - } - core.status.event.selection = parseInt(selections.shift()); - core.events.openShop(shopId, false); - - }, 750 / core.status.replay.speed); - return; - } - } - } - else if (action=='turn') { - core.turnHero(); - core.replay(); - return; - } - else if (action=='getNext') { - if (core.flags.enableGentleClick && core.getBlock(core.nextX(), core.nextY())!=null) { - var nextX = core.nextX(), nextY = core.nextY(); - var block = core.getBlock(nextX, nextY); - if (block!=null && block.block.event.trigger=='getItem') { - core.getItem(block.block.event.id, 1, nextX, nextY); - core.status.route.push("getNext"); - core.replay(); - return; - } - } - } - else if (action.indexOf('move:')==0) { - var pos=action.substring(5).split(":"); - var x=parseInt(pos[0]), y=parseInt(pos[1]); - - var ignoreSteps = core.canMoveDirectly(x, y); - if (ignoreSteps>0) { - core.clearMap('hero', 0, 0, 416, 416); - core.setHeroLoc('x', x); - core.setHeroLoc('y', y); - core.drawHero(); - core.status.route.push("move:"+x+":"+y); - core.status.hero.statistics.moveDirectly++; - core.status.hero.statistics.ignoreSteps+=ignoreSteps; - core.replay(); - return; - } - } - else if (action.indexOf('key:')==0) { - core.actions.keyUp(parseInt(action.substring(4)), true); - core.replay(); - return; - } - - core.stopReplay(); - core.insertAction("录像文件出错"); - -} - -////// 判断当前能否进入某个事件 ////// -control.prototype.checkStatus = function (name, need, item) { - if (need && core.status.event.id == name) { - core.ui.closePanel(); - return false; - } - - if (need && core.status.lockControl) return false; - if (core.isset(item) && item && !core.hasItem(name)) { - core.drawTip("你没有" + core.material.items[name].name); - return false; - } - if (!core.status.heroStop) { - core.drawTip("请先停止勇士行动"); - return false; - } - - core.lockControl(); - core.status.event.id = name; - return true; -} - -////// 点击怪物手册时的打开操作 ////// -control.prototype.openBook = function (need) { - if (core.isset(core.status.replay)&&core.status.replay.replaying) return; - - // 当前是book,且从“浏览地图”打开 - 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') { - need=false; - core.status.event.selection = core.status.event.data; - } - - if (!core.checkStatus('book', need, true)) - return; - core.useItem('book'); -} - -////// 点击楼层传送器时的打开操作 ////// -control.prototype.useFly = function (need) { - if (core.isset(core.status.replay)&&core.status.replay.replaying) return; - if (!core.checkStatus('fly', need, 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 (need) { - if (core.isset(core.status.replay)&&core.status.replay.replaying) return; - if (!core.checkStatus('toolbox', need)) - return; - core.ui.drawToolbox(); -} - -////// 点击快捷商店按钮时的打开操作 ////// -control.prototype.openQuickShop = function (need) { - if (core.isset(core.status.replay)&&core.status.replay.replaying) return; - if (!core.checkStatus('selectShop', need)) - return; - core.ui.drawQuickShop(); -} - -////// 点击保存按钮时的打开操作 ////// -control.prototype.save = function(need) { - if (core.isset(core.status.replay)&&core.status.replay.replaying) return; - if (!core.checkStatus('save', need)) - return; - - var saveIndex = core.status.saveIndex; - var page=parseInt((saveIndex-1)/5), offset=saveIndex-5*page; - - core.ui.drawSLPanel(10*page+offset); -} - -////// 点击读取按钮时的打开操作 ////// -control.prototype.load = function (need) { - if (core.isset(core.status.replay)&&core.status.replay.replaying) return; - - var saveIndex = core.getLocalStorage('saveIndex2', 1); - var page=parseInt((saveIndex-1)/5), offset=saveIndex-5*page; - - // 游戏开始前读档 - if (!core.isPlaying()) { - core.status.event = {'id': 'load', 'data': null}; - core.status.lockControl = true; - core.dom.startPanel.style.display = 'none'; - core.ui.drawSLPanel(10*page+offset); - return; - } - - if (!core.checkStatus('load', need)) - return; - core.ui.drawSLPanel(10*page+offset); -} - -////// 点击设置按钮时的操作 ////// -control.prototype.openSettings = function (need) { - if (core.isset(core.status.replay)&&core.status.replay.replaying) return; - if (!core.checkStatus('settings', need)) - return; - core.ui.drawSettings(); -} - -////// 自动存档 ////// -control.prototype.autosave = function (removeLast) { - if (core.status.event.id!=null) - return; - var x=null; - if (removeLast) - x=core.status.route.pop(); - core.setLocalStorage("autoSave", core.saveData()) - if (removeLast && core.isset(x)) - core.status.route.push(x); -} - -////// 实际进行存读档事件 ////// -control.prototype.doSL = function (id, type) { - if (type=='save') { - if (id=='autoSave') { - core.drawTip('不能覆盖自动存档!'); - return; - } - if (core.setLocalStorage("save"+id, core.saveData())) { - core.ui.closePanel(); - core.drawTip('存档成功!'); - if (id!="autoSave") { - core.status.saveIndex=id; - core.setLocalStorage('saveIndex2', core.status.saveIndex); - } - } - else { - core.drawTip('存储空间不足,请覆盖已有的存档或在菜单栏中进行清理'); - } - return; - } - else if (type=='load') { - var data = core.getLocalStorage(id=='autoSave'?id:"save"+id, null); - if (!core.isset(data)) { - core.drawTip("无效的存档"); - return; - } - if (data.version != core.firstData.version) { - // core.drawTip("存档版本不匹配"); - if (confirm("存档版本不匹配!\n你想回放此存档的录像吗?")) { - core.dom.startPanel.style.display = 'none'; - var seed = data.hero.flags.seed; - core.resetStatus(core.firstData.hero, data.hard, core.firstData.floorId, null, core.initStatus.maps); - core.events.setInitData(data.hard); - core.setFlag('seed', seed); - core.setFlag('rand', seed); - core.changeFloor(core.status.floorId, null, core.firstData.hero.loc, null, function() { - core.startReplay(core.decodeRoute(data.route)); - }, true); - } - return; - } - core.ui.closePanel(); - core.loadData(data, function() { - core.drawTip("读档成功"); - if (id!="autoSave") { - core.status.saveIndex=id; - core.setLocalStorage('saveIndex2', core.status.saveIndex); - } - }); - return; - } - else if (type == 'replayLoad') { - var data = core.getLocalStorage(id=='autoSave'?id:"save"+id, null); - if (!core.isset(data)) { - core.drawTip("无效的存档"); - return; - } - if (data.version != core.firstData.version) { - core.drawTip("存档版本不匹配"); - return; - } - if (data.hard != core.status.hard) { - core.drawTip("游戏难度不匹配!"); - return; - } - var route = core.subarray(core.status.route, core.decodeRoute(data.route)); - if (!core.isset(route) || data.hero.flags.seed!=core.getFlag('seed')) { - core.drawTip("无法从此存档回放录像"); - return; - } - core.loadData(data, function () { - core.startReplay(route); - core.drawTip("回退到存档节点"); - }); - } -} - -////// 同步存档到服务器 ////// -control.prototype.syncSave = function (type) { - var saves=null; - // data - if (type=='all') { - saves=[]; - for (var i=1;i<=5*(main.savePages||30);i++) { - var data = core.getLocalStorage("save"+i, null); - if (core.isset(data)) { - saves.push(data); - } - } - } - else { - for (var i=5*(main.savePages||30);i>=1;i--) { - saves=core.getLocalStorage("save"+i, null); - if (core.isset(saves)) { - break; - } - } - } - if (!core.isset(saves)) { - core.drawText("没有要同步的存档"); - return; - } - core.ui.drawWaiting("正在同步,请稍后..."); - - var formData = new FormData(); - formData.append('type', 'save'); - formData.append('name', core.firstData.name); - var save_text = JSON.stringify(saves); - formData.append('data', save_text); - - core.http("POST", "/games/sync.php", formData, function (data) { - var response = JSON.parse(data); - if (response.code<0) { - core.drawText("出错啦!\n无法同步存档到服务器。\n错误原因:"+response.msg); - } - else { - core.drawText("同步成功!\n\n您的存档编号: "+response.code+"\n您的存档密码: "+response.msg+"\n\n请牢记以上两个信息(如截图等),在从服务器\n同步存档时使用。") - } - }, function (e) { - core.drawText("出错啦!\n无法同步存档到服务器。\n错误原因:"+e); - }) -} - -////// 从服务器加载存档 ////// -control.prototype.syncLoad = function () { - var id = prompt("请输入存档编号:"); - if (id==null || id=="") { - core.ui.drawSyncSave(); return; - } - var password = prompt("请输入存档密码:"); - if (password==null || password=="") { - core.ui.drawSyncSave(); return; - } - core.ui.drawWaiting("正在同步,请稍后..."); - - var formData = new FormData(); - formData.append('type', 'load'); - formData.append('name', core.firstData.name); - formData.append('id', id); - formData.append('password', password); - - core.http("POST", "/games/sync.php", formData, function (data) { - var response = JSON.parse(data); - switch (response.code) { - case 0: - // 成功 - var data=JSON.parse(response.msg); - // console.log(data); - - if (data instanceof Array) { - core.status.event.selection=1; - core.ui.drawConfirmBox("所有本地存档都将被覆盖,确认?", function () { - for (var i=1;i<=5*(main.savePages||30);i++) { - if (i<=data.length) { - core.setLocalStorage("save"+i, data[i-1]); - } - else { - core.removeLocalStorage("save"+i); - } - } - core.drawText("同步成功!\n你的本地所有存档均已被覆盖。"); - }, function () { - core.status.event.selection=0; - core.ui.drawSyncSave(); - }) - } - else { - // 只覆盖单存档 - var index=5*(main.savePages||30); - for (var i=5*(main.savePages||30);i>=1;i--) { - if (core.getLocalStorage("save"+i, null)==null) - index=i; - else break; - } - core.setLocalStorage("save"+index, data); - core.drawText("同步成功!\n单存档已覆盖至存档"+index); - } - break; - case -1: - core.drawText("出错啦!\n存档编号"+id+"不存在!"); - break; - case -2: - core.drawText("出错啦!\n存档密码错误!"); - break; - default: - core.drawText("出错啦!\n无法从服务器同步存档。\n错误原因:"+response.msg); - break; - } - }, function (e) { - core.drawText("出错啦!\n无法从服务器同步存档。\n错误原因:"+e); - }); -} - -////// 存档到本地 ////// -control.prototype.saveData = function() { - var data = { - '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() - }; - // set shop times - for (var shop in core.status.shops) { - data.shops[shop]={ - 'times': core.status.shops[shop].times || 0, - 'visited': core.status.shops[shop].visited || false - } - } - core.events.beforeSaveData(data); - - return data; -} - -////// 从本地读档 ////// -control.prototype.loadData = function (data, callback) { - - core.resetStatus(data.hero, data.hard, data.floorId, core.decodeRoute(data.route), core.maps.load(data.maps)); - - // load shop times - for (var shop in core.status.shops) { - if (core.isset(data.shops[shop])) { - core.status.shops[shop].times = data.shops[shop].times; - core.status.shops[shop].visited = data.shops[shop].visited; - } - } - - // load icons - var icon = core.getFlag("heroIcon", "hero.png"); - if (core.isset(core.material.images.images[icon])) { - core.material.images.hero.src = core.material.images.images[icon].src; - core.material.icons.hero.height = core.material.images.images[icon].height/4; - } - - core.events.afterLoadData(data); - - core.changeFloor(data.floorId, null, data.hero.loc, 0, function() { - if (core.isset(callback)) callback(); - }, true); -} - -////// 设置勇士属性 ////// -control.prototype.setStatus = function (statusName, statusVal) { - if (core.isset(core.status.hero.loc[statusName])) - core.status.hero.loc[statusName] = statusVal; - else - core.status.hero[statusName] = statusVal; -} - -////// 获得勇士属性 ////// -control.prototype.getStatus = function (statusName) { - // support status:x - if (core.isset(core.status.hero.loc[statusName])) - return core.status.hero.loc[statusName]; - return core.status.hero[statusName]; -} - -////// 获得某个等级的名称 ////// -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; -} - -////// 设置某个自定义变量或flag ////// -control.prototype.setFlag = function(flag, value) { - if (!core.isset(core.status.hero)) return; - core.status.hero.flags[flag]=value; -} - -////// 获得某个自定义变量或flag ////// -control.prototype.getFlag = function(flag, defaultValue) { - if (!core.isset(core.status.hero)) return defaultValue; - var value = core.status.hero.flags[flag]; - if (core.isset(value)) return value; - return defaultValue; -} - -////// 是否存在某个自定义变量或flag,且值为true ////// -control.prototype.hasFlag = function(flag) { - if (core.getFlag(flag)) return true; - return false; -} - -////// 锁定状态栏,常常用于事件处理 ////// -control.prototype.lockControl = function () { - core.status.lockControl = true; -} - -////// 解锁状态栏 ////// -control.prototype.unLockControl = function () { - core.status.lockControl = false; -} - -////// 播放背景音乐 ////// -control.prototype.playBgm = function (bgm) { - if (main.mode!='play')return; - // 如果不允许播放 - if (!core.musicStatus.bgmStatus) return; - // 音频不存在 - if (!core.isset(core.material.bgms[bgm])) return; - - // 延迟播放 - if (core.material.bgms[bgm] == 'loading') { - core.material.bgms[bgm] = 'starting'; - return; - } - - try { - // 如果当前正在播放,且和本BGM相同,直接忽略 - if (core.musicStatus.playingBgm == bgm && core.musicStatus.isPlaying) { - return; - } - // 如果正在播放中,暂停 - if (core.isset(core.musicStatus.playingBgm) && core.musicStatus.isPlaying) { - core.material.bgms[core.musicStatus.playingBgm].pause(); - } - // 播放当前BGM - core.material.bgms[bgm].volume = core.musicStatus.volume; - core.material.bgms[bgm].play(); - core.musicStatus.playingBgm = bgm; - core.musicStatus.isPlaying = true; - } - catch (e) { - console.log("无法播放BGM "+bgm); - console.log(e); - 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 (e) { - console.log("无法暂停BGM "+bgm); - console.log(e); - } -} - -////// 恢复背景音乐的播放 ////// -control.prototype.resumeBgm = function () { - if (main.mode!='play')return; - // 如果不允许播放 - if (!core.musicStatus.bgmStatus) return; - - // 恢复BGM - 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 (e) { - console.log("无法恢复BGM "+bgm); - console.log(e); - } -} - -////// 播放音频 ////// -control.prototype.playSound = function (sound) { - if (main.mode!='play')return; - // 如果不允许播放 - if (!core.musicStatus.soundStatus) return; - // 音频不存在 - if (!core.isset(core.material.sounds[sound])) return; - - try { - if (core.musicStatus.audioContext != null) { - var source = core.musicStatus.audioContext.createBufferSource(); - source.buffer = core.material.sounds[sound]; - source.connect(core.musicStatus.gainNode); - try { - source.start(0); - } - catch (e) { - try { - source.noteOn(0); - } - catch (ee) { - } - } - } - else { - core.material.sounds[sound].volume = core.musicStatus.volume; - core.material.sounds[sound].play(); - } - } - catch (eee) { - console.log("无法播放SE "+sound); - console.log(eee); - } -} - -////// 清空状态栏 ////// -control.prototype.clearStatusBar = function() { - var statusList = ['floor', 'lv', 'hp', 'atk', 'def', 'mdef', 'money', 'experience', 'up', 'yellowKey', 'blueKey', 'redKey', 'poison', 'weak', 'curse', 'hard']; - statusList.forEach(function (e) { - core.statusBar[e].innerHTML = " "; - }); - core.statusBar.image.book.style.opacity = 0.3; - core.statusBar.image.fly.style.opacity = 0.3; -} - -////// 更新状态栏 ////// -control.prototype.updateStatusBar = function () { - - // 检查等级 - core.events.checkLvUp(); - - // 检查HP上限 - if (core.flags.enableHPMax) { - core.setStatus('hp', Math.min(core.getStatus('hpmax'), core.getStatus('hp'))); - } - - // 更新领域、阻击、显伤 - core.updateCheckBlock(); - - var lvName = core.getLvName(); - core.statusBar.lv.innerHTML = lvName; - if (/^[+-]?\d+$/.test(lvName)) - core.statusBar.lv.style.fontStyle = 'italic'; - else core.statusBar.lv.style.fontStyle = 'normal'; - - var statusList = ['hpmax', 'hp', 'atk', 'def', 'mdef', 'money', 'experience']; - statusList.forEach(function (item) { - if (core.isset(core.status.hero[item])) - core.status.hero[item] = Math.floor(core.status.hero[item]); - core.statusBar[item].innerHTML = core.formatBigNumber(core.getStatus(item)); - }); - - // 进阶 - if (core.flags.enableLevelUp && core.status.hero.lv clientHeight && clientHeight < ADAPT_WIDTH){ - isHorizontal = true; - width = clientHeight; - } - // 各元素大小的变量声明 - var gameGroupWidth, gameGroupHeight, borderRight, - canvasWidth, canvasTop, // canvasLeft, - statusBarWidth, statusBarHeight, statusBarBorder, - statusWidth, statusHeight, statusMaxWidth,statusLabelsLH, - toolBarWidth, toolBarHeight, toolBarTop, toolBarBorder, - toolsWidth, toolsHeight,toolsMargin,toolsPMaxwidth, - fontSize, toolbarFontSize, margin, statusBackground, toolsBackground; - - var count = core.dom.statusBar.children.length; - if (!core.flags.enableFloor) count--; - if (!core.flags.enableLv) count--; - if (!core.flags.enableHPMax) count--; - if (!core.flags.enableMDef) count--; - if (!core.flags.enableMoney) count--; - if (!core.flags.enableExperience) count--; - if (!core.flags.enableLevelUp) count--; - if (!core.flags.enableDebuff) count--; - if (core.isset(core.flags.enableKeys) && !core.flags.enableKeys) count--; - - var statusLineHeight = BASE_LINEHEIGHT * 9 / count; - var statusLineFontSize = DEFAULT_FONT_SIZE; - if (count>9) statusLineFontSize = statusLineFontSize * 9 / count; - - var shopDisplay; - - statusBarBorder = '3px #fff solid'; - toolBarBorder = '3px #fff solid'; - var zoom = (ADAPT_WIDTH - width) / 4.22; - var aScale = 1 - zoom / 100; - - // 移动端 - if (width < CHANGE_WIDTH) { - if(width < ADAPT_WIDTH){ - - core.domStyle.scale = aScale; - canvasWidth = width; - }else{ - canvasWidth = DEFAULT_CANVAS_WIDTH; - core.domStyle.scale = 1; - } - - var scale = core.domStyle.scale - var tempWidth = DEFAULT_CANVAS_WIDTH * scale; - if(!isHorizontal){ //竖屏 - core.domStyle.screenMode = 'vertical'; - //显示快捷商店图标 - shopDisplay = 'block'; - //判断应该显示几行 - // var col = core.flags.enableMDef || core.flags.enableExperience || core.flags.enableDebuff ? 3 : 2; - var col = parseInt((count-1)/3)+1; - - var tempTopBarH = scale * (BASE_LINEHEIGHT * col + SPACE * 2) + 6; - var tempBotBarH = scale * (BASE_LINEHEIGHT + SPACE * 4) + 6; - - gameGroupHeight = tempWidth + tempTopBarH + tempBotBarH; - - gameGroupWidth = tempWidth - canvasTop = tempTopBarH; - // canvasLeft = 0; - toolBarWidth = statusBarWidth = canvasWidth; - statusBarHeight = tempTopBarH; - statusBarBorder = '3px #fff solid'; - - statusHeight = scale*BASE_LINEHEIGHT * .8; - statusLabelsLH = .8 * BASE_LINEHEIGHT *scale; - statusMaxWidth = scale * DEFAULT_BAR_WIDTH * .95; - statusBackground = main.statusTopBackground; - toolBarHeight = tempBotBarH; - - toolBarTop = statusBarHeight + canvasWidth; - toolBarBorder = '3px #fff solid'; - toolsHeight = scale * BASE_LINEHEIGHT; - toolsPMaxwidth = scale * DEFAULT_BAR_WIDTH * .4; - toolsBackground = main.toolsBackground; - borderRight = '3px #fff solid'; - - margin = scale * SPACE * 2; - toolsMargin = scale * SPACE * 4; - fontSize = DEFAULT_FONT_SIZE * scale; - toolbarFontSize = DEFAULT_FONT_SIZE * scale; - }else { //横屏 - core.domStyle.screenMode = 'horizontal'; - shopDisplay = 'none'; - gameGroupWidth = tempWidth + DEFAULT_BAR_WIDTH * scale; - gameGroupHeight = tempWidth; - canvasTop = 0; - // canvasLeft = DEFAULT_BAR_WIDTH * scale; - toolBarWidth = statusBarWidth = DEFAULT_BAR_WIDTH * scale; - statusBarHeight = gameGroupHeight - SPACE; - statusBarBorder = '3px #fff solid'; - statusBackground = main.statusLeftBackground; - - statusHeight = scale*statusLineHeight * .8; - statusLabelsLH = .8 * statusLineHeight *scale; - toolBarTop = scale*statusLineHeight * count + SPACE * 2; - toolBarHeight = canvasWidth - toolBarTop; - toolBarBorder = '3px #fff solid'; - toolsHeight = scale * BASE_LINEHEIGHT; - toolsBackground = 'transparent'; - fontSize = statusLineFontSize * scale; - toolbarFontSize = DEFAULT_FONT_SIZE * scale; - borderRight = ''; - statusMaxWidth = scale * DEFAULT_BAR_WIDTH; - toolsPMaxwidth = scale * DEFAULT_BAR_WIDTH; - - margin = scale * SPACE * 2; - toolsMargin = 2 * SPACE * scale; - } - - }else { //大屏设备 pc端 - core.domStyle.scale = 1; - core.domStyle.screenMode = 'bigScreen'; - shopDisplay = 'none'; - - gameGroupWidth = DEFAULT_CANVAS_WIDTH + DEFAULT_BAR_WIDTH; - gameGroupHeight = DEFAULT_CANVAS_WIDTH; - canvasWidth = DEFAULT_CANVAS_WIDTH; - canvasTop = 0; - // canvasLeft = DEFAULT_BAR_WIDTH; - - toolBarWidth = statusBarWidth = DEFAULT_BAR_WIDTH; - // statusBarHeight = statusLineHeight * count + SPACE * 2; //一共有9行 - statusBackground = main.statusLeftBackground; - statusBarHeight = gameGroupHeight - SPACE; - - statusHeight = statusLineHeight * .8; - statusLabelsLH = .8 * statusLineHeight; - toolBarTop = statusLineHeight * count + SPACE * 2; - toolBarHeight = DEFAULT_CANVAS_WIDTH - toolBarTop; - toolsBackground = 'transparent'; - - toolsHeight = BASE_LINEHEIGHT; - borderRight = ''; - fontSize = statusLineFontSize; - toolbarFontSize = DEFAULT_FONT_SIZE; - statusMaxWidth = DEFAULT_BAR_WIDTH; - toolsPMaxwidth = DEFAULT_BAR_WIDTH * .9; - margin = SPACE * 2; - toolsMargin = 2 * SPACE; - } - - var unit = 'px' - core.domStyle.styles = [ - { - id: 'gameGroup', - rules:{ - width: gameGroupWidth + unit, - height: gameGroupHeight + unit, - top: (clientHeight-gameGroupHeight)/2 + unit, - left: (clientWidth-gameGroupWidth)/2 + unit, - } - }, - { - className: 'gameCanvas', - rules:{ - width: canvasWidth + unit, - height: canvasWidth + unit, - top: canvasTop + unit, - right: 0, - border: '3px #fff solid', - } - }, - { - id: 'gif', - rules: { - width: (canvasWidth - SPACE*2) + unit, - height:(canvasWidth - SPACE*2) + unit, - top: (canvasTop + SPACE) + unit, - right: SPACE + unit, - } - }, - { - id: 'gif2', - rules: { - width: (canvasWidth - SPACE*2) + unit, - height:(canvasWidth - SPACE*2) + unit, - top: (canvasTop + SPACE) + unit, - right: SPACE + unit, - } - }, - { - id: 'curtain', - rules: { - width: (canvasWidth - SPACE*2) + unit, - height:(canvasWidth - SPACE*2) + unit, - top: (canvasTop + SPACE) + unit, - right: SPACE + unit, - } - }, - { - id: 'floorMsgGroup', - rules:{ - width: (canvasWidth - SPACE*2) + unit, - height: (gameGroupHeight - SPACE*2) + unit, - top: SPACE + unit, - right: SPACE + unit, - } - }, - { - id: 'statusBar', - rules:{ - width: statusBarWidth + unit, - height: statusBarHeight + unit, - top: 0, - left: 0, - padding: SPACE + unit, - - borderTop: statusBarBorder, - borderLeft: statusBarBorder, - borderRight: borderRight, - fontSize: fontSize + unit, - background: statusBackground, - } - }, - { - className: 'status', - rules:{ - width: '100%', - maxWidth: statusMaxWidth + unit, - height: statusHeight + unit, - margin: margin/2 + unit - } - }, - { - className: 'statusLabels', - rules:{ - marginLeft: margin + unit, - lineHeight: statusLabelsLH + unit, - } - }, - { - id: 'toolBar', - rules:{ - width: toolBarWidth + unit, - height: toolBarHeight + unit, - top: toolBarTop +unit, - left: 0, - padding: SPACE + unit, - borderBottom: toolBarBorder, - borderLeft: toolBarBorder, - borderRight: borderRight, - fontSize: toolbarFontSize + unit, - background: toolsBackground, - } - }, - { - className: 'tools', - rules:{ - height: toolsHeight + unit, - maxWidth: toolsPMaxwidth + unit, - marginLeft: toolsMargin + unit, - marginTop: margin + unit, - } - }, - { - imgId: 'shop', - rules:{ - display: shopDisplay - } - }, - { - 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: toolsHeight + unit - } - } - ] - core.domRenderer(); -} - -////// 渲染DOM ////// -control.prototype.domRenderer = function(){ - - core.dom.statusBar.style.display = 'block'; - core.dom.toolBar.style.display = 'block'; - - var styles = core.domStyle.styles; - - for(var i=0; icore.animateFrame.speed && core.isset(core.status.globalAnimateObjs)) { + + for (var a = 0; a < core.status.globalAnimateObjs.length; a++) { + var obj = core.status.globalAnimateObjs[a]; + obj.status = (obj.status+1)%(obj.event.animate||1); + core.drawBlock(obj, obj.status); + } + + core.animateFrame.globalTime = timestamp; + } + } + + // Box + if (timestamp-core.animateFrame.boxTime>core.animateFrame.speed && core.isset(core.status.boxAnimateObjs) && core.status.boxAnimateObjs.length>0) { + core.drawBoxAnimate(); + core.animateFrame.boxTime = timestamp; + } + + // Hero move + if (timestamp-core.animateFrame.moveTime>16 && core.isset(core.status.heroMoving) && core.status.heroMoving>0) { + var x=core.getHeroLoc('x'), y=core.getHeroLoc('y'), direction = core.getHeroLoc('direction'); + if (core.status.heroMoving<=4) { + core.drawHero(direction, x, y, 'leftFoot', 4*core.status.heroMoving*scan[direction].x, 4*core.status.heroMoving*scan[direction].y); + } + else if (core.status.heroMoving<=8) { + core.drawHero(direction, x, y, 'rightFoot', 4*core.status.heroMoving*scan[direction].x, 4*core.status.heroMoving*scan[direction].y); + } + core.animateFrame.moveTime = timestamp; + } + + // weather + if (core.isPlaying() && timestamp-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 (p) { + core.canvas.weather.beginPath(); + core.canvas.weather.moveTo(p.x, p.y); + core.canvas.weather.lineTo(p.x + p.l * p.xs, p.y + p.l * p.ys); + core.canvas.weather.stroke(); + + p.x += p.xs; + p.y += p.ys; + if (p.x > 416 || p.y > 416) { + p.x = Math.random() * 416; + p.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 angle = core.animateFrame.weather.data; + core.animateFrame.weather.nodes.forEach(function (p) { + core.canvas.weather.moveTo(p.x, p.y); + core.canvas.weather.arc(p.x, p.y, p.r, 0, Math.PI * 2, true); + + // update + p.x += Math.sin(angle) * 2; + p.y += Math.cos(angle + p.d) + 1 + p.r / 2; + + if (p.x > 416 + 5 || p.x < -5 || p.y > 416) { + if (Math.random() > 1 / 3) { + p.x = Math.random() * 416; + p.y = -10; + } + else { + if (Math.sin(angle) > 0) { + p.x = -5; + p.y = Math.random() * 416; + } + else { + p.x = 416 + 5; + p.y = Math.random() * 416; + } + } + } + + }) + + core.canvas.weather.fill(); + + } + core.animateFrame.weather.time = timestamp; + + } + window.requestAnimationFrame(draw); + } + window.requestAnimationFrame(draw); +} + +////// 显示游戏开始界面 ////// +control.prototype.showStartAnimate = function (callback) { + 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 opacityVal = 1; + var startAnimate = window.setInterval(function () { + opacityVal -= 0.03; + if (opacityVal < 0) { + clearInterval(startAnimate); + core.dom.startTop.style.display = 'none'; + // core.playGame(); + core.dom.startButtonGroup.style.display = 'block'; + if (core.isset(callback)) callback(); + } + core.dom.startTop.style.opacity = opacityVal; + }, 20); +} + +////// 隐藏游戏开始界面 ////// +control.prototype.hideStartAnimate = function (callback) { + var opacityVal = 1; + var startAnimate = window.setInterval(function () { + opacityVal -= 0.03; + if (opacityVal < 0) { + clearInterval(startAnimate); + core.dom.startPanel.style.display = 'none'; + if (core.isset(callback)) callback(); + } + core.dom.startPanel.style.opacity = opacityVal; + }, 20); +} + +////// 游戏是否已经开始 ////// +control.prototype.isPlaying = function() { + return core.isset(core.status.played) && core.status.played; +} + +////// 清除游戏状态和数据 ////// +control.prototype.clearStatus = function() { + // 停止各个Timeout和Interval + for (var i in core.timeout) { + clearTimeout(core.timeout[i]); + core.timeout[i] = null; + } + for (var i in core.interval) { + clearInterval(core.interval[i]); + core.interval[i] = null; + } + core.status = {}; + core.clearStatusBar(); + core.resize(main.dom.body.clientWidth, main.dom.body.clientHeight); +} + +////// 重置游戏状态和初始数据 ////// +control.prototype.resetStatus = function(hero, hard, floorId, route, maps) { + + var totalTime=0; + if (core.isset(core.status) && core.isset(core.status.hero) + && core.isset(core.status.hero.statistics) && core.isset(route)) { + totalTime=core.status.hero.statistics.totalTime; + } + + this.clearStatus(); + + // 初始化status + core.status = core.clone(core.initStatus); + core.status.played = true; + // 初始化maps + core.status.floorId = floorId; + core.status.maps = core.clone(maps); + // 初始化怪物 + core.material.enemys = core.clone(core.enemys.getEnemys()); + // 初始化人物属性 + core.status.hero = core.clone(hero); + // 统计数据 + if (!core.isset(core.status.hero.statistics)) + core.status.hero.statistics = { + 'totalTime': totalTime, + '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, totalTime); + core.status.hero.statistics.start = null; + + core.status.hard = hard; + // 初始化路线 + if (core.isset(route)) + core.status.route = route; + // 保存的Index + core.status.saveIndex = core.getLocalStorage('saveIndex2', 1); + +} + +////// 开始游戏 ////// +control.prototype.startGame = function (hard, callback) { + console.log('开始游戏'); + + this.resetStatus(core.firstData.hero, hard, core.firstData.floorId, null, core.initStatus.maps); + + core.changeFloor(core.status.floorId, null, core.firstData.hero.loc, null, function() { + if (core.isset(callback)) callback(); + }, true); + + setTimeout(function () { + // Upload + var formData = new FormData(); + formData.append('type', 'people'); + formData.append('name', core.firstData.name); + formData.append('version', core.firstData.version); + formData.append('platform', core.platform.isPC?"PC":core.platform.isAndroid?"Android":core.platform.isIOS?"iOS":""); + formData.append('hard', hard); + formData.append('hardCode', core.getFlag('hard', 0)); + + core.utils.http("POST", "/games/upload.php", formData); + }) + +} + +////// 重新开始游戏;此函数将回到标题页面 ////// +control.prototype.restart = function() { + this.showStartAnimate(); + if (core.bgms.length>0) + core.playBgm(core.bgms[0]); +} + + +/////////////////////// 寻路算法 & 人物行走控制 /////////////////////// + +////// 清除自动寻路路线 ////// +control.prototype.clearAutomaticRouteNode = function (x, y) { + if (core.status.event.id==null) + core.canvas.ui.clearRect(x * 32 + 5, y * 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 () { + // 此函数只应由events.afterOpenDoor和events.afterBattle调用 + var moveStep = core.status.automaticRoute.moveStepBeforeStop; + //core.status.automaticRoute.moveStepBeforeStop = []; + if(moveStep.length===0 || (moveStep.length===1 && moveStep[0].step===1)) { + core.status.automaticRoute.moveStepBeforeStop = []; + } + else { + core.setAutoHeroMove(moveStep); + } +} + +////// 清空剩下的自动寻路列表 ////// +control.prototype.clearContinueAutomaticRoute = function () { + core.canvas.ui.clearRect(0, 0, 416, 416); + core.status.automaticRoute.moveStepBeforeStop=[]; +} + +////// 设置自动寻路路线 ////// +control.prototype.setAutomaticRoute = function (destX, destY, stepPostfix) { + if (!core.status.played || core.status.lockControl) { + return; + } + // 正在寻路中 + if (core.status.automaticRoute.autoHeroMove) { + var lastX = core.status.automaticRoute.destX, lastY=core.status.automaticRoute.destY; + core.stopAutomaticRoute(); + if (lastX==destX && lastY==destY) { + core.status.automaticRoute.moveDirectly = true; + setTimeout(function () { + if (core.status.automaticRoute.moveDirectly && core.status.heroMoving==0) { + var ignoreSteps = core.canMoveDirectly(destX, destY); + if (ignoreSteps>0) { + core.clearMap('hero', 0, 0, 416, 416); + core.setHeroLoc('x', destX); + core.setHeroLoc('y', destY); + core.drawHero(); + core.status.route.push("move:"+destX+":"+destY); + core.status.hero.statistics.moveDirectly++; + core.status.hero.statistics.ignoreSteps+=ignoreSteps; + } + } + core.status.automaticRoute.moveDirectly = false; + }, 100); + } + return; + } + if (destX == core.status.hero.loc.x && destY == core.status.hero.loc.y && stepPostfix.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 step = 0; + var tempStep = null; + var moveStep; + if (!(moveStep = core.automaticRoute(destX, destY))) { + if (destX == core.status.hero.loc.x && destY == core.status.hero.loc.y){ + moveStep=[]; + } else { + core.canvas.ui.clearRect(0, 0, 416, 416); + return; + } + } + moveStep=moveStep.concat(stepPostfix); + core.status.automaticRoute.destX=destX; + core.status.automaticRoute.destY=destY; + 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 m = 0; m < moveStep.length; m++) { + if (tempStep == null) { + step++; + tempStep = moveStep[m].direction; + } + else if (tempStep == moveStep[m].direction) { + step++; + } + else { + //core.status.automaticRoutingTemp.moveStep.push({'direction': tempStep, 'step': step}); + core.status.automaticRoute.autoStepRoutes.push({'direction': tempStep, 'step': step}); + step = 1; + tempStep = moveStep[m].direction; + } + if (m == moveStep.length - 1) { + // core.status.automaticRoutingTemp.moveStep.push({'direction': tempStep, 'step': step}); + core.status.automaticRoute.autoStepRoutes.push({'direction': tempStep, 'step': step}); + core.canvas.ui.fillRect(moveStep[m].x * 32 + 10, moveStep[m].y * 32 + 10, 12, 12); + } + else { + core.canvas.ui.beginPath(); + if (core.isset(moveStep[m + 1]) && tempStep != moveStep[m + 1].direction) { + if (tempStep == 'up' && moveStep[m + 1].direction == 'left' || tempStep == 'right' && moveStep[m + 1].direction == 'down') { + core.canvas.ui.moveTo(moveStep[m].x * 32 + 5, moveStep[m].y * 32 + 16); + core.canvas.ui.lineTo(moveStep[m].x * 32 + 16, moveStep[m].y * 32 + 16); + core.canvas.ui.lineTo(moveStep[m].x * 32 + 16, moveStep[m].y * 32 + 27); + } + else if (tempStep == 'up' && moveStep[m + 1].direction == 'right' || tempStep == 'left' && moveStep[m + 1].direction == 'down') { + core.canvas.ui.moveTo(moveStep[m].x * 32 + 27, moveStep[m].y * 32 + 16); + core.canvas.ui.lineTo(moveStep[m].x * 32 + 16, moveStep[m].y * 32 + 16); + core.canvas.ui.lineTo(moveStep[m].x * 32 + 16, moveStep[m].y * 32 + 27); + } + else if (tempStep == 'left' && moveStep[m + 1].direction == 'up' || tempStep == 'down' && moveStep[m + 1].direction == 'right') { + core.canvas.ui.moveTo(moveStep[m].x * 32 + 27, moveStep[m].y * 32 + 16); + core.canvas.ui.lineTo(moveStep[m].x * 32 + 16, moveStep[m].y * 32 + 16); + core.canvas.ui.lineTo(moveStep[m].x * 32 + 16, moveStep[m].y * 32 + 5); + } + else if (tempStep == 'right' && moveStep[m + 1].direction == 'up' || tempStep == 'down' && moveStep[m + 1].direction == 'left') { + core.canvas.ui.moveTo(moveStep[m].x * 32 + 5, moveStep[m].y * 32 + 16); + core.canvas.ui.lineTo(moveStep[m].x * 32 + 16, moveStep[m].y * 32 + 16); + core.canvas.ui.lineTo(moveStep[m].x * 32 + 16, moveStep[m].y * 32 + 5); + } + core.canvas.ui.stroke(); + continue; + } + switch (tempStep) { + case 'up': + case 'down': + core.canvas.ui.beginPath(); + core.canvas.ui.moveTo(moveStep[m].x * 32 + 16, moveStep[m].y * 32 + 5); + core.canvas.ui.lineTo(moveStep[m].x * 32 + 16, moveStep[m].y * 32 + 27); + core.canvas.ui.stroke(); + break; + case 'left': + case 'right': + core.canvas.ui.beginPath(); + core.canvas.ui.moveTo(moveStep[m].x * 32 + 5, moveStep[m].y * 32 + 16); + core.canvas.ui.lineTo(moveStep[m].x * 32 + 27, moveStep[m].y * 32 + 16); + core.canvas.ui.stroke(); + break; + } + } + } + core.canvas.ui.restore(); + + // 立刻移动 + core.setAutoHeroMove(); + +} + +////// 自动寻路算法,找寻最优路径 ////// +control.prototype.automaticRoute = function (destX, destY) { + var startX = core.getHeroLoc('x'); + var startY = core.getHeroLoc('y'); + var scan = { + 'up': {'x': 0, 'y': -1}, + 'left': {'x': -1, 'y': 0}, + 'down': {'x': 0, 'y': 1}, + 'right': {'x': 1, 'y': 0} + }; + var queue = []; + var nowDeep = 0; + var route = []; + var ans = [] + + if (destX == startX && destY == startY) return false; + queue.push(13 * startX + startY); + queue.push(-1); + route[13 * startX + startY] = ''; + + while (queue.length != 1) { + var f = queue.shift(); + if (f===-1) {nowDeep+=1;queue.push(-1);continue;} + var deep = ~~(f/169); + if (deep!==nowDeep) {queue.push(f);continue;} + f=f%169; + var nowX = parseInt(f / 13), nowY = f % 13; + var nowIsArrow = false, nowId, nowBlock = core.getBlock(nowX,nowY); + for (var direction in scan) { + if (!core.canMoveHero(nowX, nowY, direction)) + continue; + + var nx = nowX + scan[direction].x; + var ny = nowY + scan[direction].y; + + if (nx<0 || nx>12 || ny<0 || ny>12) continue; + + var nid = 13 * nx + ny; + + if (core.isset(route[nid])) continue; + + var deepAdd=1; + + var nextId, nextBlock = core.getBlock(nx,ny); + if (nextBlock!=null){ + nextId = nextBlock.block.event.id; + // 绕过亮灯(因为只有一次通行机会很宝贵) + if(nextId == "light") deepAdd=100; + // 绕过路障 + if (nextId.substring(nextId.length-3)=="Net") deepAdd=core.values.lavaDamage; + // 绕过血瓶 + if (!core.flags.potionWhileRouting && nextId.substring(nextId.length-6)=="Potion") deepAdd=20; + // 绕过传送点 + if (nextBlock.block.event.trigger == 'changeFloor') deepAdd = 10; + } + if (core.status.checkBlock.damage[nid]>0) + deepAdd = core.status.checkBlock.damage[nid]; + + if (nx == destX && ny == destY) { + route[nid] = direction; + break; + } + if (core.noPassExists(nx, ny)) + continue; + + route[nid] = direction; + queue.push(169*(nowDeep+deepAdd)+nid); + } + if (core.isset(route[13 * destX + destY])) break; + } + + if (!core.isset(route[13 * destX + destY])) { + return false; + } + + var nowX = destX, nowY = destY; + while (nowX != startX || nowY != startY) { + var dir = route[13 * nowX + nowY]; + ans.push({'direction': dir, 'x': nowX, 'y': nowY}); + nowX -= scan[dir].x; + nowY -= scan[dir].y; + } + + ans.reverse(); + return ans; +} + +////// 显示离散的寻路点 ////// +control.prototype.fillPosWithPoint = function (pos) { + core.fillRect('ui', pos.x*32+12,pos.y*32+12,8,8, '#bfbfbf'); +} + +////// 设置勇士的自动行走路线 ////// +control.prototype.setAutoHeroMove = function (steps) { + steps=steps||core.status.automaticRoute.autoStepRoutes; + if (steps.length == 0) { + return; + } + core.status.automaticRoute.autoStepRoutes=steps; + core.status.automaticRoute.autoHeroMove = true; + core.status.automaticRoute.autoStep = 1; + core.status.automaticRoute.destStep = steps[0].step; + core.moveHero(steps[0].direction); +} + +////// 设置行走的效果动画 ////// +control.prototype.setHeroMoveInterval = function (direction, x, y, callback) { + if (core.status.heroMoving>0) { + return; + } + core.status.heroMoving=1; + var scan = { + 'up': {'x': 0, 'y': -1}, + 'left': {'x': -1, 'y': 0}, + 'down': {'x': 0, 'y': 1}, + 'right': {'x': 1, 'y': 0} + }; + + var toAdd = 1; + if (core.status.replay.speed>3) + toAdd = 2; + + core.interval.heroMoveInterval = window.setInterval(function () { + core.status.heroMoving+=toAdd; + if (core.status.heroMoving>=8) { + core.setHeroLoc('x', x+scan[direction].x); + core.setHeroLoc('y', y+scan[direction].y); + core.moveOneStep(); + core.clearMap('hero', 0, 0, 416, 416); + core.drawHero(direction); + clearInterval(core.interval.heroMoveInterval); + core.status.heroMoving = 0; + if (core.isset(callback)) callback(); + } + }, 12.5 * toAdd / core.status.replay.speed); +} + +////// 实际每一步的行走过程 ////// +control.prototype.moveAction = function (callback) { + if (core.interval.openDoorAnimate!=null) return; // 开门判断 + if (core.status.heroMoving>0) return; + var scan = { + 'up': {'x': 0, 'y': -1}, + 'left': {'x': -1, 'y': 0}, + 'down': {'x': 0, 'y': 1}, + 'right': {'x': 1, 'y': 0} + }; + var direction = core.getHeroLoc('direction'); + var x = core.getHeroLoc('x'); + var y = core.getHeroLoc('y'); + var noPass = core.noPass(x + scan[direction].x, y + scan[direction].y), canMove = core.canMoveHero(); + if (noPass || !canMove) { + if (core.status.event.id!='ski') + core.status.route.push(direction); + core.status.automaticRoute.moveStepBeforeStop = []; + core.status.automaticRoute.lastDirection = core.getHeroLoc('direction'); + if (canMove) // 非箭头:触发 + core.trigger(x + scan[direction].x, y + scan[direction].y); + core.drawHero(direction, x, y); + + if (core.status.automaticRoute.moveStepBeforeStop.length==0) { + core.clearContinueAutomaticRoute(); + core.stopAutomaticRoute(); + } + if (core.isset(callback)) + callback(); + } + else { + core.setHeroMoveInterval(direction, x, y, 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(direction); + core.trigger(core.getHeroLoc('x'), core.getHeroLoc('y')); + core.checkBlock(); + if (core.isset(callback)) callback(); + }); + } +} + +////// 转向 ////// +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 (direction, callback) { + // 如果正在移动,直接return + if (core.status.heroMoving!=0) return; + if (core.isset(direction)) + core.setHeroLoc('direction', direction); + if (!core.isset(callback)) { // 如果不存在回调函数,则使用heroMoveTrigger + core.status.heroStop = false; + core.status.automaticRoute.moveDirectly = false; + + var doAction = 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; + doAction(); + }); + } + else { + core.moveAction(); + setTimeout(doAction, 50); + } + } + else { + core.stopHero(); + } + } + doAction(); + } + else { // 否则,只向某个方向移动一步,然后调用callback + core.moveAction(function () { + callback(); + }) + } +} + +/////// 使用事件让勇士移动。这个函数将不会触发任何事件 ////// +control.prototype.eventMoveHero = function(steps, time, callback) { + + time = time || 100; + + core.clearMap('ui', 0, 0, 416, 416); + core.setAlpha('ui', 1.0); + + // 要运行的轨迹:将steps展开 + var moveSteps=[]; + steps.forEach(function (e) { + if (typeof e=="string") { + moveSteps.push(e); + } + else { + if (!core.isset(e.value)) { + moveSteps.push(e.direction) + } + else { + for (var i=0;i12 || ny<0 || ny>12) continue; + if (!zoneSquare && Math.abs(dx)+Math.abs(dy)>range) continue; + core.status.checkBlock.damage[13*nx+ny]+=enemy.value; + } + } + } + // 存在阻击 + if (core.enemys.hasSpecial(enemy.special, 18)) { + for (var dx=-1;dx<=1;dx++) { + for (var dy=-1;dy<=1;dy++) { + if (dx==0 && dy==0) continue; + var nx=x+dx, ny=y+dy; + if (nx<0 || nx>12 || ny<0 || ny>12 || Math.abs(dx)+Math.abs(dy)>1) continue; + core.status.checkBlock.damage[13*nx+ny]+=enemy.value; + } + } + } + } + } + } + + + // Step3: 更新夹击点坐标,并将夹击伤害加入到damage中 + core.status.checkBlock.betweenAttack = []; // 记录(x,y)点是否有夹击 + for (var x=0;x<13;x++) { + for (var y=0;y<13;y++) { + var has=false; + if (x>0 && x<12) { + var id1=core.status.checkBlock.map[13*(x-1)+y], + id2=core.status.checkBlock.map[13*(x+1)+y]; + if (core.isset(id1) && core.isset(id2) && id1==id2) { + var enemy = core.material.enemys[id1]; + if (core.isset(enemy) && core.enemys.hasSpecial(enemy.special, 16)) { + has = true; + } + } + } + if (y>0 && y<12) { + var id1=core.status.checkBlock.map[13*x+y-1], + id2=core.status.checkBlock.map[13*x+y+1]; + if (core.isset(id1) && core.isset(id2) && id1==id2) { + var enemy = core.material.enemys[id1]; + if (core.isset(enemy) && core.enemys.hasSpecial(enemy.special, 16)) { + has = true; + } + } + } + // 存在夹击 + if (has) { + core.status.checkBlock.betweenAttack[13*x+y]=true; + var leftHp = core.status.hero.hp - core.status.checkBlock.damage[13*x+y]; + if (leftHp>1) + core.status.checkBlock.damage[13*x+y] += Math.floor((leftHp+(core.flags.betweenAttackCeil?0:1))/2); + } + } + } +} + +////// 检查并执行领域、夹击、阻击事件 ////// +control.prototype.checkBlock = function () { + var x=core.getHeroLoc('x'), y=core.getHeroLoc('y'); + var damage = core.status.checkBlock.damage[13*x+y]; + if (damage>0) { + core.status.hero.hp -= damage; + + // 检查阻击事件 + var snipe = []; + var scan = { + 'up': {'x': 0, 'y': -1}, + 'left': {'x': -1, 'y': 0}, + 'down': {'x': 0, 'y': 1}, + 'right': {'x': 1, 'y': 0} + } + for (var direction in scan) { + var nx = x+scan[direction].x, ny=y+scan[direction].y; + if (nx<0 || nx>12 || ny<0 || ny>12) continue; + var id=core.status.checkBlock.map[13*nx+ny]; + if (core.isset(id)) { + var enemy = core.material.enemys[id]; + if (core.isset(enemy) && core.enemys.hasSpecial(enemy.special, 18)) { + snipe.push({'direction': direction, 'x': nx, 'y': ny}); + } + } + } + + if (core.status.checkBlock.betweenAttack[13*x+y] && damage>0) { + core.drawTip('受到夹击,生命变成一半'); + } + else if (core.status.checkBlock.map[13*x+y]=='lavaNet') { + core.drawTip('受到血网伤害'+damage+'点'); + } + // 阻击 + else if (snipe.length>0 && damage>0) { + core.drawTip('受到阻击伤害'+damage+'点'); + } + else if (damage>0) { + core.drawTip('受到领域伤害'+damage+'点'); + } + + if (damage>0) { + core.playSound('zone.mp3'); + core.drawAnimate("zone", x, y); + } + core.status.hero.statistics.extraDamage += damage; + + if (core.status.hero.hp<=0) { + core.status.hero.hp=0; + core.updateStatusBar(); + core.events.lose(); + return; + } + snipe = snipe.filter(function (t) { + var x=t.x, y=t.y, direction = t.direction; + var nx = x+scan[direction].x, ny=y+scan[direction].y; + + return nx>=0 && nx<=12 && ny>=0 && ny<=12 && core.getBlock(nx, ny, core.status.floorId, false)==null; + }); + core.updateStatusBar(); + if (snipe.length>0) + core.snipe(snipe); + } +} + +////// 阻击事件(动画效果) ////// +control.prototype.snipe = function (snipes) { + + var scan = { + 'up': {'x': 0, 'y': -1}, + 'left': {'x': -1, 'y': 0}, + 'down': {'x': 0, 'y': 1}, + 'right': {'x': 1, 'y': 0} + }; + + snipes.forEach(function (snipe) { + var x=snipe.x, y=snipe.y, direction = snipe.direction; + snipe.nx = x+scan[snipe.direction].x; + snipe.ny = y+scan[snipe.direction].y; + + core.removeGlobalAnimate(x, y); + + var block = core.getBlock(x,y).block; + + var cls = block.event.cls; + var height = block.event.height || 32; + + snipe.animate = block.event.animate || 1; + snipe.blockIcon = core.material.icons[cls][block.event.id]; + snipe.blockImage = core.material.images[cls]; + snipe.height = height; + + var damage = core.enemys.getDamage(block.event.id); + var color = '#000000'; + + if (damage == null) { + damage = "???"; + color = '#FF0000'; + } + else { + if (damage <= 0) color = '#00FF00'; + else if (damage < core.status.hero.hp / 3) color = '#FFFFFF'; + else if (damage < core.status.hero.hp * 2 / 3) color = '#FFFF00'; + else if (damage < core.status.hero.hp) color = '#FF7F00'; + else color = '#FF0000'; + + damage = core.formatBigNumber(damage); + } + + snipe.damage = damage; + snipe.color = color; + snipe.block = core.clone(block); + + }) + + var finishSnipe = function () { + snipes.forEach(function (t) { + core.removeBlock(t.x, t.y); + var nBlock = core.clone(t.block); + nBlock.x = t.nx; nBlock.y = t.ny; + core.status.thisMap.blocks.push(nBlock); + core.drawBlock(nBlock); + core.addGlobalAnimate(nBlock); + }); + core.syncGlobalAnimate(); + core.updateStatusBar(); + return; + } + + if (core.status.replay.replaying) { + finishSnipe(); + } + else { + core.waitHeroToStop(function() { + + core.lockControl(); + + var time = 500, step = 0; + + var animateCurrent = 0; + var animateTime = 0; + + core.canvas.fg.textAlign = 'left'; + + var animate=window.setInterval(function() { + + step++; + animateTime += time / 16; + if (animateTime >= core.values.animateSpeed) { + animateCurrent++; + animateTime = 0; + } + + snipes.forEach(function (snipe) { + var x=snipe.x, y=snipe.y, direction = snipe.direction; + + var dx = scan[direction].x*2*step, dy = scan[direction].y*2*step; + var nowX = 32*x+dx, nowY = 32*y+dy; + + // 清空上一次 + core.clearMap('fg', nowX-2*scan[direction].x, nowY-2*scan[direction].y, 32, 32); + core.canvas.event.clearRect(nowX-2*scan[direction].x, nowY-2*scan[direction].y, 32, 32); + core.canvas.event2.clearRect(nowX-2*scan[direction].x, nowY-2*scan[direction].y-32, 32, 32) + + core.drawBlock(snipe.block, animateCurrent, dx, dy); + + if (core.hasItem('book')) { + // drawFG + core.setFillStyle('fg', '#000000'); + core.canvas.fg.fillText(snipe.damage, nowX + 2, nowY + 30); + core.canvas.fg.fillText(snipe.damage, nowX, nowY + 30); + core.canvas.fg.fillText(snipe.damage, nowX + 2, nowY + 32); + core.canvas.fg.fillText(snipe.damage, nowX, nowY + 32); + + core.setFillStyle('fg', snipe.color); + core.canvas.fg.fillText(snipe.damage, nowX + 1, nowY + 31); + } + + }) + + if (step==16) { // 移动完毕 + clearInterval(animate); + finishSnipe(); + // 不存在自定义事件 + if (core.status.event.id==null) + core.unLockControl(); + } + }, time/16); + }); + } +} + +////// 更改天气效果 ////// +control.prototype.setWeather = function (type, level) { + + // 非雨雪 + if (type!='rain' && type!='snow') { + core.clearMap('weather', 0, 0, 416, 416) + core.animateFrame.weather.type = null; + core.animateFrame.weather.level = 0; + core.animateFrame.weather.nodes = []; + return; + } + + level = parseInt(level); + + // 当前天气:则忽略 + if (type==core.animateFrame.weather.type && + (!core.isset(level) || 20*level==core.animateFrame.weather.level)) { + return; + } + + if (!core.isset(level)) level=5; + if (level<1) level=1; if (level>10) level=10; + level *= 20; + + core.clearMap('weather', 0, 0, 416, 416) + core.animateFrame.weather.type = type; + core.animateFrame.weather.level = level; + + core.animateFrame.weather.nodes = []; + + if (type == 'rain') { + for (var a=0;a1) color[3]=1; + + if (time==0) { + // 直接变色 + core.dom.curtain.style.background = core.arrayToRGB(color); + core.dom.curtain.style.opacity = color[3]; + core.status.curtainColor = color; + if (core.isset(callback)) callback(); + return; + } + + var step=0; + core.status.replay.animate=true; + var changeAnimate = setInterval(function() { + step++; + + var nowAlpha = fromColor[3]+(color[3]-fromColor[3])*step/25; + var nowR = parseInt(fromColor[0]+(color[0]-fromColor[0])*step/25); + var nowG = parseInt(fromColor[1]+(color[1]-fromColor[1])*step/25); + var nowB = parseInt(fromColor[2]+(color[2]-fromColor[2])*step/25); + core.dom.curtain.style.background = core.arrayToRGB([nowR,nowG,nowB]); + core.dom.curtain.style.opacity = nowAlpha; + + if (step>=25) { + clearInterval(changeAnimate); + core.status.curtainColor = color; + core.status.replay.animate=false; + if (core.isset(callback)) callback(); + } + }, time/25); +} + +////// 更新全地图显伤 ////// +control.prototype.updateFg = function () { + + if (!core.isset(core.status.thisMap) || !core.isset(core.status.thisMap.blocks)) return; + // 更新显伤 + var mapBlocks = core.status.thisMap.blocks; + core.clearMap('fg', 0, 0, 416, 416); + // 没有怪物手册 + if (!core.hasItem('book')) return; + core.setFont('fg', "bold 11px Arial"); + var hero_hp = core.status.hero.hp; + if (core.flags.displayEnemyDamage || core.flags.displayCritical) { + core.canvas.fg.textAlign = 'left'; + for (var b = 0; b < mapBlocks.length; b++) { + var x = mapBlocks[b].x, y = mapBlocks[b].y; + if (core.isset(mapBlocks[b].event) && mapBlocks[b].event.cls.indexOf('enemy')==0 + && !(core.isset(mapBlocks[b].enable) && !mapBlocks[b].enable)) { + + // 非系统默认的战斗事件(被覆盖) + if (mapBlocks[b].event.trigger != 'battle') { + // 判断显伤 + var event = core.floors[core.status.floorId].events[x+","+y]; + if (core.isset(event) && !(event instanceof Array)) { + if (core.isset(event.displayDamage) && !event.displayDamage) + continue; + } + } + + var id = mapBlocks[b].event.id; + + if (core.flags.displayEnemyDamage) { + var damage = core.enemys.getDamage(id); + var color = '#000000'; + + if (damage == null) { + damage = "???"; + color = '#FF0000'; + } + else { + if (damage <= 0) color = '#00FF00'; + else if (damage < hero_hp / 3) color = '#FFFFFF'; + else if (damage < hero_hp * 2 / 3) color = '#FFFF00'; + else if (damage < hero_hp) color = '#FF7F00'; + else color = '#FF0000'; + + damage = core.formatBigNumber(damage); + } + + core.setFillStyle('fg', '#000000'); + core.canvas.fg.fillText(damage, 32 * x + 2, 32 * (y + 1) - 2); + core.canvas.fg.fillText(damage, 32 * x, 32 * (y + 1) - 2); + core.canvas.fg.fillText(damage, 32 * x + 2, 32 * (y + 1)); + core.canvas.fg.fillText(damage, 32 * x, 32 * (y + 1)); + + core.setFillStyle('fg', color); + core.canvas.fg.fillText(damage, 32 * x + 1, 32 * (y + 1) - 1); + } + + // 临界显伤 + if (core.flags.displayCritical) { + var critical = core.enemys.nextCriticals(id); + if (critical.length>0) critical=critical[0]; + critical = core.formatBigNumber(critical[0]); + if (critical == '???') critical = '?'; + core.setFillStyle('fg', '#000000'); + core.canvas.fg.fillText(critical, 32 * x + 2, 32 * (y + 1) - 2 - 10); + core.canvas.fg.fillText(critical, 32 * x, 32 * (y + 1) - 2 - 10); + core.canvas.fg.fillText(critical, 32 * x + 2, 32 * (y + 1) - 10); + core.canvas.fg.fillText(critical, 32 * x, 32 * (y + 1) - 10); + core.setFillStyle('fg', '#FFFFFF'); + core.canvas.fg.fillText(critical, 32 * x + 1, 32 * (y + 1) - 1 - 10); + } + + } + } + } + // 如果是领域&夹击 + if (core.flags.displayExtraDamage) { + core.canvas.fg.textAlign = 'center'; + for (var x=0;x<13;x++) { + for (var y=0;y<13;y++) { + var damage = core.status.checkBlock.damage[13*x+y]; + if (damage>0) { + damage = core.formatBigNumber(damage); + core.setFillStyle('fg', '#000000'); + core.canvas.fg.fillText(damage, 32 * x + 17, 32 * (y + 1) - 13); + core.canvas.fg.fillText(damage, 32 * x + 15, 32 * (y + 1) - 15); + core.canvas.fg.fillText(damage, 32 * x + 17, 32 * (y + 1) - 15); + core.canvas.fg.fillText(damage, 32 * x + 15, 32 * (y + 1) - 13); + + core.setFillStyle('fg', '#FF7F00'); + core.canvas.fg.fillText(damage, 32 * x + 16, 32 * (y + 1) - 14); + } + } + } + } +} + +////// 执行一个表达式的effect操作 ////// +control.prototype.doEffect = function (expression) { + // 必须使用"+=" + var arr = expression.split("+="); + if (arr.length!=2) return; + var name=arr[0], value=core.calValue(arr[1]); + if (name.indexOf("status:")==0) { + var status=name.substring(7); + core.setStatus(status, core.getStatus(status)+value); + } + else if (name.indexOf("item:")==0) { + var itemId=name.substring(5); + core.setItem(itemId, core.itemCount(itemId)+value); + } +} + +////// 开启debug模式 ////// +control.prototype.debug = function() { + core.setFlag('debug', true); + core.insertAction(["\t[调试模式开启]此模式下按住Ctrl键可以穿墙并忽略一切事件。\n同时,录像将失效,也无法上传成绩。"]); + /* + 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 i in core.status.maps) + if (core.status.maps[i].canFlyTo && core.status.hero.flyRange.indexOf(i)<0) + core.status.hero.flyRange.push(i); + core.updateStatusBar(); + core.drawTip("作弊成功"); + */ +} + +////// 开始播放 ////// +control.prototype.startReplay = function (list) { + core.status.replay.replaying=true; + core.status.replay.pausing=false; + core.status.replay.speed=1.0; + core.status.replay.toReplay = core.clone(list); + core.status.replay.totalList = core.clone(list); + 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 toAdd = core.status.replay.speed>=3?3:core.status.replay.speed>=2?2:1; + core.status.replay.speed = parseInt(10*core.status.replay.speed + toAdd)/10; + if (core.status.replay.speed>6.0) core.status.replay.speed=6.0; + 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 toAdd = core.status.replay.speed>3?3:core.status.replay.speed>2?2:1; + core.status.replay.speed = parseInt(10*core.status.replay.speed - toAdd)/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.0; + 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 save = core.status.replay.save; + var data = save.pop(); + core.loadData(data.data, function () { + core.status.replay = { + "replaying": true, + "pausing": true, + "animate": false, + "toReplay": data.replay.toReplay, + "totalList": data.replay.totalList, + "speed": data.replay.speed, + "steps": data.replay.steps, + "save": save + } + 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 saveIndex = core.status.saveIndex; + var page=parseInt((saveIndex-1)/5), offset=saveIndex-5*page; + + core.ui.drawSLPanel(10*page+offset); +} + +////// 回放时查看怪物手册 ////// +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) { + //if (core.status.replay.save.length == 30) + // core.status.replay.save.shift(); + 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 action=core.status.replay.toReplay.shift(); + + if (action=='up' || action=='down' || action=='left' || action=='right') { + core.moveHero(action, function () { + setTimeout(function() { + core.replay(); + }); + }); + return; + } + else if (action.indexOf("item:")==0) { + var itemId = action.substring(5); + if (core.canUseItem(itemId)) { + var tools = Object.keys(core.status.hero.items.tools).sort(); + var constants = Object.keys(core.status.hero.items.constants).sort(); + var index; + if ((index=tools.indexOf(itemId))>=0 || (index=constants.indexOf(itemId)+100)>=100) { + core.ui.drawToolbox(index); + setTimeout(function () { + core.ui.closePanel(); + core.useItem(itemId, function () { + core.replay(); + }); + }, 750 / core.status.replay.speed); + } + return; + } + } + else if (action.indexOf("fly:")==0) { + var floorId=action.substring(4); + var toIndex=core.status.hero.flyRange.indexOf(floorId); + var nowIndex=core.status.hero.flyRange.indexOf(core.status.floorId); + if (core.hasItem('fly') && toIndex>=0 && nowIndex>=0) { + core.ui.drawFly(toIndex); + setTimeout(function () { + core.ui.closePanel(); + var stair=toIndex0) { + var shop=core.status.shops[shopId]; + if (core.isset(shop) && shop.visited) { // 商店可用 + var choices = shop.choices; + var topIndex = 6 - parseInt(choices.length / 2); + + core.status.event.selection = parseInt(selections.shift()); + + core.events.openShop(shopId, false); + var shopInterval = setInterval(function () { + if (!core.actions.clickShop(6, topIndex+core.status.event.selection)) { + clearInterval(shopInterval); + core.stopReplay(); + core.drawTip("录像文件出错"); + return; + } + if (selections.length==0) { + clearInterval(shopInterval); + core.actions.clickShop(6, topIndex+choices.length); + core.replay(); + return; + } + core.status.event.selection = parseInt(selections.shift()); + core.events.openShop(shopId, false); + + }, 750 / core.status.replay.speed); + return; + } + } + } + else if (action=='turn') { + core.turnHero(); + core.replay(); + return; + } + else if (action=='getNext') { + if (core.flags.enableGentleClick && core.getBlock(core.nextX(), core.nextY())!=null) { + var nextX = core.nextX(), nextY = core.nextY(); + var block = core.getBlock(nextX, nextY); + if (block!=null && block.block.event.trigger=='getItem') { + core.getItem(block.block.event.id, 1, nextX, nextY); + core.status.route.push("getNext"); + core.replay(); + return; + } + } + } + else if (action.indexOf('move:')==0) { + var pos=action.substring(5).split(":"); + var x=parseInt(pos[0]), y=parseInt(pos[1]); + + var ignoreSteps = core.canMoveDirectly(x, y); + if (ignoreSteps>0) { + core.clearMap('hero', 0, 0, 416, 416); + core.setHeroLoc('x', x); + core.setHeroLoc('y', y); + core.drawHero(); + core.status.route.push("move:"+x+":"+y); + core.status.hero.statistics.moveDirectly++; + core.status.hero.statistics.ignoreSteps+=ignoreSteps; + core.replay(); + return; + } + } + else if (action.indexOf('key:')==0) { + core.actions.keyUp(parseInt(action.substring(4)), true); + core.replay(); + return; + } + + core.stopReplay(); + core.insertAction("录像文件出错"); + +} + +////// 判断当前能否进入某个事件 ////// +control.prototype.checkStatus = function (name, need, item) { + if (need && core.status.event.id == name) { + core.ui.closePanel(); + return false; + } + + if (need && core.status.lockControl) return false; + if (core.isset(item) && item && !core.hasItem(name)) { + core.drawTip("你没有" + core.material.items[name].name); + return false; + } + if (!core.status.heroStop) { + core.drawTip("请先停止勇士行动"); + return false; + } + + core.lockControl(); + core.status.event.id = name; + return true; +} + +////// 点击怪物手册时的打开操作 ////// +control.prototype.openBook = function (need) { + if (core.isset(core.status.replay)&&core.status.replay.replaying) return; + + // 当前是book,且从“浏览地图”打开 + 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') { + need=false; + core.status.event.selection = core.status.event.data; + } + + if (!core.checkStatus('book', need, true)) + return; + core.useItem('book'); +} + +////// 点击楼层传送器时的打开操作 ////// +control.prototype.useFly = function (need) { + if (core.isset(core.status.replay)&&core.status.replay.replaying) return; + if (!core.checkStatus('fly', need, 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 (need) { + if (core.isset(core.status.replay)&&core.status.replay.replaying) return; + if (!core.checkStatus('toolbox', need)) + return; + core.ui.drawToolbox(); +} + +////// 点击快捷商店按钮时的打开操作 ////// +control.prototype.openQuickShop = function (need) { + if (core.isset(core.status.replay)&&core.status.replay.replaying) return; + if (!core.checkStatus('selectShop', need)) + return; + core.ui.drawQuickShop(); +} + +////// 点击保存按钮时的打开操作 ////// +control.prototype.save = function(need) { + if (core.isset(core.status.replay)&&core.status.replay.replaying) return; + if (!core.checkStatus('save', need)) + return; + + var saveIndex = core.status.saveIndex; + var page=parseInt((saveIndex-1)/5), offset=saveIndex-5*page; + + core.ui.drawSLPanel(10*page+offset); +} + +////// 点击读取按钮时的打开操作 ////// +control.prototype.load = function (need) { + if (core.isset(core.status.replay)&&core.status.replay.replaying) return; + + var saveIndex = core.getLocalStorage('saveIndex2', 1); + var page=parseInt((saveIndex-1)/5), offset=saveIndex-5*page; + + // 游戏开始前读档 + if (!core.isPlaying()) { + core.status.event = {'id': 'load', 'data': null}; + core.status.lockControl = true; + core.dom.startPanel.style.display = 'none'; + core.ui.drawSLPanel(10*page+offset); + return; + } + + if (!core.checkStatus('load', need)) + return; + core.ui.drawSLPanel(10*page+offset); +} + +////// 点击设置按钮时的操作 ////// +control.prototype.openSettings = function (need) { + if (core.isset(core.status.replay)&&core.status.replay.replaying) return; + if (!core.checkStatus('settings', need)) + return; + core.ui.drawSettings(); +} + +////// 自动存档 ////// +control.prototype.autosave = function (removeLast) { + if (core.status.event.id!=null) + return; + var x=null; + if (removeLast) + x=core.status.route.pop(); + core.setLocalStorage("autoSave", core.saveData()) + if (removeLast && core.isset(x)) + core.status.route.push(x); +} + +////// 实际进行存读档事件 ////// +control.prototype.doSL = function (id, type) { + if (type=='save') { + if (id=='autoSave') { + core.drawTip('不能覆盖自动存档!'); + return; + } + if (core.setLocalStorage("save"+id, core.saveData())) { + core.ui.closePanel(); + core.drawTip('存档成功!'); + if (id!="autoSave") { + core.status.saveIndex=id; + core.setLocalStorage('saveIndex2', core.status.saveIndex); + } + } + else { + core.drawTip('存储空间不足,请覆盖已有的存档或在菜单栏中进行清理'); + } + return; + } + else if (type=='load') { + var data = core.getLocalStorage(id=='autoSave'?id:"save"+id, null); + if (!core.isset(data)) { + core.drawTip("无效的存档"); + return; + } + if (data.version != core.firstData.version) { + // core.drawTip("存档版本不匹配"); + if (confirm("存档版本不匹配!\n你想回放此存档的录像吗?")) { + core.dom.startPanel.style.display = 'none'; + var seed = data.hero.flags.seed; + core.resetStatus(core.firstData.hero, data.hard, core.firstData.floorId, null, core.initStatus.maps); + core.events.setInitData(data.hard); + core.setFlag('seed', seed); + core.setFlag('rand', seed); + core.changeFloor(core.status.floorId, null, core.firstData.hero.loc, null, function() { + core.startReplay(core.decodeRoute(data.route)); + }, true); + } + return; + } + core.ui.closePanel(); + core.loadData(data, function() { + core.drawTip("读档成功"); + if (id!="autoSave") { + core.status.saveIndex=id; + core.setLocalStorage('saveIndex2', core.status.saveIndex); + } + }); + return; + } + else if (type == 'replayLoad') { + var data = core.getLocalStorage(id=='autoSave'?id:"save"+id, null); + if (!core.isset(data)) { + core.drawTip("无效的存档"); + return; + } + if (data.version != core.firstData.version) { + core.drawTip("存档版本不匹配"); + return; + } + if (data.hard != core.status.hard) { + core.drawTip("游戏难度不匹配!"); + return; + } + var route = core.subarray(core.status.route, core.decodeRoute(data.route)); + if (!core.isset(route) || data.hero.flags.seed!=core.getFlag('seed')) { + core.drawTip("无法从此存档回放录像"); + return; + } + core.loadData(data, function () { + core.startReplay(route); + core.drawTip("回退到存档节点"); + }); + } +} + +////// 同步存档到服务器 ////// +control.prototype.syncSave = function (type) { + var saves=null; + // data + if (type=='all') { + saves=[]; + for (var i=1;i<=5*(main.savePages||30);i++) { + var data = core.getLocalStorage("save"+i, null); + if (core.isset(data)) { + saves.push(data); + } + } + } + else { + for (var i=5*(main.savePages||30);i>=1;i--) { + saves=core.getLocalStorage("save"+i, null); + if (core.isset(saves)) { + break; + } + } + } + if (!core.isset(saves)) { + core.drawText("没有要同步的存档"); + return; + } + core.ui.drawWaiting("正在同步,请稍后..."); + + var formData = new FormData(); + formData.append('type', 'save'); + formData.append('name', core.firstData.name); + var save_text = JSON.stringify(saves); + formData.append('data', save_text); + + core.http("POST", "/games/sync.php", formData, function (data) { + var response = JSON.parse(data); + if (response.code<0) { + core.drawText("出错啦!\n无法同步存档到服务器。\n错误原因:"+response.msg); + } + else { + core.drawText("同步成功!\n\n您的存档编号: "+response.code+"\n您的存档密码: "+response.msg+"\n\n请牢记以上两个信息(如截图等),在从服务器\n同步存档时使用。") + } + }, function (e) { + core.drawText("出错啦!\n无法同步存档到服务器。\n错误原因:"+e); + }) +} + +////// 从服务器加载存档 ////// +control.prototype.syncLoad = function () { + var id = prompt("请输入存档编号:"); + if (id==null || id=="") { + core.ui.drawSyncSave(); return; + } + var password = prompt("请输入存档密码:"); + if (password==null || password=="") { + core.ui.drawSyncSave(); return; + } + core.ui.drawWaiting("正在同步,请稍后..."); + + var formData = new FormData(); + formData.append('type', 'load'); + formData.append('name', core.firstData.name); + formData.append('id', id); + formData.append('password', password); + + core.http("POST", "/games/sync.php", formData, function (data) { + var response = JSON.parse(data); + switch (response.code) { + case 0: + // 成功 + var data=JSON.parse(response.msg); + // console.log(data); + + if (data instanceof Array) { + core.status.event.selection=1; + core.ui.drawConfirmBox("所有本地存档都将被覆盖,确认?", function () { + for (var i=1;i<=5*(main.savePages||30);i++) { + if (i<=data.length) { + core.setLocalStorage("save"+i, data[i-1]); + } + else { + core.removeLocalStorage("save"+i); + } + } + core.drawText("同步成功!\n你的本地所有存档均已被覆盖。"); + }, function () { + core.status.event.selection=0; + core.ui.drawSyncSave(); + }) + } + else { + // 只覆盖单存档 + var index=5*(main.savePages||30); + for (var i=5*(main.savePages||30);i>=1;i--) { + if (core.getLocalStorage("save"+i, null)==null) + index=i; + else break; + } + core.setLocalStorage("save"+index, data); + core.drawText("同步成功!\n单存档已覆盖至存档"+index); + } + break; + case -1: + core.drawText("出错啦!\n存档编号"+id+"不存在!"); + break; + case -2: + core.drawText("出错啦!\n存档密码错误!"); + break; + default: + core.drawText("出错啦!\n无法从服务器同步存档。\n错误原因:"+response.msg); + break; + } + }, function (e) { + core.drawText("出错啦!\n无法从服务器同步存档。\n错误原因:"+e); + }); +} + +////// 存档到本地 ////// +control.prototype.saveData = function() { + var data = { + '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() + }; + // set shop times + for (var shop in core.status.shops) { + data.shops[shop]={ + 'times': core.status.shops[shop].times || 0, + 'visited': core.status.shops[shop].visited || false + } + } + core.events.beforeSaveData(data); + + return data; +} + +////// 从本地读档 ////// +control.prototype.loadData = function (data, callback) { + + core.resetStatus(data.hero, data.hard, data.floorId, core.decodeRoute(data.route), core.maps.load(data.maps)); + + // load shop times + for (var shop in core.status.shops) { + if (core.isset(data.shops[shop])) { + core.status.shops[shop].times = data.shops[shop].times; + core.status.shops[shop].visited = data.shops[shop].visited; + } + } + + // load icons + var icon = core.getFlag("heroIcon", "hero.png"); + if (core.isset(core.material.images.images[icon])) { + core.material.images.hero.src = core.material.images.images[icon].src; + core.material.icons.hero.height = core.material.images.images[icon].height/4; + } + + core.events.afterLoadData(data); + + core.changeFloor(data.floorId, null, data.hero.loc, 0, function() { + if (core.isset(callback)) callback(); + }, true); +} + +////// 设置勇士属性 ////// +control.prototype.setStatus = function (statusName, statusVal) { + if (core.isset(core.status.hero.loc[statusName])) + core.status.hero.loc[statusName] = statusVal; + else + core.status.hero[statusName] = statusVal; +} + +////// 获得勇士属性 ////// +control.prototype.getStatus = function (statusName) { + // support status:x + if (core.isset(core.status.hero.loc[statusName])) + return core.status.hero.loc[statusName]; + return core.status.hero[statusName]; +} + +////// 获得某个等级的名称 ////// +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; +} + +////// 设置某个自定义变量或flag ////// +control.prototype.setFlag = function(flag, value) { + if (!core.isset(core.status.hero)) return; + core.status.hero.flags[flag]=value; +} + +////// 获得某个自定义变量或flag ////// +control.prototype.getFlag = function(flag, defaultValue) { + if (!core.isset(core.status.hero)) return defaultValue; + var value = core.status.hero.flags[flag]; + if (core.isset(value)) return value; + return defaultValue; +} + +////// 是否存在某个自定义变量或flag,且值为true ////// +control.prototype.hasFlag = function(flag) { + if (core.getFlag(flag)) return true; + return false; +} + +////// 锁定状态栏,常常用于事件处理 ////// +control.prototype.lockControl = function () { + core.status.lockControl = true; +} + +////// 解锁状态栏 ////// +control.prototype.unLockControl = function () { + core.status.lockControl = false; +} + +////// 播放背景音乐 ////// +control.prototype.playBgm = function (bgm) { + if (main.mode!='play')return; + // 如果不允许播放 + if (!core.musicStatus.bgmStatus) return; + // 音频不存在 + if (!core.isset(core.material.bgms[bgm])) return; + + // 延迟播放 + if (core.material.bgms[bgm] == 'loading') { + core.material.bgms[bgm] = 'starting'; + return; + } + + try { + // 如果当前正在播放,且和本BGM相同,直接忽略 + if (core.musicStatus.playingBgm == bgm && core.musicStatus.isPlaying) { + return; + } + // 如果正在播放中,暂停 + if (core.isset(core.musicStatus.playingBgm) && core.musicStatus.isPlaying) { + core.material.bgms[core.musicStatus.playingBgm].pause(); + } + // 播放当前BGM + core.material.bgms[bgm].volume = core.musicStatus.volume; + core.material.bgms[bgm].play(); + core.musicStatus.playingBgm = bgm; + core.musicStatus.isPlaying = true; + } + catch (e) { + console.log("无法播放BGM "+bgm); + console.log(e); + 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 (e) { + console.log("无法暂停BGM "+bgm); + console.log(e); + } +} + +////// 恢复背景音乐的播放 ////// +control.prototype.resumeBgm = function () { + if (main.mode!='play')return; + // 如果不允许播放 + if (!core.musicStatus.bgmStatus) return; + + // 恢复BGM + 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 (e) { + console.log("无法恢复BGM "+bgm); + console.log(e); + } +} + +////// 播放音频 ////// +control.prototype.playSound = function (sound) { + if (main.mode!='play')return; + // 如果不允许播放 + if (!core.musicStatus.soundStatus) return; + // 音频不存在 + if (!core.isset(core.material.sounds[sound])) return; + + try { + if (core.musicStatus.audioContext != null) { + var source = core.musicStatus.audioContext.createBufferSource(); + source.buffer = core.material.sounds[sound]; + source.connect(core.musicStatus.gainNode); + try { + source.start(0); + } + catch (e) { + try { + source.noteOn(0); + } + catch (ee) { + } + } + } + else { + core.material.sounds[sound].volume = core.musicStatus.volume; + core.material.sounds[sound].play(); + } + } + catch (eee) { + console.log("无法播放SE "+sound); + console.log(eee); + } +} + +////// 清空状态栏 ////// +control.prototype.clearStatusBar = function() { + var statusList = ['floor', 'lv', 'hpmax', 'hp', 'atk', 'def', 'mdef', 'money', 'experience', + 'up', 'yellowKey', 'blueKey', 'redKey', 'poison', 'weak', 'curse', 'hard']; + statusList.forEach(function (e) { + core.statusBar[e].innerHTML = " "; + }); + core.statusBar.image.book.style.opacity = 0.3; + core.statusBar.image.fly.style.opacity = 0.3; +} + +////// 更新状态栏 ////// +control.prototype.updateStatusBar = function () { + + // 检查等级 + core.events.checkLvUp(); + + // 检查HP上限 + if (core.flags.enableHPMax) { + core.setStatus('hp', Math.min(core.getStatus('hpmax'), core.getStatus('hp'))); + } + + // 更新领域、阻击、显伤 + core.updateCheckBlock(); + + var lvName = core.getLvName(); + core.statusBar.lv.innerHTML = lvName; + if (/^[+-]?\d+$/.test(lvName)) + core.statusBar.lv.style.fontStyle = 'italic'; + else core.statusBar.lv.style.fontStyle = 'normal'; + + var statusList = ['hpmax', 'hp', 'atk', 'def', 'mdef', 'money', 'experience']; + statusList.forEach(function (item) { + if (core.isset(core.status.hero[item])) + core.status.hero[item] = Math.floor(core.status.hero[item]); + core.statusBar[item].innerHTML = core.formatBigNumber(core.getStatus(item)); + }); + + // 进阶 + if (core.flags.enableLevelUp && core.status.hero.lv clientHeight && clientHeight < ADAPT_WIDTH){ + isHorizontal = true; + width = clientHeight; + } + // 各元素大小的变量声明 + var gameGroupWidth, gameGroupHeight, borderRight, + canvasWidth, canvasTop, // canvasLeft, + statusBarWidth, statusBarHeight, statusBarBorder, + statusWidth, statusHeight, statusMaxWidth,statusLabelsLH, + toolBarWidth, toolBarHeight, toolBarTop, toolBarBorder, + toolsWidth, toolsHeight,toolsMargin,toolsPMaxwidth, + fontSize, toolbarFontSize, margin, statusBackground, toolsBackground; + + var count = core.dom.statusBar.children.length; + if (!core.flags.enableFloor) count--; + if (!core.flags.enableLv) count--; + if (!core.flags.enableHPMax) count--; + if (!core.flags.enableMDef) count--; + if (!core.flags.enableMoney) count--; + if (!core.flags.enableExperience) count--; + if (!core.flags.enableLevelUp) count--; + if (!core.flags.enableDebuff) count--; + if (core.isset(core.flags.enableKeys) && !core.flags.enableKeys) count--; + + var statusLineHeight = BASE_LINEHEIGHT * 9 / count; + var statusLineFontSize = DEFAULT_FONT_SIZE; + if (count>9) statusLineFontSize = statusLineFontSize * 9 / count; + + var shopDisplay; + + statusBarBorder = '3px #fff solid'; + toolBarBorder = '3px #fff solid'; + var zoom = (ADAPT_WIDTH - width) / 4.22; + var aScale = 1 - zoom / 100; + + // 移动端 + if (width < CHANGE_WIDTH) { + if(width < ADAPT_WIDTH){ + + core.domStyle.scale = aScale; + canvasWidth = width; + }else{ + canvasWidth = DEFAULT_CANVAS_WIDTH; + core.domStyle.scale = 1; + } + + var scale = core.domStyle.scale + var tempWidth = DEFAULT_CANVAS_WIDTH * scale; + if(!isHorizontal){ //竖屏 + core.domStyle.screenMode = 'vertical'; + //显示快捷商店图标 + shopDisplay = 'block'; + //判断应该显示几行 + // var col = core.flags.enableMDef || core.flags.enableExperience || core.flags.enableDebuff ? 3 : 2; + var col = parseInt((count-1)/3)+1; + + var tempTopBarH = scale * (BASE_LINEHEIGHT * col + SPACE * 2) + 6; + var tempBotBarH = scale * (BASE_LINEHEIGHT + SPACE * 4) + 6; + + gameGroupHeight = tempWidth + tempTopBarH + tempBotBarH; + + gameGroupWidth = tempWidth + canvasTop = tempTopBarH; + // canvasLeft = 0; + toolBarWidth = statusBarWidth = canvasWidth; + statusBarHeight = tempTopBarH; + statusBarBorder = '3px #fff solid'; + + statusHeight = scale*BASE_LINEHEIGHT * .8; + statusLabelsLH = .8 * BASE_LINEHEIGHT *scale; + statusMaxWidth = scale * DEFAULT_BAR_WIDTH * .95; + statusBackground = main.statusTopBackground; + toolBarHeight = tempBotBarH; + + toolBarTop = statusBarHeight + canvasWidth; + toolBarBorder = '3px #fff solid'; + toolsHeight = scale * BASE_LINEHEIGHT; + toolsPMaxwidth = scale * DEFAULT_BAR_WIDTH * .4; + toolsBackground = main.toolsBackground; + borderRight = '3px #fff solid'; + + margin = scale * SPACE * 2; + toolsMargin = scale * SPACE * 4; + fontSize = DEFAULT_FONT_SIZE * scale; + toolbarFontSize = DEFAULT_FONT_SIZE * scale; + }else { //横屏 + core.domStyle.screenMode = 'horizontal'; + shopDisplay = 'none'; + gameGroupWidth = tempWidth + DEFAULT_BAR_WIDTH * scale; + gameGroupHeight = tempWidth; + canvasTop = 0; + // canvasLeft = DEFAULT_BAR_WIDTH * scale; + toolBarWidth = statusBarWidth = DEFAULT_BAR_WIDTH * scale; + statusBarHeight = gameGroupHeight - SPACE; + statusBarBorder = '3px #fff solid'; + statusBackground = main.statusLeftBackground; + + statusHeight = scale*statusLineHeight * .8; + statusLabelsLH = .8 * statusLineHeight *scale; + toolBarTop = scale*statusLineHeight * count + SPACE * 2; + toolBarHeight = canvasWidth - toolBarTop; + toolBarBorder = '3px #fff solid'; + toolsHeight = scale * BASE_LINEHEIGHT; + toolsBackground = 'transparent'; + fontSize = statusLineFontSize * scale; + toolbarFontSize = DEFAULT_FONT_SIZE * scale; + borderRight = ''; + statusMaxWidth = scale * DEFAULT_BAR_WIDTH; + toolsPMaxwidth = scale * DEFAULT_BAR_WIDTH; + + margin = scale * SPACE * 2; + toolsMargin = 2 * SPACE * scale; + } + + }else { //大屏设备 pc端 + core.domStyle.scale = 1; + core.domStyle.screenMode = 'bigScreen'; + shopDisplay = 'none'; + + gameGroupWidth = DEFAULT_CANVAS_WIDTH + DEFAULT_BAR_WIDTH; + gameGroupHeight = DEFAULT_CANVAS_WIDTH; + canvasWidth = DEFAULT_CANVAS_WIDTH; + canvasTop = 0; + // canvasLeft = DEFAULT_BAR_WIDTH; + + toolBarWidth = statusBarWidth = DEFAULT_BAR_WIDTH; + // statusBarHeight = statusLineHeight * count + SPACE * 2; //一共有9行 + statusBackground = main.statusLeftBackground; + statusBarHeight = gameGroupHeight - SPACE; + + statusHeight = statusLineHeight * .8; + statusLabelsLH = .8 * statusLineHeight; + toolBarTop = statusLineHeight * count + SPACE * 2; + toolBarHeight = DEFAULT_CANVAS_WIDTH - toolBarTop; + toolsBackground = 'transparent'; + + toolsHeight = BASE_LINEHEIGHT; + borderRight = ''; + fontSize = statusLineFontSize; + toolbarFontSize = DEFAULT_FONT_SIZE; + statusMaxWidth = DEFAULT_BAR_WIDTH; + toolsPMaxwidth = DEFAULT_BAR_WIDTH * .9; + margin = SPACE * 2; + toolsMargin = 2 * SPACE; + } + + var unit = 'px' + core.domStyle.styles = [ + { + id: 'gameGroup', + rules:{ + width: gameGroupWidth + unit, + height: gameGroupHeight + unit, + top: (clientHeight-gameGroupHeight)/2 + unit, + left: (clientWidth-gameGroupWidth)/2 + unit, + } + }, + { + className: 'gameCanvas', + rules:{ + width: canvasWidth + unit, + height: canvasWidth + unit, + top: canvasTop + unit, + right: 0, + border: '3px #fff solid', + } + }, + { + id: 'gif', + rules: { + width: (canvasWidth - SPACE*2) + unit, + height:(canvasWidth - SPACE*2) + unit, + top: (canvasTop + SPACE) + unit, + right: SPACE + unit, + } + }, + { + id: 'gif2', + rules: { + width: (canvasWidth - SPACE*2) + unit, + height:(canvasWidth - SPACE*2) + unit, + top: (canvasTop + SPACE) + unit, + right: SPACE + unit, + } + }, + { + id: 'curtain', + rules: { + width: (canvasWidth - SPACE*2) + unit, + height:(canvasWidth - SPACE*2) + unit, + top: (canvasTop + SPACE) + unit, + right: SPACE + unit, + } + }, + { + id: 'floorMsgGroup', + rules:{ + width: (canvasWidth - SPACE*2) + unit, + height: (gameGroupHeight - SPACE*2) + unit, + top: SPACE + unit, + right: SPACE + unit, + } + }, + { + id: 'statusBar', + rules:{ + width: statusBarWidth + unit, + height: statusBarHeight + unit, + top: 0, + left: 0, + padding: SPACE + unit, + + borderTop: statusBarBorder, + borderLeft: statusBarBorder, + borderRight: borderRight, + fontSize: fontSize + unit, + background: statusBackground, + } + }, + { + className: 'status', + rules:{ + width: '100%', + maxWidth: statusMaxWidth + unit, + height: statusHeight + unit, + margin: margin/2 + unit + } + }, + { + className: 'statusLabels', + rules:{ + marginLeft: margin + unit, + lineHeight: statusLabelsLH + unit, + } + }, + { + id: 'toolBar', + rules:{ + width: toolBarWidth + unit, + height: toolBarHeight + unit, + top: toolBarTop +unit, + left: 0, + padding: SPACE + unit, + borderBottom: toolBarBorder, + borderLeft: toolBarBorder, + borderRight: borderRight, + fontSize: toolbarFontSize + unit, + background: toolsBackground, + } + }, + { + className: 'tools', + rules:{ + height: toolsHeight + unit, + maxWidth: toolsPMaxwidth + unit, + marginLeft: toolsMargin + unit, + marginTop: margin + unit, + } + }, + { + imgId: 'shop', + rules:{ + display: shopDisplay + } + }, + { + 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: toolsHeight + unit + } + } + ] + core.domRenderer(); +} + +////// 渲染DOM ////// +control.prototype.domRenderer = function(){ + + core.dom.statusBar.style.display = 'block'; + core.dom.toolBar.style.display = 'block'; + + var styles = core.domStyle.styles; + + for(var i=0; icore.animateFrame.speed&&core.isset(core.status.globalAnimateObjs)){for(var c=0;ccore.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;e12||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;j12||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.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;b1){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;a0){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=r0){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=" "});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.lvh&&h9){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=0}if(typeof a=="number"){return a!=0&&(a%100==b||this.hasSpecial(parseInt(a/100),b))}return false};enemys.prototype.getSpecialText=function(b){var a=core.material.enemys[b];if(!core.isset(a)){return[]}var c=a.special;var d=[];if(this.hasSpecial(c,1)){d.push("先攻")}if(this.hasSpecial(c,2)){d.push("魔攻")}if(this.hasSpecial(c,3)){d.push("坚固")}if(this.hasSpecial(c,4)){d.push("2连击")}if(this.hasSpecial(c,5)){d.push("3连击")}if(this.hasSpecial(c,6)){d.push((a.n||4)+"连击")}if(this.hasSpecial(c,7)){d.push("破甲")}if(this.hasSpecial(c,8)){d.push("反击")}if(this.hasSpecial(c,9)){d.push("净化")}if(this.hasSpecial(c,10)){d.push("模仿")}if(this.hasSpecial(c,11)){d.push("吸血")}if(this.hasSpecial(c,12)){d.push("中毒")}if(this.hasSpecial(c,13)){d.push("衰弱")}if(this.hasSpecial(c,14)){d.push("诅咒")}if(this.hasSpecial(c,15)){d.push("领域")}if(this.hasSpecial(c,16)){d.push("夹击")}if(this.hasSpecial(c,17)){d.push("仇恨")}if(this.hasSpecial(c,18)){d.push("阻击")}if(this.hasSpecial(c,19)){d.push("自爆")}if(this.hasSpecial(c,20)){d.push("无敌")}if(this.hasSpecial(c,21)){d.push("退化")}if(this.hasSpecial(c,22)){d.push("固伤")}if(this.hasSpecial(c,23)){d.push("重生")}return d};enemys.prototype.getSpecialHint=function(a,e){if(!core.isset(e)){var c=[];for(var d=1;d<100;d++){if(this.hasSpecial(a.special,d)){var b=this.getSpecialHint(a,d);if(b!=""){c.push(b)}}}return c}switch(e){case 1:return"先攻:怪物首先攻击";case 2:return"魔攻:怪物无视勇士的防御";case 3:return"坚固:勇士每回合最多只能对怪物造成1点伤害";case 4:return"2连击:怪物每回合攻击2次";case 5:return"3连击:怪物每回合攻击3次";case 6:return(a.n||4)+"连击: 怪物每回合攻击"+(a.n||4)+"次";case 7:return"破甲:战斗前,怪物附加角色防御的"+Math.floor(100*core.values.breakArmor||0)+"%作为伤害";case 8:return"反击:战斗时,怪物每回合附加角色攻击的"+Math.floor(100*core.values.counterAttack||0)+"%作为伤害,无视角色防御";case 9:return"净化:战斗前,怪物附加勇士魔防的"+core.values.purify+"倍作为伤害";case 10:return"模仿:怪物的攻防和勇士攻防相等";case 11:return"吸血:战斗前,怪物首先吸取角色的"+Math.floor(100*a.value||0)+"%生命作为伤害"+(a.add?",并把伤害数值加到自身生命上":"");case 12:return"中毒:战斗后,勇士陷入中毒状态,每一步损失生命"+core.values.poisonDamage+"点";case 13:return"衰弱:战斗后,勇士陷入衰弱状态,攻防暂时下降"+core.values.weakValue+"点";case 14:return"诅咒:战斗后,勇士陷入诅咒状态,战斗无法获得金币和经验";case 15:return"领域:经过怪物周围"+(a.range||1)+"格时自动减生命"+(a.value||0)+"点";case 16:return"夹击:经过两只相同的怪物中间,勇士生命值变成一半";case 17:return"仇恨:战斗前,怪物附加之前积累的仇恨值作为伤害"+(core.flags.hatredDecrease?";战斗后,释放一半的仇恨值":"")+"。(每杀死一个怪物获得"+(core.values.hatred||0)+"点仇恨值)";case 18:return"阻击:经过怪物的十字领域时自动减生命"+(a.value||0)+"点,同时怪物后退一格";case 19:return"自爆:战斗后勇士的生命值变成1";case 20:return"无敌:勇士无法打败怪物,除非拥有十字架";case 21:return"退化:战斗后勇士永久下降"+(a.atkValue||0)+"点攻击和"+(a.defValue||0)+"点防御";case 22:return"固伤:战斗前,怪物对勇士造成"+(a.damage||0)+"点固定伤害,无视勇士魔防。";case 23:return"重生:怪物被击败后,角色转换楼层则怪物将再次出现";default:break}return""};enemys.prototype.canBattle=function(b){var a=this.getDamage(b);return a!=null&&a=1;m--){var i=Math.ceil(f/m)+e;if(i<=b){break}if(i!=l){var j=this.getDamageInfo(g,core.status.hero.hp,i,core.status.hero.def,core.status.hero.mdef);if(j==null){break}d.push([i-b,c.damage-j.damage]);l=i}if(d.length>=k){break}}}else{l=c.damage;for(var a=b+1;a<=f+e;a++){var j=this.getDamageInfo(g,core.status.hero.hp,a,core.status.hero.def,core.status.hero.mdef);if(j==null){break}if(l>j.damage){l=j.damage;d.push([a-b,c.damage-j.damage]);if(d.length>=k){break}}}}if(d.length==0){d.push([0,0])}return d};enemys.prototype.getDefDamage=function(c,a){a=a||1;var b=core.material.enemys[c];var e=this.calDamage(b,core.status.hero.hp,core.status.hero.atk,core.status.hero.def,core.status.hero.mdef);var d=this.calDamage(b,core.status.hero.hp,core.status.hero.atk,core.status.hero.def+a,core.status.hero.mdef);if(e==null||d==null){return"???"}return e-d};enemys.prototype.getDamageInfo=function(l,e,c,d,f){if(typeof l=="string"){l=core.material.enemys[l]}var j=l.hp,h=l.atk,i=l.def,k=l.special;e=Math.max(0,e);c=Math.max(0,c);d=Math.max(0,d);f=Math.max(0,f);if(this.hasSpecial(k,20)&&!core.hasItem("cross")){return null}var g=0;if(this.hasSpecial(k,11)){var o=e*l.value;o=Math.floor(o)||0;if(l.add){j+=o}g+=o}if(this.hasSpecial(k,10)){h=c;i=d}if(this.hasSpecial(k,2)){d=0}if(this.hasSpecial(k,3)&&i=3){l="多属性..."}else{l=l.join(" ")}var c=this.nextCriticals(k);if(c.length>0){c=c[0]}d.push({id:k,name:j.name,hp:i,atk:g,def:h,money:j.money,experience:j.experience,point:j.point||0,special:l,damage:this.getDamage(k),critical:c[0],criticalDamage:c[1],defDamage:this.getDefDamage(k)});m[k]=true}}d.sort(function(n,o){if(n.damage==o.damage){return n.money-o.money}if(n.damage==null){return 1}if(o.damage==null){return -1}return n.damage-o.damage});return d}; \ No newline at end of file diff --git a/libs/events.min.js b/libs/events.min.js deleted file mode 100644 index 47ec006a..00000000 --- a/libs/events.min.js +++ /dev/null @@ -1 +0,0 @@ -function events(){this.init()}events.prototype.init=function(){this.eventdata=functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a.events;this.events={battle:function(c,b,a){b.battle(c.event.id,c.x,c.y);if(b.isset(a)){a()}},getItem:function(c,b,a){b.getItem(c.event.id,1,c.x,c.y);if(b.isset(a)){a()}},openDoor:function(c,b,a){b.openDoor(c.event.id,c.x,c.y,true,function(){if(b.isset(a)){a()}b.replay()})},changeFloor:function(c,b,a){var d={};if(b.isset(c.event.data.loc)){d={x:c.event.data.loc[0],y:c.event.data.loc[1]}}if(b.isset(c.event.data.direction)){d.direction=c.event.data.direction}b.changeFloor(c.event.data.floorId,c.event.data.stair,d,c.event.data.time,function(){if(b.isset(a)){a()}b.replay()})},passNet:function(c,b,a){b.events.passNet(c);if(b.isset(a)){a()}},changeLight:function(c,b,a){b.events.changeLight(c.x,c.y);if(b.isset(a)){a()}},ski:function(c,b,a){b.events.ski();if(b.isset(a)){a()}},pushBox:function(c,b,a){b.events.pushBox(c);if(b.isset(a)){a()}},action:function(c,b,a){b.events.insertAction(c.event.data,c.x,c.y,a)}}};events.prototype.getEvents=function(a){if(!core.isset(a)){return this.events}return this.events[a]};events.prototype.initGame=function(){return this.eventdata.initGame()};events.prototype.startGame=function(a){if(core.status.isStarting){return}core.status.isStarting=true;core.hideStartAnimate(function(){core.drawText(core.clone(core.firstData.startText),function(){if(core.flags.showBattleAnimateConfirm){core.status.event.selection=core.flags.battleAnimate?0:1;core.ui.drawConfirmBox("你想开启战斗动画吗?\n之后可以在菜单栏中开启或关闭。\n(强烈建议新手开启此项)",function(){core.flags.battleAnimate=true;core.setLocalStorage("battleAnimate",true);core.startGame(a);core.utils.__init_seed();core.events.setInitData(a)},function(){core.flags.battleAnimate=false;core.setLocalStorage("battleAnimate",false);core.startGame(a);core.utils.__init_seed();core.events.setInitData(a)})}else{core.startGame(a);core.utils.__init_seed();core.events.setInitData(a)}})})};events.prototype.setInitData=function(a){return this.eventdata.setInitData(a)};events.prototype.win=function(a){return this.eventdata.win(a)};events.prototype.lose=function(a){return this.eventdata.lose(a)};events.prototype.gameOver=function(c,d){core.clearMap("animate",0,0,416,416);core.dom.gif2.innerHTML="";core.clearMap("weather",0,0,416,416);core.animateFrame.weather.type=null;core.animateFrame.weather.level=0;core.animateFrame.weather.nodes=[];core.setFg(null,0);core.ui.closePanel();var a=function(){core.ui.closePanel();core.ui.drawConfirmBox("你想下载录像吗?",function(){var e={name:core.firstData.name,version:core.firstData.version,hard:core.status.hard,seed:core.getFlag("seed"),route:core.encodeRoute(core.status.route)};core.download(core.firstData.name+"_"+core.formatDate2(new Date())+".h5route",JSON.stringify(e));core.restart()},function(){core.restart()})};var b=function(){core.ui.closePanel();if(!core.isset(c)){a();return}var e=function(h){var g=core.status.hero.hp;if(h==undefined){g=1}var f=new FormData();f.append("type","score");f.append("name",core.firstData.name);f.append("version",core.firstData.version);f.append("platform",core.platform.isPC?"PC":core.platform.isAndroid?"Android":core.platform.isIOS?"iOS":"");f.append("hard",core.status.hard);f.append("username",h||"");f.append("ending",c);f.append("lv",core.status.hero.lv);f.append("hp",Math.min(g,Math.pow(2,63)));f.append("atk",core.status.hero.atk);f.append("def",core.status.hero.def);f.append("mdef",core.status.hero.mdef);f.append("money",core.status.hero.money);f.append("experience",core.status.hero.experience);f.append("steps",core.status.hero.steps);f.append("seed",core.getFlag("seed"));f.append("totalTime",Math.floor(core.status.hero.statistics.totalTime/1000));f.append("route",core.encodeRoute(core.status.route));if(main.isCompetition){core.http("POST","/games/competition/upload.php",f)}else{core.http("POST","/games/upload.php",f)}setTimeout(function(){a()},150)};core.ui.drawConfirmBox("你想记录你的ID和成绩吗?",function(){if(main.isCompetition){e("")}else{e(prompt("请输入你的ID:"))}},function(){if(main.isCompetition){a()}else{e(undefined)}});return};if(d){core.drawText("录像回放完毕!",function(){core.restart()})}else{if(core.isset(core.values.maxValidHp)&&core.status.hero.hp>core.values.maxValidHp){core.drawText("作弊可耻!",function(){core.restart()})}else{if(core.hasFlag("debug")){core.drawText("\t[系统提示]调试模式下无法上传成绩",function(){core.restart()})}else{b()}}}};events.prototype.afterChangeFloor=function(a){if(main.mode!="play"){return}return this.eventdata.afterChangeFloor(a)};events.prototype.doEvents=function(b,c,d,a){if(!core.isset(b)){return}if(!(b instanceof Array)){b=[b]}core.waitHeroToStop(function(){core.lockControl();core.status.event={id:"action",data:{list:[{todo:core.clone(b),total:core.clone(b),condition:"false"}],x:c,y:d,callback:a}};core.events.doAction()})};events.prototype.doAction=function(){core.status.boxAnimateObjs=[];clearInterval(core.status.event.interval);core.clearMap("ui",0,0,416,416);core.setAlpha("ui",1);if(core.status.event.data.list.length==0){var callback=core.status.event.data.callback;core.ui.closePanel();if(core.isset(callback)){callback()}core.replay();return}var current=core.status.event.data.list[0];if(current.todo.length==0){if(core.calValue(current.condition)){current.todo=core.clone(current.total)}else{core.status.event.data.list.shift()}this.doAction();return}var data=current.todo.shift();core.status.event.data.current=data;var x=core.status.event.data.x,y=core.status.event.data.y;if(typeof data=="string"){core.status.event.data.type="text";if(core.status.replay.replaying){core.events.doAction()}else{core.ui.drawTextBox(data)}return}core.status.event.data.type=data.type;switch(data.type){case"text":if(core.status.replay.replaying){core.events.doAction()}else{core.ui.drawTextBox(data.text)}break;case"autoText":if(core.status.replay.replaying){core.events.doAction()}else{core.ui.drawTextBox(data.text);setTimeout(function(){core.events.doAction()},data.time||3000)}break;case"setText":if(data.position=="up"||data.position=="down"||data.position=="center"){core.status.textAttribute.position=data.position}["background","title","text"].forEach(function(t){if(core.isset(data[t])&&(data[t] instanceof Array)&&data[t].length>=3){if(data[t].length==3){data[t].push(1)}core.status.textAttribute[t]=data[t]}});if(core.isset(data.bold)){core.status.textAttribute.bold=data.bold}if(core.isset(data.time)){core.status.textAttribute.time=data.time}core.events.doAction();break;case"tip":core.drawTip(core.replaceText(data.text));core.events.doAction();break;case"show":if(!core.isset(data.loc)){data.loc=[x,y]}if((typeof data.loc[0]=="number"||typeof data.loc[0]=="string")&&(typeof data.loc[1]=="number"||typeof data.loc[1]=="string")){data.loc=[[core.calValue(data.loc[0]),core.calValue(data.loc[1])]]}if(core.isset(data.time)&&data.time>0&&(!core.isset(data.floorId)||data.floorId==core.status.floorId)){core.animateBlock(data.loc,"show",data.time,function(){data.loc.forEach(function(t){core.showBlock(t[0],t[1],data.floorId)});core.events.doAction()})}else{data.loc.forEach(function(t){core.showBlock(t[0],t[1],data.floorId)});this.doAction()}break;case"hide":if(!core.isset(data.loc)){data.loc=[x,y]}if((typeof data.loc[0]=="number"||typeof data.loc[0]=="string")&&(typeof data.loc[1]=="number"||typeof data.loc[1]=="string")){data.loc=[[core.calValue(data.loc[0]),core.calValue(data.loc[1])]]}data.loc.forEach(function(t){core.removeBlock(t[0],t[1],data.floorId)});if(core.isset(data.time)&&data.time>0&&(!core.isset(data.floorId)||data.floorId==core.status.floorId)){core.animateBlock(data.loc,"hide",data.time,function(){core.events.doAction()})}else{this.doAction()}break;case"setBlock":if(core.isset(data.loc)){x=core.calValue(data.loc[0]);y=core.calValue(data.loc[1])}core.setBlock(data.number,x,y,data.floorId);this.doAction();break;case"animate":if(core.isset(data.loc)){if(data.loc=="hero"){x=core.getHeroLoc("x");y=core.getHeroLoc("y")}else{if(data.loc instanceof Array){x=core.calValue(data.loc[0]);y=core.calValue(data.loc[1])}}}core.drawAnimate(data.name,x,y,function(){core.events.doAction()});break;case"move":if(core.isset(data.loc)){x=core.calValue(data.loc[0]);y=core.calValue(data.loc[1])}core.moveBlock(x,y,data.steps,data.time,data.immediateHide,function(){core.events.doAction()});break;case"moveHero":core.eventMoveHero(data.steps,data.time,function(){core.events.doAction()});break;case"changeFloor":var heroLoc={x:core.calValue(data.loc[0]),y:core.calValue(data.loc[1])};if(core.isset(data.direction)){heroLoc.direction=data.direction}core.changeFloor(data.floorId||core.status.floorId,null,heroLoc,data.time,function(){core.lockControl();core.events.doAction()});break;case"changePos":core.clearMap("hero",0,0,416,416);if(core.isset(data.loc)){core.setHeroLoc("x",core.calValue(data.loc[0]));core.setHeroLoc("y",core.calValue(data.loc[1]))}if(core.isset(data.direction)){core.setHeroLoc("direction",data.direction)}core.drawHero();this.doAction();break;case"showImage":if(core.isset(data.loc)&&core.isset(core.material.images.images[data.name])){core.canvas.animate.drawImage(core.material.images.images[data.name],core.calValue(data.loc[0]),core.calValue(data.loc[1]))}else{core.clearMap("animate",0,0,416,416)}this.doAction();break;case"animateImage":if(core.status.replay.replaying){this.doAction()}else{if(core.isset(data.loc)&&core.isset(core.material.images.images[data.name])&&(data.action=="show"||data.action=="hide")){core.events.animateImage(data.action,core.material.images.images[data.name],data.loc,data.time,function(){core.events.doAction()})}else{this.doAction()}}break;case"showGif":if(core.isset(data.loc)&&core.isset(core.material.images.images[data.name])){var gif=new Image();gif.src=core.material.images.images[data.name].src;gif.style.position="absolute";gif.style.left=(core.calValue(data.loc[0])*core.domStyle.scale)+"px";gif.style.top=(core.calValue(data.loc[1])*core.domStyle.scale)+"px";core.dom.gif2.appendChild(gif)}else{core.dom.gif2.innerHTML=""}this.doAction();break;case"moveImage":if(core.status.replay.replaying){this.doAction()}else{if(core.isset(data.from)&&core.isset(data.to)&&core.isset(core.material.images.images[data.name])){core.events.moveImage(core.material.images.images[data.name],data.from,data.to,data.time,function(){core.events.doAction()})}else{this.doAction()}}break;case"setFg":core.setFg(data.color,data.time,function(){core.events.doAction()});break;case"setWeather":core.setWeather(data.name,data.level);this.doAction();break;case"openDoor":var floorId=data.floorId||core.status.floorId;var block=core.getBlock(core.calValue(data.loc[0]),core.calValue(data.loc[1]),floorId);if(block!=null){if(floorId==core.status.floorId){core.openDoor(block.block.event.id,block.block.x,block.block.y,false,function(){core.events.doAction()})}else{core.removeBlock(block.block.x,block.block.y,floorId);this.doAction()}break}this.doAction();break;case"openShop":if(core.status.replay.replaying){core.status.shops[data.id].visited=true;core.status.event.data.list=[];this.doAction()}else{core.events.openShop(data.id)}break;case"disableShop":core.events.disableQuickShop(data.id);this.doAction();break;case"battle":core.battle(data.id,null,null,true,function(){core.events.doAction()});break;case"trigger":var toX=core.calValue(data.loc[0]),toY=core.calValue(data.loc[1]);var block=core.getBlock(toX,toY);if(block!=null){block=block.block;if(core.isset(block.event)&&block.event.trigger=="action"){core.status.event.data.list=[{todo:core.clone(block.event.data),total:core.clone(block.event.data),condition:"false"}];core.status.event.data.x=block.x;core.status.event.data.y=block.y}}this.doAction();break;case"playSound":if(!core.status.replay.replaying){core.playSound(data.name)}this.doAction();break;case"playBgm":core.playBgm(data.name);this.doAction();break;case"pauseBgm":core.pauseBgm();this.doAction();break;case"resumeBgm":core.resumeBgm();this.doAction();break;case"setVolume":data.value=parseInt(data.value||0);if(data.value>100){data.value=100}data.value=data.value/100;core.musicStatus.volume=data.value;if(core.isset(core.musicStatus.playingBgm)){core.material.bgms[core.musicStatus.playingBgm].volume=data.value}core.musicStatus.gainNode.gain.value=data.value;this.doAction();break;case"setValue":try{var value=core.calValue(data.value);if(data.name.indexOf("status:")==0){value=parseFloat(value);core.setStatus(data.name.substring(7),value)}if(data.name.indexOf("item:")==0){value=parseInt(value);var itemId=data.name.substring(5);if(value>core.itemCount(itemId)){core.getItem(itemId,value-core.itemCount(itemId))}else{core.setItem(itemId,value)}}if(data.name.indexOf("flag:")==0){core.setFlag(data.name.substring(5),value)}}catch(e){console.log(e)}if(core.status.hero.hp<=0){core.status.hero.hp=0;core.updateStatusBar();core.events.lose()}else{core.updateStatusBar();this.doAction()}break;case"setHeroIcon":this.setHeroIcon(data.name);this.doAction();break;case"input":var value;if(core.status.replay.replaying){var action=core.status.replay.toReplay.shift();if(action.indexOf("input:")==0){value=parseInt(action.substring(6))}else{core.stopReplay();core.drawTip("录像文件出错");return}}else{core.interval.onDownInterval="tmp";value=prompt(core.replaceText(data.text))}value=Math.abs(parseInt(value)||0);core.status.route.push("input:"+value);core.setFlag("input",value);this.doAction();break;case"if":if(core.calValue(data.condition)){core.events.insertAction(data["true"])}else{core.events.insertAction(data["false"])}this.doAction();break;case"choices":if(core.status.replay.replaying){if(core.status.replay.toReplay.length==0){core.status.replay.replaying=false;core.drawTip("录像回放完毕")}else{var action=core.status.replay.toReplay.shift(),index;if(action.indexOf("choices:")==0&&((index=parseInt(action.substring(8)))>=0)&&index=10000){core.setFlag("type",1);core.setFlag("x",parseInt((value-10000)/100));core.setFlag("y",value%100)}else{core.setFlag("type",0);core.setFlag("keycode",value)}core.events.doAction()}else{core.stopReplay();core.drawTip("录像文件出错")}}break;case"revisit":var block=core.getBlock(x,y);if(block!=null){block=block.block;if(core.isset(block.event)&&block.event.trigger=="action"){core.status.event.data.list=[{todo:core.clone(block.event.data),total:core.clone(block.event.data),condition:"false"}]}}this.doAction();break;case"exit":core.status.event.data.list=[];core.events.doAction();break;default:core.status.event.data.type="text";core.ui.drawTextBox("\t[警告]出错啦!\n"+data.type+" 事件不被支持...")}return};events.prototype.insertAction=function(a,c,d,b){if(core.status.event.id==null){this.doEvents(a,c,d,b)}else{core.unshift(core.status.event.data.list[0].todo,a);if(core.isset(c)){core.status.event.data.x=c}if(core.isset(d)){core.status.event.data.y=d}if(core.isset(b)){core.status.event.data.callback=b}}};events.prototype.getNextItem=function(){if(!core.status.heroStop||!core.flags.enableGentleClick){return}var b=core.nextX(),c=core.nextY();var a=core.getBlock(b,c);if(a==null){return}if(a.block.event.trigger=="getItem"){core.getItem(a.block.event.id,1,b,c);core.status.route.push("getNext")}};events.prototype.getItem=function(d,e,f,g,a){core.playSound("item.mp3");var c=core.material.items[d].cls;core.items.getItemEffect(d,e);core.removeBlock(f,g);var h="获得 "+core.material.items[d].name;if(e>1){h+="x"+e}if(c==="items"){h+=core.items.getItemEffectTip(d)}core.drawTip(h,core.material.icons.items[d]);core.canvas.event.clearRect(f*32,g*32,32,32);core.updateStatusBar();var b=core.floors[core.status.floorId].afterGetItem[f+","+g];if(core.isset(b)){core.events.doEvents(b,f,g,a)}else{if(core.isset(a)){a()}}};events.prototype.openDoor=function(d,i,j,f,a){if(core.interval.openDoorAnimate!=null){return}if(!core.terrainExists(i,j,d)&&d!="lava"&&d!="star"){if(core.isset(a)){a()}return}if(core.status.automaticRoute.moveStepBeforeStop.length==0){core.status.automaticRoute.moveStepBeforeStop=core.status.automaticRoute.autoStepRoutes.slice(core.status.automaticRoute.autoStep-1,core.status.automaticRoute.autoStepRoutes.length);if(core.status.automaticRoute.moveStepBeforeStop.length>=1){core.status.automaticRoute.moveStepBeforeStop[0].step-=core.status.automaticRoute.movedStep}}core.stopAutomaticRoute();var g=30;var c=d;if(c.length<4||c.substring(c.length-4)!="Door"){c=c+"Door";g=70}if(!core.isset(core.material.icons.animates[c])){if(core.isset(a)){a()}return}var e=d.replace("Door","Key");if(f&&(e=="specialKey"||core.isset(core.material.items[e]))){var e=d.replace("Door","Key");if(!core.hasItem(e)){if(e!="specialKey"){core.drawTip("你没有"+core.material.items[e].name)}else{core.drawTip("无法开启此门")}core.clearContinueAutomaticRoute();return}core.autosave(true);core.removeItem(e)}core.playSound("door.mp3");var h=0;var b=core.material.icons.animates[c];core.status.replay.animate=true;core.removeGlobalAnimate(i,j);core.interval.openDoorAnimate=window.setInterval(function(){h++;if(h==4){clearInterval(core.interval.openDoorAnimate);core.interval.openDoorAnimate=null;core.removeBlock(i,j);core.status.replay.animate=false;core.events.afterOpenDoor(d,i,j,a);return}core.canvas.event.clearRect(32*i,32*j,32,32);core.canvas.event.drawImage(core.material.images.animates,32*h,32*b,32,32,32*i,32*j,32,32)},g/core.status.replay.speed)};events.prototype.battle=function(c,d,e,b,a){if(core.status.automaticRoute.moveStepBeforeStop.length==0){core.status.automaticRoute.moveStepBeforeStop=core.status.automaticRoute.autoStepRoutes.slice(core.status.automaticRoute.autoStep-1,core.status.automaticRoute.autoStepRoutes.length);if(core.status.automaticRoute.moveStepBeforeStop.length>=1){core.status.automaticRoute.moveStepBeforeStop[0].step-=core.status.automaticRoute.movedStep}}core.stopHero();core.stopAutomaticRoute();if(!core.enemys.canBattle(c)&&!b){core.drawTip("你打不过此怪物!");core.clearContinueAutomaticRoute();return}if(!core.isset(core.status.event.id)){core.autosave(true)}if(core.flags.battleAnimate&&!core.status.replay.replaying){core.waitHeroToStop(function(){core.ui.drawBattleAnimate(c,function(){core.events.afterBattle(c,d,e,a)})})}else{if(core.flags.equipment&&core.getFlag("sword","sword0")!="sword0"){core.playSound("zone.mp3");core.drawAnimate("sword",d,e)}else{core.playSound("attack.mp3");core.drawAnimate("hand",d,e)}core.events.afterBattle(c,d,e,a)}};events.prototype.trigger=function(g,h){var d=core.status.thisMap.blocks;var e;for(var a=0;a=1||e<=0){clearInterval(a);core.clearMap("data",0,0,416,416);core.setOpacity("data",1);core.status.replay.animate=false;if(core.isset(b)){b()}}},f/10)};events.prototype.moveImage=function(g,d,j,i,b){i=i||1000;clearInterval(core.interval.tipAnimate);core.setAlpha("data",1);core.setOpacity("data",1);core.status.replay.animate=true;var e=core.calValue(d[0]),f=core.calValue(d[1]),k=core.calValue(j[0]),l=core.calValue(j[1]);var h=0;var c=function(){core.clearMap("data",0,0,416,416);var m=parseInt(e+(k-e)*h/64);var n=parseInt(f+(l-f)*h/64);core.canvas.data.drawImage(g,m,n)};c();var a=setInterval(function(){h++;c();if(h>=64){clearInterval(a);core.clearMap("data",0,0,416,416);core.status.replay.animate=false;if(core.isset(b)){b()}}},i/64)};events.prototype.openShop=function(shopId,needVisited){var shop=core.status.shops[shopId];shop.times=shop.times||0;shop.visited=shop.visited||false;if(needVisited&&!shop.visited){if(shop.times==0){core.drawTip("该商店尚未开启")}else{core.drawTip("该商店已失效")}return}shop.visited=true;var selection=core.status.event.selection;var actions=[];if(core.isset(core.status.event.data)&&core.isset(core.status.event.data.actions)){actions=core.status.event.data.actions}var fromList;if(core.isset(core.status.event.data)&&core.isset(core.status.event.data.fromList)){fromList=core.status.event.data.fromList}core.ui.closePanel();core.lockControl();core.status.event.id="shop";core.status.event.data={id:shopId,shop:shop,actions:actions,fromList:fromList};core.status.event.selection=selection;var content="\t["+shop.name+","+shop.icon+"]";var times=shop.times,need=eval(shop.need);content=content+shop.text.replace(/\${([^}]+)}/g,function(word,value){return eval(value)});var use=shop.use=="experience"?"经验":"金币";var choices=[];for(var i=0;i=core.firstData.levelUp.length){return}var need=core.firstData.levelUp[core.status.hero.lv].need;if(!core.isset(need)){return}if(core.status.hero.experience>=need){core.status.hero.lv++;var effect=core.firstData.levelUp[core.status.hero.lv-1].effect;if(typeof effect=="string"){if(effect.indexOf("function")==0){eval("("+effect+")()")}else{effect.split(";").forEach(function(t){core.doEffect(t)})}}else{if(effect instanceof Function){effect()}}this.checkLvUp()}};events.prototype.useItem=function(b){core.ui.closePanel();if(b=="book"){core.openBook(false);return}if(b=="fly"){core.useFly(false);return}if(b=="centerFly"){core.status.usingCenterFly=true;var a="rgba(255,0,0,0.5)";if(core.canUseItem("centerFly")){a="rgba(0,255,0,0.5)"}core.fillRect("ui",(12-core.getHeroLoc("x"))*32,(12-core.getHeroLoc("y"))*32,32,32,a);core.drawTip("请确认当前中心对称飞行器的位置");return}if(core.canUseItem(b)){core.useItem(b)}else{core.drawTip("当前无法使用"+core.material.items[b].name)}};events.prototype.addPoint=function(a){return this.eventdata.addPoint(a)};events.prototype.afterBattle=function(b,c,d,a){return this.eventdata.afterBattle(b,c,d,a)};events.prototype.afterOpenDoor=function(b,c,d,a){return this.eventdata.afterOpenDoor(b,c,d,a)};events.prototype.passNet=function(a){if(core.hasItem("shoes")){return}if(a.event.id=="lavaNet"){}if(a.event.id=="poisonNet"){if(core.hasFlag("poison")){return}core.setFlag("poison",true)}if(a.event.id=="weakNet"){if(core.hasFlag("weak")){return}core.setFlag("weak",true);var d=core.values.weakValue;var b=d>=1?d:Math.floor(d*core.status.hero.atk);var c=d>=1?d:Math.floor(d*core.status.hero.def);core.setFlag("weakAtk",b);core.setFlag("weakDef",c);core.status.hero.atk-=b;core.status.hero.def-=c}if(a.event.id=="curseNet"){if(core.hasFlag("curse")){return}core.setFlag("curse",true)}core.updateStatusBar()};events.prototype.changeLight=function(c,d){var a=core.getBlock(c,d);if(a==null){return}var b=a.index;a=a.block;if(a.event.id!="light"){return}a.id=166;a.event={cls:"terrains",id:"darkLight",noPass:true};core.drawBlock(a);this.afterChangeLight(c,d)};events.prototype.afterChangeLight=function(a,b){return this.eventdata.afterChangeLight(a,b)};events.prototype.ski=function(a){if(!core.isset(a)){a=core.status.automaticRoute.lastDirection||core.getHeroLoc("direction")}if(core.status.event.id!="ski"){core.waitHeroToStop(function(){core.status.event.id="ski";core.events.ski(a)})}else{core.moveHero(a,function(){if(core.status.event.id=="ski"){core.status.event.id=null;core.unLockControl();core.replay()}})}};events.prototype.pushBox=function(b){if(b.event.id!="box"&&b.event.id!="boxed"){return}var f={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"),d=b.x+f[c].x,e=b.y+f[c].y;if(d<0||d>12||e<0||e>12){return}var a=core.getBlock(d,e,null,false);if(a!=null&&!(core.isset(a.block.event)&&a.block.event.id=="flower")){return}if(a==null){core.status.thisMap.blocks.push(core.maps.initBlock(d,e,169));a=core.getBlock(d,e)}else{a.block.id=170;a.block.event=core.maps.initBlock(null,null,170).event}core.drawBlock(a.block);if(b.event.id=="box"){core.removeBlock(b.x,b.y)}else{b.id=168;b.event=core.maps.initBlock(null,null,168).event;core.drawBlock(b)}core.updateStatusBar();core.status.replay.animate=true;core.moveHero(c,function(){core.status.replay.animate=false;core.status.route.pop();core.events.afterPushBox();core.replay()})};events.prototype.afterPushBox=function(){return this.eventdata.afterPushBox()};events.prototype.afterUseBomb=function(){return this.eventdata.afterUseBomb()};events.prototype.beforeSaveData=function(a){return this.eventdata.beforeSaveData(a)};events.prototype.afterLoadData=function(a){return this.eventdata.afterLoadData(a)}; \ No newline at end of file diff --git a/libs/icons.min.js b/libs/icons.min.js deleted file mode 100644 index 26e6b975..00000000 --- a/libs/icons.min.js +++ /dev/null @@ -1 +0,0 @@ -function icons(){this.init()}icons.prototype.init=function(){this.icons=icons_4665ee12_3a1f_44a4_bea3_0fccba634dc1};icons.prototype.getIcons=function(){return this.icons}; \ No newline at end of file diff --git a/libs/items.min.js b/libs/items.min.js deleted file mode 100644 index 807d8f3d..00000000 --- a/libs/items.min.js +++ /dev/null @@ -1 +0,0 @@ -function items(){this.init()}items.prototype.init=function(){this.items=items_296f5d02_12fd_4166_a7c1_b5e830c9ee3a.items;this.itemEffect=items_296f5d02_12fd_4166_a7c1_b5e830c9ee3a.itemEffect;this.itemEffectTip=items_296f5d02_12fd_4166_a7c1_b5e830c9ee3a.itemEffectTip;this.useItemEffect=items_296f5d02_12fd_4166_a7c1_b5e830c9ee3a.useItemEffect;this.canUseItemEffect=items_296f5d02_12fd_4166_a7c1_b5e830c9ee3a.canUseItemEffect};items.prototype.getItems=function(){return this.items};items.prototype.getItemEffect=function(itemId,itemNum){var itemCls=core.material.items[itemId].cls;if(itemCls==="items"){var ratio=parseInt(core.floors[core.status.floorId].item_ratio)||1;var curr_hp=core.status.hero.hp;if(itemId in this.itemEffect){eval(this.itemEffect[itemId])}core.status.hero.statistics.hp+=core.status.hero.hp-curr_hp}else{core.addItem(itemId,itemNum)}};items.prototype.getItemEffectTip=function(itemId){var itemCls=core.material.items[itemId].cls;if(itemCls==="items"){var ratio=parseInt(core.floors[core.status.floorId].item_ratio)||1;if(itemId in this.itemEffectTip){return eval(this.itemEffectTip[itemId])||""}}return""};items.prototype.useItem=function(itemId,callback){if(!this.canUseItem(itemId)){if(core.isset(callback)){callback()}return}var itemCls=core.material.items[itemId].cls;if(itemId in this.useItemEffect){eval(this.useItemEffect[itemId])}core.updateStatusBar();if(itemId!="book"&&itemId!="fly"){core.status.route.push("item:"+itemId)}if(itemCls=="tools"){core.status.hero.items[itemCls][itemId]--}if(core.status.hero.items[itemCls][itemId]==0){delete core.status.hero.items[itemCls][itemId]}if(core.isset(callback)){callback()}};items.prototype.canUseItem=function(itemId){if(!core.hasItem(itemId)){return false}if(itemId in this.canUseItemEffect){return eval(this.canUseItemEffect[itemId])}return false};items.prototype.itemCount=function(b){if(!core.isset(b)||!core.isset(core.material.items[b])){return 0}var a=core.material.items[b].cls;if(a=="items"){return 0}return core.isset(core.status.hero.items[a][b])?core.status.hero.items[a][b]:0};items.prototype.hasItem=function(a){return core.itemCount(a)>0};items.prototype.setItem=function(b,c){var a=core.material.items[b].cls;if(a=="items"){return}if(!core.isset(core.status.hero.items[a])){core.status.hero.items[a]={}}core.status.hero.items[a][b]=c;if(a!="keys"&&c==0){delete core.status.hero.items[a][b]}};items.prototype.removeItem=function(b){if(!core.hasItem(b)){return false}var a=core.material.items[b].cls;core.status.hero.items[a][b]--;if(a!="keys"&&core.status.hero.items[a][b]==0){delete core.status.hero.items[a][b]}core.updateStatusBar();return true};items.prototype.addItem=function(c,d){var b=core.material.items[c];var a=b.cls;if(a=="items"){return}if(!core.isset(core.status.hero.items[a])){core.status.hero.items[a]={};core.status.hero.items[a][c]=0}else{if(!core.isset(core.status.hero.items[a][c])){core.status.hero.items[a][c]=0}}core.status.hero.items[a][c]+=d}; \ No newline at end of file diff --git a/libs/loader.min.js b/libs/loader.min.js deleted file mode 100644 index 0d0576e9..00000000 --- a/libs/loader.min.js +++ /dev/null @@ -1 +0,0 @@ -function loader(){this.init()}loader.prototype.init=function(){};loader.prototype.setStartProgressVal=function(a){core.dom.startTopProgress.style.width=a+"%"};loader.prototype.setStartLoadTipText=function(a){core.dom.startTopLoadTips.innerHTML=a};loader.prototype.load=function(a){core.loader.loadIcons();core.loader.loadImages(core.materials,core.material.images,function(){core.material.images.images={};var b=core.clone(core.images);if(b.indexOf("hero.png")<0){b.push("hero.png")}core.loader.loadImages(b,core.material.images.images,function(){core.material.images.autotile={};core.loader.loadImages(Object.keys(core.material.icons.autotile),core.material.images.autotile,function(){core.loader.loadAnimates();core.loader.loadMusic();if(core.isset(a)){a()}})})})};loader.prototype.loadIcons=function(){this.loadImage("icons.png",function(a,b){var c=core.cropImage(b);for(var d in core.statusBar.icons){if(typeof core.statusBar.icons[d]=="number"){core.statusBar.icons[d]=c[core.statusBar.icons[d]];if(core.isset(core.statusBar.image[d])){core.statusBar.image[d].src=core.statusBar.icons[d].src}}}})};loader.prototype.loadImages=function(d,f,a){if(d.length==0){if(core.isset(a)){a()}return}var c=0;for(var b=0;b0){core.playBgm(core.bgms[0])}}; \ No newline at end of file diff --git a/libs/maps.min.js b/libs/maps.min.js deleted file mode 100644 index 44ad9e26..00000000 --- a/libs/maps.min.js +++ /dev/null @@ -1 +0,0 @@ -function maps(){this.init()}maps.prototype.init=function(){this.blocksInfo=maps_90f36752_8815_4be8_b32b_d7fad1d0542e};maps.prototype.loadFloor=function(c,d){var b=core.floors[c];var a={};a.floorId=b.floorId;a.name=b.name;a.title=b.title;a.canFlyTo=b.canFlyTo;if(!core.isset(d)){d=b.map}var e=function(m,n,h){var g=[];for(var k=0;k<13;k++){for(var l=0;l<13;l++){var f=n.initBlock(l,k,m[k][l]);n.addInfo(f);n.addEvent(f,l,k,h.events[l+","+k]);n.addChangeFloor(f,l,k,h.changeFloor[l+","+k]);if(core.isset(f.event)){g.push(f)}}}return g};if(main.mode=="editor"){main.editor.mapIntoBlocks=function(g,f){return e(g,core.maps,f)}}a.blocks=e(d,this,b);return a};maps.prototype.initBlock=function(d,e,b){var a=null;b=""+b;if(b.length>2){if(b.indexOf(":f")==b.length-2){b=b.substring(0,b.length-2);a=false}else{if(b.indexOf(":t")==b.length-2){b=b.substring(0,b.length-2);a=true}}}b=parseInt(b);var c={x:d,y:e,id:b};if(a!=null){c.enable=a}if(b in this.blocksInfo){c.event=JSON.parse(JSON.stringify(this.blocksInfo[b]))}return c};maps.prototype.addInfo=function(a){if(core.isset(a.event)){if(a.event.cls.indexOf("enemy")==0&&!core.isset(a.event.trigger)){a.event.trigger="battle"}if(a.event.cls=="items"&&!core.isset(a.event.trigger)){a.event.trigger="getItem"}if(!core.isset(a.event.noPass)){if(a.event.cls.indexOf("enemy")==0||a.event.cls.indexOf("npc")==0||a.event.cls=="terrains"){a.event.noPass=true}}if(!core.isset(a.event.animate)){if(a.event.cls=="enemys"||a.event.cls=="npcs"){a.event.animate=2}if(a.event.cls=="animates"||a.event.cls=="enemy48"||a.event.cls=="npc48"){a.event.animate=4}}a.event.height=32;if(a.event.cls=="enemy48"||a.event.cls=="npc48"){a.event.height=48}}};maps.prototype.addEvent=function(a,d,e,b){if(!core.isset(b)){return}if(!core.isset(a.event)){a.event={cls:"terrains",id:"none",noPass:false}}if(typeof b=="string"){b={data:[b]}}else{if(b instanceof Array){b={data:b}}}if(!core.isset(b.data)){b.data=[]}if(core.isset(b.noPass)){a.event.noPass=b.noPass}if(!core.isset(a.enable)&&core.isset(b.enable)){a.enable=b.enable}if(!core.isset(a.event.trigger)){if(core.isset(b.trigger)){a.event.trigger=b.trigger}else{a.event.trigger="action"}}else{if(core.isset(b.trigger)&&b.trigger!="checkBlock"){a.event.trigger=b.trigger}}for(var c in b){if(c!="enable"&&c!="trigger"&&c!="noPass"&&core.isset(b[c])){a.event[c]=core.clone(b[c])}}};maps.prototype.addChangeFloor=function(a,d,e,b,c){if(!core.isset(b)){return}this.addEvent(a,d,e,{trigger:"changeFloor",data:b},c)};maps.prototype.initMaps=function(b){var d={};for(var c=0;c=0){return false}}var h=core.getBlock(k,l,c);if(h!=null){nowId=h.block.event.id;var i=nowId.slice(0,5).toLowerCase()=="arrow";if(i){var g=nowId.slice(5).toLowerCase();if(b!=g){return false}}}var j={up:{x:0,y:-1},left:{x:-1,y:0},down:{x:0,y:1},right:{x:1,y:0}};var f=core.getBlock(k+j[b].x,l+j[b].y,c);if(f!=null){nextId=f.block.event.id;var d=nextId.slice(0,5).toLowerCase()=="arrow";if(d){var e=nextId.slice(5).toLowerCase();if((j[b].x+j[e].x)==0&&(j[b].y+j[e].y)==0){return false}}}return true};maps.prototype.canMoveDirectly=function(a,b){if(!core.flags.enableMoveDirectly){return 0}if(core.hasFlag("poison")){return 0}var e=core.getHeroLoc("x"),f=core.getHeroLoc("y");if(e==a&&f==b){return 0}if(core.getBlock(e,f)!=null||core.status.checkBlock.damage[13*e+f]>0){return 0}var m=[],l=[];m[13*e+f]=0;l.push(13*e+f);var d=[[-1,0],[1,0],[0,1],[0,-1]];while(l.length>0){var g=l.shift(),h=parseInt(g/13),i=g%13;for(var c in d){var j=h+d[c][0],k=i+d[c][1];if(j<0||j>=13||k<0||k>=13||m[13*j+k]||core.getBlock(j,k)!=null||core.status.checkBlock.damage[13*j+k]>0){continue}m[13*j+k]=m[13*h+i]+1;if(j==a&&k==b){return m[13*j+k]}l.push(13*j+k)}}return 0};maps.prototype.drawBlock=function(b,a,f,g){var e=b.event.cls,h=b.event.height||32;var c=core.material.icons[e][b.event.id];var d=core.material.images[e];a=(a||0)%(b.event.animate||1);f=f||0;g=g||0;core.canvas.event.clearRect(b.x*32+f,b.y*32+g,32,32);core.canvas.event.drawImage(d,a*32,c*h+h-32,32,32,b.x*32+f,b.y*32+g,32,32);if(h>32){core.canvas.event2.clearRect(b.x*32+f,b.y*32+32-h+g,32,h-32);core.canvas.event2.drawImage(d,a*32,c*h,32,h-32,b.x*32+f,b.y*32+32-h+g,32,h-32)}};maps.prototype.drawMap=function(d,a){core.clearMap("all");core.removeGlobalAnimate(null,null,true);var b=function(){var g=core.floors[d].defaultGround||"ground";var e=core.material.icons.terrains[g];var f=core.material.images.terrains;for(var i=0;i<13;i++){for(var j=0;j<13;j++){core.canvas.bg.drawImage(f,0,e*32,32,32,i*32,j*32,32,32)}}var h=[];if(core.isset(core.floors[d].images)){h=core.floors[d].images;if(typeof h=="string"){h=[[0,0,h]]}}h.forEach(function(s){var r=416,q=1;var k=parseInt(s[0]),l=parseInt(s[1]),o=s[2];if(core.isset(k)&&core.isset(l)&&core.isset(core.material.images.images[o])){k*=32;l*=32;var n=core.material.images.images[o];if(!s[3]){core.canvas.bg.drawImage(n,k*q,l*q,Math.min(r-k*q,q*n.width),Math.min(r-l*q,q*n.height));if(/.*\.gif/i.test(o)){core.dom.gif.innerHTML="";var m=new Image();m.src=core.material.images.images[o].src;m.style.position="absolute";m.style.left=(k*core.domStyle.scale)+"px";m.style.top=(l*core.domStyle.scale)+"px";core.dom.gif.appendChild(m)}}else{core.canvas.event2.drawImage(n,k*q,l*q,Math.min(r-k*q,q*n.width),Math.min(r-l*q,q*n.height))}}})};if(main.mode=="editor"){main.editor.drawMapBg=function(){core.clearMap("bg",0,0,416,416);b()}}else{b()}core.status.floorId=d;core.status.thisMap=core.status.maps[d];var c=function(){var i=core.status.maps[core.status.floorId];var h=i.blocks;var g=core.maps.getMapArray(h);for(var e=0;e12||u>12){return 1}else{return n[u][t]==i?1:0}};var b=function(F,G){var v=n[G][F];var E=[];for(var w=0;w<4;w++){var u=0;var C=w%2,D=~~(w/2);for(var z=0;z<4;z++){var A=z%2,B=~~(z/2);var t=g(v,F+C+A-1,G+D+B-1);u+=t*(Math.pow(2,3-z))}E.push(u)}return E};var h=function(z,A){var v=[];var w=b(z,A);for(var u=0;u<4;u++){var t=l[w[u]];v.push(t[3-u])}return v};var r=a.x,s=a.y;var o=h(r,s);if(o[0]==13){if(o[1]==16){o[1]=14}if(o[2]==31){o[2]=19}}if(o[1]==18){if(o[0]==15){o[0]=17}if(o[3]==36){o[3]=24}}if(o[2]==43){if(o[0]==25){o[0]=37}if(o[3]==46){o[3]=44}}if(o[3]==48){if(o[1]==30){o[1]=42}if(o[2]==45){o[2]=47}}for(var j=0;j<4;j++){var k=o[j];var e=r*p+p/2*(j%2),f=s*p+p/2*(~~(j/2));d(c,e+m,f+q,core.material.images.autotile[a.event.id],k,p)}};maps.prototype.noPassExists=function(c,d,b){var a=core.getBlock(c,d,b);if(a==null){return false}return core.isset(a.block.event.noPass)&&a.block.event.noPass};maps.prototype.noPass=function(a,b){return a<0||a>12||b<0||b>12||this.noPassExists(a,b)};maps.prototype.npcExists=function(c,d,b){var a=this.getBlock(c,d,b);if(a==null){return false}return a.block.event.cls.indexOf("npc")==0};maps.prototype.terrainExists=function(d,e,c,b){var a=this.getBlock(d,e,b);if(a==null){return false}return a.block.event.cls=="terrains"&&(core.isset(c)?a.block.event.id==c:true)};maps.prototype.stairExists=function(c,d,b){var a=this.getBlock(c,d,b);if(a==null){return false}return a.block.event.cls=="terrains"&&(a.block.event.id=="upFloor"||a.block.event.id=="downFloor")};maps.prototype.nearStair=function(){var a=core.getHeroLoc("x"),b=core.getHeroLoc("y");return this.stairExists(a,b)||this.stairExists(a-1,b)||this.stairExists(a,b-1)||this.stairExists(a+1,b)||this.stairExists(a,b+1)};maps.prototype.enemyExists=function(d,e,c,b){var a=this.getBlock(d,e,b);if(a==null){return false}return a.block.event.cls.indexOf("enemy")==0&&(core.isset(c)?a.block.event.id==c:true)};maps.prototype.getBlock=function(e,f,b,d){if(!core.isset(b)){b=core.status.floorId}if(!core.isset(d)){d=true}var a=core.status.maps[b].blocks;for(var c=0;c=core.values.animateSpeed){b++;c=0;if(b>=d){b=0}}if(k.length==0){if(j){n=0}else{n-=0.06}core.setOpacity("animate",n);core.clearMap("animate",l,m-i+32,32,i);core.canvas.animate.drawImage(g,b*32,f*i,32,i,l,m-i+32,32,i);if(n<=0){clearInterval(a);core.clearMap("animate",0,0,416,416);core.setOpacity("animate",1);core.status.replay.animate=false;if(core.isset(h)){h()}}}else{p++;l+=o[k[0]].x*2;m+=o[k[0]].y*2;core.clearMap("animate",l-32,m-32,96,96);core.canvas.animate.drawImage(g,b*32,f*i,32,i,l,m-i+32,32,i);if(p==16){p=0;k.shift()}}},r/16/core.status.replay.speed)};maps.prototype.animateBlock=function(e,h,g,b){if(h!="hide"){h="show"}core.clearMap("animate",0,0,416,416);if(typeof e[0]=="number"&&typeof e[1]=="number"){e=[e]}var d=[];e.forEach(function(j){var i=core.getBlock(j[0],j[1],core.status.floorId,false);if(i==null){return}i=i.block;d.push({x:j[0],y:j[1],height:i.event.height||32,blockIcon:core.material.icons[i.event.cls][i.event.id],blockImage:core.material.images[i.event.cls]})});if(d.length==0){if(core.isset(b)){b()}return}core.status.replay.animate=true;var c=function(){d.forEach(function(i){core.canvas.animate.drawImage(i.blockImage,0,i.blockIcon*i.height,32,i.height,i.x*32,i.y*32+32-i.height,32,i.height)})};var f=0;if(h=="hide"){f=1}core.setOpacity("animate",f);c();var a=window.setInterval(function(){if(h=="show"){f+=0.1}else{f-=0.1}core.setOpacity("animate",f);if(f>=1||f<=0){clearInterval(a);core.clearMap("animate",0,0,416,416);core.setOpacity("animate",1);core.status.replay.animate=false;if(core.isset(b)){b()}}},g/10/core.status.replay.speed)};maps.prototype.showBlock=function(c,d,b){b=b||core.status.floorId;var a=core.getBlock(c,d,b,false);if(a==null){return}a=a.block;if(core.isset(a.enable)&&!a.enable){a.enable=true;if(b==core.status.floorId&&core.isset(a.event)){core.drawBlock(a);core.addGlobalAnimate(a);core.syncGlobalAnimate()}core.updateStatusBar()}};maps.prototype.removeBlock=function(e,f,b){b=b||core.status.floorId;var a=core.getBlock(e,f,b,false);if(a==null){return}var d=a.index;if(b==core.status.floorId){core.removeGlobalAnimate(e,f);core.canvas.event.clearRect(e*32,f*32,32,32);var c=32;if(core.isset(a.block.event)){c=a.block.event.height||32}if(c>32){core.canvas.event2.clearRect(e*32,f*32+32-c,32,c-32)}}core.removeBlockById(d,b);core.updateStatusBar()};maps.prototype.removeBlockById=function(e,d){var b=core.status.maps[d].blocks,a=b[e];var g=a.x,h=a.y;var c=core.floors[d].events[g+","+h];if(!core.isset(c)){c=core.floors[d].changeFloor[g+","+h]}var f=false;if(core.isset(a.event)&&a.event.cls.indexOf("enemy")==0&&core.enemys.hasSpecial(core.material.enemys[a.event.id].special,23)){f=true}if(!f&&!core.isset(c)){b.splice(e,1);return}a.enable=false};maps.prototype.removeBlockByIds=function(a,b){b.sort(function(c,d){return d-c}).forEach(function(c){core.removeBlockById(c,a)})};maps.prototype.setBlock=function(c,e,f,b){b=b||core.status.floorId;if(!core.isset(c)||!core.isset(e)||!core.isset(f)){return}var d=core.getBlock(e,f,b,false);var a=core.maps.initBlock(e,f,c);core.maps.addInfo(a);core.maps.addEvent(a,e,f,core.floors[b].events[e+","+f]);core.maps.addChangeFloor(a,e,f,core.floors[b].changeFloor[e+","+f]);if(core.isset(a.event)){if(d==null){core.status.maps[b].blocks.push(a)}else{d.block.id=data.number;d.block.event=a.event}if(b==core.status.floorId){core.drawMap(b)}}};maps.prototype.addGlobalAnimate=function(a){if(main.mode=="editor"&&main.editor.disableGlobalAnimate){return}if(!core.isset(a.event)||!core.isset(a.event.animate)||a.event.animate==1){return}var c=core.clone(a);c.status=0;core.status.globalAnimateObjs.push(c)};maps.prototype.removeGlobalAnimate=function(c,d,a){if(main.mode=="editor"&&main.editor.disableGlobalAnimate){return}if(a){core.status.globalAnimateObjs=[];return}for(var b=0;b0.6||d<0){if(b){core.clearMap("data",5,5,400,a);core.setOpacity("data",1);clearInterval(core.interval.tipAnimate);return}else{if(!core.isset(core.timeout.getItemTipTimeout)){core.timeout.getItemTipTimeout=window.setTimeout(function(){b=true;core.timeout.getItemTipTimeout=null},750)}d=0.6;core.setOpacity("data",d)}}},30)};ui.prototype.drawText=function(b,a){if(core.isset(b)){if((core.isset(core.status.event)&&core.status.event.id=="action")||(core.isset(core.status.replay)&&core.status.replay.replaying)){core.insertAction(b,null,null,a);return}if(typeof b=="string"){b=[{content:b}]}else{if(b instanceof Object&&core.isset(b.content)){b=[b]}else{if(!(b instanceof Array)){core.drawTip("出错了");console.log(b);return}}}core.status.event={id:"text",data:{list:b,callback:a}};core.lockControl();core.stopAutomaticRoute();setTimeout(function(){core.drawText()},30);return}if(core.status.event.data.list.length==0){var a=core.status.event.data.callback;core.ui.closePanel(false);if(core.isset(a)){a()}return}var c=core.status.event.data.list.shift();if(typeof c=="string"){core.ui.drawTextBox(c)}else{core.ui.drawTextBox(c.content,c.id)}};ui.prototype.drawTextBox=function(c){clearInterval(core.status.event.interval);var n=null,r=null,o=null,l=null,m=32,a=null;if(c.indexOf("\t[")==0||c.indexOf("\\t[")==0){var p=c.indexOf("]");if(p>=0){var x=c.substring(2,p);if(c.indexOf("\\t[")==0){x=c.substring(3,p)}c=c.substring(p+1);var w=x.split(",");if(w.length==1){n=w[0];if(n!="hero"){if(core.isset(core.material.enemys[n])){r=core.material.enemys[n].name;if(core.isset(core.material.icons.enemy48[n])){o=core.material.images.enemy48;l=core.material.icons.enemy48[n];m=48;a=4}else{o=core.material.images.enemys;l=core.material.icons.enemys[n];m=32;a=2}}else{r=n;n="npc";o=null;l=null}}}else{n="npc";r=w[0];if(core.isset(core.material.icons.npc48[w[1]])){o=core.material.images.npc48;l=core.material.icons.npc48[w[1]];m=48;a=4}else{o=core.material.images.npcs;l=core.material.icons.npcs[w[1]];m=32;a=2}}}}var y=core.status.textAttribute||core.initStatus.textAttribute;var s=y.position,t=null,u=null,C=m-32;if(c.indexOf("\b[")==0||c.indexOf("\\b[")==0){var p=c.indexOf("]");if(p>=0){var x=c.substring(2,p);if(c.indexOf("\\b[")==0){x=c.substring(3,p)}c=c.substring(p+1);var w=x.split(",");if(w[0]=="up"||w[0]=="center"||w[0]=="down"){s=w[0];if(core.status.event.id=="action"){t=core.status.event.data.x;u=core.status.event.data.y}if(w.length>=2){if(w[1]=="hero"){t=core.getHeroLoc("x");u=core.getHeroLoc("y");C=core.material.icons.hero.height-32}else{if(w.length>=3){t=parseInt(w[1]);u=parseInt(w[2])}}}}}}c=core.replaceText(c);var b=core.canvas.ui.createPattern(core.material.ground,"repeat");core.status.boxAnimateObjs=[];core.clearMap("ui",0,0,416,416);var q=10,v=416-2*q;var d=q+25;if(n=="hero"||core.isset(l)){d=q+63}var A=v-(d-q)-13;var h="16px Verdana";if(y.bold){h="bold "+h}var f=core.splitLines("ui",c,A,h);var i=20+21*(f.length+1)+(n=="hero"?core.material.icons.hero.height-10:core.isset(r)?m-10:0);var B=6,D=22;var z;if(s=="center"){z=parseInt((416-i)/2)}else{if(s=="up"){if(t==null||u==null){z=5}else{z=32*u-i-C-D}}else{if(s=="down"){if(t==null||u==null){z=416-i-5}else{z=32*u+32+D}}}}core.setAlpha("ui",y.background[3]);core.setFillStyle("ui",core.arrayToRGB(y.background));core.setStrokeStyle("ui","#FFFFFF");core.fillRect("ui",q,z,v,i);core.strokeRect("ui",q-1,z-1,v+1,i+1,"#FFFFFF",2);var B=9;if(s=="up"&&core.isset(t)&&core.isset(u)){core.canvas.ui.clearRect(32*t+B,z+i-1,32-2*B,2);core.canvas.ui.beginPath();core.canvas.ui.moveTo(32*t+B-1,z+i-1);core.canvas.ui.lineTo(32*t+16,z+i+D-2);core.canvas.ui.lineTo(32*t+32-B+1,z+i-1);core.canvas.ui.moveTo(32*t+B-1,z+i-1);core.canvas.ui.closePath();core.canvas.ui.fill();core.drawLine("ui",32*t+B,z+i,32*t+16,z+i+D-2);core.drawLine("ui",32*t+32-B,z+i,32*t+16,z+i+D-2)}if(s=="down"&&core.isset(t)&&core.isset(u)){core.canvas.ui.clearRect(32*t+B,z-2,32-2*B,3);core.canvas.ui.beginPath();core.canvas.ui.moveTo(32*t+B-1,z+1);core.canvas.ui.lineTo(32*t+16-1,z-D+2);core.canvas.ui.lineTo(32*t+32-B-1,z+1);core.canvas.ui.moveTo(32*t+B-1,z+1);core.canvas.ui.closePath();core.canvas.ui.fill();core.drawLine("ui",32*t+B,z,32*t+16,z-D+2);core.drawLine("ui",32*t+32-B,z,32*t+16,z-D+2)}core.canvas.ui.textAlign="left";var e=z+35;if(core.isset(n)){e=z+57;core.setAlpha("ui",y.title[3]);core.setFillStyle("ui",core.arrayToRGB(y.title));core.setStrokeStyle("ui",core.arrayToRGB(y.title));if(n=="hero"){var j=core.material.icons.hero.height;core.strokeRect("ui",q+15-1,z+40-1,34,j+2,null,2);core.fillText("ui",core.status.hero.name,d,z+30,null,"bold 22px Verdana");core.clearMap("ui",q+15,z+40,32,j);core.fillRect("ui",q+15,z+40,32,j,b);var k=core.material.icons.hero.down;core.canvas.ui.drawImage(core.material.images.hero,k.stop*32,k.loc*j,32,j,q+15,z+40,32,j)}else{core.fillText("ui",r,d,z+30,null,"bold 22px Verdana");if(core.isset(l)){core.strokeRect("ui",q+15-1,z+40-1,34,m+2,null,2);core.status.boxAnimateObjs=[];core.status.boxAnimateObjs.push({bgx:q+15,bgy:z+40,bgWidth:32,bgHeight:m,x:q+15,y:z+40,height:m,animate:a,image:o,pos:l*m});core.drawBoxAnimate()}}}var g=function(E){core.clearMap("ui",d,e-18,A,z+i-e+10);core.setAlpha("ui",y.background[3]);core.setFillStyle("ui",core.arrayToRGB(y.background));core.fillRect("ui",d,e-18,A,z+i-e+10);core.setAlpha("ui",y.text[3]);core.setFillStyle("ui",core.arrayToRGB(y.text));var F=core.splitLines("ui",E,A,h);for(var G=0;G=0){var z=g.substring(2,t);g=g.substring(t+1);var y=z.split(",");if(y.length==1){r=y[0];if(r!="hero"){if(core.isset(core.material.enemys[r])){x=core.material.enemys[r].name;if(core.isset(core.material.icons.enemy48[r])){s=core.material.images.enemy48;p=core.material.icons.enemy48[r];q=48;a=4}else{s=core.material.images.enemys;p=core.material.icons.enemys[r];q=32;a=2}}else{x=r;r="npc";s=null;p=null}}}else{r="npc";x=y[0];if(core.isset(core.material.icons.npc48[y[1]])){s=core.material.images.npc48;p=core.material.icons.npc48[y[1]];q=48;a=4}else{s=core.material.images.npcs;p=core.material.icons.npcs[y[1]];q=32;a=2}}}}g=core.replaceText(g);if(r=="hero"||core.isset(p)){h=u+60}k=core.splitLines("ui",g,C-(h-u)-10,"bold 15px Verdana");var d=0;if(x!=null){d+=25}d+=k.length*20;l+=d}var B=c-l;core.fillRect("ui",u,B,C,l,b);core.strokeRect("ui",u-1,B-1,C+1,l+1,"#FFFFFF",2);if(core.isset(k)){var j=B+35;if(core.isset(r)){core.canvas.ui.textAlign="center";j=B+55;var A=u+C/2;if(r=="hero"||core.isset(p)){A+=22}if(r=="hero"){var m=core.material.icons.hero.height;core.strokeRect("ui",u+15-1,B+30-1,34,m+2,"#DDDDDD",2);core.fillText("ui",core.status.hero.name,A,B+27,"#FFD700","bold 19px Verdana");core.clearMap("ui",u+15,B+30,32,m);core.fillRect("ui",u+15,B+30,32,m,b);var n=core.material.icons.hero.down;core.canvas.ui.drawImage(core.material.images.hero,n.stop*32,n.loc*m,32,m,u+15,B+30,32,m)}else{core.fillText("ui",x,A,B+27,"#FFD700","bold 19px Verdana");if(core.isset(p)){core.strokeRect("ui",u+15-1,B+30-1,34,q+2,"#DDDDDD",2);core.status.boxAnimateObjs=[];core.status.boxAnimateObjs.push({bgx:u+15,bgy:B+30,bgWidth:32,bgHeight:q,x:u+15,y:B+30,height:q,animate:a,image:s,pos:p*q});core.drawBoxAnimate()}}}core.canvas.ui.textAlign="left";for(var o=0;o0){if(!core.isset(core.status.event.selection)){core.status.event.selection=0}while(core.status.event.selection<0){core.status.event.selection+=f.length}while(core.status.event.selection>=f.length){core.status.event.selection-=f.length}var v=core.canvas.ui.measureText(core.replaceText(f[core.status.event.selection].text||f[core.status.event.selection])).width;core.strokeRect("ui",208-v/2-5,e+32*core.status.event.selection-20,v+10,28,"#FFD700",2)}return};ui.prototype.drawConfirmBox=function(l,n,j){core.lockControl();core.status.event.id="confirmBox";core.status.event.data={yes:n,no:j};core.status.event.ui=l;if(!core.isset(core.status.event.selection)||core.status.event.selection>1){core.status.event.selection=1}if(core.status.event.selection<0){core.status.event.selection=0}var a=core.canvas.ui.createPattern(core.material.ground,"repeat");core.clearMap("ui",0,0,416,416);core.setAlpha("ui",1);core.setFillStyle("ui",a);core.setFont("ui","bold 19px Verdana");var c=l.split("\n");var g=c.length;var h=0;for(var d in c){h=Math.max(h,core.canvas.ui.measureText(c[d]).width)}var e=Math.min(208-40-parseInt(h/2),100);var m=140-(g-1)*30;var k=416-2*e,b=416-140-m;if(core.isPlaying()){core.fillRect("ui",e,m,k,b,a)}if(core.isPlaying()){core.strokeRect("ui",e-1,m-1,k+1,b+1,"#FFFFFF",2)}core.canvas.ui.textAlign="center";for(var d in c){core.fillText("ui",c[d],208,m+50+d*30,"#FFFFFF")}core.fillText("ui","确定",208-38,m+b-35,"#FFFFFF","bold 17px Verdana");core.fillText("ui","取消",208+38,m+b-35);var f=core.canvas.ui.measureText("确定").width;if(core.status.event.selection==0){core.strokeRect("ui",208-38-parseInt(f/2)-5,m+b-35-20,f+10,28,"#FFD700",2)}if(core.status.event.selection==1){core.strokeRect("ui",208+38-parseInt(f/2)-5,m+b-35-20,f+10,28,"#FFD700",2)}};ui.prototype.drawSwitchs=function(){core.status.event.id="switchs";var a=["背景音乐:"+(core.musicStatus.bgmStatus?"[ON]":"[OFF]"),"背景音效:"+(core.musicStatus.soundStatus?"[ON]":"[OFF]"),"战斗动画: "+(core.flags.battleAnimate?"[ON]":"[OFF]"),"怪物显伤: "+(core.flags.displayEnemyDamage?"[ON]":"[OFF]"),"临界显伤: "+(core.flags.displayCritical?"[ON]":"[OFF]"),"领域显伤: "+(core.flags.displayExtraDamage?"[ON]":"[OFF]"),"下载离线版本","返回主菜单"];this.drawChoices(null,a)};ui.prototype.drawSettings=function(){core.status.event.id="settings";this.drawChoices(null,["系统设置","快捷商店","浏览地图","同步存档","返回标题","数据统计","操作帮助","关于本塔","返回游戏"])};ui.prototype.drawQuickShop=function(){core.status.event.id="selectShop";var d=core.status.shops,c=Object.keys(d);var a=[];for(var b=0;b0){E-=h-C}if(E<0){E=0}core.clearMap("data",M,P+A+10,z,40);core.canvas.data.textAlign="left";core.fillText("data",E,M,P+A+10+26,"#DDDDDD","bold 16px Verdana");if(core.enemys.hasSpecial(G,8)){m-=Math.floor(core.values.counterAttack*h);if(m<0){l+=m;m=0}core.clearMap("data",w,P+A+10,z,40);core.canvas.data.textAlign="right";core.fillText("data",l,v,P+A+10+26,"#DDDDDD","bold 16px Verdana");if(core.flags.enableMDef){core.clearMap("data",w,P+A+10+3*x,z,40);core.fillText("data",m,v,P+A+10+26+3*x)}}}else{core.drawLine("data",u+A+6,P+A+n+(e-32)-6,u+A+e-6,P+A+6,"#FF0000",4);setTimeout(function(){core.clearMap("data",u+A,P+A,e,n+e-32)},250);var i=B-k;if(i<0){i=0}m-=i;if(m<0){l+=m;m=0}core.clearMap("data",w,P+A+10,z,40);core.canvas.data.textAlign="right";core.fillText("data",l,v,P+A+10+26,"#DDDDDD","bold 16px Verdana");if(core.flags.enableMDef){core.clearMap("data",w,P+A+10+3*x,z,40);core.fillText("data",m,v,P+A+10+26+3*x)}}Q++;if(Q>=R){Q=0}if(l<=0||E<=0){clearInterval(c);core.status.boxAnimateObjs=[];core.clearMap("ui",0,0,416,416);core.setAlpha("ui",1);core.clearMap("data",0,0,416,416);if(core.status.event.id=="battle"){core.unLockControl();core.status.event.id=null}if(core.isset(f)){f()}return}},500)};ui.prototype.drawWaiting=function(e){core.lockControl();core.status.event.id="waiting";var a=core.canvas.ui.createPattern(core.material.ground,"repeat");core.clearMap("ui",0,0,416,416);core.setAlpha("ui",1);core.setFillStyle("ui",a);core.setFont("ui","bold 17px Verdana");var f=core.canvas.ui.measureText(e).width;var d=Math.max(f+50,220);var c=208-parseInt(d/2),g=208-32-16,b=416-2*g;core.fillRect("ui",c,g,d,b,a);core.strokeRect("ui",c-1,g-1,d+1,b+1,"#FFFFFF",2);core.canvas.ui.textAlign="center";core.fillText("ui",e,208,g+56,"#FFFFFF")};ui.prototype.drawSyncSave=function(){core.status.event.id="syncSave";this.drawChoices(null,["同步存档到服务器","从服务器加载存档","存档至本地文件","从本地文件读档","下载当前录像","清空本地存档","返回主菜单"])};ui.prototype.drawSyncSelect=function(){core.status.event.id="syncSelect";this.drawChoices(null,["同步本地所有存档","只同步最新单存档","返回上级菜单"])};ui.prototype.drawLocalSaveSelect=function(){core.status.event.id="localSaveSelect";this.drawChoices(null,["下载所有存档","只下载最新单存档","返回上级菜单"])};ui.prototype.drawStorageRemove=function(){core.status.event.id="storageRemove";this.drawChoices(null,["清空全部塔的存档","只清空当前塔的存档","返回上级菜单"])};ui.prototype.drawReplay=function(){core.lockControl();core.status.event.id="replay";this.drawChoices(null,["从头回放录像","从存档开始回放","返回游戏"])};ui.prototype.drawPagination=function(b,c){core.setFont("ui","bold 15px Verdana");core.setFillStyle("ui","#DDDDDD");var a=core.canvas.ui.measureText(b+" / "+b).width;core.canvas.ui.textAlign="left";core.fillText("ui",b+" / "+c,parseInt((416-a)/2),403);core.canvas.ui.textAlign="center";if(b>1){core.fillText("ui","上一页",208-80,403)}if(b12){core.status.automaticRoute.cursorX=12}if(!core.isset(core.status.automaticRoute.cursorY)){core.status.automaticRoute.cursorY=core.getHeroLoc("y")}if(core.status.automaticRoute.cursorY<0){core.status.automaticRoute.cursorY=0}if(core.status.automaticRoute.cursorY>12){core.status.automaticRoute.cursorY=12}core.status.event.id="cursor";core.lockControl();core.clearMap("ui",0,0,416,416);core.setAlpha("ui",1);var a=4;core.strokeRect("ui",32*core.status.automaticRoute.cursorX+a/2,32*core.status.automaticRoute.cursorY+a/2,32-a,32-a,"#FFD700",a)};ui.prototype.drawBook=function(n){var j=core.enemys.getCurrentEnemys(core.floorIds[core.status.event.selection]);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);core.fillRect("ui",0,0,416,416);core.setAlpha("ui",0.6);core.setFillStyle("ui","#000000");core.fillRect("ui",0,0,416,416);core.setAlpha("ui",1);core.canvas.ui.textAlign="left";core.setFont("ui","bold 15px Verdana");if(j.length==0){core.fillText("ui","本层无怪物",83,222,"#999999","bold 50px Verdana");core.canvas.ui.textAlign="center";core.fillText("ui","返回游戏",370,403,"#DDDDDD","bold 15px Verdana");return}if(n<0){n=0}if(n>=j.length){n=j.length-1}var q=6;var p=parseInt(n/q)+1;var s=parseInt((j.length-1)/q)+1;core.status.event.data=n;var r=(p-1)*q,g=Math.min(p*q,j.length);j=j.slice(r,g);core.status.boxAnimateObjs=[];for(var m=0;m=core.status.hero.hp){d="#FF0000"}if(e<=0){d="#00FF00"}e=core.formatBigNumber(e)}core.fillText("ui",e,f,62*m+50,d,"bold 13px Verdana");core.canvas.ui.textAlign="left";core.fillText("ui","临界",165,62*m+68,"#DDDDDD","13px Verdana");core.fillText("ui",core.formatBigNumber(h.critical),195,62*m+68,"#DDDDDD","bold 13px Verdana");core.fillText("ui","减伤",255,62*m+68,"#DDDDDD","13px Verdana");core.fillText("ui",core.formatBigNumber(h.criticalDamage),285,62*m+68,"#DDDDDD","bold 13px Verdana");core.fillText("ui","1防",335,62*m+68,"#DDDDDD","13px Verdana");core.fillText("ui",core.formatBigNumber(h.defDamage),365,62*m+68,"#DDDDDD","bold 13px Verdana");if(n==r+m){core.strokeRect("ui",10,62*m+13,416-10*2,62,"#FFD700")}}core.drawBoxAnimate();this.drawPagination(p,s)};ui.prototype.drawBookDetail=function(n){var j=core.enemys.getCurrentEnemys(core.floorIds[core.status.event.selection]);if(j.length==0){return}if(n<0){n=0}if(n>=j.length){n=j.length-1}var g=j[n];var h=g.id;var l=core.enemys.getSpecialHint(core.material.enemys[h]);if(l.length==0){l.push("该怪物无特殊属性。")}l.push("");var f=core.enemys.nextCriticals(h,10).map(function(i){return i[0]+":"+i[1]});while(f[0]=="0:0"){f.shift()}l.push("临界表:"+JSON.stringify(f));var b=l.join("\n");core.status.event.id="book-detail";clearInterval(core.interval.tipAnimate);core.clearMap("data",0,0,416,416);core.setOpacity("data",1);var o=10,q=416-2*o;var c=o+25;var t=q-(c-o)-13;var e=core.splitLines("data",b,t,"16px Verdana");var k=416-10-Math.min(416-24*(e.length+1)-65,250);var s=(416-k)/2,a=k;core.setAlpha("data",0.9);core.fillRect("data",o,s,q,a,"#000000");core.setAlpha("data",1);core.strokeRect("data",o-1,s-1,q+1,a+1,"#FFFFFF",2);core.canvas.data.textAlign="left";core.fillText("data",g.name,c,s+30,"#FFD700","bold 22px Verdana");var d=s+57;for(var m=0;m=0){var u=r.substring(0,n+1);core.fillText("data",u,c,d,"#FF6A6A","bold 16px Verdana");var p=core.canvas.data.measureText(u).width;core.fillText("data",r.substring(n+1),c+p,d,"#FFFFFF","16px Verdana")}else{core.fillText("data",e[m],c,d,"#FFFFFF","16px Verdana")}d+=24}core.fillText("data","<点击任意位置继续>",270,s+k-13,"#CCCCCC","13px Verdana")};ui.prototype.drawFly=function(b){if(b<0){b=0}if(b>=core.status.hero.flyRange.length){b=core.status.hero.flyRange.length-1}core.status.event.data=b;var a=core.status.hero.flyRange[b];var c=core.status.maps[a].title;core.clearMap("ui",0,0,416,416);core.setAlpha("ui",0.85);core.fillRect("ui",0,0,416,416,"#000000");core.setAlpha("ui",1);core.canvas.ui.textAlign="center";core.fillText("ui","楼层跳跃",208,60,"#FFFFFF","bold 28px Verdana");core.fillText("ui","返回游戏",208,403,"#FFFFFF","bold 15px Verdana");core.fillText("ui",c,356,247,"#FFFFFF","bold 19px Verdana");if(b0){core.fillText("ui","▼",356,247+64,"#FFFFFF","17px Verdana")}core.strokeRect("ui",20,100,273,273,"#FFFFFF",2);this.drawThumbnail(a,"ui",core.status.maps[a].blocks,20,100,273)};ui.prototype.drawMaps=function(c){if(!core.isset(c)){c=core.floorIds.indexOf(core.status.floorId)}if(c<0){c=0}if(c>=core.floorIds.length){c=core.floorIds.length-1}core.lockControl();core.status.event.id="viewMaps";core.status.event.data=c;var a=core.floorIds[c];clearTimeout(core.interval.tipAnimate);core.clearMap("ui",0,0,416,416);core.setAlpha("ui",1);this.drawThumbnail(a,"ui",core.status.maps[a].blocks,0,0,416);core.clearMap("data",0,0,416,416);core.setOpacity("data",0.2);core.canvas.data.textAlign="left";core.setFont("data","16px Arial");var d=core.floors[a].title;var e=16,f=18,g=e+core.canvas.data.measureText(d).width+16,b=42;core.fillRect("data",5,5,g,b,"#000");core.setOpacity("data",0.5);core.fillText("data",d,e+5,f+15,"#fff")};ui.prototype.drawToolbox=function(f){var n=Object.keys(core.status.hero.items.tools).sort();var b=Object.keys(core.status.hero.items.constants).sort();if(!core.isset(f)){if(n.length>0){f=0}else{if(b.length>0){f=100}else{f=0}}}core.status.event.selection=f;var k;if(f<100){k=n[f]}else{k=b[f-100]}if(!core.hasItem(k)){k=null}core.status.event.data=k;core.clearMap("ui",0,0,416,416);core.setAlpha("ui",0.85);core.fillRect("ui",0,0,416,416,"#000000");core.setAlpha("ui",1);core.setFillStyle("ui","#DDDDDD");core.setStrokeStyle("ui","#DDDDDD");core.canvas.ui.lineWidth=2;core.canvas.ui.strokeWidth=2;core.canvas.ui.beginPath();core.canvas.ui.moveTo(0,130);core.canvas.ui.lineTo(416,130);core.canvas.ui.stroke();core.canvas.ui.beginPath();core.canvas.ui.moveTo(0,129);core.canvas.ui.lineTo(0,105);core.canvas.ui.lineTo(72,105);core.canvas.ui.lineTo(102,129);core.canvas.ui.fill();core.canvas.ui.beginPath();core.canvas.ui.moveTo(0,290);core.canvas.ui.lineTo(416,290);core.canvas.ui.stroke();core.canvas.ui.beginPath();core.canvas.ui.moveTo(0,289);core.canvas.ui.lineTo(0,265);core.canvas.ui.lineTo(72,265);core.canvas.ui.lineTo(102,289);core.canvas.ui.fill();core.canvas.ui.textAlign="left";core.fillText("ui","消耗道具",5,124,"#333333","bold 16px Verdana");core.fillText("ui","永久道具",5,284);if(core.isset(k)){var g=core.material.items[k];core.fillText("ui",g.name,10,32,"#FFD700","bold 20px Verdana");var l=g.text||"该道具暂无描述。";var j=core.splitLines("ui",l,406,"17px Verdana");core.fillText("ui",j[0],10,62,"#FFFFFF","17px Verdana");if(j.length==1){core.fillText("ui","<继续点击该道具即可进行使用>",10,89,"#CCCCCC","14px Verdana")}else{var h=l.substring(j[0].length);core.fillText("ui",h,10,89,"#FFFFFF","17px Verdana")}}core.canvas.ui.textAlign="right";var e=core.material.images.items;for(var c=0;c=e){h=e-1}if(g>5){g=5}d=10*h+g;core.status.event.data=d;core.clearMap("ui",0,0,416,416);core.setAlpha("ui",0.85);core.fillRect("ui",0,0,416,416,"#000000");core.setAlpha("ui",1);core.canvas.ui.textAlign="center";var l=416/6,j=118;var k="#FFD700";if(core.status.event.selection){k="#FF6A6A"}var f=core.status.event.id=="save"?"存档":core.status.event.id=="load"?"读档":core.status.event.id=="replayLoad"?"回放":"";for(var b=0;b<6;b++){var c=5*h+b;var a=core.getLocalStorage(b==0?"autoSave":"save"+c,null);if(b<3){core.fillText("ui",b==0?"自动存档":f+c,(2*b+1)*l,35,"#FFFFFF","bold 17px Verdana");core.strokeRect("ui",(2*b+1)*l-j/2,50,j,j,b==g?k:"#FFFFFF",b==g?6:2);if(core.isset(a)&&core.isset(a.floorId)){this.drawThumbnail(a.floorId,"ui",core.maps.load(a.maps,a.floorId).blocks,(2*b+1)*l-j/2,50,j,a.hero.loc,a.hero.flags.heroIcon||"hero.png");core.fillText("ui",core.formatDate(new Date(a.time)),(2*b+1)*l,65+j,"#FFFFFF","10px Verdana")}else{core.fillRect("ui",(2*b+1)*l-j/2,50,j,j,"#333333",2);core.fillText("ui","空",(2*b+1)*l,117,"#FFFFFF","bold 30px Verdana")}}else{core.fillText("ui",f+c,(2*b-5)*l,230,"#FFFFFF","bold 17px Verdana");core.strokeRect("ui",(2*b-5)*l-j/2,245,j,j,b==g?k:"#FFFFFF",b==g?6:2);if(core.isset(a)&&core.isset(a.floorId)){this.drawThumbnail(a.floorId,"ui",core.maps.load(a.maps,a.floorId).blocks,(2*b-5)*l-j/2,245,j,a.hero.loc,a.hero.flags.heroIcon||"hero.png");core.fillText("ui",core.formatDate(new Date(a.time)),(2*b-5)*l,260+j,"#FFFFFF","10px Verdana")}else{core.fillRect("ui",(2*b-5)*l-j/2,245,j,j,"#333333",2);core.fillText("ui","空",(2*b-5)*l,245+70,"#FFFFFF","bold 30px Verdana")}}}this.drawPagination(h+1,e);if(core.status.event.selection){core.setFillStyle("ui","#FF6A6A")}core.fillText("ui","删除模式",48,403)};ui.prototype.drawThumbnail=function(h,g,f,w,z,v,n,m){core.clearMap(g,w,z,v,v);var k=core.floors[h].defaultGround||"ground";var d=core.material.icons.terrains[k];var e=core.material.images.terrains;var t=v/13;for(var o=0;o<13;o++){for(var r=0;r<13;r++){core.canvas[g].drawImage(e,0,d*32,32,32,w+o*t,z+r*t,t,t)}}var q=[];if(core.isset(core.floors[h].images)){q=core.floors[h].images;if(typeof q=="string"){q=[[0,0,q]]}}q.forEach(function(A){var y=v/416;var b=parseInt(A[0]),i=parseInt(A[1]),x=A[2];if(core.isset(b)&&core.isset(i)&&!A[3]&&core.isset(core.material.images.images[x])){b*=32;i*=32;var j=core.material.images.images[x];core.canvas.ui.drawImage(j,w+b*y,z+i*y,Math.min(v-b*y,y*j.width),Math.min(v-i*y,y*j.height))}});var s=core.maps.getMapArray(f);for(var a in f){var c=f[a];if(core.isset(c.event)&&!(core.isset(c.enable)&&!c.enable)){if(c.event.cls=="autotile"){core.drawAutotile(core.canvas.ui,s,c,t,w,z)}else{if(c.event.id!="none"){var d=core.material.icons[c.event.cls][c.event.id];var e=core.material.images[c.event.cls];var l=c.event.height||32;core.canvas[g].drawImage(e,0,d*l,32,l,w+c.x*t,z+c.y*t+(t-t*l/32),t,t*l/32)}}}}if(core.isset(n)){if(!core.isset(core.material.images.images[m])){m="hero.png"}var p=core.material.icons.hero[n.direction];var l=core.material.images.images[m].height/4;var u=t*l/32;core.canvas[g].drawImage(core.material.images.images[m],p.stop*32,p.loc*l,32,l,w+t*n.x,z+t*n.y+t-u,t,u)}q.forEach(function(A){var y=v/416;var b=parseInt(A[0]),i=parseInt(A[1]),x=A[2];if(core.isset(b)&&core.isset(i)&&A[3]&&core.isset(core.material.images.images[x])){b*=32;i*=32;var j=core.material.images.images[x];core.canvas.ui.drawImage(j,w+b*y,z+i*y,Math.min(v-b*y,y*j.width),Math.min(v-i*y,y*j.height))}})};ui.prototype.drawKeyBoard=function(){core.lockControl();core.status.event.id="keyBoard";core.clearMap("ui",0,0,416,416);var c=16,g=48,f=416-2*c,b=416-2*g;var a=core.canvas.ui.createPattern(core.material.ground,"repeat");core.fillRect("ui",c,g,f,b,a);core.strokeRect("ui",c-1,g-1,f+1,b+1,"#FFFFFF",2);core.canvas.ui.textAlign="center";core.fillText("ui","虚拟键盘",208,g+35,"#FFD700","bold 22px Verdana");core.setFont("ui","17px Verdana");core.setFillStyle("ui","#FFFFFF");var e=128-9;var d=[["F1","F2","F3","F4","F5","F6","F7","F8","F9","10","11"],["1","2","3","4","5","6","7","8","9","0"],["Q","W","E","R","T","Y","U","I","O","P"],["A","S","D","F","G","H","J","K","L"],["Z","X","C","V","B","N","M"],["-","=","[","]","\\",";","'",",",".","/","`"],["ES","TA","CA","SH","CT","AL","SP","BS","EN","DE"]];d.forEach(function(j){for(var h=0;h0){var name="";if(key=="yellowDoor"){name="黄门"}else{if(key=="blueDoor"){name="蓝门"}else{if(key=="redDoor"){name="红门"}else{if(key=="steelDoor"){name="铁门"}else{name=core.material.items[key].name}}}}if(core.isset(name)){text+=name+value+"个;"}}});text+="\n\n";text+="共加生命值"+core.formatBigNumber(data.add.hp)+"点,攻击"+core.formatBigNumber(data.add.atk)+"点,防御"+core.formatBigNumber(data.add.def)+"点,魔防"+core.formatBigNumber(data.add.mdef)+"点。";return text};var formatTime=function(time){return core.setTwoDigits(parseInt(time/3600000))+":"+core.setTwoDigits(parseInt(time/60000)%60)+":"+core.setTwoDigits(parseInt(time/1000)%60)};var statistics=core.status.hero.statistics;core.drawText([getText("全塔",total),getText("当前",current),"当前总步数:"+core.status.hero.steps+",当前游戏时长:"+formatTime(statistics.currTime)+",总游戏时长"+formatTime(statistics.totalTime)+"。\n瞬间移动次数:"+statistics.moveDirectly+",共计少走"+statistics.ignoreSteps+"步。\n\n总计通过血瓶恢复生命值为"+core.formatBigNumber(statistics.hp)+"点。\n\n总计受到的伤害为"+core.formatBigNumber(statistics.battleDamage+statistics.poisonDamage+statistics.extraDamage)+",其中战斗伤害"+core.formatBigNumber(statistics.battleDamage)+"点"+(core.flags.enableDebuff?(",中毒伤害"+core.formatBigNumber(statistics.poisonDamage)+"点"):"")+",领域/夹击/阻击/血网伤害"+core.formatBigNumber(statistics.extraDamage)+"点。","\t[说明]1. 地图数据统计的效果仅模拟当前立刻获得该道具的效果。\n2. 不会计算“不可被浏览地图”的隐藏层的数据。\n3. 不会计算任何通过事件得到的道具(显示事件、改变图块、或直接增加道具等)。\n4. 在自定义道具(例如其他宝石)后,需在ui.js的drawStatistics中注册,不然不会进行统计。\n5. 所有统计信息仅供参考,如有错误,概不负责。"])};ui.prototype.drawAbout=function(){return this.uidata.drawAbout()};ui.prototype.drawHelp=function(){core.drawText(["\t[键盘快捷键列表][CTRL] 跳过对话\n[Z] 转向\n[X] 打开/关闭怪物手册\n[G] 打开/关闭楼层传送器\n[A] 读取自动存档(回退)\n[S/D] 打开/关闭存/读档页面\n[K] 打开/关闭快捷商店选择列表\n[T] 打开/关闭工具栏\n[ESC] 打开/关闭系统菜单\n[H] 打开帮助页面\n[R] 回放\n[SPACE] 轻按(仅在轻按开关打开时有效)\n[PgUp/PgDn] 浏览地图\n[1] 快捷使用破墙镐\n[2] 快捷使用炸弹/圣锤\n[3] 快捷使用中心对称飞行器","\t[鼠标操作]点状态栏中图标: 进行对应的操作\n点任意块: 寻路并移动\n点任意块并拖动: 指定寻路路线\n单击勇士: 转向\n双击勇士: 轻按(仅在轻按开关打开时有效)\n长按任意位置:跳过剧情对话或打开虚拟键盘\n"])}; \ No newline at end of file diff --git a/libs/utils.min.js b/libs/utils.min.js deleted file mode 100644 index dcf9c21d..00000000 --- a/libs/utils.min.js +++ /dev/null @@ -1 +0,0 @@ -function utils(){}utils.prototype.init=function(){};utils.prototype.replaceText=function(a){return a.replace(/\${([^}]+)}/g,function(c,b){return core.calValue(b)})};utils.prototype.calValue=function(value){if(typeof value=="number"){return value}if(value instanceof Function){return value()}value=value.replace(/status:([\w\d_]+)/g,"core.getStatus('$1')");value=value.replace(/item:([\w\d_]+)/g,"core.itemCount('$1')");value=value.replace(/flag:([\w\d_]+)/g,"core.getFlag('$1', 0)");return eval(value)};utils.prototype.splitLines=function(a,g,f,c){if(core.isset(c)){core.setFont(a,c)}var b=[];var e=0;for(var d=0;df){b.push(g.substring(e,d));e=d}}}}b.push(g.substring(e));return b};utils.prototype.unshift=function(c,d){if(!(c instanceof Array)||!core.isset(d)){return}if(d instanceof Array){core.clone(d).reverse().forEach(function(a){c.unshift(a)})}else{c.unshift(d)}return c};utils.prototype.setLocalStorage=function(b,c){try{localStorage.setItem(core.firstData.name+"_"+b,JSON.stringify(c));return true}catch(a){console.log(a);return false}};utils.prototype.getLocalStorage=function(b,a){var c=localStorage.getItem(core.firstData.name+"_"+b);if(core.isset(c)){return JSON.parse(c)}return a};utils.prototype.removeLocalStorage=function(a){localStorage.removeItem(core.firstData.name+"_"+a)};utils.prototype.clone=function(b){if(!core.isset(b)){return b}if(b instanceof Date){var a=new Date();a.setTime(b.getTime());return a}if(b instanceof Array){var a=[];for(var c in b){a[c]=core.clone(b[c])}return a}if(b instanceof Function){return b}if(b instanceof Object){var a={};for(var c in b){if(b.hasOwnProperty(c)){a[c]=core.clone(b[c])}}return a}return b};utils.prototype.cropImage=function(e,g){g=g||32;var b=document.createElement("canvas");var c=b.getContext("2d");b.width=g;b.height=g;var a=[];for(var d=0;d=10*e.val){var f=g/e.val;return b+f.toFixed(Math.max(0,Math.floor(4-Math.log10(f+1))))+e.c}}return b+g};utils.prototype.arrayToRGB=function(a){var d=parseInt(a[0])||0,c=parseInt(a[1])||0,b=parseInt(a[2])||0;if(d<0){d=0}if(b<0){b=0}if(c<0){c=0}if(d>255){d=255}if(b>255){b=255}if(c>255){c=255}return"#"+((1<<24)+(d<<16)+(c<<8)+b).toString(16).slice(1)};utils.prototype.encodeRoute=function(d){var a="";var c="",b=0;d.forEach(function(e){if(e=="up"||e=="down"||e=="left"||e=="right"){if(e!=c&&b>0){a+=c.substring(0,1).toUpperCase();if(b>1){a+=b}b=0}c=e;b++}else{if(b>0){a+=c.substring(0,1).toUpperCase();if(b>1){a+=b}b=0}if(e.indexOf("item:")==0){a+="I"+e.substring(5)+":"}else{if(e.indexOf("fly:")==0){a+="F"+e.substring(4)+":"}else{if(e.indexOf("choices:")==0){a+="C"+e.substring(8)}else{if(e.indexOf("shop:")==0){a+="S"+e.substring(5)}else{if(e=="turn"){a+="T"}else{if(e=="getNext"){a+="G"}else{if(e.indexOf("input:")==0){a+="P"+e.substring(6)}else{if(e=="no"){a+="N"}else{if(e.indexOf("move:")==0){a+="M"+e.substring(5)}else{if(e.indexOf("key:")==0){a+="K"+e.substring(4)}else{if(e.indexOf("random:")==0){a+="X"+e.substring(7)}}}}}}}}}}}}});if(b>0){a+=c.substring(0,1).toUpperCase();if(b>1){a+=b}}return a};utils.prototype.decodeRoute=function(j){if(!core.isset(j)){return j}var a=[],g=0;var d=function(c){var i="";while(g0){if(e.shift()!=f.shift()){return null}}return e};utils.prototype.__init_seed=function(){var a=new Date().getTime()%34834795+3534;a=this.__next_rand(a);a=this.__next_rand(a);a=this.__next_rand(a);core.setFlag("seed",a);core.setFlag("rand",a)};utils.prototype.__next_rand=function(a){a=(a%127773)*16807-~~(a/127773)*2836;a+=a<0?2147483647:0;return a};utils.prototype.rand=function(b){var c=core.getFlag("rand");c=this.__next_rand(c);core.setFlag("rand",c);var a=c/2147483647;if(core.isset(b)&&b>0){return Math.floor(a*b)}return a};utils.prototype.rand2=function(b){b=b||2147483648;var c;if(core.status.replay.replaying){var a=core.status.replay.toReplay.shift();if(a.indexOf("random:")==0){c=parseInt(a.substring(7))}else{core.stopReplay();core.drawTip("录像文件出错");return}}else{c=Math.floor(Math.random()*b)}core.status.route.push("random:"+c);return c};utils.prototype.readFile=function(c,a,b){core.platform.successCallback=c;core.platform.errorCallback=a;if(core.isset(window.jsinterface)){window.jsinterface.readFile();return}if(!core.platform.isOnline){alert("离线状态下不支持文件读取!");if(core.isset(a)){a()}return}if(core.platform.fileReader==null){alert("当前浏览器不支持FileReader!");if(core.isset(a)){a()}return}if(core.platform.fileInput==null){core.platform.fileInput=document.createElement("input");core.platform.fileInput.style.opacity=0;core.platform.fileInput.type="file";core.platform.fileInput.onchange=function(){var d=core.platform.fileInput.files;if(d.length==0){if(core.isset(core.platform.errorCallback)){core.platform.errorCallback()}return}if(!b){core.platform.fileReader.readAsText(core.platform.fileInput.files[0])}else{core.platform.fileReader.readAsDataURL(core.platform.fileInput.files[0])}core.platform.fileInput.value=""}}core.platform.fileInput.click()};utils.prototype.readFileContent=function(a){var c=null;if(a.slice(0,4)==="data"){if(core.isset(core.platform.successCallback)){core.platform.successCallback(a)}return}try{c=JSON.parse(a);if(core.isset(c)){if(core.isset(core.platform.successCallback)){core.platform.successCallback(c)}return}}catch(b){console.log(b)}alert("不是有效的JSON文件!");if(core.isset(core.platform.errorCallback)){core.platform.errorCallback()}};utils.prototype.download=function(d,b){if(core.isset(window.jsinterface)){window.jsinterface.download(d,b);return}if(!core.platform.isOnline){alert("离线状态下不支持下载操作!");return}if(core.platform.isIOS){alert("iOS平台下不支持下载操作!");return}if(!core.platform.isPC){if(!core.platform.isChrome||core.platform.isQQ||core.platform.isWeChat){if(core.copy(b)){alert("移动端只有Chrome浏览器支持直接下载文件!\n所有应下载内容已经复制到您的剪切板,请自行创建空白文件并粘贴。")}else{alert("该平台或浏览器暂不支持下载操作!")}return}}if(core.platform.isSafari){alert("你当前使用的是Safari浏览器,不支持直接下载文件。\n即将打开一个新窗口为应下载内容,请自行全选复制然后创建空白文件并粘贴。");var a=new Blob([b],{type:"text/plain;charset=utf-8"});var e=window.URL.createObjectURL(a);var f=window.open(e,"_blank");window.URL.revokeObjectURL(e);return}var a=new Blob([b],{type:"text/plain;charset=utf-8"});if(window.navigator.msSaveOrOpenBlob){window.navigator.msSaveBlob(a,d)}else{var e=window.URL.createObjectURL(a);var c=window.document.createElement("a");c.href=e;c.download=d;document.body.appendChild(c);c.click();document.body.removeChild(c);window.URL.revokeObjectURL(e)}};utils.prototype.copy=function(a){if(core.isset(window.jsinterface)){window.jsinterface.copy(filename,content);return true}if(!core.platform.supportCopy){return false}var d=document.createElement("textarea");d.style.position="fixed";d.style.top=0;d.style.left=0;d.style.width="2em";d.style.height="2em";d.style.padding=0;d.style.border="none";d.style.outline="none";d.style.boxShadow="none";d.style.background="transparent";d.value=a;document.body.appendChild(d);d.select();var c=false;try{c=document.execCommand("copy")}catch(b){c=false}document.body.removeChild(d);return c};utils.prototype.show=function(b,e,a){if(!core.isset(e)){b.style.display="block";return}b.style.display="block";if(main.mode!="play"){b.style.opacity=1;if(core.isset(a)){a()}return}b.style.opacity=0;var c=0;var d=window.setInterval(function(){c+=0.03;b.style.opacity=c;if(c>1){clearInterval(d);if(core.isset(a)){a()}}},e)};utils.prototype.hide=function(c,e,a){if(!core.isset(e)){c.style.display="none";return}if(main.mode!="play"){c.style.display="none";if(core.isset(a)){a()}return}var d=1;var b=window.setInterval(function(){d-=0.03;c.style.opacity=d;if(d<0){c.style.display="none";clearInterval(b);if(core.isset(a)){a()}}},e)};utils.prototype.http=function(f,g,b,e,a,c,d){var h=new XMLHttpRequest();h.open(f,g,true);if(core.isset(c)){h.overrideMimeType(c)}if(core.isset(d)){h.responseType=d}h.onload=function(i){if(h.status==200){if(core.isset(e)){e(h.response)}}else{if(core.isset(a)){a("HTTP "+h.status)}}};h.onabort=function(){if(core.isset(a)){a("Abort")}};h.ontimeout=function(){if(core.isset(a)){a("Timeout")}};h.onerror=function(){if(core.isset(a)){a("Error on Connection")}};if(core.isset(b)){h.send(b)}else{h.send()}}; \ No newline at end of file diff --git a/main.js b/main.js index 6a89dd6d..4892caa0 100644 --- a/main.js +++ b/main.js @@ -1,536 +1,536 @@ -function main() { - - //------------------------ 用户修改内容 ------------------------// - - this.version = "2.2"; // 游戏版本号;如果更改了游戏内容建议修改此version以免造成缓存问题。 - - this.useCompress = false; // 是否使用压缩文件 - // 当你即将发布你的塔时,请使用“JS代码压缩工具”将所有js代码进行压缩,然后将这里的useCompress改为true。 - // 请注意,只有useCompress是false时才会读取floors目录下的文件,为true时会直接读取libs目录下的floors.min.js文件。 - // 如果要进行剧本的修改请务必将其改成false。 - - this.bgmRemote = false; // 是否采用远程BGM - this.bgmRemoteRoot = "https://gitee.com/ckcz123/h5music/raw/master/"; // 远程BGM的根目录 - - this.isCompetition = false; // 是否是比赛模式 - - this.savePages = 30; // 存档页数,每页可存5个;默认为30页150个存档 - - //------------------------ 用户修改内容 END ------------------------// - - this.dom = { - 'body': document.body, - 'gameGroup': document.getElementById('gameGroup'), - 'mainTips': document.getElementById('mainTips'), - 'musicBtn': document.getElementById('musicBtn'), - 'startPanel': document.getElementById('startPanel'), - 'startTop': document.getElementById('startTop'), - 'startTopProgressBar': document.getElementById('startTopProgressBar'), - 'startTopProgress': document.getElementById('startTopProgress'), - 'startTopLoadTips': document.getElementById('startTopLoadTips'), - 'startBackground': document.getElementById('startBackground'), - 'startLogo': document.getElementById('startLogo'), - 'startButtonGroup': document.getElementById('startButtonGroup'), - 'floorMsgGroup': document.getElementById('floorMsgGroup'), - 'logoLabel': document.getElementById('logoLabel'), - 'versionLabel': document.getElementById('versionLabel'), - 'floorNameLabel': document.getElementById('floorNameLabel'), - 'statusBar': document.getElementById('statusBar'), - 'status': document.getElementsByClassName('status'), - 'toolBar': document.getElementById('toolBar'), - 'tools': document.getElementsByClassName('tools'), - 'gameCanvas': document.getElementsByClassName('gameCanvas'), - 'gif': document.getElementById('gif'), - 'gif2': document.getElementById('gif2'), - 'curtain': document.getElementById('curtain'), - 'startButtons': document.getElementById('startButtons'), - 'playGame': document.getElementById('playGame'), - 'loadGame': document.getElementById('loadGame'), - 'replayGame': document.getElementById('replayGame'), - 'levelChooseButtons': document.getElementById('levelChooseButtons'), - 'data': document.getElementById('data'), - 'statusLabels': document.getElementsByClassName('statusLabel'), - 'floorCol': document.getElementById('floorCol'), - 'lvCol': document.getElementById('lvCol'), - 'hpmaxCol': document.getElementById('hpmaxCol'), - 'mdefCol': document.getElementById('mdefCol'), - 'moneyCol': document.getElementById('moneyCol'), - 'expCol': document.getElementById('expCol'), - 'upCol': document.getElementById('upCol'), - 'keyCol': document.getElementById('keyCol'), - 'debuffCol': document.getElementById('debuffCol'), - 'hard': document.getElementById('hard'), - }; - this.mode = 'play'; - this.loadList = [ - 'loader', 'control', 'utils', 'items', 'icons', 'maps', 'enemys', 'events', 'actions', 'data', 'ui', 'core' - ]; - this.pureData = [ - "data","enemys","icons","maps","items","functions" - ]; - this.materials = [ - 'animates', 'enemys', 'hero', 'items', 'npcs', 'terrains', 'enemy48', 'npc48' - ]; - - this.statusBar = { - 'image': { - 'floor': document.getElementById('img-floor'), - 'lv': document.getElementById('img-lv'), - 'hpmax': document.getElementById('img-hpmax'), - 'hp': document.getElementById("img-hp"), - 'atk': document.getElementById("img-atk"), - 'def': document.getElementById("img-def"), - 'mdef': document.getElementById("img-mdef"), - 'money': document.getElementById("img-money"), - 'experience': document.getElementById("img-experience"), - 'up': document.getElementById("img-up"), - 'book': document.getElementById("img-book"), - 'fly': document.getElementById("img-fly"), - 'toolbox': document.getElementById("img-toolbox"), - 'shop': document.getElementById("img-shop"), - 'save': document.getElementById("img-save"), - 'load': document.getElementById("img-load"), - 'settings': document.getElementById("img-settings") - }, - 'icons': { - 'floor': 0, - 'lv': 1, - 'hpmax': 2, - 'hp': 3, - 'atk': 4, - 'def': 5, - 'mdef': 6, - 'money': 7, - 'experience': 8, - 'up': 9, - 'book': 10, - 'fly': 11, - 'toolbox': 12, - 'shop': 13, - 'save': 14, - 'load': 15, - 'settings': 16, - 'play': 17, - 'pause': 18, - 'stop': 19, - 'speedDown': 20, - 'speedUp': 21, - 'rewind': 22, - }, - 'floor': document.getElementById('floor'), - 'lv': document.getElementById('lv'), - 'hpmax': document.getElementById('hpmax'), - 'hp': document.getElementById('hp'), - 'atk': document.getElementById('atk'), - 'def': document.getElementById("def"), - 'mdef': document.getElementById('mdef'), - 'money': document.getElementById("money"), - 'experience': document.getElementById("experience"), - 'up': document.getElementById('up'), - 'yellowKey': document.getElementById("yellowKey"), - 'blueKey': document.getElementById("blueKey"), - 'redKey': document.getElementById("redKey"), - 'poison': document.getElementById('poison'), - 'weak':document.getElementById('weak'), - 'curse': document.getElementById('curse'), - 'hard': document.getElementById("hard") - } - this.floors = {} - this.canvas = {}; -} - -main.prototype.init = function (mode, callback) { - for (var i = 0; i < main.dom.gameCanvas.length; i++) { - main.canvas[main.dom.gameCanvas[i].id] = main.dom.gameCanvas[i].getContext('2d'); - } - if (({"editor":0}).hasOwnProperty(mode)) { - main.mode = mode; - if (mode === 'editor')main.editor = {'disableGlobalAnimate':true}; - } - - main.loaderJs('project', main.pureData, function(){ - var mainData = data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d.main; - for(var ii in mainData)main[ii]=mainData[ii]; - - main.dom.startBackground.src="project/images/"+main.startBackground; - main.dom.startLogo.style=main.startLogoStyle; - main.levelChoose.forEach(function(value){ - var span = document.createElement('span'); - span.setAttribute('class','startButton'); - span.innerText=value[0]; - (function(span,str_){ - span.onclick = function () { - core.events.startGame(str_); - } - })(span,value[1]); - main.dom.levelChooseButtons.appendChild(span); - }); - - main.loaderJs('libs', main.loadList, function () { - main.core = core; - - for (i = 0; i < main.loadList.length; i++) { - var name = main.loadList[i]; - if (name === 'core') continue; - main.core[name] = new (eval(name))(); - } - - main.loaderFloors(function() { - var coreData = {}; - ["dom", "statusBar", "canvas", "images", "materials", - "animates", "bgms", "sounds", "floorIds", "floors"].forEach(function (t) { - coreData[t] = main[t]; - }) - main.core.init(coreData, callback); - main.core.resize(main.dom.body.clientWidth, main.dom.body.clientHeight); - }); - }); - }); -} - -////// 动态加载所有核心JS文件 ////// -main.prototype.loaderJs = function (dir, loadList, callback) { - - // 加载js - main.setMainTipsText('正在加载核心js文件...') - - if (this.useCompress) { - main.loadMod(dir, dir, function () { - callback(); - }) - } - else { - var instanceNum = 0; - for (var i = 0; i < loadList.length; i++) { - main.loadMod(dir, loadList[i], function (modName) { - main.setMainTipsText(modName + '.js 加载完毕'); - instanceNum++; - if (instanceNum === loadList.length) { - callback(); - } - }); - } - } -} - -////// 加载某一个JS文件 ////// -main.prototype.loadMod = function (dir, modName, callback) { - var script = document.createElement('script'); - var name = modName; - script.src = dir + '/' + modName + (this.useCompress?".min":"") + '.js?v=' + this.version; - main.dom.body.appendChild(script); - script.onload = function () { - callback(name); - } -} - -////// 动态加载所有楼层(剧本) ////// -main.prototype.loaderFloors = function (callback) { - - // 加载js - main.setMainTipsText('正在加载楼层文件...') - if (this.useCompress) { // 读取压缩文件 - var script = document.createElement('script'); - script.src = 'project/floors.min.js?v=' + this.version; - main.dom.body.appendChild(script); - script.onload = function () { - main.dom.mainTips.style.display = 'none'; - callback(); - } - } - else { - for (var i = 0; i < main.floorIds.length; i++) { - main.loadFloor(main.floorIds[i], function (modName) { - main.setMainTipsText("楼层 " + modName + '.js 加载完毕'); - if (Object.keys(main.floors).length === main.floorIds.length) { - main.dom.mainTips.style.display = 'none'; - callback(); - } - }); - } - } -} - -////// 加载某一个楼层 ////// -main.prototype.loadFloor = function(floorId, callback) { - var script = document.createElement('script'); - script.src = 'project/floors/' + floorId +'.js?v=' + this.version; - main.dom.body.appendChild(script); - script.onload = function () { - callback(floorId); - } -} - -////// 加载过程提示 ////// -main.prototype.setMainTipsText = function (text) { - main.dom.mainTips.innerHTML = text; -} - - -main.prototype.listen = function () { - -////// 窗口大小变化时 ////// -window.onresize = function () { - try { - main.core.resize(main.dom.body.clientWidth, main.dom.body.clientHeight); - }catch (e) {} -} - -////// 在界面上按下某按键时 ////// -main.dom.body.onkeydown = function(e) { - try { - if (main.core.isPlaying() || main.core.status.lockControl) - main.core.onkeyDown(e); - } catch (ee) {} -} - -////// 在界面上放开某按键时 ////// -main.dom.body.onkeyup = function(e) { - try { - if (main.core.isPlaying() || main.core.status.lockControl) - main.core.onkeyUp(e); - } catch (ee) {} -} - -////// 开始选择时 ////// -main.dom.body.onselectstart = function () { - return false; -} - -////// 鼠标按下时 ////// -main.dom.data.onmousedown = function (e) { - try { - e.stopPropagation(); - if(e.button==1){// 把鼠标中键绑定为ESC - core.keyUp(27); - return; - } - var loc = main.core.getClickLoc(e.clientX, e.clientY); - if (loc == null) return; - var x = parseInt(loc.x / loc.size), y = parseInt(loc.y / loc.size); - main.core.ondown(x, y); - } catch (ee) {} -} - -////// 鼠标移动时 ////// -main.dom.data.onmousemove = function (e) { - try { - e.stopPropagation(); - var loc = main.core.getClickLoc(e.clientX, e.clientY); - if (loc == null) return; - var x = parseInt(loc.x / loc.size), y = parseInt(loc.y / loc.size); - main.core.onmove(x, y); - }catch (ee) {} -} - -////// 鼠标放开时 ////// -main.dom.data.onmouseup = function () { - try { - main.core.onup(); - }catch (e) {} -} - -////// 鼠标滑轮滚动时 ////// -main.dom.data.onmousewheel = function(e) { - try { - if (e.wheelDelta) - main.core.onmousewheel(Math.sign(e.wheelDelta)) - else if (e.detail) - main.core.onmousewheel(Math.sign(e.detail)); - } catch (ee) {} -} - -////// 手指在触摸屏开始触摸时 ////// -main.dom.data.ontouchstart = function (e) { - try { - e.preventDefault(); - var loc = main.core.getClickLoc(e.targetTouches[0].clientX, e.targetTouches[0].clientY); - if (loc == null) return; - var x = parseInt(loc.x / loc.size), y = parseInt(loc.y / loc.size); - //main.core.onclick(x, y, []); - main.core.ondown(x, y); - }catch (ee) {} -} - -////// 手指在触摸屏上移动时 ////// -main.dom.data.ontouchmove = function (e) { - try { - e.preventDefault(); - var loc = main.core.getClickLoc(e.targetTouches[0].clientX, e.targetTouches[0].clientY); - if (loc == null) return; - var x = parseInt(loc.x / loc.size), y = parseInt(loc.y / loc.size); - main.core.onmove(x, y); - }catch (ee) {} -} - -////// 手指离开触摸屏时 ////// -main.dom.data.ontouchend = function () { - try { - main.core.onup(); - } catch (e) { - } -} - -////// 点击状态栏中的怪物手册时 ////// -main.statusBar.image.book.onclick = function () { - if (core.isset(core.status.replay) && core.status.replay.replaying) { - core.triggerReplay(); - return; - } - - if (main.core.isPlaying()) - main.core.openBook(true); -} - -////// 点击状态栏中的楼层传送器时 ////// -main.statusBar.image.fly.onclick = function () { - - if (core.isset(core.status.replay) && core.status.replay.replaying) { - core.stopReplay(); - return; - } - - if (main.core.isPlaying()) - main.core.useFly(true); -} - -////// 点击状态栏中的工具箱时 ////// -main.statusBar.image.toolbox.onclick = function () { - - if (core.isset(core.status.replay) && core.status.replay.replaying) { - core.rewindReplay(); - return; - } - - if (main.core.isPlaying()) - main.core.openToolbox(true); -} - -////// 点击状态栏中的快捷商店时 ////// -main.statusBar.image.shop.onclick = function () { - - if (core.isset(core.status.replay) && core.status.replay.replaying) { - core.bookReplay(); - return; - } - - if (main.core.isPlaying()) - main.core.openQuickShop(true); -} - -////// 点击状态栏中的存档按钮时 ////// -main.statusBar.image.save.onclick = function () { - - if (core.isset(core.status.replay) && core.status.replay.replaying) { - core.speedDownReplay(); - return; - } - - if (main.core.isPlaying()) - main.core.save(true); -} - -////// 点击状态栏中的读档按钮时 ////// -main.statusBar.image.load.onclick = function () { - - if (core.isset(core.status.replay) && core.status.replay.replaying) { - core.speedUpReplay(); - return; - } - - if (main.core.isPlaying()) - main.core.load(true); -} - -////// 点击状态栏中的系统菜单时 ////// -main.statusBar.image.settings.onclick = function () { - - if (core.isset(core.status.replay) && core.status.replay.replaying) { - core.saveReplay(); - return; - } - - if (main.core.isPlaying()) - main.core.openSettings(true); -} - -////// 点击“开始游戏”时 ////// -main.dom.playGame.onclick = function () { - main.dom.startButtons.style.display='none'; - - if (main.core.isset(main.core.musicStatus) && main.core.musicStatus.startDirectly - && main.core.musicStatus.bgmStatus) { - if (main.core.musicStatus.playingBgm==null - || core.material.bgms[main.core.musicStatus.playingBgm].paused) { - main.core.musicStatus.playingBgm=null; - main.core.playBgm(main.core.bgms[0]); - } - } - - if (main.core.isset(main.core.flags.startDirectly) && main.core.flags.startDirectly) { - core.events.startGame(""); - } - else { - main.dom.levelChooseButtons.style.display='block'; - } -} - -////// 点击“载入游戏”时 ////// -main.dom.loadGame.onclick = function() { - - if (main.core.isset(main.core.musicStatus) && main.core.musicStatus.startDirectly - && main.core.musicStatus.bgmStatus) { - if (main.core.musicStatus.playingBgm==null - || core.material.bgms[main.core.musicStatus.playingBgm].paused) { - main.core.musicStatus.playingBgm=null; - main.core.playBgm(main.core.bgms[0]); - } - } - - main.core.load(); -} - -////// 点击“录像回放”时 ////// -main.dom.replayGame.onclick = function () { - - if (main.core.isset(main.core.musicStatus) && main.core.musicStatus.startDirectly - && main.core.musicStatus.bgmStatus) { - if (main.core.musicStatus.playingBgm==null - || core.material.bgms[main.core.musicStatus.playingBgm].paused) { - main.core.musicStatus.playingBgm=null; - main.core.playBgm(main.core.bgms[0]); - } - } - - core.readFile(function (obj) { - if (obj.name!=core.firstData.name) { - alert("存档和游戏不一致!"); - return; - } - if (core.isset(obj.version) && obj.version!=core.firstData.version) { - // alert("游戏版本不一致!"); - if (!confirm("游戏版本不一致!\n你仍然想播放录像吗?")) - return; - } - if (!core.isset(obj.route) || !core.isset(obj.hard)) { - alert("无效的录像!"); - return; - } - - core.dom.startPanel.style.display = 'none'; - core.resetStatus(core.firstData.hero, obj.hard, core.firstData.floorId, null, core.initStatus.maps); - core.setFlag('seed', obj.seed); - core.setFlag('rand', obj.seed); - core.events.setInitData(obj.hard); - core.changeFloor(core.status.floorId, null, core.firstData.hero.loc, null, function() { - core.startReplay(core.decodeRoute(obj.route)); - }, true); - }, function () { - - }) -} - - -}//listen end - +function main() { + + //------------------------ 用户修改内容 ------------------------// + + this.version = "2.3"; // 游戏版本号;如果更改了游戏内容建议修改此version以免造成缓存问题。 + + this.useCompress = false; // 是否使用压缩文件 + // 当你即将发布你的塔时,请使用“JS代码压缩工具”将所有js代码进行压缩,然后将这里的useCompress改为true。 + // 请注意,只有useCompress是false时才会读取floors目录下的文件,为true时会直接读取libs目录下的floors.min.js文件。 + // 如果要进行剧本的修改请务必将其改成false。 + + this.bgmRemote = false; // 是否采用远程BGM + this.bgmRemoteRoot = "https://gitee.com/ckcz123/h5music/raw/master/"; // 远程BGM的根目录 + + this.isCompetition = false; // 是否是比赛模式 + + this.savePages = 30; // 存档页数,每页可存5个;默认为30页150个存档 + + //------------------------ 用户修改内容 END ------------------------// + + this.dom = { + 'body': document.body, + 'gameGroup': document.getElementById('gameGroup'), + 'mainTips': document.getElementById('mainTips'), + 'musicBtn': document.getElementById('musicBtn'), + 'startPanel': document.getElementById('startPanel'), + 'startTop': document.getElementById('startTop'), + 'startTopProgressBar': document.getElementById('startTopProgressBar'), + 'startTopProgress': document.getElementById('startTopProgress'), + 'startTopLoadTips': document.getElementById('startTopLoadTips'), + 'startBackground': document.getElementById('startBackground'), + 'startLogo': document.getElementById('startLogo'), + 'startButtonGroup': document.getElementById('startButtonGroup'), + 'floorMsgGroup': document.getElementById('floorMsgGroup'), + 'logoLabel': document.getElementById('logoLabel'), + 'versionLabel': document.getElementById('versionLabel'), + 'floorNameLabel': document.getElementById('floorNameLabel'), + 'statusBar': document.getElementById('statusBar'), + 'status': document.getElementsByClassName('status'), + 'toolBar': document.getElementById('toolBar'), + 'tools': document.getElementsByClassName('tools'), + 'gameCanvas': document.getElementsByClassName('gameCanvas'), + 'gif': document.getElementById('gif'), + 'gif2': document.getElementById('gif2'), + 'curtain': document.getElementById('curtain'), + 'startButtons': document.getElementById('startButtons'), + 'playGame': document.getElementById('playGame'), + 'loadGame': document.getElementById('loadGame'), + 'replayGame': document.getElementById('replayGame'), + 'levelChooseButtons': document.getElementById('levelChooseButtons'), + 'data': document.getElementById('data'), + 'statusLabels': document.getElementsByClassName('statusLabel'), + 'floorCol': document.getElementById('floorCol'), + 'lvCol': document.getElementById('lvCol'), + 'hpmaxCol': document.getElementById('hpmaxCol'), + 'mdefCol': document.getElementById('mdefCol'), + 'moneyCol': document.getElementById('moneyCol'), + 'expCol': document.getElementById('expCol'), + 'upCol': document.getElementById('upCol'), + 'keyCol': document.getElementById('keyCol'), + 'debuffCol': document.getElementById('debuffCol'), + 'hard': document.getElementById('hard'), + }; + this.mode = 'play'; + this.loadList = [ + 'loader', 'control', 'utils', 'items', 'icons', 'maps', 'enemys', 'events', 'actions', 'data', 'ui', 'core' + ]; + this.pureData = [ + "data","enemys","icons","maps","items","functions" + ]; + this.materials = [ + 'animates', 'enemys', 'hero', 'items', 'npcs', 'terrains', 'enemy48', 'npc48' + ]; + + this.statusBar = { + 'image': { + 'floor': document.getElementById('img-floor'), + 'lv': document.getElementById('img-lv'), + 'hpmax': document.getElementById('img-hpmax'), + 'hp': document.getElementById("img-hp"), + 'atk': document.getElementById("img-atk"), + 'def': document.getElementById("img-def"), + 'mdef': document.getElementById("img-mdef"), + 'money': document.getElementById("img-money"), + 'experience': document.getElementById("img-experience"), + 'up': document.getElementById("img-up"), + 'book': document.getElementById("img-book"), + 'fly': document.getElementById("img-fly"), + 'toolbox': document.getElementById("img-toolbox"), + 'shop': document.getElementById("img-shop"), + 'save': document.getElementById("img-save"), + 'load': document.getElementById("img-load"), + 'settings': document.getElementById("img-settings") + }, + 'icons': { + 'floor': 0, + 'lv': 1, + 'hpmax': 2, + 'hp': 3, + 'atk': 4, + 'def': 5, + 'mdef': 6, + 'money': 7, + 'experience': 8, + 'up': 9, + 'book': 10, + 'fly': 11, + 'toolbox': 12, + 'shop': 13, + 'save': 14, + 'load': 15, + 'settings': 16, + 'play': 17, + 'pause': 18, + 'stop': 19, + 'speedDown': 20, + 'speedUp': 21, + 'rewind': 22, + }, + 'floor': document.getElementById('floor'), + 'lv': document.getElementById('lv'), + 'hpmax': document.getElementById('hpmax'), + 'hp': document.getElementById('hp'), + 'atk': document.getElementById('atk'), + 'def': document.getElementById("def"), + 'mdef': document.getElementById('mdef'), + 'money': document.getElementById("money"), + 'experience': document.getElementById("experience"), + 'up': document.getElementById('up'), + 'yellowKey': document.getElementById("yellowKey"), + 'blueKey': document.getElementById("blueKey"), + 'redKey': document.getElementById("redKey"), + 'poison': document.getElementById('poison'), + 'weak':document.getElementById('weak'), + 'curse': document.getElementById('curse'), + 'hard': document.getElementById("hard") + } + this.floors = {} + this.canvas = {}; +} + +main.prototype.init = function (mode, callback) { + for (var i = 0; i < main.dom.gameCanvas.length; i++) { + main.canvas[main.dom.gameCanvas[i].id] = main.dom.gameCanvas[i].getContext('2d'); + } + if (({"editor":0}).hasOwnProperty(mode)) { + main.mode = mode; + if (mode === 'editor')main.editor = {'disableGlobalAnimate':true}; + } + + main.loaderJs('project', main.pureData, function(){ + var mainData = data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d.main; + for(var ii in mainData)main[ii]=mainData[ii]; + + main.dom.startBackground.src="project/images/"+main.startBackground; + main.dom.startLogo.style=main.startLogoStyle; + main.levelChoose.forEach(function(value){ + var span = document.createElement('span'); + span.setAttribute('class','startButton'); + span.innerText=value[0]; + (function(span,str_){ + span.onclick = function () { + core.events.startGame(str_); + } + })(span,value[1]); + main.dom.levelChooseButtons.appendChild(span); + }); + + main.loaderJs('libs', main.loadList, function () { + main.core = core; + + for (i = 0; i < main.loadList.length; i++) { + var name = main.loadList[i]; + if (name === 'core') continue; + main.core[name] = new (eval(name))(); + } + + main.loaderFloors(function() { + var coreData = {}; + ["dom", "statusBar", "canvas", "images", "materials", + "animates", "bgms", "sounds", "floorIds", "floors"].forEach(function (t) { + coreData[t] = main[t]; + }) + main.core.init(coreData, callback); + main.core.resize(main.dom.body.clientWidth, main.dom.body.clientHeight); + }); + }); + }); +} + +////// 动态加载所有核心JS文件 ////// +main.prototype.loaderJs = function (dir, loadList, callback) { + + // 加载js + main.setMainTipsText('正在加载核心js文件...') + + if (this.useCompress) { + main.loadMod(dir, dir, function () { + callback(); + }) + } + else { + var instanceNum = 0; + for (var i = 0; i < loadList.length; i++) { + main.loadMod(dir, loadList[i], function (modName) { + main.setMainTipsText(modName + '.js 加载完毕'); + instanceNum++; + if (instanceNum === loadList.length) { + callback(); + } + }); + } + } +} + +////// 加载某一个JS文件 ////// +main.prototype.loadMod = function (dir, modName, callback) { + var script = document.createElement('script'); + var name = modName; + script.src = dir + '/' + modName + (this.useCompress?".min":"") + '.js?v=' + this.version; + main.dom.body.appendChild(script); + script.onload = function () { + callback(name); + } +} + +////// 动态加载所有楼层(剧本) ////// +main.prototype.loaderFloors = function (callback) { + + // 加载js + main.setMainTipsText('正在加载楼层文件...') + if (this.useCompress) { // 读取压缩文件 + var script = document.createElement('script'); + script.src = 'project/floors.min.js?v=' + this.version; + main.dom.body.appendChild(script); + script.onload = function () { + main.dom.mainTips.style.display = 'none'; + callback(); + } + } + else { + for (var i = 0; i < main.floorIds.length; i++) { + main.loadFloor(main.floorIds[i], function (modName) { + main.setMainTipsText("楼层 " + modName + '.js 加载完毕'); + if (Object.keys(main.floors).length === main.floorIds.length) { + main.dom.mainTips.style.display = 'none'; + callback(); + } + }); + } + } +} + +////// 加载某一个楼层 ////// +main.prototype.loadFloor = function(floorId, callback) { + var script = document.createElement('script'); + script.src = 'project/floors/' + floorId +'.js?v=' + this.version; + main.dom.body.appendChild(script); + script.onload = function () { + callback(floorId); + } +} + +////// 加载过程提示 ////// +main.prototype.setMainTipsText = function (text) { + main.dom.mainTips.innerHTML = text; +} + + +main.prototype.listen = function () { + +////// 窗口大小变化时 ////// +window.onresize = function () { + try { + main.core.resize(main.dom.body.clientWidth, main.dom.body.clientHeight); + }catch (e) {} +} + +////// 在界面上按下某按键时 ////// +main.dom.body.onkeydown = function(e) { + try { + if (main.core.isPlaying() || main.core.status.lockControl) + main.core.onkeyDown(e); + } catch (ee) {} +} + +////// 在界面上放开某按键时 ////// +main.dom.body.onkeyup = function(e) { + try { + if (main.core.isPlaying() || main.core.status.lockControl) + main.core.onkeyUp(e); + } catch (ee) {} +} + +////// 开始选择时 ////// +main.dom.body.onselectstart = function () { + return false; +} + +////// 鼠标按下时 ////// +main.dom.data.onmousedown = function (e) { + try { + e.stopPropagation(); + if(e.button==1){// 把鼠标中键绑定为ESC + core.keyUp(27); + return; + } + var loc = main.core.getClickLoc(e.clientX, e.clientY); + if (loc == null) return; + var x = parseInt(loc.x / loc.size), y = parseInt(loc.y / loc.size); + main.core.ondown(x, y); + } catch (ee) {} +} + +////// 鼠标移动时 ////// +main.dom.data.onmousemove = function (e) { + try { + e.stopPropagation(); + var loc = main.core.getClickLoc(e.clientX, e.clientY); + if (loc == null) return; + var x = parseInt(loc.x / loc.size), y = parseInt(loc.y / loc.size); + main.core.onmove(x, y); + }catch (ee) {} +} + +////// 鼠标放开时 ////// +main.dom.data.onmouseup = function () { + try { + main.core.onup(); + }catch (e) {} +} + +////// 鼠标滑轮滚动时 ////// +main.dom.data.onmousewheel = function(e) { + try { + if (e.wheelDelta) + main.core.onmousewheel(Math.sign(e.wheelDelta)) + else if (e.detail) + main.core.onmousewheel(Math.sign(e.detail)); + } catch (ee) {} +} + +////// 手指在触摸屏开始触摸时 ////// +main.dom.data.ontouchstart = function (e) { + try { + e.preventDefault(); + var loc = main.core.getClickLoc(e.targetTouches[0].clientX, e.targetTouches[0].clientY); + if (loc == null) return; + var x = parseInt(loc.x / loc.size), y = parseInt(loc.y / loc.size); + //main.core.onclick(x, y, []); + main.core.ondown(x, y); + }catch (ee) {} +} + +////// 手指在触摸屏上移动时 ////// +main.dom.data.ontouchmove = function (e) { + try { + e.preventDefault(); + var loc = main.core.getClickLoc(e.targetTouches[0].clientX, e.targetTouches[0].clientY); + if (loc == null) return; + var x = parseInt(loc.x / loc.size), y = parseInt(loc.y / loc.size); + main.core.onmove(x, y); + }catch (ee) {} +} + +////// 手指离开触摸屏时 ////// +main.dom.data.ontouchend = function () { + try { + main.core.onup(); + } catch (e) { + } +} + +////// 点击状态栏中的怪物手册时 ////// +main.statusBar.image.book.onclick = function () { + if (core.isset(core.status.replay) && core.status.replay.replaying) { + core.triggerReplay(); + return; + } + + if (main.core.isPlaying()) + main.core.openBook(true); +} + +////// 点击状态栏中的楼层传送器时 ////// +main.statusBar.image.fly.onclick = function () { + + if (core.isset(core.status.replay) && core.status.replay.replaying) { + core.stopReplay(); + return; + } + + if (main.core.isPlaying()) + main.core.useFly(true); +} + +////// 点击状态栏中的工具箱时 ////// +main.statusBar.image.toolbox.onclick = function () { + + if (core.isset(core.status.replay) && core.status.replay.replaying) { + core.rewindReplay(); + return; + } + + if (main.core.isPlaying()) + main.core.openToolbox(true); +} + +////// 点击状态栏中的快捷商店时 ////// +main.statusBar.image.shop.onclick = function () { + + if (core.isset(core.status.replay) && core.status.replay.replaying) { + core.bookReplay(); + return; + } + + if (main.core.isPlaying()) + main.core.openQuickShop(true); +} + +////// 点击状态栏中的存档按钮时 ////// +main.statusBar.image.save.onclick = function () { + + if (core.isset(core.status.replay) && core.status.replay.replaying) { + core.speedDownReplay(); + return; + } + + if (main.core.isPlaying()) + main.core.save(true); +} + +////// 点击状态栏中的读档按钮时 ////// +main.statusBar.image.load.onclick = function () { + + if (core.isset(core.status.replay) && core.status.replay.replaying) { + core.speedUpReplay(); + return; + } + + if (main.core.isPlaying()) + main.core.load(true); +} + +////// 点击状态栏中的系统菜单时 ////// +main.statusBar.image.settings.onclick = function () { + + if (core.isset(core.status.replay) && core.status.replay.replaying) { + core.saveReplay(); + return; + } + + if (main.core.isPlaying()) + main.core.openSettings(true); +} + +////// 点击“开始游戏”时 ////// +main.dom.playGame.onclick = function () { + main.dom.startButtons.style.display='none'; + + if (main.core.isset(main.core.musicStatus) && main.core.musicStatus.startDirectly + && main.core.musicStatus.bgmStatus) { + if (main.core.musicStatus.playingBgm==null + || core.material.bgms[main.core.musicStatus.playingBgm].paused) { + main.core.musicStatus.playingBgm=null; + main.core.playBgm(main.core.bgms[0]); + } + } + + if (main.core.isset(main.core.flags.startDirectly) && main.core.flags.startDirectly) { + core.events.startGame(""); + } + else { + main.dom.levelChooseButtons.style.display='block'; + } +} + +////// 点击“载入游戏”时 ////// +main.dom.loadGame.onclick = function() { + + if (main.core.isset(main.core.musicStatus) && main.core.musicStatus.startDirectly + && main.core.musicStatus.bgmStatus) { + if (main.core.musicStatus.playingBgm==null + || core.material.bgms[main.core.musicStatus.playingBgm].paused) { + main.core.musicStatus.playingBgm=null; + main.core.playBgm(main.core.bgms[0]); + } + } + + main.core.load(); +} + +////// 点击“录像回放”时 ////// +main.dom.replayGame.onclick = function () { + + if (main.core.isset(main.core.musicStatus) && main.core.musicStatus.startDirectly + && main.core.musicStatus.bgmStatus) { + if (main.core.musicStatus.playingBgm==null + || core.material.bgms[main.core.musicStatus.playingBgm].paused) { + main.core.musicStatus.playingBgm=null; + main.core.playBgm(main.core.bgms[0]); + } + } + + core.readFile(function (obj) { + if (obj.name!=core.firstData.name) { + alert("存档和游戏不一致!"); + return; + } + if (core.isset(obj.version) && obj.version!=core.firstData.version) { + // alert("游戏版本不一致!"); + if (!confirm("游戏版本不一致!\n你仍然想播放录像吗?")) + return; + } + if (!core.isset(obj.route) || !core.isset(obj.hard)) { + alert("无效的录像!"); + return; + } + + core.dom.startPanel.style.display = 'none'; + core.resetStatus(core.firstData.hero, obj.hard, core.firstData.floorId, null, core.initStatus.maps); + core.setFlag('seed', obj.seed); + core.setFlag('rand', obj.seed); + core.events.setInitData(obj.hard); + core.changeFloor(core.status.floorId, null, core.firstData.hero.loc, null, function() { + core.startReplay(core.decodeRoute(obj.route)); + }, true); + }, function () { + + }) +} + + +}//listen end + var main = new main(); \ No newline at end of file diff --git a/project/data.js b/project/data.js index e03c802b..1e44739f 100644 --- a/project/data.js +++ b/project/data.js @@ -1,168 +1,168 @@ -data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d = -{ - "main" : { - "floorIds" : [ - "sample0", "sample1", "sample2", "MT0" - ], - "images" : [ - "bg.jpg" - ], - "animates" : [ - "hand", "sword", "zone", - ], - "bgms" : [ - 'bgm.mp3' - ], - "sounds" : [ - 'floor.mp3', 'attack.mp3', 'door.mp3', 'item.mp3', 'zone.mp3' - ], - "startBackground" : "bg.jpg", - "startLogoStyle" : "color: black", - "levelChoose" : [["简单","Easy"],["普通","Normal"],["困难","Hard"],["噩梦","Hell"]], - "statusLeftBackground": "url(project/images/ground.png) repeat", - "statusTopBackground": "url(project/images/ground.png) repeat", - "toolsBackground": "url(project/images/ground.png) repeat" - }, - "firstData" : { - "title": "魔塔样板", - "name": "template", - "version": "Ver 2.2", - "floorId": "sample0", - "hero": { - "name": "阳光", - 'lv': 1, - "hpmax": 9999, - "hp": 1000, - "atk": 100, - "def": 100, - "mdef": 100, - "money": 100, - "experience": 0, - "items": { - "keys": { - "yellowKey": 0, - "blueKey": 0, - "redKey": 0 - }, - "constants": {}, - "tools": {} - }, - "flyRange": [], - "loc": {"direction": "up", "x": 6, "y": 10}, - "flags": {}, - "steps": 0, - }, - "startText": [ - "Hi,欢迎来到 HTML5 魔塔样板!\n\n本样板由艾之葵制作,可以让你在不会写任何代码\n的情况下也能做出属于自己的H5魔塔!", - "这里游戏开始时的剧情。\n定义在data.js的startText处。\n\n你可以在这里写上自己的内容。", - "赶快来试一试吧!" - ], - "shops": [ - { - "id": "moneyShop1", - "name": "贪婪之神", - "icon": "blueShop", - "textInList": "1F金币商店", - "use": "money", - "need": "20+10*times*(times+1)", - "text": "勇敢的武士啊,给我${need}金币就可以:", - "choices": [ - {"text": "生命+800", "effect": "status:hp+=800"}, - {"text": "攻击+4", "effect": "status:atk+=4"}, - {"text": "防御+4", "effect": "status:def+=4"}, - {"text": "魔防+10", "effect": "status:mdef+=10"} - ] - }, - { - "id": "expShop1", - "name": "经验之神", - "icon": "pinkShop", - "textInList": "1F经验商店", - "use": "experience", - "need": "-1", - "text": "勇敢的武士啊,给我若干经验就可以:", - "choices": [ - {"text": "等级+1", "need": "100", "effect": "status:lv+=1;status:hp+=1000;status:atk+=7;status:def+=7"}, - {"text": "攻击+5", "need": "30", "effect": "status:atk+=5"}, - {"text": "防御+5", "need": "30", "effect": "status:def+=5"}, - ] - } - ], - "levelUp": [ - {}, - {"need": 20, "name": "第二级", "effect": "status:hp+=2*(status:atk+status:def);status:atk+=10;status:def+=10"}, - {"need": 40, "effect": function () { - core.insertAction("恭喜升级!"); - core.status.hero.hp *= 2; - core.status.hero.atk += 100; - core.status.hero.def += 100; - }}, - ] - }, - - "values" : { - "lavaDamage": 100, - "poisonDamage": 10, - "weakValue": 20, - "redJewel": 3, - "blueJewel": 3, - "greenJewel": 5, - "redPotion": 100, - "bluePotion": 250, - "yellowPotion": 500, - "greenPotion": 800, - "sword0": 0, - "shield0": 0, - "sword1": 10, - "shield1": 10, - "sword2": 20, - "shield2": 20, - "sword3": 40, - "shield3": 40, - "sword4": 80, - "shield4": 80, - "sword5": 160, - "shield5": 160, - "moneyPocket": 500, - 'breakArmor': 0.9, - 'counterAttack': 0.1, - 'purify': 3, - 'hatred': 2, - 'maxValidHp': null, - 'animateSpeed': 300, - }, - - "flags" : { - "enableFloor": true, - "enableLv": false, - "enableHPMax": false, - "enableMDef": true, - "enableMoney": true, - "enableExperience": false, - "enableLevelUp": false, - "enableKeys": true, - "enableDebuff": false, - "flyNearStair": true, - "pickaxeFourDirections": false, - "bombFourDirections": false, - "bigKeyIsBox": false, - "equipment": false, - "enableDeleteItem": true, - "enableAddPoint": false, - "enableNegativeDamage": false, - "hatredDecrease": true, - "betweenAttackCeil": false, - "startDirectly": false, - "canOpenBattleAnimate": true, - "showBattleAnimateConfirm": true, - "battleAnimate": true, - "displayEnemyDamage": true, - "displayCritical": true, - "displayExtraDamage": true, - "enableGentleClick": true, - "potionWhileRouting": false, - "enableViewMaps": true, - "portalWithoutTrigger": true, - "enableMoveDirectly": true, - } +data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d = +{ + "main" : { + "floorIds" : [ + "sample0", "sample1", "sample2", "MT0" + ], + "images" : [ + "bg.jpg" + ], + "animates" : [ + "hand", "sword", "zone", + ], + "bgms" : [ + 'bgm.mp3' + ], + "sounds" : [ + 'floor.mp3', 'attack.mp3', 'door.mp3', 'item.mp3', 'zone.mp3' + ], + "startBackground" : "bg.jpg", + "startLogoStyle" : "color: black", + "levelChoose" : [["简单","Easy"],["普通","Normal"],["困难","Hard"],["噩梦","Hell"]], + "statusLeftBackground": "url(project/images/ground.png) repeat", + "statusTopBackground": "url(project/images/ground.png) repeat", + "toolsBackground": "url(project/images/ground.png) repeat" + }, + "firstData" : { + "title": "魔塔样板", + "name": "template", + "version": "Ver 2.3", + "floorId": "sample0", + "hero": { + "name": "阳光", + 'lv': 1, + "hpmax": 9999, + "hp": 1000, + "atk": 100, + "def": 100, + "mdef": 100, + "money": 100, + "experience": 0, + "items": { + "keys": { + "yellowKey": 0, + "blueKey": 0, + "redKey": 0 + }, + "constants": {}, + "tools": {} + }, + "flyRange": [], + "loc": {"direction": "up", "x": 6, "y": 10}, + "flags": {}, + "steps": 0, + }, + "startText": [ + "Hi,欢迎来到 HTML5 魔塔样板!\n\n本样板由艾之葵制作,可以让你在不会写任何代码\n的情况下也能做出属于自己的H5魔塔!", + "这里游戏开始时的剧情。\n定义在data.js的startText处。\n\n你可以在这里写上自己的内容。", + "赶快来试一试吧!" + ], + "shops": [ + { + "id": "moneyShop1", + "name": "贪婪之神", + "icon": "blueShop", + "textInList": "1F金币商店", + "use": "money", + "need": "20+10*times*(times+1)", + "text": "勇敢的武士啊,给我${need}金币就可以:", + "choices": [ + {"text": "生命+800", "effect": "status:hp+=800"}, + {"text": "攻击+4", "effect": "status:atk+=4"}, + {"text": "防御+4", "effect": "status:def+=4"}, + {"text": "魔防+10", "effect": "status:mdef+=10"} + ] + }, + { + "id": "expShop1", + "name": "经验之神", + "icon": "pinkShop", + "textInList": "1F经验商店", + "use": "experience", + "need": "-1", + "text": "勇敢的武士啊,给我若干经验就可以:", + "choices": [ + {"text": "等级+1", "need": "100", "effect": "status:lv+=1;status:hp+=1000;status:atk+=7;status:def+=7"}, + {"text": "攻击+5", "need": "30", "effect": "status:atk+=5"}, + {"text": "防御+5", "need": "30", "effect": "status:def+=5"}, + ] + } + ], + "levelUp": [ + {}, + {"need": 20, "name": "第二级", "effect": "status:hp+=2*(status:atk+status:def);status:atk+=10;status:def+=10"}, + {"need": 40, "effect": function () { + core.insertAction("恭喜升级!"); + core.status.hero.hp *= 2; + core.status.hero.atk += 100; + core.status.hero.def += 100; + }}, + ] + }, + + "values" : { + "lavaDamage": 100, + "poisonDamage": 10, + "weakValue": 20, + "redJewel": 3, + "blueJewel": 3, + "greenJewel": 5, + "redPotion": 100, + "bluePotion": 250, + "yellowPotion": 500, + "greenPotion": 800, + "sword0": 0, + "shield0": 0, + "sword1": 10, + "shield1": 10, + "sword2": 20, + "shield2": 20, + "sword3": 40, + "shield3": 40, + "sword4": 80, + "shield4": 80, + "sword5": 160, + "shield5": 160, + "moneyPocket": 500, + 'breakArmor': 0.9, + 'counterAttack': 0.1, + 'purify': 3, + 'hatred': 2, + 'maxValidHp': null, + 'animateSpeed': 300, + }, + + "flags" : { + "enableFloor": true, + "enableLv": false, + "enableHPMax": false, + "enableMDef": true, + "enableMoney": true, + "enableExperience": false, + "enableLevelUp": false, + "enableKeys": true, + "enableDebuff": false, + "flyNearStair": true, + "pickaxeFourDirections": false, + "bombFourDirections": false, + "bigKeyIsBox": false, + "equipment": false, + "enableDeleteItem": true, + "enableAddPoint": false, + "enableNegativeDamage": false, + "hatredDecrease": true, + "betweenAttackCeil": false, + "startDirectly": false, + "canOpenBattleAnimate": true, + "showBattleAnimateConfirm": true, + "battleAnimate": true, + "displayEnemyDamage": true, + "displayCritical": true, + "displayExtraDamage": true, + "enableGentleClick": true, + "potionWhileRouting": false, + "enableViewMaps": true, + "portalWithoutTrigger": true, + "enableMoveDirectly": true, + } } \ No newline at end of file