From 69e44861aae0f02e3d9bf2d6a80e6d6739a75a7b Mon Sep 17 00:00:00 2001 From: ckcz123 Date: Sun, 25 Nov 2018 12:14:07 +0800 Subject: [PATCH] Floor ParallelDo --- _server/comment.js | 7 +++++++ _server/editor_file.js | 1 + docs/event.md | 27 +++++++++++++++++++++++++++ libs/items.js | 18 ++++++++++++++++-- libs/ui.js | 5 ++++- project/functions.js | 20 ++++++++++++++++---- 6 files changed, 71 insertions(+), 7 deletions(-) diff --git a/_server/comment.js b/_server/comment.js index 7477667b..ac58c192 100644 --- a/_server/comment.js +++ b/_server/comment.js @@ -359,6 +359,13 @@ comment_c456ea59_6018_45ef_8bcc_211a24c627dc = "_event": "firstArrive", "_data": "第一次到该楼层触发的事件,可以双击进入事件编辑器。" }, + "parallelDo": { + "_leaf": true, + "_type": "textarea", + "_string": true, + "_lint": true, + "_data": "在该层楼时执行的并行事件处理。\n可以在这里写上任意需要自动执行的脚本,比如打怪自动开门等。\n详见文档-个性化-并行事件处理。" + }, "underGround": { "_leaf": true, "_type": "checkbox", diff --git a/_server/editor_file.js b/_server/editor_file.js index e9e857db..b44dfd5b 100644 --- a/_server/editor_file.js +++ b/_server/editor_file.js @@ -157,6 +157,7 @@ editor_file = function (editor, callback) { color: saveStatus?currData.color:null, weather: saveStatus?currData.weather:null, firstArrive: [], + parallelDo: null, events: {}, changeFloor: {}, afterBattle: {}, diff --git a/docs/event.md b/docs/event.md index 1d7f484e..70ef6199 100644 --- a/docs/event.md +++ b/docs/event.md @@ -1611,6 +1611,8 @@ core.insertAction([ 在脚本编辑里面提供了一个parallelDo函数,这个函数可以用来做并行处理内容。 +从V2.5.2开始,每层楼的楼层属性中也增加了一个parallelDo选项,可以在里面写任何脚本代码。该部分代码仅在人物在该楼层时才会被反复执行。 + ``` js "parallelDo": function (timestamp) { // 并行事件处理,可以在这里写任何需要并行处理的脚本或事件 @@ -1619,6 +1621,15 @@ core.insertAction([ // 检查当前是否处于游戏开始状态 if (!core.isPlaying()) return; + + // 执行当前楼层的并行事件处理 + if (core.isset(core.status.floorId)) { + try { + eval(core.floors[core.status.floorId].parallelDo); + } catch (e) { + console.log(e); + } + } // 下面是一个并行事件开门的样例 /* @@ -1644,6 +1655,22 @@ core.insertAction([ !> 判定flag后千万别忘了将该flag清空!否则下次仍然会执行这段代码。 +每层楼的并行事件处理类似,只有角色在当前楼层时才会反复执行当前楼层中parallelDo部分的代码。 + +下面是一个打怪开门的样例:(假设每打一个怪的战后事件把`flag:door`+1) + +``` js +// 每层楼的并行事件处理代码样例 +if (core.getFlag("door",0)==2) { + // 将该flag清空 + core.setFlag("door", 0); + // 开门,如果是当前层则无需写floorId + core.insertAction([ + {"type":"openDoor", "loc":[0,0]} + ]); +} +``` + ## 加点事件 打败怪物后可以进行加点。 diff --git a/libs/items.js b/libs/items.js index bf20d5bb..a20c62aa 100644 --- a/libs/items.js +++ b/libs/items.js @@ -28,7 +28,14 @@ items.prototype.getItemEffect = function(itemId, itemNum) { if (itemCls === 'items') { var ratio = parseInt(core.status.thisMap.item_ratio) || 1; var curr_hp = core.status.hero.hp; - if (itemId in this.itemEffect)eval(this.itemEffect[itemId]); + if (itemId in this.itemEffect) { + try { + eval(this.itemEffect[itemId]); + } + catch (e) { + console.log(e); + } + } core.status.hero.statistics.hp += core.status.hero.hp - curr_hp; } else { @@ -42,7 +49,14 @@ items.prototype.getItemEffectTip = function(itemId) { // 消耗品 if (itemCls === 'items') { var ratio = parseInt(core.status.thisMap.item_ratio) || 1; - if (itemId in this.itemEffectTip) return eval(this.itemEffectTip[itemId])||""; + if (itemId in this.itemEffectTip) { + try { + return eval(this.itemEffectTip[itemId])||""; + } catch (e) { + console.log(e); + return ""; + } + } } return ""; } diff --git a/libs/ui.js b/libs/ui.js index ecf31465..dec5c0a6 100644 --- a/libs/ui.js +++ b/libs/ui.js @@ -2311,7 +2311,10 @@ ui.prototype.drawStatistics = function () { if (cls[id]=='items' && id!='superPotion') { var ratio = floor.item_ratio||1; if (core.isset(core.items.itemEffect[id])) { - eval(core.items.itemEffect[id]); + try { + eval(core.items.itemEffect[id]); + } + catch (e) {} } hp = core.status.hero.hp - temp.hp; atk = core.status.hero.atk - temp.atk; diff --git a/project/functions.js b/project/functions.js index f3d3bf5d..78d475af 100644 --- a/project/functions.js +++ b/project/functions.js @@ -87,9 +87,11 @@ functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a = "afterChangeFloor": function (floorId, fromLoad) { // 转换楼层结束的事件 // floorId是切换到的楼层;fromLoad若为true则代表是从读档行为造成的楼层切换 - if (!core.hasFlag("visited_"+floorId)) { + var visited = core.getFlag("__visited__", []); + if (visited.indexOf(floorId)===-1) { core.insertAction(core.floors[floorId].firstArrive); - core.setFlag("visited_"+floorId, true); + visited.push(floorId); + core.setFlag("__visited__", visited); } }, "addPoint": function (enemy) { @@ -1034,7 +1036,16 @@ functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a = // 检查当前是否处于游戏开始状态 if (!core.isPlaying()) return; - + + // 执行当前楼层的并行事件处理 + if (core.isset(core.status.floorId)) { + try { + eval(core.floors[core.status.floorId].parallelDo); + } catch (e) { + console.log(e); + } + } + // 下面是一个并行事件开门的样例 /* // 如果某个flag为真 @@ -1048,7 +1059,8 @@ functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a = // 也可以写任意其他的脚本代码 } */ - + + }, "plugin": function () { ////// 插件编写,可以在这里写自己额外需要执行的脚本 //////