From 51f813e3a9bb8981b9747ecee45a83e13c2299c2 Mon Sep 17 00:00:00 2001 From: oc Date: Sat, 16 Mar 2019 02:30:22 +0800 Subject: [PATCH] Remove core.isset(block.event) --- libs/events.js | 6 +-- libs/maps.js | 101 ++++++++++++++++++------------------------- libs/ui.js | 3 +- project/functions.js | 9 ++-- project/items.js | 14 +++--- 5 files changed, 58 insertions(+), 75 deletions(-) diff --git a/libs/events.js b/libs/events.js index 7ef4ef98..2631afec 100644 --- a/libs/events.js +++ b/libs/events.js @@ -257,7 +257,7 @@ events.prototype._trigger = function (x, y) { var block = core.getBlock(x, y); if (block == null) return; block = block.block; - if (core.isset(block.event) && core.isset(block.event.trigger)) { + if (block.event.trigger) { var noPass = block.event.noPass, trigger = block.event.trigger; if (noPass) core.clearAutomaticRouteNode(x, y); if (trigger == 'ski') core.status.isSkiing = true; @@ -1283,7 +1283,7 @@ events.prototype.doAction = function() { var block=core.getBlock(toX, toY); if (block!=null) { block = block.block; - if (core.isset(block.event) && core.isset(block.event.trigger)) { + if (block.event.trigger) { core.status.event.data.x=block.x; core.status.event.data.y=block.y; core.status.event.data.list = [ @@ -1661,7 +1661,7 @@ events.prototype.doAction = function() { var block=core.getBlock(x,y); // 重新获得事件 if (block!=null) { block = block.block; - if (core.isset(block.event) && block.event.trigger=='action') { + if (block.event.trigger=='action') { core.status.event.data.list = [ {"todo": core.clone(block.event.data), "total": core.clone(block.event.data), "condition": "false"} ]; diff --git a/libs/maps.js b/libs/maps.js index 1d516e2b..22c42747 100644 --- a/libs/maps.js +++ b/libs/maps.js @@ -51,8 +51,7 @@ maps.prototype._mapIntoBlocks = function (map,floor,floorId){ var mh = core.floors[floorId].height; for (var i = 0; i < mh; i++) { for (var j = 0; j < mw; j++) { - var block = this.initBlock(j, i, (map[i]||[])[j], true, floor); - if (core.isset(block.event)) blocks.push(block); + blocks.push(this.initBlock(j, i, (map[i]||[])[j], true, floor)); } } return blocks; @@ -87,6 +86,7 @@ maps.prototype.initBlock = function (x, y, id, addInfo, eventFloor) { if (id==17) block.event = {"cls": "terrains", "id": "airwall", "noPass": true}; else if (id in this.blocksInfo) block.event = JSON.parse(JSON.stringify(this.blocksInfo[id])); else if (core.icons.getTilesetOffset(id)) block.event = {"cls": "tileset", "id": "X"+id, "noPass": true}; + else block.event = {'cls': 'terrains', 'id': 'none', 'noPass': false}; if (addInfo) this._addInfo(block); if (eventFloor) { @@ -100,33 +100,28 @@ maps.prototype.initBlock = function (x, y, id, addInfo, eventFloor) { ////// 添加一些信息到block上 ////// maps.prototype._addInfo = function (block) { - if (core.isset(block.event)) { - if (block.event.cls.indexOf("enemy")==0 && !core.isset(block.event.trigger)) { - block.event.trigger = 'battle'; - } - if (block.event.cls == 'items' && !core.isset(block.event.trigger)) { - block.event.trigger = 'getItem'; - } - if (!core.isset(block.event.noPass)) { - if (block.event.cls != 'items') { - block.event.noPass = true; - } - } - if (!core.isset(block.event.animate)) { - block.event.animate = core.icons._getAnimateFrames(block.event.cls, false); - } - block.event.height = 32; - if (block.event.cls == 'enemy48' || block.event.cls == 'npc48') - block.event.height = 48; + if (block.event.cls.indexOf("enemy")==0 && !core.isset(block.event.trigger)) { + block.event.trigger = 'battle'; } + if (block.event.cls == 'items' && !core.isset(block.event.trigger)) { + block.event.trigger = 'getItem'; + } + if (!core.isset(block.event.noPass)) { + if (block.event.cls != 'items') { + block.event.noPass = true; + } + } + if (!core.isset(block.event.animate)) { + block.event.animate = core.icons._getAnimateFrames(block.event.cls, false); + } + block.event.height = 32; + if (block.event.cls == 'enemy48' || block.event.cls == 'npc48') + block.event.height = 48; } ////// 向该楼层添加剧本的自定义事件 ////// maps.prototype._addEvent = function (block, x, y, event) { if (!core.isset(event)) return; - if (!core.isset(block.event)) { // 本身是空地? - block.event = {'cls': 'terrains', 'id': 'none', 'noPass': false}; - } // event是字符串或数组? if (typeof event == "string") { event = {"data": [event]}; @@ -685,7 +680,6 @@ maps.prototype._drawBgFgMap = function (floorId, ctx, name, onMap) { for (var x = 0; x < width; x++) { for (var y = 0; y < height; y++) { var block = this.initBlock(x, y, arr[y][x], true); - if (!core.isset(block.event)) continue; block.name = name; var blockInfo = this.getBlockInfo(block); if (!core.isset(blockInfo)) continue; @@ -1058,17 +1052,13 @@ maps.prototype.getBlock = function (x, y, floorId, showDisable) { ////// 获得某个点的blockId ////// maps.prototype.getBlockId = function (x, y, floorId, showDisable) { var block = core.getBlock(x, y, floorId, showDisable); - if (block == null) return null; - if (core.isset(block.block.event)) return block.block.event.id; - return null; + return block == null ? null : block.block.event.id; } ////// 获得某个点的blockCls ////// maps.prototype.getBlockCls = function (x, y, floorId, showDisable) { var block = core.getBlock(x, y, floorId, showDisable); - if (block == null) return null; - if (core.isset(block.block.event)) return block.block.event.cls; - return null; + return block == null ? null : block.block.event.cls; } ////// 获得某个图块或素材的信息,包括 ID,cls,图片,坐标,faceIds 等等 ////// @@ -1081,7 +1071,6 @@ maps.prototype.getBlockInfo = function (block) { if (block == 0) return null; block = this.initBlock(0, 0, block, true); } - if (!core.isset(block.event)) return null; var number = block.id, id = block.event.id, cls = block.event.cls, image = null, posX = 0, posY = 0, height = block.event.height || 32, faceIds = {}; @@ -1142,7 +1131,7 @@ maps.prototype.showBlock = function(x, y, floorId) { if (block.disable) { block.disable = false; // 在本层,添加动画 - if (floorId == core.status.floorId && core.isset(block.event)) { + if (floorId == core.status.floorId) { core.drawBlock(block); core.addGlobalAnimate(block); } @@ -1162,8 +1151,7 @@ maps.prototype.hideBlock = function (x, y, floorId) { if (floorId==core.status.floorId) { core.removeGlobalAnimate(x, y); core.clearMap('event', x * 32, y * 32, 32, 32); - var height = 32; - if (core.isset(block.block.event)) height=block.block.event.height||32; + var height = block.block.event.height || 32; if (height>32) core.clearMap('event2', x * 32, y * 32 +32-height, 32, height-32); } @@ -1186,8 +1174,7 @@ maps.prototype.removeBlock = function (x, y, floorId) { if (floorId==core.status.floorId) { core.removeGlobalAnimate(x, y); core.clearMap('event', x * 32, y * 32, 32, 32); - var height = 32; - if (core.isset(block.block.event)) height=block.block.event.height||32; + var height = block.block.event.height||32; if (height>32) core.clearMap('event2', x * 32, y * 32 +32-height, 32, height-32); } @@ -1333,30 +1320,28 @@ maps.prototype.setBlock = function (number, x, y, floorId) { var originBlock=core.getBlock(x,y,floorId,true); var block = this.initBlock(x,y,number,true,core.floors[floorId]); - if (core.isset(block.event)) { - if (floorId == core.status.floorId) { - core.removeGlobalAnimate(x, y); - core.clearMap('event', x * 32, y * 32, 32, 32); - if (originBlock != null) { - var height = (originBlock.block.event||{}).height||32; - if (height>32) - core.clearMap('event2', x * 32, y * 32 +32-height, 32, height-32); - } - } - if (originBlock==null) { - core.status.maps[floorId].blocks.push(block); - } - else { - originBlock.block.id = number; - originBlock.block.event = block.event; - block = originBlock.block; - } - if (floorId==core.status.floorId && !block.disable) { - core.drawBlock(block); - core.addGlobalAnimate(block); - core.updateStatusBar(); + if (floorId == core.status.floorId) { + core.removeGlobalAnimate(x, y); + core.clearMap('event', x * 32, y * 32, 32, 32); + if (originBlock != null) { + var height = (originBlock.block.event||{}).height||32; + if (height>32) + core.clearMap('event2', x * 32, y * 32 +32-height, 32, height-32); } } + if (originBlock==null) { + core.status.maps[floorId].blocks.push(block); + } + else { + originBlock.block.id = number; + originBlock.block.event = block.event; + block = originBlock.block; + } + if (floorId==core.status.floorId && !block.disable) { + core.drawBlock(block); + core.addGlobalAnimate(block); + core.updateStatusBar(); + } } ////// 改变前景背景的图块 ////// diff --git a/libs/ui.js b/libs/ui.js index 9a1d4b47..b5bdfe4e 100644 --- a/libs/ui.js +++ b/libs/ui.js @@ -2283,8 +2283,7 @@ ui.prototype.drawStatistics = function () { if (floor.cannotViewMap && floorId!=core.status.floorId) return; blocks.forEach(function (block) { - if (!core.isset(block.event) || block.disable) - return; + if (block.disable) return; var event = block.event; if (event.cls.indexOf("enemy")==0) { var enemyId = event.id, enemy = core.material.enemys[enemyId]; diff --git a/project/functions.js b/project/functions.js index 4c8f9f6f..024e425c 100644 --- a/project/functions.js +++ b/project/functions.js @@ -109,8 +109,7 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a = // 检查重生怪并重置 if (!fromLoad) { core.status.maps[floorId].blocks.forEach(function(block) { - if (block.disable && core.isset(block.event) && block.event.cls.indexOf('enemy')==0 && - core.enemys.hasSpecial(core.material.enemys[block.event.id].special, 23)) { + if (block.disable && core.enemys.hasSpecial(block.event.id, 23)) { block.disable = false; } }); @@ -523,7 +522,7 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a = if (!core.isset(cache)) { // 没有该点的缓存,则遍历每个图块 core.status.maps[floorId].blocks.forEach(function (block) { - if (core.isset(block.event) && !block.disable) { + if (!block.disable) { // 获得该图块的ID var id = block.event.id, enemy = core.material.enemys[id]; @@ -1037,7 +1036,7 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a = core.status.checkBlock.map = []; // 记录怪物地图 for (var n = 0; n < blocks.length; n++) { var block = blocks[n]; - if (core.isset(block.event) && !block.disable && block.event.cls.indexOf('enemy') == 0) { + if (!block.disable && block.event.cls.indexOf('enemy') == 0) { var id = block.event.id, enemy = core.material.enemys[id]; if (core.isset(enemy)) { @@ -1045,7 +1044,7 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a = } } // 血网 - if (core.isset(block.event) && !block.disable && + if (!block.disable && block.event.id == 'lavaNet' && block.event.trigger == 'passNet' && !core.hasItem("shoes")) { core.status.checkBlock.map[block.x + width * block.y] = "lavaNet"; } diff --git a/project/items.js b/project/items.js index 793296cb..1abd9db9 100644 --- a/project/items.js +++ b/project/items.js @@ -390,16 +390,16 @@ var items_296f5d02_12fd_4166_a7c1_b5e830c9ee3a = "canUseItemEffect": { "book": "true", "fly": "(function () {\n\treturn core.status.hero.flyRange.indexOf(core.status.floorId)>=0 && (core.status.maps[core.status.floorId]||{}).canFlyTo;\n})();", - "pickaxe": "(function() {\n\tvar ids = [], id2s = [];\n\tfor (var i in core.status.thisMap.blocks) {\n\t\tvar block = core.status.thisMap.blocks[i];\n\t\tif (core.isset(block.event) && !block.disable && core.nearHero(block.x, block.y) && \n\t\t\t(block.event.canBreak || block.event.id == 'yellowWall' || block.event.id=='whiteWall' || block.event.id=='blueWall')) { // 能破哪些墙\n\t\t\t// 四个方向\n\t\t\tif (core.flags.pickaxeFourDirections || (block.x == core.nextX() && block.y == core.nextY()))\n\t\t\t\tids.push(i);\n\t\t\telse id2s.push(i);\n\t\t}\n\t}\n\tif (ids.length>0) {\n\t\tcore.status.event.ui = ids;\n\t\treturn true;\n\t}\n\telse if (id2s.length==1) {\n\t\tcore.status.event.ui = id2s;\n\t\treturn true;\n\t}\n\treturn false;\n})();", - "icePickaxe": "(function() {\n\tfor (var i in core.status.thisMap.blocks) {\n\t\tvar block = core.status.thisMap.blocks[i];\n\t\tif (core.isset(block.event) && !block.disable && block.x==core.nextX() && block.y==core.nextY() && block.event.id=='ice') {\n\t\t\tcore.status.event.ui = [i];\n\t\t\treturn true;\n\t\t}\n\t}\n\treturn false;\n})();", - "bomb": "(function () {\n\tvar ids = [], id2s = [];\n\tfor (var i in core.status.thisMap.blocks) {\n\t\tvar block = core.status.thisMap.blocks[i];\n\t\tif (core.isset(block.event) && !block.disable && block.event.cls.indexOf('enemy')==0 && core.nearHero(block.x, block.y)) {\n\t\t\tvar enemy = core.material.enemys[block.event.id];\n\t\t\tif (core.isset(enemy) && enemy.notBomb) continue;\n\t\t\tif (core.flags.bombFourDirections || (block.x==core.nextX() && block.y==core.nextY()))\n\t\t\t\tids.push(i);\n\t\t\telse\n\t\t\t\tid2s.push(i);\n\t\t}\n\t}\n\tif (ids.length>0) {\n\t\tcore.status.event.ui = ids;\n\t\treturn true;\n\t}\n\tif (id2s.length==1) {\n\t\tcore.status.event.ui = id2s;\n\t\treturn true;\n\t}\n\treturn false;\n})();", - "hammer": "(function() {\n\tvar ids = [], id2s = [];\n\tfor (var i in core.status.thisMap.blocks) {\n\t\tvar block = core.status.thisMap.blocks[i];\n\t\tif (core.isset(block.event) && !block.disable && block.event.cls.indexOf('enemy')==0 && core.nearHero(block.x, block.y)) {\n\t\t\tvar enemy = core.material.enemys[block.event.id];\n\t\t\tif (core.isset(enemy) && enemy.notBomb) continue;\n\t\t\tif (block.x==core.nextX() && block.y==core.nextY())\n\t\t\t\tids.push(i);\n\t\t\telse\n\t\t\t\tid2s.push(i);\n\t\t}\n\t}\n\tif (ids.length>0) {\n\t\tcore.status.event.ui = ids;\n\t\treturn true;\n\t}\n\telse if (id2s.length==1) {\n\t\tcore.status.event.ui = id2s;\n\t\treturn true;\n\t}\n\treturn false;\n})();", - "earthquake": "(function () {\n\tvar able=false;\n\tvar ids = [];\n\tfor (var i in core.status.thisMap.blocks) {\n\t\tvar block = core.status.thisMap.blocks[i];\n\t\tif (core.isset(block.event) && !block.disable &&\n\t\t\t(block.event.canBreak || block.event.id == 'yellowWall' || block.event.id == 'blueWall' || block.event.id == 'whiteWall')) { // 能炸的墙壁\n\t\t\tids.push(i);\n\t\t}\n\t}\n\tif (ids.length>0) {\n\t\tcore.status.event.ui = ids;\n\t\table=true;\n\t}\n\treturn able;\n})();", + "pickaxe": "(function() {\n\tvar ids = [], id2s = [];\n\tfor (var i in core.status.thisMap.blocks) {\n\t\tvar block = core.status.thisMap.blocks[i];\n\t\tif (!block.disable && core.nearHero(block.x, block.y) && \n\t\t\t(block.event.canBreak || block.event.id == 'yellowWall' || block.event.id=='whiteWall' || block.event.id=='blueWall')) { // 能破哪些墙\n\t\t\t// 四个方向\n\t\t\tif (core.flags.pickaxeFourDirections || (block.x == core.nextX() && block.y == core.nextY()))\n\t\t\t\tids.push(i);\n\t\t\telse id2s.push(i);\n\t\t}\n\t}\n\tif (ids.length>0) {\n\t\tcore.status.event.ui = ids;\n\t\treturn true;\n\t}\n\telse if (id2s.length==1) {\n\t\tcore.status.event.ui = id2s;\n\t\treturn true;\n\t}\n\treturn false;\n})();", + "icePickaxe": "(function() {\n\tfor (var i in core.status.thisMap.blocks) {\n\t\tvar block = core.status.thisMap.blocks[i];\n\t\tif (!block.disable && block.x==core.nextX() && block.y==core.nextY() && block.event.id=='ice') {\n\t\t\tcore.status.event.ui = [i];\n\t\t\treturn true;\n\t\t}\n\t}\n\treturn false;\n})();", + "bomb": "(function () {\n\tvar ids = [], id2s = [];\n\tfor (var i in core.status.thisMap.blocks) {\n\t\tvar block = core.status.thisMap.blocks[i];\n\t\tif (!block.disable && block.event.cls.indexOf('enemy')==0 && core.nearHero(block.x, block.y)) {\n\t\t\tvar enemy = core.material.enemys[block.event.id];\n\t\t\tif (core.isset(enemy) && enemy.notBomb) continue;\n\t\t\tif (core.flags.bombFourDirections || (block.x==core.nextX() && block.y==core.nextY()))\n\t\t\t\tids.push(i);\n\t\t\telse\n\t\t\t\tid2s.push(i);\n\t\t}\n\t}\n\tif (ids.length>0) {\n\t\tcore.status.event.ui = ids;\n\t\treturn true;\n\t}\n\tif (id2s.length==1) {\n\t\tcore.status.event.ui = id2s;\n\t\treturn true;\n\t}\n\treturn false;\n})();", + "hammer": "(function() {\n\tvar ids = [], id2s = [];\n\tfor (var i in core.status.thisMap.blocks) {\n\t\tvar block = core.status.thisMap.blocks[i];\n\t\tif (!block.disable && block.event.cls.indexOf('enemy')==0 && core.nearHero(block.x, block.y)) {\n\t\t\tvar enemy = core.material.enemys[block.event.id];\n\t\t\tif (core.isset(enemy) && enemy.notBomb) continue;\n\t\t\tif (block.x==core.nextX() && block.y==core.nextY())\n\t\t\t\tids.push(i);\n\t\t\telse\n\t\t\t\tid2s.push(i);\n\t\t}\n\t}\n\tif (ids.length>0) {\n\t\tcore.status.event.ui = ids;\n\t\treturn true;\n\t}\n\telse if (id2s.length==1) {\n\t\tcore.status.event.ui = id2s;\n\t\treturn true;\n\t}\n\treturn false;\n})();", + "earthquake": "(function () {\n\tvar able=false;\n\tvar ids = [];\n\tfor (var i in core.status.thisMap.blocks) {\n\t\tvar block = core.status.thisMap.blocks[i];\n\t\tif (!block.disable &&\n\t\t\t(block.event.canBreak || block.event.id == 'yellowWall' || block.event.id == 'blueWall' || block.event.id == 'whiteWall')) { // 能炸的墙壁\n\t\t\tids.push(i);\n\t\t}\n\t}\n\tif (ids.length>0) {\n\t\tcore.status.event.ui = ids;\n\t\table=true;\n\t}\n\treturn able;\n})();", "centerFly": "(function () {\n\tvar toX = core.bigmap.width-1-core.getHeroLoc('x'), toY = core.bigmap.height-1-core.getHeroLoc('y');\n\tvar id = core.getBlockId(toX, toY);\n\treturn id == null;\n})();", "upFly": "(function() {\n\tvar floorId = core.status.floorId, index = core.floorIds.indexOf(floorId);\n\tif (index=0 && toX=0 && toY0) {\n\t\tvar toId = core.floorIds[index-1], toX = core.getHeroLoc('x'), toY = core.getHeroLoc('y');\n\t\tvar mw = core.floors[toId].width, mh = core.floors[toId].height;\n\t\tif (toX>=0 && toX=0 && toY0) {\n\t\tcore.status.event.ui = ids;\n\t\treturn true;\n\t}\n\tif (id2s.length==1) {\n\t\tcore.status.event.ui = id2s;\n\t\treturn true;\n\t}\n\treturn false;\n})();", - "bigKey": "(function() {\n\tvar able=false, ids = [];\n\tfor (var i in core.status.thisMap.blocks) {\n\t\tvar block = core.status.thisMap.blocks[i];\n\t\tif (core.isset(block.event) && !block.disable && block.event.id == 'yellowDoor') {\n\t\t\tids.push(i);\n\t\t}\n\t}\n\tif (ids.length>0) {\n\t\tcore.status.event.ui = ids;\n\t\table=true;\n\t}\n\treturn able;\n})();", + "snow": "(function () {\n\tvar ids = [], id2s = [];\n\tfor (var i in core.status.thisMap.blocks) {\n\t\tvar block = core.status.thisMap.blocks[i];\n\t\tif (!block.disable && block.event.id == 'lava' && core.nearHero(block.x, block.y)) {\n\t\t\tif (core.flags.snowFourDirections || (block.x == core.nextX() && block.y == core.nextY()))\n\t\t\t\tids.push(i);\n\t\t\telse id2s.push(i);\n\t\t}\n\t}\n\tif (ids.length>0) {\n\t\tcore.status.event.ui = ids;\n\t\treturn true;\n\t}\n\tif (id2s.length==1) {\n\t\tcore.status.event.ui = id2s;\n\t\treturn true;\n\t}\n\treturn false;\n})();", + "bigKey": "(function() {\n\tvar able=false, ids = [];\n\tfor (var i in core.status.thisMap.blocks) {\n\t\tvar block = core.status.thisMap.blocks[i];\n\t\tif (!block.disable && block.event.id == 'yellowDoor') {\n\t\t\tids.push(i);\n\t\t}\n\t}\n\tif (ids.length>0) {\n\t\tcore.status.event.ui = ids;\n\t\table=true;\n\t}\n\treturn able;\n})();", "poisonWine": "core.hasFlag('poison');", "weakWine": "core.hasFlag('weak');", "curseWine": "core.hasFlag('curse');",