Independent Switch

This commit is contained in:
ckcz123 2018-12-25 18:39:18 +08:00
parent dd31fe605e
commit 8e2cb367df
13 changed files with 109 additions and 69 deletions

View File

@ -1571,6 +1571,7 @@ expression
| negate_e
| bool_e
| idString_e
| evFlag_e
| evalString_e
@ -1642,6 +1643,7 @@ colour : this.idstring_eColor
default : [null,"自定义flag"]
//todo 将其output改成'idString_e'
var code = Id_List_0+':'+IdText_0;
if (Id_List_0 === 'flag0') code = "flag:__"+IdText_0+"__";
return [code, Blockly.JavaScript.ORDER_ATOMIC];
*/;
@ -1657,6 +1659,19 @@ var code = FixedId_List_0;
return [code, Blockly.JavaScript.ORDER_ATOMIC];
*/;
evFlag_e
: '独立开关' Letter_List
/* evFlag_e
colour : this.idstring_eColor
default : ["A"]
var code = "flag:__"+Letter_List_0+"__";
return [code, Blockly.JavaScript.ORDER_ATOMIC];
*/;
evalString_e
: EvalString
@ -1735,6 +1750,11 @@ Bool: 'TRUE'
Int : '0' | [1-9][0-9]* ; // no leading zeros
Letter_List
: 'A'|'B'|'C'|'D'|'E'|'F'|'G'|'H'|'I'|'J'|'K'|'L'|'M'|'N'|'O'|'P'|'Q'|'R'|'S'|'T'|'U'|'V'|'W'|'X'|'Y'|'Z'
/*Letter_List ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']*/;
Number
: '-'? Int '.' Int EXP? // 1.35, 1.35E-9, 0.3, -4.5
| '-'? Int EXP // 1e10 -3e4
@ -1763,8 +1783,8 @@ FixedId_List
/*FixedId_List ['status:hp','status:atk','status:def','status:mdef','item:yellowKey','item:blueKey','item:redKey','status:money','status:experience']*/;
Id_List
: '变量' | '状态' | '物品'
/*Id_List ['flag','status','item']*/;
: '变量' | '状态' | '物品' | '独立开关'
/*Id_List ['flag','status','item', 'flag0']*/;
//转blockly后不保留需要加"
EvalString

File diff suppressed because one or more lines are too long

View File

@ -158,6 +158,7 @@ editor_blockly = function () {
MotaActionBlocks['idString_1_e'].xmlText(['status','hp'])
]),
MotaActionBlocks['expression_arithmetic_0'].xmlText(),
MotaActionBlocks['evFlag_e'].xmlText(),
MotaActionBlocks['negate_e'].xmlText(),
MotaActionBlocks['bool_e'].xmlText(),
MotaActionBlocks['idString_e'].xmlText(),

View File

@ -281,7 +281,7 @@ core.replaceText(text)
将一段文字中的${}进行计算并替换。
core.calValue(value)
core.calValue(value, prefix, need, times)
计算表达式的实际值。这个函数可以传入status:atk等这样的参数。

View File

