From a749cb302f9fd1b4e00f33cd269358262b89b2b0 Mon Sep 17 00:00:00 2001 From: ckcz123 Date: Thu, 14 May 2020 19:13:52 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B7=A6=E5=8F=B3=E8=BD=AC,=E6=A5=BC=E5=B1=82?= =?UTF-8?q?=E5=88=87=E6=8D=A2,=E4=BA=8B=E4=BB=B6=E8=BD=AC=E5=90=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _server/MotaAction.g4 | 91 ++++++++++++++++++++++++++++++++------- _server/editor_blockly.js | 14 +++++- libs/control.js | 3 +- libs/events.js | 8 ++-- libs/maps.js | 22 +++++++++- libs/utils.js | 14 +++++- project/functions.js | 3 +- v2.x-final更新.txt | 2 +- 8 files changed, 129 insertions(+), 28 deletions(-) diff --git a/_server/MotaAction.g4 b/_server/MotaAction.g4 index f720c1d3..34705f97 100644 --- a/_server/MotaAction.g4 +++ b/_server/MotaAction.g4 @@ -283,6 +283,7 @@ if (Floor_List_0!='floorId') toFloorId = Floor_List_0; var loc = ', "loc": ['+Number_0+', '+Number_1+']'; if (Stair_List_0===':now') loc = ''; else if (Stair_List_0!=='loc')loc = ', "stair": "'+Stair_List_0+'"'; +if (DirectionEx_List_0 == 'null') DirectionEx_List_0 = ''; DirectionEx_List_0 = DirectionEx_List_0 && (', "direction": "'+DirectionEx_List_0+'"'); IntString_0 = IntString_0 ?(', "time": '+IntString_0):''; if (IgnoreChangeFloor_List_0!='null') { @@ -341,6 +342,7 @@ action | insert_2_s | exit_s | setBlock_s + | turnBlock_s | showFloorImg_s | hideFloorImg_s | showBgFgMap_s @@ -825,6 +827,39 @@ var code = '{"type": "setBlock", "number": "'+EvalString_0+'"'+floorstr+IdString return code; */; +turnBlock_s + : '事件转向' DirectionEx_List 'x' EvalString? ',' 'y' EvalString? '楼层' IdString? Newline + + +/* turnBlock_s +tooltip : turnBlock:事件转向;自动检索faceIds +helpUrl : https://h5mota.com/games/template/_docs/#/event?id=setblock%EF%BC%9A%E8%AE%BE%E7%BD%AE%E6%9F%90%E4%B8%AA%E5%9B%BE%E5%9D%97 +colour : this.mapColor +default : [null,"","",""] +var floorstr = ''; +if (EvalString_0 && EvalString_1) { + var pattern1 = MotaActionFunctions.pattern.id; + if(pattern1.test(EvalString_0) || pattern1.test(EvalString_1)){ + EvalString_0=MotaActionFunctions.PosString_pre(EvalString_0); + EvalString_1=MotaActionFunctions.PosString_pre(EvalString_1); + EvalString_0=[EvalString_0,EvalString_1] + } else { + var pattern2 = /^([+-]?\d+)(,[+-]?\d+)*$/; + if(!pattern2.test(EvalString_0) || !pattern2.test(EvalString_1))throw new Error('坐标格式错误,请右键点击帮助查看格式'); + EvalString_0=EvalString_0.split(','); + EvalString_1=EvalString_1.split(','); + if(EvalString_0.length!==EvalString_1.length)throw new Error('坐标格式错误,请右键点击帮助查看格式'); + for(var ii=0;ii= 0) { diff --git a/libs/control.js b/libs/control.js index 923b5833..e7ba51c1 100644 --- a/libs/control.js +++ b/libs/control.js @@ -756,8 +756,7 @@ control.prototype.turnHero = function(direction) { core.status.route.push("turn:"+direction); return; } - var dirs = {'up':'right','right':'down','down':'left','left':'up'}; - core.setHeroLoc('direction', dirs[core.getHeroLoc('direction')]); + core.setHeroLoc('direction', core.turnDirection(':right')); core.drawHero(); core.status.route.push("turn"); } diff --git a/libs/events.js b/libs/events.js index ea9a45b4..5ddfb968 100644 --- a/libs/events.js +++ b/libs/events.js @@ -599,6 +599,8 @@ events.prototype._changeFloor_getInfo = function (floorId, stair, heroLoc, time) var index = core.floorIds.indexOf(core.status.floorId); if (index < core.floorIds.length - 1) floorId = core.floorIds[index + 1]; else floorId = core.status.floorId; + } else if (floorId == ':now') { + floorId = core.status.floorId; } if (!core.status.maps[floorId]) { main.log("不存在的楼层:" + floorId); @@ -780,7 +782,7 @@ events.prototype._sys_action = function (data, callback) { var ev = core.clone(data.event.data), ex = data.x, ey = data.y; // 检查是否需要改变朝向 if (ex == core.nextX() && ey == core.nextY()) { - var dir = core.reverseDirection(); + var dir = core.turnDirection(":back"); var id = data.event.id, toId = (data.event.faceIds || {})[dir]; if (toId && id != toId) { var number = core.getNumberById(toId); @@ -1363,7 +1365,7 @@ events.prototype._action_changeFloor = function (data, x, y, prefix) { events.prototype._action_changePos = function (data, x, y, prefix) { core.clearMap('hero'); if (data.x == null && data.y == null && data.direction) { - core.setHeroLoc('direction', data.direction, true); + core.setHeroLoc('direction', core.turnDirection(data.direction), true); core.drawHero(); return core.doAction(); } @@ -1371,7 +1373,7 @@ events.prototype._action_changePos = function (data, x, y, prefix) { var loc = this.__action_getHeroLoc(data.loc, prefix); core.setHeroLoc('x', loc[0]); core.setHeroLoc('y', loc[1]); - if (data.direction) core.setHeroLoc('direction', data.direction); + if (data.direction) core.setHeroLoc('direction', core.turnDirection(data.direction)); core.drawHero(); core.doAction(); } diff --git a/libs/maps.js b/libs/maps.js index 0ff7ba5d..5323bb22 100644 --- a/libs/maps.js +++ b/libs/maps.js @@ -516,7 +516,7 @@ maps.prototype._canMoveHero_checkCannotInOut = function (number, name, direction } return false; } - if (name == 'cannotIn') direction = core.reverseDirection(direction); + if (name == 'cannotIn') direction = core.turnDirection(":back", direction); return core.inArray((this.getBlockByNumber(number).event || {})[name], direction); } @@ -1642,6 +1642,26 @@ maps.prototype.setBlock = function (number, x, y, floorId) { } } +////// 事件转向 ////// +maps.prototype.turnBlock = function (direction, x, y, floorId) { + var id = core.getBlockId(x, y, floorId, true); + var blockInfo = core.getBlockInfo(id); + if (blockInfo == null) return; + var faceIds = blockInfo.faceIds; + var currDirection = null; + for (var dir in core.utils.scan) { + if (faceIds[dir] == id) { + currDirection = dir; + } + } + if (currDirection == null) return; + var nextDirection = core.turnDirection(direction, currDirection); + var nextId = faceIds[nextDirection]; + if (nextId != null && nextId != id) { + this.setBlock(nextId, x, y, floorId); + } +} + ////// 将地图中所有某个图块替换成另一个图块 ////// maps.prototype.replaceBlock = function (fromNumber, toNumber, floorId) { floorId = floorId || core.status.floorId; diff --git a/libs/utils.js b/libs/utils.js index 9f3df032..7cd1ff71 100644 --- a/libs/utils.js +++ b/libs/utils.js @@ -691,9 +691,19 @@ utils.prototype.strlen = function (str) { return count; }; -utils.prototype.reverseDirection = function (direction) { +utils.prototype.turnDirection = function (turn, direction) { direction = direction || core.getHeroLoc('direction'); - return {"left":"right","right":"left","down":"up","up":"down"}[direction] || direction; + var directionList = ["left", "up", "right", "down"]; + if (directionList.indexOf(turn) >= 0) return turn; + switch (turn) { + case ':left': turn = 3; break; // turn left + case ':right': turn = 1; break; // turn right + case ':back': turn = 2; break; // turn back + default: turn = 0; break; + } + var index = directionList.indexOf(direction); + if (index < 0) return direction; + return directionList[(index + (turn || 0)) % 4]; } utils.prototype.matchWildcard = function (pattern, string) { diff --git a/project/functions.js b/project/functions.js index 3490a227..27ee7246 100644 --- a/project/functions.js +++ b/project/functions.js @@ -111,6 +111,7 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a = // 重置画布尺寸 core.maps.resizeMap(floorId); // 设置勇士的位置 + heroLoc.direction = core.turnDirection(heroLoc.direction); core.status.hero.loc = heroLoc; // 检查重生怪并重置 if (!fromLoad) { @@ -1107,7 +1108,7 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a = type[currloc] = type[currloc] || {}; type[currloc]["阻击伤害"] = true; - var rdir = core.reverseDirection(dir); + var rdir = core.turnDirection(":back", dir); // 检查下一个点是否存在事件(从而判定是否移动) var rnx = x + core.utils.scan[rdir].x, rny = y + core.utils.scan[rdir].y; diff --git a/v2.x-final更新.txt b/v2.x-final更新.txt index ffcb1d30..a04d2b2f 100644 --- a/v2.x-final更新.txt +++ b/v2.x-final更新.txt @@ -33,7 +33,7 @@ (已完成!) 图块ID不可全数字 怪物详细信息富文本化 (已完成!) for和forEach事件 -转向:顺时针/逆时针/反向 +(已完成!) 转向:顺时针/逆时针/反向 事件转向 (已完成!) 合并数值操作事件 (已完成!) fromLoad,聚集问题