diff --git a/_server/MotaAction.g4 b/_server/MotaAction.g4 index bce0fd45..60658a76 100644 --- a/_server/MotaAction.g4 +++ b/_server/MotaAction.g4 @@ -2121,13 +2121,13 @@ return code; */; move_s - : '移动事件' 'x' PosString? ',' 'y' PosString? '动画时间' IntString? '不消失' Bool '不等待执行完毕' Bool BGNL? StepString Newline + : '移动事件' 'x' PosString? ',' 'y' PosString? '动画时间' IntString? '不消失' Bool '不等待执行完毕' Bool BGNL? moveDirection+ Newline /* move_s tooltip : move: 让某个NPC/怪物移动,位置可不填代表当前事件 helpUrl : /_docs/#/instruction -default : ["","",500,true,false,"上右3下2后4左前2"] +default : ["","",500,true,false,null] selectPoint : ["PosString_0", "PosString_1"] colour : this.mapColor var floorstr = ''; @@ -2137,10 +2137,21 @@ if (PosString_0 && PosString_1) { IntString_0 = IntString_0 ?(', "time": '+IntString_0):''; Bool_0 = Bool_0?', "keep": true':''; Bool_1 = Bool_1?', "async": true':''; -var code = '{"type": "move"'+floorstr+IntString_0+Bool_0+Bool_1+', "steps": '+JSON.stringify(StepString_0)+'},\n'; +var code = '{"type": "move"'+floorstr+IntString_0+Bool_0+Bool_1+', "steps": ['+moveDirection_0.trim().substring(2)+']},\n'; return code; */; +moveDirection + : '移动方向' Move_List '格数' Int Newline + +/* moveDirection +tooltip : 移动方向 +helpUrl : /_docs/#/instruction +default : ["up", 0] +colour : this.subColor +return ', "' + Move_List_0 + ':' + Int_0 + '"'; +*/; + moveAction_s : '勇士前进一格或撞击' Newline @@ -2155,7 +2166,7 @@ return '{"type": "moveAction"},\n'; moveHero_s - : '无视地形移动勇士' '动画时间' IntString? '不等待执行完毕' Bool BGNL? StepString Newline + : '无视地形移动勇士' '动画时间' IntString? '不等待执行完毕' Bool BGNL? moveDirection+ Newline /* moveHero_s @@ -2165,7 +2176,7 @@ default : ["",false,"上右3下2后4左前2"] colour : this.mapColor IntString_0 = IntString_0 ?(', "time": '+IntString_0):''; Bool_0 = Bool_0?', "async": true':''; -var code = '{"type": "moveHero"'+IntString_0+Bool_0+', "steps": '+JSON.stringify(StepString_0)+'},\n'; +var code = '{"type": "moveHero"'+IntString_0+Bool_0+', "steps": ['+moveDirection_0.trim().substring(2)+']},\n'; return code; */; @@ -3664,6 +3675,10 @@ Key_List : '黄钥匙'|'蓝钥匙'|'红钥匙'|'绿钥匙'|'铁门钥匙' /*Key_List ['yellowKey','blueKey','redKey','greenKey','steelKey']*/; +Move_List + : '上'|'下'|'左'|'右'|'前'|'后'|'左上'|'左下'|'右上'|'右下' + /*Move_List ['up','down','left','right','forward','backward','leftup','leftdown','rightup','rightdown']*/; + //转blockly后不保留需要加" EvalString : Equote_double (ESC_double | ~["\\])* Equote_double diff --git a/_server/MotaActionParser.js b/_server/MotaActionParser.js index cc917a69..5cb79336 100644 --- a/_server/MotaActionParser.js +++ b/_server/MotaActionParser.js @@ -399,15 +399,33 @@ ActionParser.prototype.parseAction = function() { break; case "move": // 移动事件 data.loc=data.loc||['','']; + var buildMoveDirection= function (obj) { + obj = MotaActionFunctions.processMoveDirections(obj||[]); + var res = null; + for(var ii=obj.length-1,one;one=obj[ii];ii--) { + var v = one.split(':'); + res=MotaActionBlocks['moveDirection'].xmlText([v[0], parseInt(v[1]), res]); + } + return res; + } this.next = MotaActionBlocks['move_s'].xmlText([ - data.loc[0],data.loc[1],data.time,data.keep||false,data.async||false,this.StepString(data.steps),this.next]); + data.loc[0],data.loc[1],data.time,data.keep||false,data.async||false,buildMoveDirection(data.steps),this.next]); break; case "moveAction": // 前进一格或撞击 this.next = MotaActionBlocks['moveAction_s'].xmlText([this.next]); break; case "moveHero": // 无视地形移动勇士 + var buildMoveDirection= function (obj) { + obj = MotaActionFunctions.processMoveDirections(obj||[]); + var res = null; + for(var ii=obj.length-1,one;one=obj[ii];ii--) { + var v = one.split(':'); + res=MotaActionBlocks['moveDirection'].xmlText([v[0], parseInt(v[1]), res]); + } + return res; + } this.next = MotaActionBlocks['moveHero_s'].xmlText([ - data.time,data.async||false,this.StepString(data.steps),this.next]); + data.time,data.async||false,buildMoveDirection(data.steps),this.next]); break; case "jump": // 跳跃事件 data.from=data.from||['','']; @@ -1273,6 +1291,24 @@ MotaActionFunctions.PosString_pre = function(PosString){ return '"'+MotaActionFunctions.replaceFromName(PosString)+'"'; } +MotaActionFunctions.processMoveDirections = function (steps) { + var curr = null, num = null; + var result = []; + steps.forEach(function (one) { + var v = one.split(':'); + if (v.length == 1) v.push("1"); + if (v[0] != curr) { + if (curr != null) result.push(curr+":"+num); + curr = v[0]; + num = parseInt(v[1]); + } else { + num += parseInt(v[1]); + } + }); + if (curr != null) result.push(curr+":"+num); + return result; +} + MotaActionFunctions.StepString_pre = function(StepString){ //StepString='上右3下2左上左2' var route = StepString.replace(/上/g,'U').replace(/下/g,'D').replace(/左/g,'L').replace(/右/g,'R').replace(/前/g,'F').replace(/后/g,'B'); diff --git a/libs/control.js b/libs/control.js index e86f4147..7c2db1a5 100644 --- a/libs/control.js +++ b/libs/control.js @@ -795,7 +795,7 @@ control.prototype.drawHero = function (status, offset, frame) { var x = core.getHeroLoc('x'), y = core.getHeroLoc('y'), direction = core.getHeroLoc('direction'); status = status || 'stop'; offset = offset || 0; - var way = core.utils.scan[direction]; + var way = core.utils.scan2[direction]; var dx = way.x, dy = way.y, offsetX = dx * offset, offsetY = dy * offset; core.bigmap.offsetX = core.clamp((x - core.__HALF_SIZE__) * 32 + offsetX, 0, 32*core.bigmap.width-core.__PIXELS__); core.bigmap.offsetY = core.clamp((y - core.__HALF_SIZE__) * 32 + offsetY, 0, 32*core.bigmap.height-core.__PIXELS__); @@ -871,8 +871,8 @@ control.prototype._drawHero_getDrawObjs = function (direction, x, y, status, off "width": core.material.icons.hero.width || 32, "height": core.material.icons.hero.height, "heroIcon": heroIconArr[direction], - "posx": x * 32 - core.bigmap.offsetX + core.utils.scan[direction].x * offset, - "posy": y * 32 - core.bigmap.offsetY + core.utils.scan[direction].y * offset, + "posx": x * 32 - core.bigmap.offsetX + core.utils.scan2[direction].x * offset, + "posy": y * 32 - core.bigmap.offsetY + core.utils.scan2[direction].y * offset, "status": status, "index": index++, }); @@ -882,8 +882,8 @@ control.prototype._drawHero_getDrawObjs = function (direction, x, y, status, off "width": core.material.images.images[t.name].width/4, "height": core.material.images.images[t.name].height/4, "heroIcon": heroIconArr[t.direction], - "posx": 32*t.x - core.bigmap.offsetX + (t.stop?0:core.utils.scan[t.direction].x*Math.abs(offset)), - "posy": 32*t.y - core.bigmap.offsetY + (t.stop?0:core.utils.scan[t.direction].y*Math.abs(offset)), + "posx": 32*t.x - core.bigmap.offsetX + (t.stop?0:core.utils.scan2[t.direction].x*Math.abs(offset)), + "posy": 32*t.y - core.bigmap.offsetY + (t.stop?0:core.utils.scan2[t.direction].y*Math.abs(offset)), "status": t.stop?"stop":status, "index": index++ }); @@ -1028,8 +1028,8 @@ control.prototype.gatherFollowers = function () { control.prototype.updateFollowers = function () { core.status.hero.followers.forEach(function (t) { if (!t.stop) { - t.x += core.utils.scan[t.direction].x; - t.y += core.utils.scan[t.direction].y; + t.x += core.utils.scan2[t.direction].x; + t.y += core.utils.scan2[t.direction].y; } }) @@ -1037,8 +1037,8 @@ control.prototype.updateFollowers = function () { core.status.hero.followers.forEach(function (t) { t.stop = true; var dx = nowx - t.x, dy = nowy - t.y; - for (var dir in core.utils.scan) { - if (core.utils.scan[dir].x == dx && core.utils.scan[dir].y == dy) { + for (var dir in core.utils.scan2) { + if (core.utils.scan2[dir].x == dx && core.utils.scan2[dir].y == dy) { t.stop = false; t.direction = dir; } diff --git a/libs/events.js b/libs/events.js index 7d37f902..9981c7f7 100644 --- a/libs/events.js +++ b/libs/events.js @@ -3068,8 +3068,10 @@ events.prototype._vibrate_update = function (shakeInfo) { /////// 使用事件让勇士移动。这个函数将不会触发任何事件 ////// events.prototype.eventMoveHero = function(steps, time, callback) { time = time || core.values.moveSpeed; - var step = 0, moveSteps = (steps||[]).filter(function (t) { - return ['up','down','left','right','forward','backward'].indexOf(t)>=0; + var step = 0, moveSteps = (steps||[]).map(function (t) { + return [t.split(':')[0], parseInt(t.split(':')[1]||"1")]; + }).filter(function (t) { + return ['up','down','left','right','forward','backward','leftup','leftdown','rightup','rightdown'].indexOf(t[0])>=0; }); core.status.heroMoving = -1; var animate=window.setInterval(function() { @@ -3090,11 +3092,20 @@ events.prototype.eventMoveHero = function(steps, time, callback) { } events.prototype._eventMoveHero_moving = function (step, moveSteps) { - var direction = moveSteps[0], x = core.getHeroLoc('x'), y = core.getHeroLoc('y'); + var curr = moveSteps[0]; + var direction = curr[0], x = core.getHeroLoc('x'), y = core.getHeroLoc('y'); // ------ 前进/后退 var o = direction == 'backward' ? -1 : 1; if (direction == 'forward' || direction == 'backward') direction = core.getHeroLoc('direction'); + var faceDirection = direction; + if (direction == 'leftup' || direction == 'leftdown') faceDirection = 'left'; + if (direction == 'rightup' || direction == 'rightdown') faceDirection = 'right'; core.setHeroLoc('direction', direction); + if (curr[1] <= 0) { + core.setHeroLoc('direction', faceDirection); + moveSteps.shift(); + return true; + } if (step <= 4) { core.drawHero('leftFoot', 4 * o * step); } @@ -3102,10 +3113,12 @@ events.prototype._eventMoveHero_moving = function (step, moveSteps) { core.drawHero('rightFoot', 4 * o * step); } if (step == 8) { - core.setHeroLoc('x', x + o * core.utils.scan[direction].x, true); - core.setHeroLoc('y', y + o * core.utils.scan[direction].y, true); + core.setHeroLoc('x', x + o * core.utils.scan2[direction].x, true); + core.setHeroLoc('y', y + o * core.utils.scan2[direction].y, true); core.updateFollowers(); - moveSteps.shift(); + curr[1]--; + if (curr[1] <= 0) moveSteps.shift(); + core.setHeroLoc('direction', faceDirection); return true; } return false; diff --git a/libs/icons.js b/libs/icons.js index f9eef5ff..1c2b70a2 100644 --- a/libs/icons.js +++ b/libs/icons.js @@ -15,7 +15,10 @@ icons.prototype._init = function () { } icons.prototype.getIcons = function () { - return core.clone(this.icons); + var icons = core.clone(this.icons); + icons.hero.leftup = icons.hero.leftdown = icons.hero.left; + icons.hero.rightup = icons.hero.rightdown = icons.hero.right; + return icons; } ////// 根据道具ID获得其cls ////// diff --git a/libs/maps.js b/libs/maps.js index 31655939..28aa3ba4 100644 --- a/libs/maps.js +++ b/libs/maps.js @@ -2244,8 +2244,10 @@ maps.prototype.moveBlock = function (x, y, steps, time, keep, callback) { return; } var block = blockArr[0], blockInfo = blockArr[1]; - var moveSteps = (steps||[]).filter(function (t) { - return ['up','down','left','right','forward','backward'].indexOf(t)>=0; + var moveSteps = (steps||[]).map(function (t) { + return [t.split(':')[0], parseInt(t.split(':')[1]||"1")]; + }).filter(function (t) { + return ['up','down','left','right','forward','backward','leftup','leftdown','rightup','rightdown'].indexOf(t[0])>=0; }); var canvases = this._initDetachedBlock(blockInfo, x, y, block.event.animate !== false); this._moveDetachedBlock(blockInfo, 32 * x, 32 * y, 1, canvases); @@ -2278,7 +2280,7 @@ maps.prototype._moveBlock_doMove = function (blockInfo, canvases, moveInfo, call maps.prototype._moveBlock_updateDirection = function (blockInfo, moveInfo) { moveInfo.offset = 1; - var direction = moveInfo.moveSteps[0]; + var curr = moveInfo.moveSteps[0]; if (moveInfo.lastDirection == null) { for (var d in blockInfo.faceIds) { if (blockInfo.faceIds[d] == blockInfo.id) { @@ -2287,24 +2289,36 @@ maps.prototype._moveBlock_updateDirection = function (blockInfo, moveInfo) { } } } - if (direction == 'forward' || direction == 'backward') { + if (curr[0] == 'forward' || curr[0] == 'backward') { if (moveInfo.lastDirection == null) { moveInfo.moveSteps.shift(); return false; } - if (direction == 'backward') + if (curr[0] == 'backward') moveInfo.offset = -1; - direction = moveInfo.lastDirection; + curr[0] = moveInfo.lastDirection; } - moveInfo.lastDirection = moveInfo.moveSteps[0] = direction; - moveInfo.x += core.utils.scan[direction].x * moveInfo.offset; - moveInfo.y += core.utils.scan[direction].y * moveInfo.offset; + moveInfo.lastDirection = curr[0]; + // 根据faceIds修改朝向 - var currid = blockInfo.faceIds[direction]; + var faceDirection = curr[0]; + if (faceDirection == 'leftup' || faceDirection == 'leftdown') faceDirection = 'left'; + if (faceDirection == 'rightup' || faceDirection == 'rightdown') faceDirection = 'right'; + var currid = blockInfo.faceIds[faceDirection]; if (currid) { var posY = core.material.icons[blockInfo.cls][currid]; - if (posY != null) blockInfo.posY = posY; + if (posY != null) { + blockInfo.number = core.getNumberById(currid) || blockInfo.number; + blockInfo.posY = posY; + } } + // 处理 left:0 的情况,仅转向 + if (curr[1] <= 0) { + moveInfo.moveSteps.shift(); + return false; + } + moveInfo.x += core.utils.scan2[curr[0]].x * moveInfo.offset; + moveInfo.y += core.utils.scan2[curr[0]].y * moveInfo.offset; return true; } @@ -2312,14 +2326,17 @@ maps.prototype._moveBlock_moving = function (blockInfo, canvases, moveInfo) { if (moveInfo.step == 0) { if (!this._moveBlock_updateDirection(blockInfo, moveInfo)) return; } - var direction = moveInfo.moveSteps[0]; + var curr = moveInfo.moveSteps[0]; moveInfo.step++; - moveInfo.px += core.utils.scan[direction].x * 2 * moveInfo.offset; - moveInfo.py += core.utils.scan[direction].y * 2 * moveInfo.offset; + moveInfo.px += core.utils.scan2[curr[0]].x * 2 * moveInfo.offset; + moveInfo.py += core.utils.scan2[curr[0]].y * 2 * moveInfo.offset; this._moveDetachedBlock(blockInfo, moveInfo.px, moveInfo.py, moveInfo.opacity, canvases); if (moveInfo.step == 16) { moveInfo.step = 0; - moveInfo.moveSteps.shift(); + moveInfo.moveSteps[0][1]--; + if (moveInfo.moveSteps[0][1]<=0) { + moveInfo.moveSteps.shift(); + } } } diff --git a/libs/utils.js b/libs/utils.js index a1e22203..7857e440 100644 --- a/libs/utils.js +++ b/libs/utils.js @@ -15,6 +15,16 @@ function utils() { 'down': {'x': 0, 'y': 1}, 'right': {'x': 1, 'y': 0} }; + this.scan2 = { + 'up': {'x': 0, 'y': -1}, + 'left': {'x': -1, 'y': 0}, + 'down': {'x': 0, 'y': 1}, + 'right': {'x': 1, 'y': 0}, + 'leftup': {'x': -1, 'y': -1}, + 'leftdown': {'x': -1, 'y': 1}, + 'rightup': {'x': 1, 'y': -1}, + 'rightdown': {'x': 1, 'y': 1} + }; } utils.prototype._init = function () {