setValue2

This commit is contained in:
oc 2019-02-27 21:19:43 +08:00
parent 337827c17a
commit 42e04f58be
4 changed files with 50 additions and 4 deletions

View File

@ -440,6 +440,23 @@ value是一个表达式将通过这个表达式计算出的结果赋值给nam
另外注意一点的是如果hp被设置成了0或以下将触发lose事件直接死亡。
### setValue2增减勇士的某个属性、道具个数或某个变量/Flag的值
和`{"type": "setValue"}`的写法完全相同,不过此项是可以直接将值加减到原始数值上。
即下面的写法是等价的:
``` js
"x,y": [ // 实际执行的事件列表
{"type": "setValue", "name": "status:atk", "value": "status:atk+10" } // 攻击提高10点
{"type": "setValue2", "name": "status:atk", "value": "10" } // 和上面写法等价
{"type": "setValue", "name": "item:yellowKey", "value": "item:yellowKey-3" } // 黄钥匙个数-3
{"type": "setValue2", "name": "item:yellowKey", "value": "-3" } // 和上面写法等价
{"type": "setValue", "name": "flag:door2", "value": "flag:door2+1" } // 将变量door值+1
{"type": "setValue2", "name": "flag:door2", "value": "01" } // 和上面写法等价
]
```
### setFloor设置楼层属性
使用`{"type":"setFloor"}`可以设置某层楼的楼层属性。

View File

@ -229,6 +229,7 @@ action
| setText_s
| tip_s
| setValue_s
| setValue2_s
| setFloor_s
| setGlobalAttribute_s
| setGlobalValue_s
@ -465,6 +466,18 @@ var code = '{"type": "setValue", "name": "'+idString_e_0+'", "value": "'+express
return code;
*/;
setValue2_s
: '数值增减' ':' '名称' idString_e '+=' expression Newline
/* setValue2_s
tooltip : setValue2增减勇士的某个属性、道具个数, 或某个变量/Flag的值
helpUrl : https://h5mota.com/games/template/docs/#/event?id=setValue2%ef%bc%9a%e5%a2%9e%e5%87%8f%e5%8b%87%e5%a3%ab%e7%9a%84%e6%9f%90%e4%b8%aa%e5%b1%9e%e6%80%a7%e3%80%81%e9%81%93%e5%85%b7%e4%b8%aa%e6%95%b0%ef%bc%8c%e6%88%96%e6%9f%90%e4%b8%aa%e5%8f%98%e9%87%8f%2fFlag%e7%9a%84%e5%80%bc
colour : this.dataColor
var code = '{"type": "setValue2", "name": "'+idString_e_0+'", "value": "'+expression_0+'"},\n';
return code;
*/;
setFloor_s
: '设置楼层属性' ':' Floor_Meta_List '楼层名' IdString? '值' EvalString Newline
@ -2365,6 +2378,13 @@ ActionParser.prototype.parseAction = function() {
MotaActionBlocks['evalString_e'].xmlText([data.value]),
this.next]);
break;
case "setValue2":
this.next = MotaActionBlocks['setValue2_s'].xmlText([
// MotaActionBlocks['idString_e'].xmlText([data.name]),
this.tryToUseEvFlag_e('idString_e', [data.name]),
MotaActionBlocks['evalString_e'].xmlText([data.value]),
this.next]);
break;
case "setFloor":
this.next = MotaActionBlocks['setFloor_s'].xmlText([
data.name, data.floorId||null, data.value, this.next]);

View File

@ -75,6 +75,9 @@ editor_blockly = function () {
MotaActionBlocks['setValue_s'].xmlText([
MotaActionBlocks['idString_1_e'].xmlText(['status','hp'])
]),
MotaActionBlocks['setValue2_s'].xmlText([
MotaActionBlocks['idString_1_e'].xmlText(['status','hp'])
]),
MotaActionBlocks['setFloor_s'].xmlText(),
MotaActionBlocks['setGlobalAttribute_s'].xmlText(),
MotaActionBlocks['setGlobalValue_s'].xmlText(),
@ -154,6 +157,9 @@ editor_blockly = function () {
MotaActionBlocks['setValue_s'].xmlText([
MotaActionBlocks['idString_1_e'].xmlText(['status','hp'])
]),
MotaActionBlocks['setValue2_s'].xmlText([
MotaActionBlocks['idString_1_e'].xmlText(['status','hp'])
]),
MotaActionBlocks['expression_arithmetic_0'].xmlText(),
MotaActionBlocks['evFlag_e'].xmlText(),
MotaActionBlocks['negate_e'].xmlText(),
@ -178,8 +184,8 @@ editor_blockly = function () {
{"text": "黄钥匙(\${9+flag:shop_times}金币)", "color": [255,255,0,1], "action": [
{"type": "if", "condition": "status:money>=9+flag:shop_times",
"true": [
{"type": "setValue", "name": "status:money", "value": "status:money-(9+flag:shop_times)"},
{"type": "setValue", "name": "item:yellowKey", "value": "item:yellowKey+1"},
{"type": "setValue2", "name": "status:money", "value": "-(9+flag:shop_times)"},
{"type": "setValue2", "name": "item:yellowKey", "value": "1"},
],
"false": [
"\t[老人,man]你的金钱不足!",
@ -194,7 +200,7 @@ editor_blockly = function () {
]}
]
},
{"type": "setValue", "name": "flag:shop_times", "value": "flag:shop_times+1"},
{"type": "setValue2", "name": "flag:shop_times", "value": "1"},
{"type": "revisit"}
], 'event'),
'<label text="战前剧情"></label>',
@ -217,7 +223,7 @@ editor_blockly = function () {
],'afterBattle'),
'<label text="打怪开门"></label>',
MotaActionFunctions.actionParser.parse([
{"type": "setValue", "name": "flag:__door__", "value": "flag:__door__+1"},
{"type": "setValue2", "name": "flag:__door__", "value": "1"},
{"type": "if", "condition": "flag:__door__==2",
"true": [
{"type": "openDoor", "loc": [10,5]}

View File

@ -1001,8 +1001,11 @@ events.prototype.doAction = function() {
}
break;
case "setValue":
case "setValue2":
try {
var value=core.calValue(data.value, prefix);
if (data.type == 'setValue2')
value += core.calValue(data.name, prefix);
// 属性
if (data.name.indexOf("status:")==0) {
core.setStatus(data.name.substring(7), value);