diff --git a/_server/blockly/MotaAction.g4 b/_server/blockly/MotaAction.g4 index 92c52eb2..d1e4757d 100644 --- a/_server/blockly/MotaAction.g4 +++ b/_server/blockly/MotaAction.g4 @@ -37,6 +37,31 @@ var code = '{"type": "choices", "choices": [\n'+choicesContext_0+']}\n'; return code; */; +//升级 事件编辑器入口之一 +level_m + : '等级提升' BGNL? Newline levelCase+ BEND + + +/* level_m +tooltip : 升级事件 +helpUrl : https://ckcz123.github.io/mota-js/#/event?id=%e7%bb%8f%e9%aa%8c%e5%8d%87%e7%ba%a7%ef%bc%88%e8%bf%9b%e9%98%b6%2f%e5%a2%83%e7%95%8c%e5%a1%94%ef%bc%89 +var code = '[\n'+levelCase_0+']\n'; +return code; +*/; + +levelCase + : '需求' expression '称号' EvalString? BGNL? Newline action+ + + +/* levelCase +tooltip : 升级设定 +helpUrl : https://ckcz123.github.io/mota-js/#/event?id=%e7%bb%8f%e9%aa%8c%e5%8d%87%e7%ba%a7%ef%bc%88%e8%bf%9b%e9%98%b6%2f%e5%a2%83%e7%95%8c%e5%a1%94%ef%bc%89 +default : [0,"",null] +colour : this.subColor +var code = '{"need": "'+expression_0+'", "title": "'+EvalString_0+'", "action": [\n'+action_0+']},\n'; +return code; +*/; + //商店 事件编辑器入口之一 shop_m : '全局商店列表' BGNL? Newline shoplist+ @@ -1679,6 +1704,15 @@ ActionParser.prototype.parse = function (obj,type) { } return MotaActionBlocks['point_m'].xmlText([text_choices]); + case 'level': + if(!obj)obj={}; + var text_choices = null; + for(var ii=obj.length-1,choice;choice=obj[ii];ii--) { + text_choices=MotaActionBlocks['levelCase'].xmlText([ + MotaActionBlocks['evalString_e'].xmlText([choice.need]),choice.title,this.parseList(choice.action),text_choices]); + } + return MotaActionBlocks['level_m'].xmlText([text_choices]); + case 'shop': var buildsub = function(obj,parser,next){ var text_choices = null; diff --git a/_server/data.comment.js b/_server/data.comment.js index 6d277522..24537bd3 100644 --- a/_server/data.comment.js +++ b/_server/data.comment.js @@ -268,9 +268,10 @@ data_comment_c456ea59_6018_45ef_8bcc_211a24c627dc = }, "levelUp": { "_leaf": true, - "_type": "textarea", + "_type": "event", + "_event": "level", "_range": "thiseval==null || thiseval instanceof Array", - "_data": "经验升级所需要的数值,是一个数组,可以双击进行编辑。 \n 第一项为初始等级,可以简单留空,也可以写name \n 每一个里面可以含有三个参数 need, name, effect \n need为所需要的经验数值,是一个正整数。请确保need所需的依次递增 \n name为该等级的名称,也可以省略代表使用系统默认值;本项将显示在状态栏中 \n effect为本次升级所执行的操作,可由若干项组成,由分号分开 \n 其中每一项写法和上面的商店完全相同,同样必须是X+=Y的形式,Y是一个表达式,同样可以使用status:xxx或item:xxx代表勇士的某项数值/道具个数" + "_data": "经验升级所需要的数值,是一个数组,可以双击进行编辑。 \n 第一项为初始等级,仅title生效 \n 每一个里面可以含有三个参数 need, title, action \n need为所需要的经验数值,可以是个表达式。请确保need依次递增 \n title为该等级的名称,也可以省略代表使用系统默认值;本项将显示在状态栏中 \n action为本次升级所执行的事件,可由若干项组成" } } }, diff --git a/_server/editor_blockly.js b/_server/editor_blockly.js index 1c1c2f21..dddcbddd 100644 --- a/_server/editor_blockly.js +++ b/_server/editor_blockly.js @@ -52,6 +52,7 @@ editor_blockly = function () { MotaActionBlocks['afterGetItem_m'].xmlText(), MotaActionBlocks['afterOpenDoor_m'].xmlText(), MotaActionBlocks['firstArrive_m'].xmlText(), + MotaActionBlocks['level_m'].xmlText(), ], '显示文字':[ MotaActionBlocks['text_0_s'].xmlText(), diff --git a/docs/event.md b/docs/event.md index 12b2aacb..1d7f484e 100644 --- a/docs/event.md +++ b/docs/event.md @@ -1950,37 +1950,36 @@ core.insertAction([ 要经验升级,你需要先在`data.js`中的全局变量中启用。你需要将`enableExperience`启用经验,且`enableLevelUp`启用进阶。同时你也可以将`enableLv`置为true以在状态栏中显示当前等级(境界)。 -同时,你还需要在`data.js`中的`levelUp`来定义每一个进阶所需要的生命值,以及进阶时的效果。 +同时,你还需要在`data.js`中的`levelUp`来定义每一个进阶所需要的经验值,以及进阶时的效果。 ``` js "levelUp": [ // 经验升级所需要的数值,是一个数组 - {}, // 第一项为初始等级,可以简单留空,也可以写name + {"need": "0", "title": "", "action": []}, // 第一项为初始等级,仅title生效 - // 每一个里面可以含有三个参数 need, name, effect - // need为所需要的经验数值,是一个正整数。请确保need所需的依次递增 - // name为该等级的名称,也可以省略代表使用系统默认值;本项将显示在状态栏中 - // effect为本次升级所执行的操作,可由若干项组成,由分号分开 - // 其中每一项写法和上面的商店完全相同,同样必须是X+=Y的形式,Y是一个表达式,同样可以使用status:xxx或item:xxx代表勇士的某项数值/道具个数 - {"need": 20, "name": "第二级", "effect": "status:hp+=2*(status:atk+status:def);status:atk+=10;status:def+=10"}, // 先将生命提升攻防和的2倍;再将攻击+10,防御+10 + // 每一个里面可以含有三个参数 need, title, action + // need为所需要的经验数值,可以是个表达式。请确保need依次递增 + // title为该等级的名称,也可以省略代表使用系统默认值;本项将显示在状态栏中 + // action为本次升级所执行的操作,可由若干项组成 + {"need": "20", "title": "第二级", "action": [ + {"type": "setValue","name": "status:atk","value": "status:atk+10"}, // 攻击+10 + {"type": "setValue","name": "status:def","value": "status:def+10"} // 防御+10 + ] + }, - // effect也允许写一个function,代表本次升级将会执行的操作,比如可以显示一段提示文字,或者触发一个事件 - {"need": 40, "effect": function () { - core.drawTip("恭喜升级!"); - core.status.hero.hp *= 2; - core.status.hero.atk += 100; - core.status.hero.def += 100; - }}, + // action也允许其他操作,比如可以显示一段提示文字,或者触发一个事件 + {"need": "40", "effect": [ + {"type": "tip", "text": "恭喜升级"}, + ] + }, // 依次往下写需要的数值即可 ] ``` -`levelUp`是一个数组,里面分别定义了每个等级的信息。里面每一项是一个object,主要有三个参数`need`, `name`, `effect` -- `need` 该等级所需要的经验值,是一个正整数。请确保数组中的need依次递增。 -- `name` 该等级的名称,比如“佣兵下级”等。该项可以忽略,以使用系统默认的等级。该项将显示在状态栏中。 -- `effect` 为本次等级执行的操作。它有两种写法:字符串,或函数。 - - 如果`effect`为字符串,则和上面的全局商店的写法完全相同。可由分号分开,每一项为X+=Y的形式,X为你要修改的勇士属性/道具个数,Y为一个表达式。 - - 如果`effect`为函数,则也允许写一个`function`,来代表本次升级将会执行的操作。 +`levelUp`是一个数组,里面分别定义了每个等级的信息。里面每一项有三个参数`need`, `title`, `effect` +- `need` 该等级所需要的经验值,可以是个表达式。请确保数组中的need依次递增。 +- `title` 该等级的名称,比如“佣兵下级”等。该项可以忽略,以使用系统默认的等级。该项将显示在状态栏中。 +- `action` 为本次等级执行的操作。 ## 开始,难度分歧,获胜与失败,多结局 diff --git a/editor-mobile.html b/editor-mobile.html index cd51f4ed..9141fe2d 100644 --- a/editor-mobile.html +++ b/editor-mobile.html @@ -168,6 +168,7 @@ + diff --git a/editor.html b/editor.html index 0ae3917b..41e3e25c 100644 --- a/editor.html +++ b/editor.html @@ -167,6 +167,7 @@ + diff --git a/libs/control.js b/libs/control.js index 134ae37f..f291252e 100644 --- a/libs/control.js +++ b/libs/control.js @@ -2513,7 +2513,7 @@ control.prototype.getStatus = function (statusName) { ////// 获得某个等级的名称 ////// control.prototype.getLvName = function () { - return ((core.firstData.levelUp||[])[core.status.hero.lv-1]||{}).name || core.status.hero.lv; + return ((core.firstData.levelUp||[])[core.status.hero.lv-1]||{}).title || core.status.hero.lv; } ////// 设置某个自定义变量或flag ////// diff --git a/libs/events.js b/libs/events.js index 5a688f59..30a24ad9 100644 --- a/libs/events.js +++ b/libs/events.js @@ -1685,25 +1685,12 @@ events.prototype.checkLvUp = function () { if (!core.flags.enableLevelUp || !core.isset(core.firstData.levelUp) || core.status.hero.lv>=core.firstData.levelUp.length) return; // 计算下一个所需要的数值 - var need=(core.firstData.levelUp[core.status.hero.lv]||{}).need; + var need=core.calValue((core.firstData.levelUp[core.status.hero.lv]||{}).need); if (!core.isset(need)) return; if (core.status.hero.experience>=need) { // 升级 core.status.hero.lv++; - var effect = core.firstData.levelUp[core.status.hero.lv-1].effect; - if (typeof effect == "string") { - if (effect.indexOf("function")==0) { - eval("("+effect+")()"); - } - else { - effect.split(";").forEach(function (t) { - core.doEffect(t); - }); - } - } - else if (effect instanceof Function) { - effect(); - } + core.insertAction(core.firstData.levelUp[core.status.hero.lv-1].action); this.checkLvUp(); } } diff --git a/project/data.js b/project/data.js index e8c3c64b..072fa120 100644 --- a/project/data.js +++ b/project/data.js @@ -162,15 +162,41 @@ data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d = } ], "levelUp": [ - {}, { - "need": 20, - "name": "第二级", - "effect": "status:hp+=2*(status:atk+status:def);status:atk+=10;status:def+=10" + "need": "0", + "title": "", + "action": [ + { + "type": "comment", + "text": "此处是初始等级,只需填写称号" + } + ] }, { - "need": 40, - "effect": "function () {\r\n\t\t\tcore.insertAction(\"恭喜升级!\");\r\n\t\t\tcore.status.hero.hp *= 2;\r\n\t\t\tcore.status.hero.atk += 100;\r\n\t\t\tcore.status.hero.def += 100;\r\n\t\t}" + "need": "20", + "title": "第二级", + "action": [ + { + "type": "setValue", + "name": "status:atk", + "value": "status:atk+10" + }, + { + "type": "setValue", + "name": "status:def", + "value": "status:def+10" + } + ] + }, + { + "need": "40", + "title": "", + "action": [ + { + "type": "tip", + "text": "恭喜升级" + } + ] } ] }, diff --git a/project/functions.js b/project/functions.js index ca618442..f3d3bf5d 100644 --- a/project/functions.js +++ b/project/functions.js @@ -817,7 +817,7 @@ functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a = // 进阶 if (core.flags.enableLevelUp && core.status.hero.lv