From bb8182d589e9f8c6fbc8f74f643eb25ad31a8eee Mon Sep 17 00:00:00 2001 From: oc Date: Tue, 19 Mar 2019 23:57:43 +0800 Subject: [PATCH] type:insert --- _docs/event.md | 16 +++++++++-- _server/blockly/MotaAction.g4 | 51 +++++++++++++++++++++++++++++------ libs/control.js | 4 +-- libs/events.js | 22 ++++++++++----- libs/ui.js | 2 ++ main.js | 1 + project/events.js | 34 +++++++++-------------- project/functions.js | 18 +++++-------- 8 files changed, 96 insertions(+), 52 deletions(-) diff --git a/_docs/event.md b/_docs/event.md index bb18169f..0ff220b4 100644 --- a/_docs/event.md +++ b/_docs/event.md @@ -616,10 +616,11 @@ NPC对话事件结束后如果需要NPC消失也需要调用 `{"type": "hide"}` ``` js "x,y": [ // 实际执行的事件列表 - {"type": "insert", "name": "加点事件"}, // 插入公共事件:加点事件 - {"type": "insert", "name": "毒衰咒处理"}, // 插入公共事件:毒衰咒处理 + {"type": "insert", "name": "加点事件", "args": [10] }, // 插入公共事件:加点事件,传入参数10 + {"type": "insert", "name": "毒衰咒处理", "args": [0]}, // 插入公共事件:毒衰咒处理,传入参数0 {"type": "insert", "loc": [3,6]}, // 插入[3,6]点的事件并执行 {"type": "insert", "loc": [10,10], "floorId": "MT1"}, // 插入MT1层[10,10]点的事件并执行 + {"type": "insert", "loc": [2,2], "args": [1,"flag:abc","status:atk+status:def"]}, // 传入三个参数 "上面的插入事件执行完毕后会接着继续执行后面的事件" ] ``` @@ -631,6 +632,7 @@ NPC对话事件结束后如果需要NPC消失也需要调用 `{"type": "hide"}` - 否则,如果写了`"loc": [x,y]`,则会插入另一个地点的事件 - loc为另一个地点的坐标 - floorId可选,代表另一个地点所在的楼层;如果不写则默认为当前层。 + - 从V2.6开始,还可以传可选的which,可以为`afterBattle`/`afterGetItem`/`afterOpenDoor`,代表插入该点的战后/获得道具后/开门后事件。 和`type:trigger`不同的是,**`type:trigger`是立刻将当前事件结束(剩下所有内容都忽略),然后重新启动另一个地点的action事件。** @@ -638,6 +640,16 @@ NPC对话事件结束后如果需要NPC消失也需要调用 `{"type": "hide"}` **这个过程中,当前事件不会被结束,当前的楼层和事件坐标不会发生改变。** 插入的事件执行完毕后,会继续执行接下来的内容。 +从V2.6开始,插入事件允许传参。如果需要传参,则需要增加一个`args`数组。 + +例如: `"args": [1,"flag:abc","status:atk+status:def"]` 传入了三个参数。 + +系统会自动把`flag:arg1`设置为第一个参数数值,`flag:arg2`设置为第二个参数数值,等等。 + +(`flag:arg0`则会被置为公共事件名称,或者插入的点的坐标) + +即可在事件中直接取用`flag:arg1`等等来获得各项参数值!。 + ### revisit:立即重启当前事件 revisit和trigger完全相同,只不过是立刻触发的还是本地点的事件 diff --git a/_server/blockly/MotaAction.g4 b/_server/blockly/MotaAction.g4 index 1b2005b3..a31b4afd 100644 --- a/_server/blockly/MotaAction.g4 +++ b/_server/blockly/MotaAction.g4 @@ -614,29 +614,55 @@ return code; */; insert_1_s - : '插入公共事件' EvalString Newline + : '插入公共事件' EvalString '参数列表' EvalString? Newline /* insert_1_s tooltip : insert: 插入公共事件并执行 helpUrl : https://h5mota.com/games/template/docs/#/event?id=insert%ef%bc%9a%e6%8f%92%e5%85%a5%e5%85%ac%e5%85%b1%e4%ba%8b%e4%bb%b6%e6%88%96%e5%8f%a6%e4%b8%80%e4%b8%aa%e5%9c%b0%e7%82%b9%e7%9a%84%e4%ba%8b%e4%bb%b6%e5%b9%b6%e6%89%a7%e8%a1%8c -default : ["加点事件"] +default : ["加点事件", ""] colour : this.eventColor -var code = '{"type": "insert", "name": "'+EvalString_0+'"},\n'; +if (EvalString_1) { + if (EvalString_1.indexOf('"')>=0) + throw new Error('请勿在此处使用双引号!尝试使用单引号吧~'); + // 检查是不是数组 + try { + if (!(JSON.parse(EvalString_1.replace(/'/g, '"')) instanceof Array)) throw new Error(); + } + catch (e) { + throw new Error('参数列表必须是个有效的数组!'); + } + EvalString_1 = ', "args": ' +EvalString_1; +} +var code = '{"type": "insert", "name": "'+EvalString_0+'"'+EvalString_1+'},\n'; return code; */; insert_2_s - : '插入事件' 'x' PosString ',' 'y' PosString '楼层' IdString? Newline + : '插入事件' 'x' PosString ',' 'y' PosString Event_List? '楼层' IdString? '参数列表' EvalString? ENewline /* insert_2_s tooltip : insert: 立即插入另一个地点的事件执行,当前事件不会中断,事件坐标不会改变 helpUrl : https://h5mota.com/games/template/docs/#/event?id=insert%ef%bc%9a%e6%8f%92%e5%85%a5%e5%85%ac%e5%85%b1%e4%ba%8b%e4%bb%b6%e6%88%96%e5%8f%a6%e4%b8%80%e4%b8%aa%e5%9c%b0%e7%82%b9%e7%9a%84%e4%ba%8b%e4%bb%b6%e5%b9%b6%e6%89%a7%e8%a1%8c -default : ["0","0",""] +default : ["0","0",null,"",""] colour : this.eventColor IdString_0 = IdString_0 && (', "floorId": "'+IdString_0+'"'); -var code = '{"type": "insert", "loc": ['+PosString_0+','+PosString_1+']'+IdString_0+'},\n'; +if (EvalString_0) { + if (EvalString_0.indexOf('"')>=0) + throw new Error('请勿在此处使用双引号!尝试使用单引号吧~'); + try { + if (!(JSON.parse(EvalString_0.replace(/'/g, '"')) instanceof Array)) throw new Error(); + } + catch (e) { + throw new Error('参数列表必须是个有效的数组!'); + } + EvalString_0 = ', "args": ' +EvalString_0; +} +if (Event_List_0 && Event_List_0 !=='null') + Event_List_0 = ', "which": "'+Event_List_0+'"'; +else Event_List_0 = ''; +var code = '{"type": "insert", "loc": ['+PosString_0+','+PosString_1+']'+Event_List_0+IdString_0+EvalString_0+'},\n'; return code; */; @@ -1852,6 +1878,10 @@ Bg_Fg_List : '背景层'|'前景层' /*Bg_Fg_List ['bg','fg']*/; +Event_List + : '事件'|'战后事件'|'道具后事件'|'开门后事件' + /*Event_List ['null','afterBattle','afterGetItem','afterOpenDoor']*/; + Floor_Meta_List : '楼层中文名'|'状态栏名称'|'能否使用楼传'|'能否打开快捷商店'|'是否不可浏览地图'|'是否不可瞬间移动'|'默认地面ID'|'楼层贴图'|'宝石血瓶效果'|'上楼点坐标'|'下楼点坐标'|'背景音乐'|'画面色调'|'天气和强度'|'是否地下层' /*Floor_Meta_List ['title','name','canFlyTo', 'canUseQuickShop', 'cannotViewMap', 'cannotMoveDirectly', 'defaultGround', 'images', 'item_ratio', 'upFloor', 'downFloor', 'bgm', 'color', 'weather', 'underGround']*/; @@ -2329,13 +2359,18 @@ ActionParser.prototype.parseAction = function() { data.loc[0],data.loc[1],this.next]); break; case "insert": // 强制插入另一个点的事件在当前事件列表执行,当前坐标和楼层不会改变 + if (data.args instanceof Array) { + try { data.args = JSON.stringify(data.args).replace(/"/g, "'"); } + catch (e) {data.args = '';} + } + else data.args = null; if (this.isset(data.name)) { this.next = MotaActionBlocks['insert_1_s'].xmlText([ - data.name, this.next]); + data.name, data.args||"", this.next]); } else { this.next = MotaActionBlocks['insert_2_s'].xmlText([ - data.loc[0],data.loc[1],data.floorId||'',this.next]); + data.loc[0],data.loc[1],data.which,data.floorId||'',data.args||"",this.next]); } break; case "playSound": diff --git a/libs/control.js b/libs/control.js index 2b4ce7ca..7bc57e08 100644 --- a/libs/control.js +++ b/libs/control.js @@ -2141,8 +2141,8 @@ control.prototype.clearStatusBar = function() { ////// 更新状态栏 ////// control.prototype.updateStatusBar = function () { - if (core.isPlaying()) - this.controldata.updateStatusBar(); + if (!core.isPlaying()) return; + this.controldata.updateStatusBar(); this._updateStatusBar_setToolboxIcon(); } diff --git a/libs/events.js b/libs/events.js index 8f481339..6821c204 100644 --- a/libs/events.js +++ b/libs/events.js @@ -579,16 +579,13 @@ events.prototype.passNet = function (data) { if (core.hasItem('shoes')) return; // 血网 lavaNet 移动到 checkBlock 中处理 if (data.event.id == 'poisonNet') { // 毒网 - core.setFlag('debuff', 'poison'); - core.insertAction('毒衰咒处理'); + core.insertAction({"type":"insert","name":"毒衰咒处理","args":[0]}); } else if (data.event.id == 'weakNet') { // 衰网 - core.setFlag('debuff', 'weak'); - core.insertAction('毒衰咒处理'); + core.insertAction({"type":"insert","name":"毒衰咒处理","args":[1]}); } else if (data.event.id == 'curseNet') { // 咒网 - core.setFlag('debuff', 'curse'); - core.insertAction('毒衰咒处理'); + core.insertAction({"type":"insert","name":"毒衰咒处理","args":[2]}); } core.updateStatusBar(); } @@ -1166,13 +1163,24 @@ events.prototype._action_trigger = function (data, x, y, prefix) { } events.prototype._action_insert = function (data, x, y, prefix) { + // 设置参数 + if (data.args instanceof Array) { + for (var i = 0; i < data.args.length; ++i) { + try { + core.setFlag('arg'+(i+1), core.calValue(data.args[i], prefix)); + } catch (e) { main.log(e); } + } + } if (data.name) { // 公共事件 + core.setFlag('arg0', data.name); core.insertAction(this.getCommonEvent(data.name)); } else { var loc = this.__action_getLoc(data.loc, x, y, prefix); + core.setFlag('arg0', loc); var floorId = data.floorId || core.status.floorId; - var event = core.floors[floorId].events[loc[0] + "," + loc[1]]; + var which = data.which || "events"; + var event = (core.floors[floorId][which]||[])[loc[0] + "," + loc[1]]; if (event) this.insertAction(event.data || event); } core.doAction(); diff --git a/libs/ui.js b/libs/ui.js index 76ad2603..700de21c 100644 --- a/libs/ui.js +++ b/libs/ui.js @@ -1483,6 +1483,7 @@ ui.prototype.drawBookDetail = function (index) { var enemy = enemys[index], enemyId = enemy.id; var hints=core.enemys.getSpecialHint(enemyId); + var damageInfo = core.enemys.getDamageInfo(enemy, null, null, null, floorId); if (hints.length==0) hints.push("该怪物无特殊属性。"); @@ -1553,6 +1554,7 @@ ui.prototype.drawBookDetail = function (index) { } hints.push(""); + hints.push("战斗回合数:"+((damageInfo||{}).turn||0)); var criticals = core.enemys.nextCriticals(enemyId, 10, null, null, floorId).map(function (v) { return core.formatBigNumber(v[0])+":"+core.formatBigNumber(v[1]); }); diff --git a/main.js b/main.js index a84e55f0..54edafc8 100644 --- a/main.js +++ b/main.js @@ -69,6 +69,7 @@ function main() { 'skillCol': document.getElementById('skillCol'), 'hard': document.getElementById('hard'), 'statusCanvas': document.getElementById('statusCanvas'), + 'statusCanvasCtx': document.getElementById('statusCanvas').getContext('2d') }; this.mode = 'play'; this.loadList = [ diff --git a/project/events.js b/project/events.js index 63924e63..fef815b6 100644 --- a/project/events.js +++ b/project/events.js @@ -4,60 +4,55 @@ var events_c12a15a8_c380_4b28_8144_256cba95f760 = "加点事件": [ { "type": "comment", - "text": "flag:point表示当前应该的加点数值" + "text": "通过传参,flag:arg1表示当前应该的加点数值" }, { "type": "choices", "choices": [ { - "text": "攻击+${1*flag:point}", + "text": "攻击+${1*flag:arg1}", "action": [ { "type": "setValue", "name": "status:atk", - "value": "status:atk+1*flag:point" + "value": "status:atk+1*flag:arg1" } ] }, { - "text": "防御+${2*flag:point}", + "text": "防御+${2*flag:arg1}", "action": [ { "type": "setValue", "name": "status:def", - "value": "status:def+2*flag:point" + "value": "status:def+2*flag:arg1" } ] }, { - "text": "生命+${200*flag:point}", + "text": "生命+${200*flag:arg1}", "action": [ { "type": "setValue", "name": "status:hp", - "value": "status:hp+200*flag:point" + "value": "status:hp+200*flag:arg1" } ] } ] - }, - { - "type": "setValue", - "name": "flag:point", - "value": "null" } ], "毒衰咒处理": [ { "type": "comment", - "text": "获得毒衰咒效果,flag:debuff为要获得的类型" + "text": "获得毒衰咒效果,flag:arg1为要获得的类型" }, { "type": "switch", - "condition": "flag:debuff", + "condition": "flag:arg1", "caseList": [ { - "case": "'poison'", + "case": "0", "action": [ { "type": "comment", @@ -78,7 +73,7 @@ var events_c12a15a8_c380_4b28_8144_256cba95f760 = ] }, { - "case": "'weak'", + "case": "1", "action": [ { "type": "comment", @@ -133,7 +128,7 @@ var events_c12a15a8_c380_4b28_8144_256cba95f760 = ] }, { - "case": "'curse'", + "case": "2", "action": [ { "type": "comment", @@ -154,11 +149,6 @@ var events_c12a15a8_c380_4b28_8144_256cba95f760 = ] } ] - }, - { - "type": "setValue", - "name": "flag:debuff", - "value": "null" } ] } diff --git a/project/functions.js b/project/functions.js index d3387715..c8c7ce29 100644 --- a/project/functions.js +++ b/project/functions.js @@ -271,18 +271,15 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a = var special = enemy.special; // 中毒 if (core.enemys.hasSpecial(special, 12)) { - core.push(todo, [{ "type": "setValue", "name": "flag:debuff", "value": "'poison'" }]); - core.push(todo, [{ "type": "insert", "name": "毒衰咒处理" }]); + core.push(todo, [{ "type": "insert", "name": "毒衰咒处理", "args": [0] }]); } // 衰弱 if (core.enemys.hasSpecial(special, 13)) { - core.push(todo, [{ "type": "setValue", "name": "flag:debuff", "value": "'weak'" }]); - core.push(todo, [{ "type": "insert", "name": "毒衰咒处理" }]); + core.push(todo, [{ "type": "insert", "name": "毒衰咒处理", "args": [1] }]); } // 诅咒 if (core.enemys.hasSpecial(special, 14)) { - core.push(todo, [{ "type": "setValue", "name": "flag:debuff", "value": "'curse'" }]); - core.push(todo, [{ "type": "insert", "name": "毒衰咒处理" }]); + core.push(todo, [{ "type": "insert", "name": "毒衰咒处理", "args": [2] }]); } // 仇恨属性:减半 if (core.flags.hatredDecrease && core.enemys.hasSpecial(special, 17)) { @@ -318,8 +315,7 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a = // 如果有加点 var point = core.material.enemys[enemyId].point; if (core.flags.enableAddPoint && point > 0) { - core.push(todo, [{ "type": "setValue", "name": "flag:point", "value": point }]); - core.push(todo, [{ "type": "insert", "name": "加点事件" }]); + core.push(todo, [{ "type": "insert", "name": "加点事件", "args": [point] }]); } // 如果该点存在事件 -- V2.5.4 以后阻击怪也可以有战后事件了 @@ -1289,7 +1285,7 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a = // 如果是非状态栏canvas化,直接返回 if (!core.flags.statusCanvas) return; var canvas = core.dom.statusCanvas, - ctx = canvas.getContext('2d'); + ctx = core.dom.statusCanvasCtx; // 清空状态栏 ctx.clearRect(0, 0, canvas.width, canvas.height); // 如果是隐藏状态栏模式,直接返回 @@ -1372,7 +1368,7 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a = core.lockControl(); core.status.event.id = 'about'; - var left = 48, top = 36, right = 416 - 2 * left, bottom = 416 - 2 * top; + var left = 48, top = 36, right = core.__PIXELS__ - 2 * left, bottom = core.__PIXELS__ - 2 * top; core.setAlpha('ui', 0.85); core.fillRect('ui', left, top, right, bottom, '#000000'); @@ -1459,7 +1455,7 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a = var ctx = core.getContextByName(name); if (ctx == null) { if (typeof name == 'string') - ctx = core.createCanvas(name, 0, 0, 416, 416, 98); + ctx = core.createCanvas(name, 0, 0, core.__PIXELS__, core.__PIXELS__, 98); else return; }