@ -1689,6 +1689,21 @@ core.insertAction([
!> 从V2.5.3开始,提供了一个"不自动执行下一个事件"的选项(`"async": true`)。如果设置了此项,那么在该部分代码执行完毕后,不会立刻执行下一个事件。你需要在脚本中手动调用`core.events.doAction()`来执行下一个事件。可以通过此项来实现一些异步的代码,即在异步函数的回调中再执行下一个事件。使用此选项请谨慎,最好向开发者寻求咨询。
## 独立开关
从V2.5.3开始,针对每个事件都提供了独立开关。
独立开关的写法是`flag:__A__`, `flag:__B__`直到`flag:__Z__`共计26个。
独立开关算是特殊的flag它在事件中使用时会和事件的楼层及坐标进行绑定换句话说每个事件对应的`flag:__A__`都是不同的。
事实上在某个楼层某个点的事件的独立开关对应的系统flag为`floorId@x@y__X__`
比如在`MT0`层的`[2,5]`点事件,对应的`flag:__B__`独立开关,实际会被映射到`flag:MT0@2@5__B__`。
如果在事件外想访问某个事件的独立开关也需要通过上面这个方式。
通过独立开关的方式我们无需对某些NPC的对话都设立单独的互不重复flag只需要关注该事件自身的逻辑即可。
## 同一个点的多事件处理
我们可以发现,就目前而且,每个点的事件是和该点进行绑定,并以该点坐标作为唯一索引来查询。

View File

@ -20,7 +20,8 @@ HTML5魔塔是使用画布canvas来绘制存在若干个图层它们
- weather**[D]**:天气层;主要用来绘制天气(雨/雪/雾) (z-index: 80)
- route**[D]**:路线层;主要用来绘制勇士的行走路线图。 (z-index: 95)
- paint**[D]**绘图层主要用来进行绘图模式。z-index: 95)
- curtain色调层用来控制当前楼层的画面色调 (z-index: 100)
- curtain色调层用来控制当前楼层的画面色调 (z-index: 125)
- image\***[D]**图片层用来绘制图片等操作。z-index: 100+code, 101~150也就是图片编号在1~25的在色调层之下26~50的在色调层之上
- uiUI层用来绘制一切UI窗口如剧情文本、怪物手册、楼传器、系统菜单等等 (z-index: 160)
- data数据层用来绘制一些顶层的或更新比较快的数据如左上角的提示战斗界面中数据的变化等等。 (z-index: 170)

View File

@ -1096,13 +1096,13 @@ actions.prototype.clickShop = function(x,y) {
core.status.event.selection=y-topIndex;
var money = core.getStatus('money'), experience = core.getStatus('experience');
var times = shop.times, need = core.calValue(shop.need, null, times);
var times = shop.times, need = core.calValue(shop.need, null, null, times);
var use = shop.use;
var use_text = use=='money'?"金币":"经验";
var choice = choices[y-topIndex];
if (core.isset(choice.need))
need = core.calValue(choice.need, null, times);
need = core.calValue(choice.need, null, null, times);
if (need > eval(use)) {
core.drawTip("你的"+use_text+"不足");

View File

@ -1475,7 +1475,7 @@ control.prototype.doEffect = function (effect, need, times) {
effect.split(";").forEach(function (expression) {
var arr = expression.split("+=");
if (arr.length!=2) return;
var name=arr[0], value=core.calValue(arr[1], need, times);
var name=arr[0], value=core.calValue(arr[1], null, need, times);
if (name.indexOf("status:")==0) {
var status=name.substring(7);
core.setStatus(status, core.getStatus(status)+value);

View File

@ -1038,8 +1038,8 @@ core.prototype.replaceText = function (text, need, times) {
}
////// 计算表达式的值 //////
core.prototype.calValue = function (value, need, times) {
return core.utils.calValue(value, need, times);
core.prototype.calValue = function (value, prefix, need, times) {
return core.utils.calValue(value, prefix, need, times);
}
////// 执行一个表达式的effect操作 //////

View File

@ -383,9 +383,12 @@ events.prototype.doAction = function() {
return;
}
var x=core.status.event.data.x, y=core.status.event.data.y;
var prefix = [core.status.floorId||"f", x||"x", y||"y"].join("@");
var current = core.status.event.data.list[0];
if (current.todo.length == 0) { // current list is empty
if (core.calValue(current.condition)) { // check condition
if (core.calValue(current.condition, prefix)) { // check condition
current.todo = core.clone(current.total);
}
else {
@ -397,8 +400,6 @@ events.prototype.doAction = function() {
var data = current.todo.shift();
core.status.event.data.current = data;
var x=core.status.event.data.x, y=core.status.event.data.y;
// 不同种类的事件
// 如果是文字:显示
@ -477,7 +478,7 @@ events.prototype.doAction = function() {
data.loc = [x,y];
if ((typeof data.loc[0] == 'number' || typeof data.loc[0] == 'string')
&& (typeof data.loc[1] == 'number' || typeof data.loc[1] == 'string'))
data.loc = [[core.calValue(data.loc[0]), core.calValue(data.loc[1])]];
data.loc = [[core.calValue(data.loc[0], prefix), core.calValue(data.loc[1], prefix)]];
if (core.isset(data.time) && data.time>0 && (!core.isset(data.floorId) || data.floorId==core.status.floorId)) {
if (data.async) {
core.animateBlock(data.loc, 'show', data.time);
@ -501,7 +502,7 @@ events.prototype.doAction = function() {
data.loc = [x,y];
if ((typeof data.loc[0] == 'number' || typeof data.loc[0] == 'string')
&& (typeof data.loc[1] == 'number' || typeof data.loc[1] == 'string'))
data.loc = [[core.calValue(data.loc[0]), core.calValue(data.loc[1])]];
data.loc = [[core.calValue(data.loc[0], prefix), core.calValue(data.loc[1], prefix)]];
if (core.isset(data.time) && data.time>0 && (!core.isset(data.floorId) || data.floorId==core.status.floorId)) {
data.loc.forEach(function (t) {
core.hideBlock(t[0],t[1],data.floorId);
@ -526,8 +527,8 @@ events.prototype.doAction = function() {
case "setBlock": // 设置某图块
{
if (core.isset(data.loc)) {
x=core.calValue(data.loc[0]);
y=core.calValue(data.loc[1]);
x=core.calValue(data.loc[0], prefix);
y=core.calValue(data.loc[1], prefix);
}
core.setBlock(data.number, x, y, data.floorId);
this.doAction();
@ -538,7 +539,7 @@ events.prototype.doAction = function() {
data.loc = [x,y];
if ((typeof data.loc[0] == 'number' || typeof data.loc[0] == 'string')
&& (typeof data.loc[1] == 'number' || typeof data.loc[1] == 'string'))
data.loc = [[core.calValue(data.loc[0]), core.calValue(data.loc[1])]];
data.loc = [[core.calValue(data.loc[0], prefix), core.calValue(data.loc[1], prefix)]];
core.maps.setFloorImage("show", data.loc, data.floorId, function() {
core.events.doAction();
})
@ -548,7 +549,7 @@ events.prototype.doAction = function() {
data.loc = [x,y];
if ((typeof data.loc[0] == 'number' || typeof data.loc[0] == 'string')
&& (typeof data.loc[1] == 'number' || typeof data.loc[1] == 'string'))
data.loc = [[core.calValue(data.loc[0]), core.calValue(data.loc[1])]];
data.loc = [[core.calValue(data.loc[0], prefix), core.calValue(data.loc[1], prefix)]];
core.maps.setFloorImage("hide", data.loc, data.floorId, function() {
core.events.doAction();
})
@ -558,7 +559,7 @@ events.prototype.doAction = function() {
data.loc = [x,y];
if ((typeof data.loc[0] == 'number' || typeof data.loc[0] == 'string')
&& (typeof data.loc[1] == 'number' || typeof data.loc[1] == 'string'))
data.loc = [[core.calValue(data.loc[0]), core.calValue(data.loc[1])]];
data.loc = [[core.calValue(data.loc[0], prefix), core.calValue(data.loc[1], prefix)]];
core.maps.setBgFgMap("show", data.name, data.loc, data.floorId, function() {
core.events.doAction();
})
@ -568,7 +569,7 @@ events.prototype.doAction = function() {
data.loc = [x,y];
if ((typeof data.loc[0] == 'number' || typeof data.loc[0] == 'string')
&& (typeof data.loc[1] == 'number' || typeof data.loc[1] == 'string'))
data.loc = [[core.calValue(data.loc[0]), core.calValue(data.loc[1])]];
data.loc = [[core.calValue(data.loc[0], prefix), core.calValue(data.loc[1], prefix)]];
core.maps.setBgFgMap("hide", data.name, data.loc, data.floorId, function() {
core.events.doAction();
})
@ -576,8 +577,8 @@ events.prototype.doAction = function() {
case "setBgFgBlock": // 设置图层块
{
if (core.isset(data.loc)) {
x=core.calValue(data.loc[0]);
y=core.calValue(data.loc[1]);
x=core.calValue(data.loc[0], prefix);
y=core.calValue(data.loc[1], prefix);
}
core.setBgFgBlock(data.name, data.number, x, y, data.floorId);
this.doAction();
@ -626,8 +627,8 @@ events.prototype.doAction = function() {
y=core.getHeroLoc('y');
}
else if (data.loc instanceof Array) {
x=core.calValue(data.loc[0]);
y=core.calValue(data.loc[1]);
x=core.calValue(data.loc[0], prefix);
y=core.calValue(data.loc[1], prefix);
}
}
if (data.async) {
@ -642,8 +643,8 @@ events.prototype.doAction = function() {
break;
case "move": // 移动事件
if (core.isset(data.loc)) {
x=core.calValue(data.loc[0]);
y=core.calValue(data.loc[1]);
x=core.calValue(data.loc[0], prefix);
y=core.calValue(data.loc[1], prefix);
}
if (data.async) {
core.moveBlock(x,y,data.steps,data.time,data.keep);
@ -670,12 +671,12 @@ events.prototype.doAction = function() {
{
var sx=x, sy=y, ex=x,ey=y;
if (core.isset(data.from)) {
sx=core.calValue(data.from[0]);
sy=core.calValue(data.from[1]);
sx=core.calValue(data.from[0], prefix);
sy=core.calValue(data.from[1], prefix);
}
if (core.isset(data.to)) {
ex=core.calValue(data.to[0]);
ey=core.calValue(data.to[1]);
ex=core.calValue(data.to[0], prefix);
ey=core.calValue(data.to[1], prefix);
}
if (data.async) {
core.jumpBlock(sx,sy,ex,ey,data.time,data.keep);
@ -692,8 +693,8 @@ events.prototype.doAction = function() {
{
var ex=core.status.hero.loc.x, ey=core.status.hero.loc.y;
if (core.isset(data.loc)) {
ex=core.calValue(data.loc[0]);
ey=core.calValue(data.loc[1]);
ex=core.calValue(data.loc[0], prefix);
ey=core.calValue(data.loc[1], prefix);
}
if (data.async) {
core.jumpHero(ex,ey,data.time);
@ -708,7 +709,7 @@ events.prototype.doAction = function() {
}
case "changeFloor": // 楼层转换
{
var heroLoc = {"x": core.calValue(data.loc[0]), "y": core.calValue(data.loc[1])};
var heroLoc = {"x": core.calValue(data.loc[0], prefix), "y": core.calValue(data.loc[1], prefix)};
if (core.isset(data.direction)) heroLoc.direction=data.direction;
core.changeFloor(data.floorId||core.status.floorId, null, heroLoc, data.time, function() {
core.lockControl();
@ -719,8 +720,8 @@ events.prototype.doAction = function() {
case "changePos": // 直接更换勇士位置,不切换楼层
core.clearMap('hero');
if (core.isset(data.loc)) {
core.setHeroLoc('x', core.calValue(data.loc[0]));
core.setHeroLoc('y', core.calValue(data.loc[1]));
core.setHeroLoc('x', core.calValue(data.loc[0], prefix));
core.setHeroLoc('y', core.calValue(data.loc[1], prefix));
}
if (core.isset(data.direction)) core.setHeroLoc('direction', data.direction);
core.drawHero();
@ -782,8 +783,8 @@ events.prototype.doAction = function() {
var gif = new Image();
gif.src = core.material.images.images[data.name].src;
gif.style.position = 'absolute';
gif.style.left = (core.calValue(data.loc[0])*core.domStyle.scale)+"px";
gif.style.top = (core.calValue(data.loc[1])*core.domStyle.scale)+"px";
gif.style.left = (core.calValue(data.loc[0], prefix)*core.domStyle.scale)+"px";
gif.style.top = (core.calValue(data.loc[1], prefix)*core.domStyle.scale)+"px";
gif.style.width = core.material.images.images[data.name].width*core.domStyle.scale+"px";
gif.style.height = core.material.images.images[data.name].height*core.domStyle.scale+"px";
core.dom.gif2.appendChild(gif);
@ -843,8 +844,8 @@ events.prototype.doAction = function() {
case "openDoor": // 开一个门,包括暗墙
{
if (core.isset(data.loc)) {
x = core.calValue(data.loc[0]);
y = core.calValue(data.loc[1]);
x = core.calValue(data.loc[0], prefix);
y = core.calValue(data.loc[1], prefix);
}
var floorId=data.floorId || core.status.floorId;
if (floorId==core.status.floorId)
@ -878,7 +879,7 @@ events.prototype.doAction = function() {
break;
case "trigger": // 触发另一个事件;当前事件会被立刻结束。需要另一个地点的事件是有效的
{
var toX=core.calValue(data.loc[0]), toY=core.calValue(data.loc[1]);
var toX=core.calValue(data.loc[0], prefix), toY=core.calValue(data.loc[1], prefix);
var block=core.getBlock(toX, toY);
if (block!=null) {
block = block.block;
@ -896,7 +897,7 @@ events.prototype.doAction = function() {
}
case "insert":
{
var toX=core.calValue(data.loc[0]), toY=core.calValue(data.loc[1]);
var toX=core.calValue(data.loc[0], prefix), toY=core.calValue(data.loc[1], prefix);
var floorId = data.floorId || core.status.floorId;
var event = core.floors[floorId].events[toX+","+toY];
if (core.isset(event)) core.insertAction(event);
@ -943,11 +944,16 @@ events.prototype.doAction = function() {
break;
case "setValue":
try {
var value=core.calValue(data.value);
var value=core.calValue(data.value, prefix);
// 属性
if (data.name.indexOf("status:")==0) {
// value=parseFloat(value);
core.setStatus(data.name.substring(7), value);
if (core.status.hero.hp<=0) {
core.status.hero.hp=0;
core.updateStatusBar();
core.events.lose();
break;
}
}
// 道具
if (data.name.indexOf("item:")==0) {
@ -959,22 +965,17 @@ events.prototype.doAction = function() {
}
// flag
if (data.name.indexOf("flag:")==0) {
core.setFlag(data.name.substring(5), value);
var flag = data.name.substring(5);
if (/^__[A-Z]__$/.test(flag)) flag = (prefix||"")+flag;
core.setFlag(flag, value);
}
}
catch (e) {console.log(e)}
if (core.status.hero.hp<=0) {
core.status.hero.hp=0;
core.updateStatusBar();
core.events.lose();
}
else {
core.updateStatusBar();
this.doAction();
}
core.updateStatusBar();
this.doAction();
break;
case "setFloor":
core.status.maps[data.floorId||core.status.floorId][data.name] = core.calValue(data.value);
core.status.maps[data.floorId||core.status.floorId][data.name] = core.calValue(data.value, prefix);
core.updateStatusBar();
this.doAction();
break;
@ -1050,16 +1051,16 @@ events.prototype.doAction = function() {
}
break;
case "if": // 条件判断
if (core.calValue(data.condition))
if (core.calValue(data.condition, prefix))
core.events.insertAction(data["true"])
else
core.events.insertAction(data["false"])
this.doAction();
break;
case "switch": // 条件选择
var key = core.calValue(data.condition)
var key = core.calValue(data.condition, prefix)
for (var i = 0; i < data.caseList.length; i++) {
if (data.caseList[i]["case"]=="default" || core.calValue(data.caseList[i]["case"]) == key) {
if (data.caseList[i]["case"]=="default" || core.calValue(data.caseList[i]["case"], prefix) == key) {
core.events.insertAction(data.caseList[i].action);
break;
}
@ -1092,7 +1093,7 @@ events.prototype.doAction = function() {
core.ui.drawChoices(data.text, data.choices);
break;
case "while":
if (core.calValue(data.condition)) {
if (core.calValue(data.condition, prefix)) {
core.unshift(core.status.event.data.list,
{"todo": core.clone(data.data), "total": core.clone(data.data), "condition": data.condition}
);
@ -1104,7 +1105,7 @@ events.prototype.doAction = function() {
this.doAction();
break;
case "continue":
if (core.calValue(core.status.event.data.list[0].condition)) {
if (core.calValue(core.status.event.data.list[0].condition, prefix)) {
core.status.event.data.list[0].todo = core.clone(core.status.event.data.list[0].total);
}
else {
@ -1815,7 +1816,7 @@ events.prototype.openShop = function(shopId, needVisited) {
// 拼词
var content = "\t["+shop.name+","+shop.icon+"]";
var times = shop.times, need=core.calValue(shop.need, null, times);
var times = shop.times, need=core.calValue(shop.need, null, null, times);
content += core.replaceText(shop.text, need, times);
@ -1826,7 +1827,7 @@ events.prototype.openShop = function(shopId, needVisited) {
var choice = shop.choices[i];
var text = core.replaceText(choice.text, need, times);
if (core.isset(choice.need))
text += ""+core.calValue(choice.need, null, times)+use+"";
text += ""+core.calValue(choice.need, null, null, times)+use+"";
choices.push({"text": text, "color":shop.visited?null:"#999999"});
}
choices.push("离开");

View File

@ -375,11 +375,11 @@ maps.prototype.drawBlock = function (block, animate, dx, dy) {
dy = dy || 0;
if (core.isset(block.name)) {
core.canvas[block.name].clearRect(block.x * 32, block.y * 32, 32, 32);
core.clearMap(block.name, block.x * 32, block.y * 32, 32, 32);
if (block.name == 'bg') {
core.drawImage('bg', core.material.groundCanvas.canvas, block.x * 32, block.y * 32);
}
core.canvas[block.name].drawImage(image, x * 32, y * 32, 32, 32, block.x * 32, block.y * 32, 32, 32);
core.drawImage(block.name, image, x * 32, y * 32, 32, 32, block.x * 32, block.y * 32, 32, 32);
return;
}

View File

@ -47,12 +47,12 @@ utils.prototype.init = function () {
////// 将文字中的${和}(表达式)进行替换 //////
utils.prototype.replaceText = function (text, need, times) {
return text.replace(/\${(.*?)}/g, function (word, value) {
return core.calValue(value, need, times);
return core.calValue(value, null, need, times);
});
}
////// 计算表达式的值 //////
utils.prototype.calValue = function (value, need, times) {
utils.prototype.calValue = function (value, prefix, need, times) {
if (!core.isset(value)) return value;
if (typeof value == 'number') {
return value;
@ -62,7 +62,10 @@ utils.prototype.calValue = function (value, need, times) {
}
value=value.replace(/status:([\w\d_]+)/g, "core.getStatus('$1')");
value=value.replace(/item:([\w\d_]+)/g, "core.itemCount('$1')");
value=value.replace(/flag:([\w\d_]+)/g, "core.getFlag('$1', 0)");
value=value.replace(/flag:([\w\d_]+)/g, function (word, value) {
if (/^__[A-Z]__$/.test(value)) value = (prefix||"")+value;
return core.getFlag(value, 0);
});
return eval(value);
}

View File

@ -287,7 +287,7 @@ p#name {
}
#curtain {
z-index: 100;
z-index: 125;
}
#ui {