mota-js/libs/items.min.js
2017-12-04 01:35:38 +08:00

1 line
7.5 KiB
JavaScript

function items(){}items.prototype.init=function(){this.items={yellowKey:{cls:"keys",name:"黄钥匙"},blueKey:{cls:"keys",name:"蓝钥匙"},redKey:{cls:"keys",name:"红钥匙"},redJewel:{cls:"items",name:"红宝石"},blueJewel:{cls:"items",name:"蓝宝石"},greenJewel:{cls:"items",name:"绿宝石"},yellowJewel:{cls:"items",name:"黄宝石"},redPotion:{cls:"items",name:"红血瓶"},bluePotion:{cls:"items",name:"蓝血瓶"},yellowPotion:{cls:"items",name:"黄血瓶"},greenPotion:{cls:"items",name:"绿血瓶"},sword1:{cls:"items",name:"铁剑"},sword2:{cls:"items",name:"银剑"},sword3:{cls:"items",name:"骑士剑"},sword4:{cls:"items",name:"圣剑"},sword5:{cls:"items",name:"神圣剑"},shield1:{cls:"items",name:"铁盾"},shield2:{cls:"items",name:"银盾"},shield3:{cls:"items",name:"骑士盾"},shield4:{cls:"items",name:"圣盾"},shield5:{cls:"items",name:"神圣盾"},superPotion:{cls:"items",name:"圣水"},bigKey:{cls:"items",name:"钥匙盒"},greenKey:{cls:"tools",name:"绿钥匙",text:"可以打开一扇绿门"},steelKey:{cls:"tools",name:"铁门钥匙",text:"可以打开一扇铁门"},book:{cls:"constants",name:"怪物手册",text:"可以查看当前楼层各怪物属性。"},fly:{cls:"constants",name:"楼层传送器",text:"可以自由往来去过的楼层。"},coin:{cls:"constants",name:"幸运金币",text:"持有时打败怪物可得双倍金币"},snow:{cls:"constants",name:"冰冻徽章",text:"可以将面前的一块熔岩变成平地"},cross:{cls:"constants",name:"十字架",text:"持有后无视怪物的无敌属性"},pickaxe:{cls:"tools",name:"破墙镐",text:"可以破坏勇士四周的墙。"},icePickaxe:{cls:"tools",name:"破冰稿",text:"可以破坏勇士面前的一堵冰墙。"},bomb:{cls:"tools",name:"炸弹",text:"可以炸掉勇士四周的怪物。"},centerFly:{cls:"tools",name:"中心对称飞行器",text:"可以飞向当前楼层中心对称的位置。"},upFly:{cls:"tools",name:"上楼器",text:"可以飞往楼上的相同位置。"},downFly:{cls:"tools",name:"下楼器",text:"可以飞往楼下的相同位置。"},earthquake:{cls:"tools",name:"地震卷轴",text:"可以破坏当前层的所有墙"}}};items.prototype.getItems=function(a){if(a==undefined){return this.items}return this.items[itemsName]};main.instance.items=new items();items.prototype.useItem=function(b){if(!this.canUseItem(b)){return}var a=core.material.items[b].cls;if(a=="constants"){if(b=="book"){core.ui.drawEnemyBook(1)}if(b=="fly"){core.ui.drawFly(core.status.hero.flyRange.indexOf(core.status.floorId))}}if(a=="tools"){core.status.hero.items[a][b]--;if(b=="earthquake"||b=="bomb"||b=="pickaxe"){core.removeBlockByIds(core.status.floorId,core.status.event.data);core.drawMap(core.status.floorId,function(){core.drawHero(core.getHeroLoc("direction"),core.getHeroLoc("x"),core.getHeroLoc("y"),"stop");core.updateFg();core.drawTip(core.material.items[b].name+"使用成功");if(b=="bomb"&&core.flags.bombTrigger){core.events.afterBattle()}})}if(b=="centerFly"){core.clearMap("hero",0,0,416,416);core.setHeroLoc("x",core.status.event.data.x);core.setHeroLoc("y",core.status.event.data.y);core.drawHero(core.getHeroLoc("direction"),core.getHeroLoc("x"),core.getHeroLoc("y"),"stop");core.drawTip(core.material.items[b].name+"使用成功")}if(b=="upFly"||b=="downFly"){core.changeFloor(core.status.event.data.id,null,{direction:core.status.hero.loc.direction,x:core.status.event.data.x,y:core.status.event.data.y},function(){core.drawTip(core.material.items[b].name+"使用成功")})}if(core.status.hero.items[a][b]==0){delete core.status.hero.items[a][b]}}};items.prototype.canUseItem=function(k){if(!core.hasItem(k)){return false}var e=core.material.items[k].cls;if(k=="book"){return true}if(k=="fly"){return core.status.hero.flyRange.indexOf(core.status.floorId)>=0}if(k=="pickaxe"){var b=[];for(var h in core.status.thisMap.blocks){var g=core.status.thisMap.blocks[h];if(core.isset(g.event)&&g.event.id=="yellowWall"){if(core.flags.picaxeFourDirections){if(Math.abs(g.x-core.status.hero.loc.x)+Math.abs(g.y-core.status.hero.loc.y)<=1){b.push(h)}}else{var o={up:{x:0,y:-1},left:{x:-1,y:0},down:{x:0,y:1},right:{x:1,y:0}};if(g.x==core.status.hero.loc.x+o[core.status.hero.loc.direction].x&&g.y==core.status.hero.loc.y+o[core.status.hero.loc.direction].y){b.push(h)}}}}if(b.length>0){core.status.event.data=b;return true}return false}if(k=="bomb"){var b=[];for(var h in core.status.thisMap.blocks){var g=core.status.thisMap.blocks[h];if(core.isset(g.event)&&g.event.cls=="enemys"&&Math.abs(g.x-core.status.hero.loc.x)+Math.abs(g.y-core.status.hero.loc.y)<=1){var f=core.material.enemys[g.event.id];if(core.isset(f.bomb)&&!f.bomb){continue}b.push(h)}}if(b.length>0){core.status.event.data=b;return true}return false}if(k=="earthquake"){var b=[];for(var h in core.status.thisMap.blocks){var g=core.status.thisMap.blocks[h];if(core.isset(g.event)&&(g.event.id=="yellowWall"||g.event.id=="blueWall"||g.event.id=="whiteWall")){b.push(h)}}if(b.length>0){core.status.event.data=b;return true}return false}if(k=="centerFly"){var l=12-core.getHeroLoc("x"),j=12-core.getHeroLoc("y");var a=core.status.thisMap.blocks;for(var n=0;n<a.length;n++){if(a[n].x==l&&a[n].y==j){return false}}core.status.event.data={x:l,y:j};return true}if(k=="upFly"){if(core.status.floorId=="MT20"||core.status.floorId=="MT21"){return false}var d=null,m=false;for(var c in core.status.maps){if(m){d=c;break}if(c==core.status.floorId){m=true}}if(!m){return false}var l=core.getHeroLoc("x"),j=core.getHeroLoc("y");var a=core.status.maps[d].blocks;for(var n=0;n<a.length;n++){if(a[n].x==l&&a[n].y==j){return false}}core.status.event.data={id:d,x:l,y:j};return true}if(k=="downFly"){if(core.status.floorId=="MT0"||core.status.floorId=="MT21"){return false}var d=null;for(var c in core.status.maps){if(c==core.status.floorId){break}d=c}if(d==null){return false}var l=core.getHeroLoc("x"),j=core.getHeroLoc("y");var a=core.status.maps[d].blocks;for(var n=0;n<a.length;n++){if(a[n].x==l&&a[n].y==j){return false}}core.status.event.data={id:d,x:l,y:j};return true}return false};items.prototype.getItemEffect=function(c,b){var a=core.material.items[c].cls;if(a==="items"){if(c==="redJewel"){core.status.hero.atk+=3}if(c==="blueJewel"){core.status.hero.def+=3}if(c==="greenJewel"){core.status.hero.mdef+=3}if(c==="redPotion"){core.status.hero.hp+=200}if(c==="bluePotion"){core.status.hero.hp+=500}if(c==="yellowPotion"){core.status.hero.hp+=500}if(c==="greenPotion"){core.status.hero.hp+=800}if(c==="sword1"){core.status.hero.atk+=10}if(c==="sword2"){core.status.hero.atk+=100}if(c==="sword5"){core.status.hero.atk+=1000}if(c==="shield1"){core.status.hero.def+=10}if(c==="shield2"){core.status.hero.def+=100}if(c==="shield5"){core.status.hero.def+=1000;core.status.hero.flags.hasShield5=true}if(c==="bigKey"){core.status.hero.items.keys.yellowKey++;core.status.hero.items.keys.blueKey++;core.status.hero.items.keys.redKey++}if(c=="superPotion"){core.status.hero.hp*=2}}else{core.addItem(c,b)}};items.prototype.getItemEffectTip=function(a){if(a==="redJewel"){return",攻击+3"}if(a==="blueJewel"){return",防御+3"}if(a==="greenJewel"){return",魔防+3"}if(a==="redPotion"){return",生命+200"}if(a==="bluePotion"){return",生命+500"}if(a==="yellowPotion"){return",生命+500"}if(a==="greenPotion"){return",生命+800"}if(a==="sword1"){return",攻击+10"}if(a==="sword2"){return",攻击+100"}if(a==="sword5"){return",攻击+1000"}if(a==="shield1"){return",防御+10"}if(a==="shield2"){return",防御+100"}if(a==="shield5"){return",防御+1000"}if(a==="bigKey"){return",全钥匙+1"}if(a==="superPotion"){return",生命值翻倍"}return""};