diff --git a/API列表.txt b/API列表.txt index b2013082..4ed96670 100644 --- a/API列表.txt +++ b/API列表.txt @@ -661,8 +661,9 @@ core.clearStatusBar() 清空状态栏的数据。 -core.updateStatusBar() +core.updateStatusBar(doNotCheckAutoEvents) 更新状态栏,被转发到了脚本编辑中。此函数还会根据是否在回放来设置工具栏的图标。 +如果doNotCheckAutoEvents为true则此时不检查自动事件。 core.showStatusBar() / core.hideStatusBar(showToolbox) diff --git a/_docs/api.md b/_docs/api.md index 6424dcf3..4a86ff92 100644 --- a/_docs/api.md +++ b/_docs/api.md @@ -654,9 +654,9 @@ core.clearStatusBar() 清空状态栏的数据。 -core.updateStatusBar() +core.updateStatusBar(doNotCheckAutoEvents) 更新状态栏,被转发到了脚本编辑中。此函数还会根据是否在回放来设置工具栏的图标。 - +如果doNotCheckAutoEvents为true则此时不检查自动事件。 core.showStatusBar() / core.hideStatusBar(showToolbox) 显示和隐藏状态栏。 diff --git a/_server/MotaAction.g4 b/_server/MotaAction.g4 index 1bf93de3..3cf3adc3 100644 --- a/_server/MotaAction.g4 +++ b/_server/MotaAction.g4 @@ -28,13 +28,13 @@ return code; //自动事件 事件编辑器入口之一 autoEvent_m - : '自动事件' BGNL? Newline '触发条件' EvalString '优先级' Int BGNL? Newline '仅在本层检测' Bool '延迟执行' Bool '多次执行' Bool BGNL? Newline action+ BEND + : '自动事件:' '触发条件' EvalString '优先级' Int BGNL? Newline '仅在本层检测' Bool '事件流中延迟执行' Bool '允许多次执行' Bool BGNL? Newline action+ BEND /* autoEvent_m tooltip : ????? helpUrl : https://h5mota.com/games/template/_docs/#/event -default : ["flag:__door__==2",0,null,null,null,null] +default : ["flag:__door__==2",0,true,false,false,null] var code = { "condition": EvalString_0, // 条件不可为null "currentFloor": Bool_0, // 是否仅在本层检测 diff --git a/_server/editor.js b/_server/editor.js index ad24d7f1..872142d3 100644 --- a/_server/editor.js +++ b/_server/editor.js @@ -253,8 +253,15 @@ editor.prototype.drawEventBlock = function () { var loc=(i+core.bigmap.offsetX/32)+","+(j+core.bigmap.offsetY/32); if (editor.currentFloorData.events[loc]) color.push('#FF0000'); - if (editor.currentFloorData.autoEvent[loc]) - color.push('#FFA500'); + if (editor.currentFloorData.autoEvent[loc]) { + var x = editor.currentFloorData.autoEvent[loc]; + for (var index in x) { + if (x[index] && x[index].data) { + color.push('#FFA500'); + break; + } + } + } if (editor.currentFloorData.afterBattle[loc]) color.push('#FFFF00'); if (editor.currentFloorData.changeFloor[loc]) diff --git a/_server/editor_datapanel.js b/_server/editor_datapanel.js index 84b6edfa..143eac68 100644 --- a/_server/editor_datapanel.js +++ b/_server/editor_datapanel.js @@ -123,6 +123,20 @@ editor_datapanel_wrapper = function (editor) { /////////////////////////////////////////////////////////////////////// + // 添加自动事件页,无需双击 + editor.uifunctions.addAutoEvent = function () { + if (editor_mode.mode != 'loc') return false; + var newid = '2'; + var ae = editor.currentFloorData.autoEvent[editor_mode.pos.x + ',' + editor_mode.pos.y]; + if (ae != null) { + var testid; + for (testid = 2; Object.hasOwnProperty.call(ae, testid); testid++); + newid = testid + ''; + } + editor_mode.addAction(['add', "['autoEvent']['" + newid + "']", null]); + editor_mode.onmode('save'); + } + diff --git a/_server/editor_table.js b/_server/editor_table.js index 70ed6246..6ad458c6 100644 --- a/_server/editor_table.js +++ b/_server/editor_table.js @@ -341,12 +341,12 @@ editor_table_wrapper = function (editor) { var mode = editor.dom.editModeSelect.value; // 1.输入id - var newid = '3'; + var newid = '2'; if (mode == 'loc') { var ae = editor.currentFloorData.autoEvent[editor_mode.pos.x + ',' + editor_mode.pos.y]; if (ae != null) { var testid; - for (testid = 3; Object.hasOwnProperty.call(ae, testid); testid++); // 从3开始是因为comment中设置了始终显示012 + for (testid = 2; Object.hasOwnProperty.call(ae, testid); testid++); // 从3开始是因为comment中设置了始终显示012 newid = testid + ''; } } else { diff --git a/_server/table/comment.js b/_server/table/comment.js index 6fe25a60..7f95d918 100644 --- a/_server/table/comment.js +++ b/_server/table/comment.js @@ -435,6 +435,24 @@ var comment_c456ea59_6018_45ef_8bcc_211a24c627dc = { "_event": "event", "_data": "该点的可能事件列表,可以双击进入事件编辑器。" }, + "autoEvent": { + "_type": "object", + "_leaf": false, + "_action": function (args) { + args.vobj=args.vobj||{}; + for(var ii=0;ii<2;ii++){ + args.vobj[ii]=args.vobj[ii]||null; + } + }, + "_data": function (key) { + return { + "_leaf": true, + "_type": "event", + "_event": "autoEvent", + "_data": "自动事件页" + } + } + }, "changeFloor": { "_leaf": true, "_type": "event", @@ -465,24 +483,6 @@ var comment_c456ea59_6018_45ef_8bcc_211a24c627dc = { "_range": "thiseval==null||(thiseval instanceof Array)", "_data": "该点不可通行的方向 \n 可以在这里定义该点不能前往哪个方向,可以达到悬崖之类的效果\n例如 [\"up\", \"left\"] 代表该点不能往上和左走" }, - "autoEvent": { - "_type": "object", - "_leaf": false, - "_action": function (args) { - args.vobj=args.vobj||{}; - for(var ii=0;ii<3;ii++){ - args.vobj[ii]=args.vobj[ii]||null; - } - }, - "_data": function (key) { - return { - "_leaf": true, - "_type": "event", - "_event": "autoEvent", - "_data": "自动事件" - } - } - } } } } diff --git a/editor-mobile.html b/editor-mobile.html index cc411f89..8c861bef 100644 --- a/editor-mobile.html +++ b/editor-mobile.html @@ -101,7 +101,7 @@
0,0
diff --git a/editor.html b/editor.html index 548cd01f..67ad8e81 100644 --- a/editor.html +++ b/editor.html @@ -97,7 +97,7 @@0,0
diff --git a/libs/actions.js b/libs/actions.js index 648b8dd6..7caba11d 100644 --- a/libs/actions.js +++ b/libs/actions.js @@ -2626,7 +2626,6 @@ actions.prototype.exitPaint = function () { core.ui.closePanel(); core.statusBar.image.keyboard.style.opacity = 1; core.statusBar.image.shop.style.opacity = 1; - core.updateStatusBar(); core.drawTip("退出绘图模式"); } diff --git a/libs/control.js b/libs/control.js index d87455ae..d9d22fee 100644 --- a/libs/control.js +++ b/libs/control.js @@ -2329,9 +2329,10 @@ control.prototype.clearStatusBar = function() { } ////// 更新状态栏 ////// -control.prototype.updateStatusBar = function () { +control.prototype.updateStatusBar = function (doNotCheckAutoEvents) { if (!core.isPlaying()) return; this.controldata.updateStatusBar(); + if (!doNotCheckAutoEvents) core.checkAutoEvents(); this._updateStatusBar_setToolboxIcon(); } diff --git a/libs/core.js b/libs/core.js index a9e571bc..75a5fab2 100644 --- a/libs/core.js +++ b/libs/core.js @@ -16,7 +16,7 @@ function core() { 'ground': null, 'items': {}, 'enemys': {}, - 'icons': {} + 'icons': {}, } this.timeout = { 'tipTimeout': null, @@ -170,6 +170,7 @@ function core() { 'ui': null, 'interval': null, }, + 'autoEvents': [], 'textAttribute': { 'position': "center", "offset": 0, @@ -236,6 +237,32 @@ core.prototype._init_flags = function () { document.title = core.firstData.title + " - HTML5魔塔"; document.getElementById("startLogo").innerHTML = core.firstData.title; (core.firstData.shops||[]).forEach(function (t) { core.initStatus.shops[t.id] = t; }); + // 初始化自动事件 + for (var floorId in core.floors) { + var autoEvents = core.floors[floorId].autoEvent || {}; + for (var loc in autoEvents) { + var locs = loc.split(","), x = parseInt(locs[0]), y = parseInt(locs[1]); + for (var index in autoEvents[loc]) { + var autoEvent = core.clone(autoEvents[loc][index]); + if (autoEvent && autoEvent.data) { + autoEvent.floorId = floorId; + autoEvent.x = x; + autoEvent.y = y; + autoEvent.index = index; + autoEvent.symbol = floorId + "@" + x + "@" + y + "@" + index; + core.initStatus.autoEvents.push(autoEvent); + } + } + } + } + core.initStatus.autoEvents.sort(function (e1, e2) { + if (e1.priority != e2.priority) return e2.priority - e1.priority; + if (e1.floorId != e2.floorId) return core.floorIds.indexOf(e1.floorId) - core.floorIds.indexOf(e2.floorId); + if (e1.x != e2.x) return e1.x - e2.x; + if (e1.y != e2.y) return e1.y - e2.y; + return e1.index - e2.index; + }) + core.maps._setFloorSize(); // 初始化怪物、道具等 core.material.enemys = core.enemys.getEnemys(); diff --git a/libs/events.js b/libs/events.js index 16d626b5..a22fa928 100644 --- a/libs/events.js +++ b/libs/events.js @@ -802,6 +802,8 @@ events.prototype.setEvents = function (list, x, y, callback) { if (x != null) data.x = x; if (y != null) data.y = y; if (callback) data.callback = callback; + if (!data.appendingEvents) data.appendingEvents = []; + if (!data.locStack) data.locStack = []; core.status.event.id = 'action'; core.status.event.data = data; } @@ -848,6 +850,11 @@ events.prototype.doAction = function (keepUI) { events.prototype._doAction_finishEvents = function () { // 事件处理完毕 if (core.status.event.data.list.length == 0) { + // 检测并执行延迟自动事件 + if (core.status.event.data.appendingEvents.length > 0) { + this.setEvents(core.status.event.data.appendingEvents.shift()); + return false; + } var callback = core.status.event.data.callback; core.ui.closePanel(); if (callback) callback(); @@ -917,6 +924,81 @@ events.prototype.recoverEvents = function (data) { return false; } +////// 检测自动事件 ////// +events.prototype.checkAutoEvents = function () { + // 只有在无操作或事件流中才能执行自动事件! + if (!core.isPlaying() || core.status.lockControl && core.status.event.id != 'action') return; + var todo = [], delay = []; + core.status.autoEvents.forEach(function (autoEvent) { + var symbol = autoEvent.symbol, x = autoEvent.x, y = autoEvent.y, floorId = autoEvent.floorId; + // 不在当前楼层 or 已经执行过 or 正在执行中 + if (autoEvent.currentFloor && floorId != core.status.floorId) return; + if (!autoEvent.multiExecute && autoEvent.executed) return; + if (core.autoEventExecuting(symbol)) return; + var prefix = floorId + "@" + x + "@" + y; + try { + if (!core.calValue(autoEvent.condition, prefix)) return; + } catch (e) { + return; + } + + core.autoEventExecuting(symbol, true); + autoEvent.executed = true; + + var event = [ + {"type": "function", "function": + "function() { core.pushEventLoc(" + x + ", " + y + ", '" + floorId + "' ); }"}, + // 用do-while(0)包一层防止break影响事件流 + {"type": "dowhile", "condition": "false", "data": autoEvent.data}, + {"type": "function", "function": + "function() { core.popEventLoc(); core.autoEventExecuting('" + symbol + "', false); }"} + ]; + + if (autoEvent.delayExecute) + delay.push(event); + else + core.push(todo, event); + }); + + if (todo.length == 0 && delay.length == 0) return; + + if (core.status.event.id == 'action' || todo.length > 0) { + core.insertAction(todo); + core.push(core.status.event.data.appendingEvents, delay); + } else { + core.insertAction(delay); + } + +} + +events.prototype.autoEventExecuting = function (symbol, value) { + var name = '_executing_autoEvent_' + symbol; + if (value == null) return core.getFlag(name, false); + else core.setFlag(name, value || null); +} + +events.prototype.pushEventLoc = function (x, y, floorId) { + if (core.status.event.id != 'action') return; + core.status.event.data.locStack.push({ + x: core.status.event.data.x, + y: core.status.event.data.y, + floorId: core.status.event.data.floorId + }); + core.status.event.data.x = x; + core.status.event.data.y = y; + core.status.event.data.floorId = floorId; +} + +events.prototype.popEventLoc = function () { + if (core.status.event.id != 'action') return; + var loc = core.status.event.data.locStack.shift(); + if (loc) { + core.status.event.data.x = loc.x; + core.status.event.data.y = loc.y; + core.status.event.data.floorId = loc.floorId; + } +} + // ------ 样板提供的的自定义事件 ------ // events.prototype.__action_checkReplaying = function () { diff --git a/libs/ui.js b/libs/ui.js index fe5f3eed..cf3de210 100644 --- a/libs/ui.js +++ b/libs/ui.js @@ -440,7 +440,7 @@ ui.prototype._uievent_drawIcon = function (data) { ui.prototype.closePanel = function () { this.clearUI(); core.maps.generateGroundPattern(); - core.updateStatusBar(); + core.updateStatusBar(true); core.unLockControl(); core.status.event.data = null; core.status.event.id = null; diff --git a/project/floors/sample1.js b/project/floors/sample1.js index 92b3a0e8..8b5c8646 100644 --- a/project/floors/sample1.js +++ b/project/floors/sample1.js @@ -728,20 +728,6 @@ main.floors.sample1= "type": "setValue", "name": "flag:door", "value": "flag:door+1" - }, - { - "type": "if", - "condition": "flag:door==2", - "true": [ - { - "type": "openDoor", - "loc": [ - 10, - 5 - ] - } - ], - "false": [] } ], "11,6": [ @@ -749,20 +735,6 @@ main.floors.sample1= "type": "setValue", "name": "flag:door", "value": "flag:door+1" - }, - { - "type": "if", - "condition": "flag:door==2", - "true": [ - { - "type": "openDoor", - "loc": [ - 10, - 5 - ] - } - ], - "false": [] } ] }, @@ -775,4 +747,21 @@ main.floors.sample1= "fgmap": [ ], +"autoEvent": { + "10,5": { + "0": { + "condition": "flag:door==2", + "currentFloor": true, + "priority": 0, + "delayExecute": false, + "multiExecute": false, + "data": [ + { + "type": "openDoor" + } + + ] + } + } +} } \ No newline at end of file diff --git a/project/functions.js b/project/functions.js index f09b5bda..8cd9de88 100644 --- a/project/functions.js +++ b/project/functions.js @@ -353,7 +353,6 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a = core.setFlag('skill', 0); core.setFlag('skillName', '无'); } - core.updateStatusBar(); // 如果有加点 var point = core.material.enemys[enemyId].point; @@ -375,6 +374,7 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a = // 如果事件不为空,将其插入 if (todo.length > 0) core.insertAction(todo, x, y); + core.updateStatusBar(); // 如果已有事件正在处理中 if (core.status.event.id == null)