From dc5326c982aa6dfaa246b3c91936fe8379ab4d2c Mon Sep 17 00:00:00 2001 From: ckcz123 Date: Fri, 30 Jul 2021 22:31:59 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A3=85=E5=A4=87=E7=A9=BF=E4=B8=8A=20&=20?= =?UTF-8?q?=E8=84=B1=E4=B8=8B=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _server/MotaAction.g4 | 10 ++++++---- _server/MotaActionParser.js | 3 ++- libs/actions.js | 4 ++++ libs/core.js | 38 ++++++++++++++++++++++++++++++++----- libs/events.js | 28 ++++++++++++++++++--------- 5 files changed, 64 insertions(+), 19 deletions(-) diff --git a/_server/MotaAction.g4 b/_server/MotaAction.g4 index b99e8246..6708c405 100644 --- a/_server/MotaAction.g4 +++ b/_server/MotaAction.g4 @@ -456,7 +456,7 @@ return code; // equip 事件编辑器入口之一 equip_m - : '装备' '类型' EvalString '装备动画(第一个装备格有效)' IdString? BGNL? '数值提升项' equipList+ '百分比提升项' equipList+ '此道具cls须为equips并设置canUseItemEffect' BEND + : '装备' '类型' EvalString '装备动画(第一个装备格有效)' IdString? BGNL? '数值提升项' equipList+ '百分比提升项' equipList+ '穿上时事件' action+ '脱下时事件' action+ '此道具cls须为equips并设置canUseItemEffect' BEND /* equip_m @@ -468,7 +468,9 @@ if (!/^\d+$/.test(EvalString_0)) { EvalString_0 = '"' + EvalString_0 + '"'; } IdString_0 = IdString_0 && (', "animate": "'+IdString_0+'"'); -var code = '{"type": '+EvalString_0+IdString_0+', "value": {\n'+equipList_0+'\n}, "percentage": {\n'+equipList_1+'\n}}'; +if (action_0.trim()) action_0 = ', "equipEvent": [\n' + action_0 + ']'; +if (action_1.trim()) action_1 = ', "unequipEvent": [\n' + action_1 + ']'; +var code = '{"type": '+EvalString_0+IdString_0+', "value": {\n'+equipList_0+'\n}, "percentage": {\n'+equipList_1+'\n}'+action_0+action_1+'}'; return code; */; @@ -2034,7 +2036,7 @@ return code; */; unloadEquip_s - : '卸下装备孔' Int '的装备' Newline + : '卸下第' Int '格装备孔的装备' Newline /* unloadEquip_s @@ -3868,7 +3870,7 @@ return [code, Blockly.JavaScript.ORDER_ATOMIC]; equip_e - : '装备孔:' Int + : '第' Int '格装备孔' /* equip_e diff --git a/_server/MotaActionParser.js b/_server/MotaActionParser.js index 2118755d..8505d954 100644 --- a/_server/MotaActionParser.js +++ b/_server/MotaActionParser.js @@ -82,7 +82,8 @@ ActionParser.prototype.parse = function (obj,type) { }) return text_choices; } - return MotaActionBlocks['equip_m'].xmlText([obj.type, obj.animate, buildEquip(obj.value), buildEquip(obj.percentage)]); + return MotaActionBlocks['equip_m'].xmlText([obj.type, obj.animate, buildEquip(obj.value), buildEquip(obj.percentage), + this.parseList(obj.equipEvent), this.parseList(obj.unequipEvent)]); case 'doorInfo': if(!obj) obj={}; diff --git a/libs/actions.js b/libs/actions.js index 4c1f2270..15a48294 100644 --- a/libs/actions.js +++ b/libs/actions.js @@ -1503,6 +1503,7 @@ actions.prototype._clickToolbox = function (x, y) { if (x >= this.LAST - 2 && y == this.LAST) { core.playSound('取消'); core.ui.closePanel(); + core.checkAutoEvents(); return; } @@ -1678,6 +1679,7 @@ actions.prototype._keyUpToolbox = function (keycode) { if (keycode == 84 || keycode == 27 || keycode == 88) { core.playSound('取消'); core.ui.closePanel(); + core.checkAutoEvents(); return; } if (core.status.event.data == null) return; @@ -1704,6 +1706,7 @@ actions.prototype._clickEquipbox = function (x, y) { if (x >= this.LAST - 2 && y == this.LAST) { core.playSound('取消'); core.ui.closePanel(); + core.checkAutoEvents(); return; } @@ -1861,6 +1864,7 @@ actions.prototype._keyUpEquipbox = function (keycode, altKey) { if (keycode == 81 || keycode == 27 || keycode == 88) { core.playSound('取消'); core.ui.closePanel(); + core.checkAutoEvents(); return; } if (!core.status.event.data.selectId) return; diff --git a/libs/core.js b/libs/core.js index c87f809e..d82d9592 100644 --- a/libs/core.js +++ b/libs/core.js @@ -292,6 +292,13 @@ core.prototype._init_flags = function () { document.title = core.firstData.title + " - HTML5魔塔"; document.getElementById("startLogo").innerText = core.firstData.title; (core.firstData.shops||[]).forEach(function (t) { core.initStatus.shops[t.id] = t; }); + + core.maps._initFloors(); + // 初始化怪物、道具等 + core.material.enemys = core.enemys.getEnemys(); + core.material.items = core.items.getItems(); + core.material.icons = core.icons.getIcons(); + // 初始化自动事件 for (var floorId in core.floors) { var autoEvents = core.floors[floorId].autoEvent || {}; @@ -312,7 +319,33 @@ core.prototype._init_flags = function () { } } } + // 道具的穿上/脱下,视为自动事件 + for (var equipId in core.material.items) { + var equip = core.material.items[equipId]; + if (equip.cls != 'equips' || !equip.equip) continue; + if (!equip.equip.equipEvent && !equip.equip.unequipEvent) continue; + var equipFlag = '_equipEvent_' + equipId; + var autoEvent1 = { + symbol: "_equipEvent_" + equipId, + currentFloor: false, + multiExecute: true, + condition: "core.hasEquip('" + equipId + "') && !core.hasFlag('"+equipFlag+"')", + data: core.precompile([{"type": "setValue", "name": "flag:" + equipFlag, "value": "true"}].concat(equip.equip.equipEvent||[])), + }; + var autoEvent2 = { + symbol: "_unequipEvent_" + equipId, + currentFloor: false, + multiExecute: true, + condition: "!core.hasEquip('" + equipId + "') && core.hasFlag('"+equipFlag+"')", + data: core.precompile([{"type": "setValue", "name": "flag:" + equipFlag, "value": "null"}].concat(equip.equip.unequipEvent||[])), + }; + core.initStatus.autoEvents.push(autoEvent1); + core.initStatus.autoEvents.push(autoEvent2); + } + core.initStatus.autoEvents.sort(function (e1, e2) { + if (e1.floorId == null) return 1; + if (e2.floorId == null) return -1; 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; @@ -320,11 +353,6 @@ core.prototype._init_flags = function () { return e1.index - e2.index; }) - core.maps._initFloors(); - // 初始化怪物、道具等 - core.material.enemys = core.enemys.getEnemys(); - core.material.items = core.items.getItems(); - core.material.icons = core.icons.getIcons(); } core.prototype._init_sys_flags = function () { diff --git a/libs/events.js b/libs/events.js index 298215a2..338ae6f7 100644 --- a/libs/events.js +++ b/libs/events.js @@ -1104,15 +1104,25 @@ events.prototype.checkAutoEvents = function () { core.autoEventExecuting(symbol, true); core.autoEventExecuted(symbol, 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); }"} - ]; + + var event; + if (x == null && y == null) { + event = [ + // 用do-while(0)包一层防止break影响事件流 + {"type": "dowhile", "condition": "false", "data": autoEvent.data}, + {"type": "function", "function": + "function() { core.autoEventExecuting('" + symbol + "', false); }"} + ]; + } else { + 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);