From f306af2d3d258831a3a342c7f6ce0daa7d95eea7 Mon Sep 17 00:00:00 2001 From: ckcz123 Date: Fri, 30 Jul 2021 12:54:07 +0800 Subject: [PATCH] =?UTF-8?q?=E6=88=98=E5=89=8D=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _server/MotaAction.g4 | 20 ++++++++++++++++---- _server/editor.js | 3 +++ _server/editor_blocklyconfig.js | 3 ++- _server/editor_datapanel.js | 2 +- _server/editor_ui.js | 2 +- _server/table/comment.js | 15 +++++++++++++++ libs/core.js | 2 +- libs/events.js | 24 +++++++++++++++++++++--- libs/maps.js | 9 ++++++--- project/functions.js | 2 +- project/plugins.js | 7 +++---- 11 files changed, 70 insertions(+), 19 deletions(-) diff --git a/_server/MotaAction.g4 b/_server/MotaAction.g4 index 0ad9ac2f..90d56193 100644 --- a/_server/MotaAction.g4 +++ b/_server/MotaAction.g4 @@ -252,6 +252,18 @@ code=JSON.stringify(code,null,2)+',\n'; return code; */; +//beforeBattle 事件编辑器入口之一 +beforeBattle_m + : '战斗开始前' BGNL? Newline action+ BEND + + +/* beforeBattle_m +tooltip : 战斗开始前 +helpUrl : /_docs/#/instruction +var code = '[\n'+action_0+']\n'; +return code; +*/; + //afterBattle 事件编辑器入口之一 afterBattle_m : '战斗结束后' BGNL? Newline action+ BEND @@ -3975,8 +3987,8 @@ IgnoreChangeFloor_List /*IgnoreChangeFloor_List ['null','true','false']*/; Event_List - : '普通事件'|'战后事件'|'道具后事件'|'开门后事件' - /*Event_List ['null','afterBattle','afterGetItem','afterOpenDoor']*/; + : '普通事件'|'战前事件'|'战后事件'|'道具后事件'|'开门后事件' + /*Event_List ['null','beforeBattle','afterBattle','afterGetItem','afterOpenDoor']*/; Floor_Meta_List : '楼层中文名'|'状态栏名称'|'能否楼传飞到'|'能否楼传飞出'|'能否打开快捷商店'|'是否不可浏览地图'|'是否不可瞬间移动'|'默认地面ID'|'宝石血瓶效果'|'上楼点坐标'|'下楼点坐标'|'楼传落点坐标'|'背景音乐'|'画面色调'|'天气和强度'|'是否地下层' @@ -4052,8 +4064,8 @@ IdString ; FixedId_List - : '生命'|'生命上限'|'攻击'|'防御'|'护盾'|'黄钥匙'|'蓝钥匙'|'红钥匙'|'金币'|'经验'|'魔力'|'魔力上限'|'生命增益'|'攻击增益'|'防御增益'|'护盾增益' - /*FixedId_List ['status:hp','status:hpmax','status:atk','status:def','status:mdef','item:yellowKey','item:blueKey','item:redKey','status:money','status:exp','status:mana','status:manamax','buff:hp','buff:atk','buff:def','buff:mdef']*/; + : '生命'|'生命上限'|'攻击'|'防御'|'护盾'|'黄钥匙'|'蓝钥匙'|'红钥匙'|'金币'|'经验'|'魔力'|'魔力上限'|'横坐标'|'纵坐标'|'攻击增益'|'防御增益'|'护盾增益' + /*FixedId_List ['status:hp','status:hpmax','status:atk','status:def','status:mdef','item:yellowKey','item:blueKey','item:redKey','status:money','status:exp','status:mana','status:manamax','status:x','status:y','buff:atk','buff:def','buff:mdef']*/; Id_List : '变量' | '状态' | '物品' | '增益' | '独立开关' | '临时变量' |'全局存储' diff --git a/_server/editor.js b/_server/editor.js index 883d57a5..b7b8fdd6 100644 --- a/_server/editor.js +++ b/_server/editor.js @@ -326,6 +326,7 @@ editor.prototype.mapInit = function () { editor.currentFloorData.events = {}; editor.currentFloorData.autoEvent = {}; editor.currentFloorData.changeFloor = {}; + editor.currentFloorData.beforeBattle = {}; editor.currentFloorData.afterBattle = {}; editor.currentFloorData.afterGetItem = {}; editor.currentFloorData.afterOpenDoor = {}; @@ -442,6 +443,8 @@ editor.prototype._drawEventBlock_getColor = function (loc) { } } } + if (editor.currentFloorData.beforeBattle[loc]) + color.push('#009090'); if (editor.currentFloorData.afterBattle[loc]) color.push('#FFFF00'); if (editor.currentFloorData.changeFloor[loc]) diff --git a/_server/editor_blocklyconfig.js b/_server/editor_blocklyconfig.js index 59f2bcf5..22f5a190 100644 --- a/_server/editor_blocklyconfig.js +++ b/_server/editor_blocklyconfig.js @@ -60,6 +60,7 @@ editor_blocklyconfig=(function(){ "args": "" }],'shop'), MotaActionBlocks['common_m'].xmlText(), + MotaActionBlocks['beforeBattle_m'].xmlText(), MotaActionBlocks['afterBattle_m'].xmlText(), MotaActionBlocks['afterGetItem_m'].xmlText(), MotaActionBlocks['afterOpenDoor_m'].xmlText(), @@ -535,7 +536,7 @@ var workspace = Blockly.inject(blocklyDiv,{ }); editor_blockly.isCommonEntry = function () { - var commonEntries = ['afterBattle', 'afterOpenDoor', 'firstArrive', 'eachArrive', 'commonEvent', 'item']; + var commonEntries = ['beforeBattle', 'afterBattle', 'afterOpenDoor', 'firstArrive', 'eachArrive', 'commonEvent', 'item']; return commonEntries.indexOf(editor_blockly.entryType) >= 0; } diff --git a/_server/editor_datapanel.js b/_server/editor_datapanel.js index da3f7932..bf699656 100644 --- a/_server/editor_datapanel.js +++ b/_server/editor_datapanel.js @@ -596,7 +596,7 @@ editor_datapanel_wrapper = function (editor) { }); // Step 3:更新所有坐标 - ["events", "afterBattle", "afterGetItem", "afterOpenDoor", "changeFloor", "autoEvent", "cannotMove"].forEach(function (name) { + ["events", "beforeBattle", "afterBattle", "afterGetItem", "afterOpenDoor", "changeFloor", "autoEvent", "cannotMove"].forEach(function (name) { newFloorData[name] = {}; if (!currentFloorData[name]) return; for (var loc in currentFloorData[name]) { diff --git a/_server/editor_ui.js b/_server/editor_ui.js index e7824c0f..c85d9f15 100644 --- a/_server/editor_ui.js +++ b/_server/editor_ui.js @@ -696,7 +696,7 @@ editor_ui_wrapper = function (editor) { uievent._searchUsedFlags = function (flag) { var list = []; - var events = ["events", "autoEvent", "changeFloor", "afterBattle", "afterGetItem", "afterOpenDoor"] + var events = ["events", "autoEvent", "changeFloor", "beforeBattle", "afterBattle", "afterGetItem", "afterOpenDoor"] for (var floorId in core.floors) { var floor = core.floors[floorId]; if (hasUsedFlags(floor.firstArrive, flag)) list.push([floorId, "firstArrive"]); diff --git a/_server/table/comment.js b/_server/table/comment.js index 5dbfdbea..236f5e1b 100644 --- a/_server/table/comment.js +++ b/_server/table/comment.js @@ -244,6 +244,13 @@ var comment_c456ea59_6018_45ef_8bcc_211a24c627dc = { "_docs": "固伤", "_data": "战前扣血的点数" }, + "beforeBattle": { + "_leaf": true, + "_type": "event", + "_event": "beforeBattle", + "_docs": "战前事件", + "_data": "和该怪物战斗前触发的事件列表" + }, "afterBattle": { "_leaf": true, "_type": "event", @@ -570,6 +577,13 @@ var comment_c456ea59_6018_45ef_8bcc_211a24c627dc = { "_docs": "楼层转换", "_data": "该点楼层转换事件;该事件不能和上面的events同时出现,否则会被覆盖" }, + "beforeBattle": { + "_leaf": true, + "_type": "event", + "_event": "beforeBattle", + "_docs": "战前事件", + "_data": "该点战斗前可能触发的事件列表,可以双击进入事件编辑器。" + }, "afterBattle": { "_leaf": true, "_type": "event", @@ -630,6 +644,7 @@ var comment_c456ea59_6018_45ef_8bcc_211a24c627dc = { "parallelDo": "", "events": {}, "changeFloor": {}, + "beforeBattle": {}, "afterBattle": {}, "afterGetItem": {}, "afterOpenDoor": {}, diff --git a/libs/core.js b/libs/core.js index f91efbeb..128964be 100644 --- a/libs/core.js +++ b/libs/core.js @@ -317,7 +317,7 @@ core.prototype._init_flags = function () { return e1.index - e2.index; }) - core.maps._setFloorSize(); + core.maps._initFloors(); // 初始化怪物、道具等 core.material.enemys = core.enemys.getEnemys(); core.material.items = core.items.getItems(); diff --git a/libs/events.js b/libs/events.js index 229200d0..18773f18 100644 --- a/libs/events.js +++ b/libs/events.js @@ -403,7 +403,26 @@ events.prototype._trigger_ignoreChangeFloor = function (block) { } events.prototype._sys_battle = function (data, callback) { - this.battle(data.event.id, data.x, data.y, false, callback); + // 检查战前事件 + var beforeBattle = []; + core.push(beforeBattle, core.floors[core.status.floorId].beforeBattle[data.x + "," + data.y]); + core.push(beforeBattle, (core.material.enemys[data.event.id]||{}).beforeBattle); + if (beforeBattle.length > 0) { + core.push(beforeBattle, [{"type": "battle", "x": data.x, "y": data.y}]); + core.clearContinueAutomaticRoute(); + + // 自动存档 + var inAction = core.status.event.id == 'action'; + if (inAction) { + core.insertAction(beforeBattle, data.x, data.y); + core.doAction(); + } else { + core.autosave(true); + core.insertAction(beforeBattle, data.x, data.y, callback); + } + } else { + this.battle(data.event.id, data.x, data.y, false, callback); + } } ////// 战斗 ////// @@ -859,8 +878,7 @@ events.prototype._sys_action = function (data, callback) { events.prototype._sys_custom = function (data, callback) { core.insertAction(["请使用\r[yellow]core.registerSystemEvent('custom', func)\r来处理自己添加的系统触发器!"], - data.x, data.y); - if (callback) callback(); + data.x, data.y, callback); } // ------ 自定义事件的处理 ------ // diff --git a/libs/maps.js b/libs/maps.js index e8585c31..c2eb38de 100644 --- a/libs/maps.js +++ b/libs/maps.js @@ -11,15 +11,18 @@ maps.prototype._init = function () { //delete(maps_90f36752_8815_4be8_b32b_d7fad1d0542e); } -maps.prototype._setFloorSize = function (floorId) { +maps.prototype._initFloors = function (floorId) { if (!floorId) { core.floorIds.forEach(function (floorId) { - core.maps._setFloorSize(floorId); + core.maps._initFloors(floorId); }); return; } core.floors[floorId].width = core.floors[floorId].width || core.__SIZE__; core.floors[floorId].height = core.floors[floorId].height || core.__SIZE__; + + // 战前事件兼容性 + if (!core.floors[floorId].beforeBattle) core.floors[floorId].beforeBattle = {} } maps.prototype._resetFloorImages = function () { @@ -71,7 +74,7 @@ maps.prototype.loadFloor = function (floorId, map) { maps.prototype._loadFloor_doNotCopy = function () { return [ "firstArrive", "eachArrive", "blocks", "parallelDo", "map", "bgmap", "fgmap", - "events", "changeFloor", "afterBattle", "afterGetItem", "afterOpenDoor", "cannotMove" + "events", "changeFloor", "beforeBattle", "afterBattle", "afterGetItem", "afterOpenDoor", "cannotMove" ]; } diff --git a/project/functions.js b/project/functions.js index e1ed36fa..e9d3b51e 100644 --- a/project/functions.js +++ b/project/functions.js @@ -250,7 +250,7 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a = }); core.push(actions, [ { "type": "waitAsync" }, // 等待所有异步事件执行完毕 - { "type": "trigger", "loc": [x, y] } // 重要!重新触发本点事件(即重新触发战斗) + { "type": "battle", "loc": [x, y] } // 重要!重新触发本次战斗 ]); core.insertAction(actions); return false; diff --git a/project/plugins.js b/project/plugins.js index f3d14c06..3b3f5f6e 100644 --- a/project/plugins.js +++ b/project/plugins.js @@ -466,11 +466,10 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = parent.appendChild(input2); } } + + var _loadFloor_doNotCopy = core.maps._loadFloor_doNotCopy; core.maps._loadFloor_doNotCopy = function () { - return [ - "firstArrive", "eachArrive", "blocks", "parallelDo", "map", "bgmap", "fgmap", "bg2map", "fg2map", - "events", "changeFloor", "afterBattle", "afterGetItem", "afterOpenDoor", "cannotMove" - ]; + return ["bg2map", "fg2map"].concat(_loadFloor_doNotCopy()); } ////// 绘制背景和前景层 ////// core.maps._drawBg_draw = function (floorId, toDrawCtx, cacheCtx, config) {