Merge pull request #261 from tocque/levelUp

Level up
This commit is contained in:
Zhang Chen 2018-11-24 22:34:54 +08:00 committed by GitHub
commit 7db822e04a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 96 additions and 46 deletions

View File

@ -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;

View File

@ -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为本次升级所执行的事件可由若干项组成"
}
}
},

View File

@ -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(),

View File

@ -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` 为本次等级执行的操作。
## 开始,难度分歧,获胜与失败,多结局

View File

@ -168,6 +168,7 @@
<option value="event">event</option>
<option value="changeFloor">changeFloor</option>
<option value="point">point</option>
<option value="level">level</option>
<option value="shop">shop</option>
<option value="afterBattle">afterBattle</option>
<option value="afterGetItem">afterGetItem</option>

View File

@ -167,6 +167,7 @@
<option value="event">event</option>
<option value="changeFloor">changeFloor</option>
<option value="point">point</option>
<option value="level">level</option>
<option value="shop">shop</option>
<option value="afterBattle">afterBattle</option>
<option value="afterGetItem">afterGetItem</option>

View File

@ -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 //////

View File

@ -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();
}
}

View File

@ -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": "恭喜升级"
}
]
}
]
},

View File

@ -817,7 +817,7 @@ functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a =
// 进阶
if (core.flags.enableLevelUp && core.status.hero.lv<core.firstData.levelUp.length) {
var need = core.firstData.levelUp[core.status.hero.lv].need;
var need = core.calValue(core.firstData.levelUp[core.status.hero.lv].need);
if (core.flags.levelUpLeftMode)
core.statusBar.up.innerHTML = (need - core.getStatus('experience')) || " ";
else