1 line
14 KiB
JavaScript
1 line
14 KiB
JavaScript
function events(){}events.prototype.init=function(){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);if(b.isset(a)){a()}},changeFloor:function(c,b,a){var d=null;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,a)},openShop:function(c,b,a){b.ui.drawShop(c.event.shopid);if(b.isset(a)){a()}},passNet:function(c,b,a){b.events.passNet(c);if(b.isset(a)){a()}},checkBlock:function(c,b,a){b.events.checkBlock(c.x,c.y);if(b.isset(a)){a()}},action:function(c,b,a){b.events.doEvents(c.event.data,c.x,c.y);if(b.isset(a)){a()}}}};events.prototype.getEvents=function(a){if(a==undefined){return this.events}return this.events[a]};main.instance.events=new events();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(){core.startGame(a)})})};events.prototype.win=function(a){core.waitHeroToStop(function(){core.removeGlobalAnimate(0,0,true);core.clearMap("all");core.drawText(["\t[结局2]恭喜通关!你的分数是${status:hp}。"],function(){core.restart()})})};events.prototype.lose=function(a){core.waitHeroToStop(function(){core.drawText("\t[结局1]你死了。",function(){core.restart()})})};events.prototype.checkBlock=function(g, h){var b=0;var c=[[0,-1],[-1,0],[0,1],[1,0]];var d=[null,null,null,null];for(var f in c){var a=core.getBlock(g+c[f][0],h+c[f][1]);if(a==null){continue}if(a.block.event.cls=="enemys"){d[f]=core.material.enemys[a.block.event.id]}}for(var f in d){if(d[f]!=null&&d[f].special==15){b+=d[f].value}}if(b>0){core.drawTip("受到领域伤害"+b+"点")}core.status.hero.hp-=b;if(core.status.hero.hp<=0){core.status.hero.hp=0;core.updateStatusBar();core.events.lose("zone");return}var e=false;if(d[0]!=null&&d[2]!=null&&d[0].id==d[2].id&&d[0].special==16){e=true}if(d[1]!=null&&d[3]!=null&&d[1].id==d[3].id&&d[1].special==16){e=true}if(e&&core.status.hero.hp>1){core.status.hero.hp=parseInt(core.status.hero.hp/2);core.drawTip("受到夹击,生命变成一半")}core.updateStatusBar()};events.prototype.afterChangeFloor=function(a){if(!core.hasFlag("visited_"+a)){this.doEvents(core.floors[a].firstArrive);core.setFlag("visited_"+a,true)}};events.prototype.doEvents=function(b,c,d,a){core.waitHeroToStop(function(){if(!core.isset(b)){return}if(!(b instanceof Array)){b=[b]}core.lockControl();core.status.event={id:"action",data:{list:core.clone(b),x:c,y:d,callback:a}};core.events.doAction()})};events.prototype.doAction=function(){clearInterval(core.interval.boxAnimate);core.clearMap("ui",0,0,416,416);core.setAlpha("ui",1);if(core.status.event.data.list.length==0){if(core.isset(core.status.event.data.callback)){core.status.event.data.callback()}core.ui.closePanel(false);return}var b=core.status.event.data.list.shift();core.status.event.data.current=b;var m=core.status.event.data.x,n=core.status.event.data.y;if(typeof b=="string"){core.status.event.data.type="text";core.ui.drawTextBox(b);return}core.status.event.data.type=b.type;switch(b.type){case"text":core.ui.drawTextBox(b.data);break;case"show":if(core.isset(b.time)&&b.time>0&&(!core.isset(b.floorId)||b.floorId==core.status.floorId)){core.animateBlock(b.loc[0],b.loc[1],"show",b.time,function(){core.addBlock(b.loc[0],b.loc[1],b.floorId);core.events.doAction()})}else{core.addBlock(b.loc[0],b.loc[1],b.floorId);this.doAction()}break;case"hide":var j=m,k=n,i=core.status.floorId;if(core.isset(b.loc)){j=b.loc[0];k=b.loc[1]}if(core.isset(b.floorId)){i=b.floorId}core.removeBlock(j,k,i);if(core.isset(b.time)&&b.time>0&&i==core.status.floorId){core.animateBlock(j,k,"hide",b.time,function(){core.events.doAction()})}else{this.doAction()}break;case"move":core.moveBlock(m,n,b.steps,b.time,b.disappear,function(){core.events.doAction()});break;case"changeFloor":var f={x:b.loc[0],y:b.loc[1]};if(core.isset(b.direction)){f.direction=b.direction}core.changeFloor(b.floorId||core.status.floorId,null,f,b.time,function(){core.lockControl();core.events.doAction()});break;case"changePos":core.clearMap("hero",0,0,416,416);core.setHeroLoc("x",b.loc[0]);core.setHeroLoc("y",b.loc[1]);core.drawHero(core.getHeroLoc("direction"),core.getHeroLoc("x"),core.getHeroLoc("y"),"stop");this.doAction();break;case"openDoor":var d=b.floorId||core.status.floorId;var a=core.getBlock(b.loc[0],b.loc[1],d);if(a!=null){if(d==core.status.floorId){core.openDoor(a.block.event.id,a.block.x,a.block.y,false,function(){core.events.doAction()})}else{core.removeBlock(a.block.x,a.block.y,d);this.doAction()}break}this.doAction();break;case"openShop":core.events.openShop(b.id);break;case"battle":core.battle(b.id,null,null,true,function(){core.events.doAction()});break;case"trigger":var j=b.loc[0],k=b.loc[1];var a=core.getBlock(j,k);if(a!=null){a=a.block;if(core.isset(a.event)&&a.event.trigger=="action"){core.status.event={id:"action",data:{list:core.clone(a.event.data),x:a.x,y:a.y,callback:core.status.event.data.callback}}}}this.doAction();break;case"playSound":var h=b.name.split(".");if(h.length==2){core.playSound(h[0],h[1])}this.doAction();break;case"setValue":try{var l=core.calValue(b.value);if(b.name.indexOf("status:")==0){l=parseInt(l);core.setStatus(b.name.substring(7),l)}if(b.name.indexOf("item:")==0){l=parseInt(l);var g=b.name.substring(5);if(l>core.itemCount(g)){core.getItem(g,l-core.itemCount(g))}else{core.setItem(g,l)}}if(b.name.indexOf("flag:")==0){core.setFlag(b.name.substring(5),l)}}catch(c){console.log(c)}core.updateStatusBar();this.doAction();break;case"if":if(core.calValue(b.condition)){core.events.insertAction(b["true"])}else{core.events.insertAction(b["false"])}this.doAction();break;case"choices":core.ui.drawChoices(b.text,b.choices);break;case"win":core.events.win(b.reason);break;case"lose":core.events.lose(b.reason);break;case"function":if(core.isset(b["function"])){b["function"]()}this.doAction();break;case"update":core.updateStatusBar();this.doAction();break;case"sleep":setTimeout(function(){core.events.doAction()},b.time);break;case"revisit":var a=core.getBlock(m,n);if(a!=null){a=a.block;if(core.isset(a.event)&&a.event.trigger=="action"){core.status.event.data.list=core.clone(a.event.data)}}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"+b.type+" 事件不被支持...")}return};events.prototype.insertAction=function(a){core.unshift(core.status.event.data.list,a)};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;core.ui.closePanel();core.lockControl();core.status.event={id:"shop",data:{id:shopId,shop:shop}};var content="\t["+shop.name+","+shop.icon+"]";var times=shop.times,need=eval(shop.need);if(need<0){need="若干"}var use=shop.use=="experience"?"经验":"金币";content=content+"勇敢的武士啊,给我"+need+"\n"+use+",你就可以:";var choices=[];for(var i=0;i<shop.choices.length;i++){var choice=shop.choices[i];var text=choice.text;if(core.isset(choice.need)){text+="("+eval(choice.need)+use+")"}choices.push({text:text})}choices.push({text:"离开"});core.ui.drawChoices(content,choices)};events.prototype.disableQuickShop=function(a){core.status.shops[a].visited=false};events.prototype.canUseQuickShop=function(a){if(core.isset(core.values.cannotUseQuickShop)&&core.values.cannotUseQuickShop.indexOf(core.status.floorId)>=0){return"当前不能使用快捷商店。"}return null};events.prototype.useItem=function(a){core.ui.closePanel(false);if(a=="book"){core.openBook(false);return}if(a=="fly"){core.useFly(false);return}if(core.canUseItem(a)){core.useItem(a)}else{core.drawTip("当前无法使用"+core.material.items[a].name)}};events.prototype.afterBattle=function(b,e,f,a){var d=core.material.enemys[b].special;if(d==12&&!core.hasFlag("poison")){core.setFlag("poison",true);core.updateStatusBar()}if(d==13&&!core.hasFlag("weak")){core.setFlag("weak",true);core.status.hero.atk-=core.values.weakValue;core.status.hero.def-=core.values.weakValue;core.updateStatusBar()}if(d==14&&!core.hasFlag("curse")){core.setFlag("curse",true);core.updateStatusBar()}if(core.status.lockControl){if(core.isset(a)){a()}return}var c=core.floors[core.status.floorId].afterBattle[e+","+f];if(core.isset(c)){core.events.doEvents(c,e,f,a)}else{core.continueAutomaticRoute();if(core.isset(a)){a()}}};events.prototype.afterOpenDoor=function(b,d,e,a){if(core.status.lockControl){if(core.isset(a)){a()}return}var c=core.floors[core.status.floorId].afterOpenDoor[d+","+e];if(core.isset(c)){core.events.doEvents(c,d,e,a)}else{core.continueAutomaticRoute();if(core.isset(a)){a()}}};events.prototype.passNet=function(a){if(core.hasItem("shoes")){return}if(a.event.id=="lavaNet"){core.status.hero.hp-=core.values.lavaDamage;if(core.status.hero.hp<=0){core.status.hero.hp=0;core.updateStatusBar();core.events.lose("lava");return}core.drawTip("经过血网,生命-"+core.values.lavaDamage)}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);core.status.hero.atk-=core.values.weakValue;core.status.hero.def-=core.values.weakValue}if(a.event.id=="curseNet"){if(core.hasFlag("curse")){return}core.setFlag("curse",true)}core.updateStatusBar()};events.prototype.beforeSaveData=function(a){};events.prototype.afterLoadData=function(a){};events.prototype.clickAction=function(d,e){if(core.status.event.data.type=="text"){this.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&&e<c+a.length){this.insertAction(a[e-c].action);this.doAction()}}}};events.prototype.clickBook=function(a,b){if((a==3||a==4)&&b==12){core.ui.drawEnemyBook(core.status.event.data-1)}if((a==8||a==9)&&b==12){core.ui.drawEnemyBook(core.status.event.data+1)}if(a>=10&&a<=12&&b==12){core.ui.closePanel(true)}return};events.prototype.clickFly=function(d,e){if((d==10||d==11)&&e==9){core.ui.drawFly(core.status.event.data-1)}if((d==10||d==11)&&e==5){core.ui.drawFly(core.status.event.data+1)}if(d>=5&&d<=7&&e==12){core.ui.closePanel()}if(d>=0&&d<=9&&e>=3&&e<=11){var b=core.status.hero.flyRange.indexOf(core.status.floorId);var c=core.status.event.data<b?"upFloor":"downFloor";var a=core.status.event.data;core.changeFloor(core.status.hero.flyRange[a],c);core.ui.closePanel()}return};events.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&&y<topIndex+choices.length){var money=core.getStatus("money"),experience=core.getStatus("experience");var times=shop.times,need=eval(shop.need);var use=shop.use;var use_text=use=="money"?"金币":"经验";var choice=choices[y-topIndex];if(core.isset(choice.need)){need=eval(choice.need)}if(need>eval(use)){core.drawTip("你的"+use_text+"不足");return}eval(use+"-="+need);core.setStatus("money",money);core.setStatus("experience",experience);choice.effect.split(";").forEach(function(t){if(t.indexOf("status:")==0){eval(t.replace("status:","core.status.hero."))}else{if(t.indexOf("item:")==0){eval(t.replace("item:","core.getItem('").replace("+=","', ")+")")}}});core.updateStatusBar();shop.times++;this.openShop(core.status.event.data.id)}else{if(y==topIndex+choices.length){core.status.boxAnimateObjs=[];core.setBoxAnimate();if(core.status.event.data.fromList){core.ui.drawQuickShop()}else{core.ui.closePanel()}}}}};events.prototype.clickQuickShop=function(f, g){if(f>=5&&f<=7){var d=core.status.shops,b=Object.keys(d);var e=6-parseInt((b.length+1)/2);var a=6+parseInt((b.length+1)/2);if(g>=e&&g-e<b.length){var c=core.events.canUseQuickShop(g-e);if(core.isset(c)){core.drawText(c);return}this.openShop(b[g-e],true);if(core.status.event.id=="shop"){core.status.event.data.fromList=true}}if(g==a){core.ui.closePanel()}}};events.prototype.clickToolbox=function(c, d){if(c>=10&&c<=12&&d==12){core.ui.closePanel(false);return}var b=null;if(d>=4&&d<=7&&c!=12){b=Object.keys(core.status.hero.items.tools).sort()}if(d>=9&&d<=12&&c!=12){b=Object.keys(core.status.hero.items.constants).sort()}if(b==null){return}var a=0;if(d==4||d==5||d==9||d==10){a=parseInt(c/2)}else{a=6+parseInt(c/2)}if(a>=b.length){return}itemId=b[a];if(itemId==core.status.event.data){core.events.useItem(itemId)}else{core.ui.drawToolbox(itemId)}};events.prototype.clickSL=function(b,c){if((b==3||b==4)&&c==12){core.ui.drawSLPanel(core.status.event.data-1)}if((b==8||b==9)&&c==12){core.ui.drawSLPanel(core.status.event.data+1)}if(b>=10&&b<=12&&c==12){core.ui.closePanel(false);if(!core.isPlaying()){core.showStartAnimate()}return}var a=6*core.status.event.data+1;if(c>=1&&c<=4){if(b>=1&&b<=3){core.doSL(a,core.status.event.id)}if(b>=5&&b<=7){core.doSL(a+1,core.status.event.id)}if(b>=9&&b<=11){core.doSL(a+2,core.status.event.id)}}if(c>=7&&c<=10){if(b>=1&&b<=3){core.doSL(a+3,core.status.event.id)}if(b>=5&&b<=7){core.doSL(a+4,core.status.event.id)}if(b>=9&&b<=11){core.doSL(a+5,core.status.event.id)}}};events.prototype.clickSettings=function(a,b){if(a<5||a>7){return}if(b==3){if(core.musicStatus.isIOS){core.drawTip("iOS设备不支持播放音乐");return}core.changeSoundStatus();core.ui.drawSettings(false)}if(b==4){core.ui.drawQuickShop()}if(b==5){core.ui.drawSyncSave()}if(b==6){core.ui.drawConfirmBox("你确定要清空所有本地存档吗?",function(){localStorage.clear();core.drawText("\t[操作成功]你的本地所有存档已被清空。")},function(){core.ui.drawSettings(false)})}if(b==7){core.ui.drawConfirmBox("你确定要重新开始吗?",function(){core.ui.closePanel();core.restart()},function(){core.ui.drawSettings(false)})}if(b==8){core.ui.drawAbout()}if(b==9){core.ui.closePanel()}return}; |