From 20781645d4cfa66f07ed3c8da2396ef07233cac2 Mon Sep 17 00:00:00 2001 From: oc Date: Thu, 21 Mar 2019 22:31:13 +0800 Subject: [PATCH] type:closeDoor --- _docs/event.md | 24 ++++++++++++++++++++++++ _server/blockly/MotaAction.g4 | 23 +++++++++++++++++++++++ _server/editor.js | 2 +- _server/editor_blockly.js | 1 + libs/events.js | 31 +++++++++++++++++++++++++++++++ 5 files changed, 80 insertions(+), 1 deletion(-) diff --git a/_docs/event.md b/_docs/event.md index 0ff220b4..73961975 100644 --- a/_docs/event.md +++ b/_docs/event.md @@ -901,6 +901,30 @@ needKey是可选的,如果设置为true则需要钥匙才能打开此门。如 !> needKey仅对当前楼层开门有效!跨楼层的门仍然不需要钥匙即可打开,如有需求请自行判定。 +### closeDoor:关门 + +从V2.6开始提供了关门事件`{"type": "closeDoor"}`,拥有关门动画和对应的音效。 + +``` js +"x,y": [ // 实际执行的事件列表 + {"type": "closeDoor", "id": "yellowDoor", "loc": [3,6]}, // 给(3,6)点关上黄门 + {"type": "closeDoor", "id": "specialDoor"}, // 不写loc则视为当前点 +] +``` + +id为你要关门的ID,需要是一个合法的门,系统默认只支持如下几种: + +``` +yellowDoor, blueDoor, redDoor, greenDoor, specialDoor, steelDoor, +yellowWall, blueWall, whiteWall +``` + +如果需要自己添加门,请参考[新增门和对应的钥匙](personalization#新增门和对应的钥匙)。 + +loc可选,为要关的位置,不填默认为当前点。 + +关门事件需要保证该点是空地,否则将无视此事件。 + ### changeFloor:楼层切换 在事件中也可以对楼层进行切换。一个比较典型的例子就是TSW中,勇士在三楼的陷阱被扔到了二楼,就是一个楼层切换事件。 diff --git a/_server/blockly/MotaAction.g4 b/_server/blockly/MotaAction.g4 index a31b4afd..6cf3b5d3 100644 --- a/_server/blockly/MotaAction.g4 +++ b/_server/blockly/MotaAction.g4 @@ -256,6 +256,7 @@ action | waitAsync_s | battle_s | openDoor_s + | closeDoor_s | changeFloor_s | changePos_0_s | changePos_1_s @@ -961,6 +962,23 @@ var code = '{"type": "openDoor"'+floorstr+IdString_0+Bool_0+'},\n'; return code; */; +closeDoor_s + : '关门' 'x' PosString? ',' 'y' PosString? 'ID' IdString Newline + + +/* closeDoor_s +tooltip : closeDoor: 关门事件,需要该点本身无事件 +helpUrl : https://h5mota.com/games/template/docs/#/event?id=opendoor%EF%BC%9A%E5%BC%80%E9%97%A8 +default : ["","","yellowDoor"] +colour : this.dataColor +var floorstr = ''; +if (PosString_0 && PosString_1) { + floorstr = ', "loc": ['+PosString_0+','+PosString_1+']'; +} +var code = '{"type": "closeDoor", "id": "'+IdString_0+'"'+floorstr+'},\n'; +return code; +*/; + changeFloor_s : '楼层切换' IdString? 'x' PosString? ',' 'y' PosString? '朝向' DirectionEx_List '动画时间' Int? Newline @@ -2338,6 +2356,11 @@ ActionParser.prototype.parseAction = function() { this.next = MotaActionBlocks['openDoor_s'].xmlText([ data.loc[0],data.loc[1],data.floorId||'',data.needKey||false,this.next]); break; + case "closeDoor": // 关一个门,需要该点无事件 + data.loc=data.loc||['',''] + this.next = MotaActionBlocks['closeDoor_s'].xmlText([ + data.loc[0],data.loc[1],data.id,this.next]); + break; case "useItem": // 使用道具 this.next = MotaActionBlocks['useItem_s'].xmlText([ data.id,this.next]); diff --git a/_server/editor.js b/_server/editor.js index bd1524f3..7ef741bd 100644 --- a/_server/editor.js +++ b/_server/editor.js @@ -721,7 +721,7 @@ editor.prototype.listen = function () { mouseOutCheck = 2; setTimeout(clear1); e.stopPropagation(); - uc.clearRect(0, 0, core.__SIZE__, core.__SIZE__); + uc.clearRect(0, 0, core.__PIXELS__, core.__PIXELS__); var loc = eToLoc(e); var pos = locToPos(loc,true); stepPostfix = []; diff --git a/_server/editor_blockly.js b/_server/editor_blockly.js index 5cc6747a..a1a01045 100644 --- a/_server/editor_blockly.js +++ b/_server/editor_blockly.js @@ -93,6 +93,7 @@ editor_blockly = function () { MotaActionBlocks['changePos_1_s'].xmlText(), MotaActionBlocks['battle_s'].xmlText(), MotaActionBlocks['openDoor_s'].xmlText(), + MotaActionBlocks['closeDoor_s'].xmlText(), MotaActionBlocks['useItem_s'].xmlText(), MotaActionBlocks['openShop_s'].xmlText(), MotaActionBlocks['setBlock_s'].xmlText(), diff --git a/libs/events.js b/libs/events.js index 93d5e143..b573fb03 100644 --- a/libs/events.js +++ b/libs/events.js @@ -1118,6 +1118,11 @@ events.prototype._action_openDoor = function (data, x, y, prefix) { } } +events.prototype._action_closeDoor = function (data, x, y, prefix) { + var loc = this.__action_getLoc(data.loc, x, y, prefix); + core.closeDoor(loc[0], loc[1], data.id, core.doAction); +} + events.prototype._action_useItem = function (data, x, y, prefix) { // 考虑到可能覆盖楼传事件的问题,这里不对fly进行检查。 if (data.id != 'book' && core.canUseItem(data.id)) { @@ -1800,6 +1805,32 @@ events.prototype.setGlobalFlag = function (name, value) { core.resize(); } +events.prototype.closeDoor = function (x, y, id, callback) { + id = id || ""; + if (!(id.endsWith("Door") || id.endsWith("Wall")) + || !core.material.icons.animates[id] || core.getBlock(x, y) != null) { + if (callback) callback(); + return; + } + // 关门动画 + core.playSound('door.mp3'); + var door = core.material.icons.animates[id]; + var speed = id.endsWith("Door") ? 30 : 70, state = 0; + var animate = window.setInterval(function () { + state++; + if (state == 4) { + clearInterval(animate); + delete core.animateFrame.asyncId[animate]; + core.setBlock(core.getNumberById(id), x, y); + if (callback) callback(); + return; + } + core.clearMap('event', 32 * x, 32 * y, 32, 32); + core.drawImage('event', core.material.images.animates, 32 * (4-state), 32 * door, 32, 32, 32 * x, 32 * y, 32, 32); + }, speed / core.status.replay.speed); + core.animateFrame.asyncId[animate] = true; +} + ////// 显示图片 ////// events.prototype.showImage = function (code, image, x, y, dw, dh, opacityVal, time, callback) { dw /= 100;