diff --git a/docs/api.md b/docs/api.md index f7591ef6..8593f9b9 100644 --- a/docs/api.md +++ b/docs/api.md @@ -168,6 +168,10 @@ core.nextY(n) 获得勇士面向的第n个位置的y坐标,n可以省略默认为1(即正前方) +core.nearHero(x, y) +判断某个点是否和勇士的距离不超过1。 + + core.openDoor(id, x, y, needKey, callback) [异步] 尝试开门操作。id为目标点的ID,x和y为坐标,needKey表示是否需要使用钥匙,callback为开门完毕后的回调函数。 id可为null代表使用地图上的值。 diff --git a/libs/control.js b/libs/control.js index 096bb1d2..1fdfe3e9 100644 --- a/libs/control.js +++ b/libs/control.js @@ -1125,6 +1125,11 @@ control.prototype.nextY = function (n) { return core.getHeroLoc('y')+core.utils.scan[core.getHeroLoc('direction')].y*(n||1); } +////// 某个点是否在勇士旁边 ////// +control.prototype.nearHero = function (x, y) { + return Math.abs(x-core.getHeroLoc('x'))+Math.abs(y-core.getHeroLoc('y'))<=1; +} + ////// 聚集跟随者 ////// control.prototype.gatherFollowers = function () { if (!core.isset(core.status.hero.followers) || core.status.hero.followers.length==0) return; diff --git a/libs/core.js b/libs/core.js index 3694ef92..da5b109d 100644 --- a/libs/core.js +++ b/libs/core.js @@ -602,6 +602,11 @@ core.prototype.nextY = function (n) { return core.control.nextY(n); } +////// 某个点是否在勇士旁边 ////// +core.prototype.nearHero = function (x, y) { + return core.control.nearHero(x, y); +} + /////////// 自动行走 & 行走控制 END /////////// diff --git a/project/items.js b/project/items.js index 8b25809c..2074a79d 100644 --- a/project/items.js +++ b/project/items.js @@ -385,23 +385,23 @@ var items_296f5d02_12fd_4166_a7c1_b5e830c9ee3a = }, "canUseItemEffect": { "book": "true", - "fly": "core.status.hero.flyRange.indexOf(core.status.floorId)>=0", - "pickaxe": "var able=false;\nvar ids = [], id2s = [];\nfor (var i in core.status.thisMap.blocks) {\n\tvar block = core.status.thisMap.blocks[i];\n\tif (core.isset(block.event) && !block.disable && Math.abs(block.x-core.status.hero.loc.x)+Math.abs(block.y-core.status.hero.loc.y)<=1 && \n\t\t(block.event.canBreak || block.event.id == 'yellowWall' || block.event.id=='whiteWall' || block.event.id=='blueWall')) { // 能破哪些墙\n\t\t// 四个方向\n\t\tif (core.flags.pickaxeFourDirections || (block.x == core.nextX() && block.y == core.nextY()))\n\t\t\tids.push(i);\n\t\telse id2s.push(i);\n\t}\n}\nif (ids.length>0) {\n\tcore.status.event.data = ids;\n\table=true;\n}\nelse if (id2s.length==1) {\n\tcore.status.event.data = id2s;\n\table=true;\n}\nable", - "icePickaxe": "var able=false;\nfor (var i in core.status.thisMap.blocks) {\n\tvar block = core.status.thisMap.blocks[i];\n\tif (core.isset(block.event) && !block.disable && block.x==core.nextX() && block.y==core.nextY() && block.event.id=='ice') {\n\t\tcore.status.event.data = [i];\n\t\table=true;\n\t}\n}\nable", - "bomb": "var able=false;\nvar ids = [], id2s = [];\nfor (var i in core.status.thisMap.blocks) {\n\tvar block = core.status.thisMap.blocks[i];\n\tif (core.isset(block.event) && !block.disable && block.event.cls.indexOf('enemy')==0 && Math.abs(block.x-core.getHeroLoc('x'))+Math.abs(block.y-core.getHeroLoc('y'))<=1) {\n\t\tvar enemy = core.material.enemys[block.event.id];\n\t\tif (core.isset(enemy) && enemy.notBomb) continue;\n\t\tif (core.flags.bombFourDirections || (block.x==core.nextX() && block.y==core.nextY()))\n\t\t\tids.push(i);\n\t\telse\n\t\t\tid2s.push(i);\n\t}\n}\nif (ids.length>0) {\n\tcore.status.event.data = ids;\n\table=true;\n}\nelse if (id2s.length==1) {\n\tcore.status.event.data = id2s;\n\table=true;\n}\nable", - "hammer": "var able=false;\nvar ids = [], id2s = [];\nfor (var i in core.status.thisMap.blocks) {\n\tvar block = core.status.thisMap.blocks[i];\n\tif (core.isset(block.event) && !block.disable && block.event.cls.indexOf('enemy')==0 && Math.abs(block.x-core.getHeroLoc('x'))+Math.abs(block.y-core.getHeroLoc('y'))<=1) {\n\t\tvar enemy = core.material.enemys[block.event.id];\n\t\tif (core.isset(enemy) && enemy.notBomb) continue;\n\t\tif (block.x==core.nextX() && block.y==core.nextY())\n\t\t\tids.push(i);\n\t\telse\n\t\t\tid2s.push(i);\n\t}\n}\nif (ids.length>0) {\n\tcore.status.event.data = ids;\n\table=true;\n}\nelse if (id2s.length==1) {\n\tcore.status.event.data = id2s;\n\table=true;\n}\nable", - "earthquake": "var able=false;\nvar ids = [];\nfor (var i in core.status.thisMap.blocks) {\n\tvar block = core.status.thisMap.blocks[i];\n\tif (core.isset(block.event) && !block.disable &&\n\t\t(block.event.canBreak || block.event.id == 'yellowWall' || block.event.id == 'blueWall' || block.event.id == 'whiteWall')) { // 能炸的墙壁\n\t\tids.push(i);\n\t}\n}\nif (ids.length>0) {\n\tcore.status.event.data = ids;\n\table=true;\n}\nable", - "centerFly": "var toX = (core.bigmap.width||13)-1-core.getHeroLoc('x'), toY = (core.bigmap.height||13)-1-core.getHeroLoc('y');\ncore.getBlockId(toX, toY) == null", - "upFly": "var able=false;\nvar floorId = core.status.floorId, index = core.floorIds.indexOf(floorId);\nif (index=0 && toX=0 && toY0) {\n\tvar toId = core.floorIds[index-1], toX = core.getHeroLoc('x'), toY = core.getHeroLoc('y');\n\tvar mw = core.floors[toId].width||13, mh = core.floors[toId].height||13;\n\tif (toX>=0 && toX=0 && toY0) {\n\tcore.status.event.data = ids;\n\table=true;\n}\nelse if (id2s.length==1) {\n\tcore.status.event.data = id2s;\n\table=true;\n}\nable", - "bigKey": "var able=false;\nvar ids = [];\nfor (var i in core.status.thisMap.blocks) {\n\tvar block = core.status.thisMap.blocks[i];\n\tif (core.isset(block.event) && !block.disable && block.event.id == 'yellowDoor') {\n\t\tids.push(i);\n\t}\n}\nif (ids.length>0) {\n\tcore.status.event.data = ids;\n\table=true;\n}\nable", - "poisonWine": "core.hasFlag('poison')", - "weakWine": "core.hasFlag('weak')", - "curseWine": "core.hasFlag('curse')", - "superWine": "core.hasFlag('poison') || core.hasFlag('weak') || core.hasFlag('curse')", + "fly": "(function () {\n\treturn core.status.hero.flyRange.indexOf(core.status.floorId)>=0;\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.data = ids;\n\t\treturn true;\n\t}\n\telse if (id2s.length==1) {\n\t\tcore.status.event.data = 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.data = [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.data = ids;\n\t\treturn true;\n\t}\n\tif (id2s.length==1) {\n\t\tcore.status.event.data = 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.data = ids;\n\t\treturn true;\n\t}\n\telse if (id2s.length==1) {\n\t\tcore.status.event.data = 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.data = ids;\n\t\table=true;\n\t}\n\treturn able;\n})();", + "centerFly": "(function () {\n\tvar toX = (core.bigmap.width||13)-1-core.getHeroLoc('x'), toY = (core.bigmap.height||13)-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||13, mh = core.floors[toId].height||13;\n\t\tif (toX>=0 && toX=0 && toY0) {\n\t\tcore.status.event.data = ids;\n\t\treturn true;\n\t}\n\tif (id2s.length==1) {\n\t\tcore.status.event.data = 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.data = ids;\n\t\table=true;\n\t}\n\treturn able;\n})();", + "poisonWine": "core.hasFlag('poison');", + "weakWine": "core.hasFlag('weak');", + "curseWine": "core.hasFlag('curse');", + "superWine": "(function() {\n\treturn core.hasFlag('poison') || core.hasFlag('weak') || core.hasFlag('curse');\n})();", "lifeWand": "true", - "jumpShoes": "var nx=core.nextX(2),ny=core.nextY(2);nx>=0&&nx=0&&ny=0 && nx=0 && ny