From 6b5615fd4e5d69c27872b834135d88c4011ee4ff Mon Sep 17 00:00:00 2001 From: lizhuoyuan <2820814112@qq.com> Date: Thu, 13 Feb 2025 14:58:13 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E8=B0=83=E6=95=B4core.getEnemyValue?= =?UTF-8?q?=E9=80=BB=E8=BE=91=EF=BC=8C=E4=B8=8D=E5=A1=ABname=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E8=AF=A5=E7=82=B9=E5=AE=8C=E6=95=B4metadata?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/enemys.js | 25 +++++++++++++++++++------ project/floors/MT0.js | 20 ++++++++++++++++---- project/plugins.js | 2 +- runtime.d.ts | 11 +++++++++-- 4 files changed, 45 insertions(+), 13 deletions(-) diff --git a/libs/enemys.js b/libs/enemys.js index 7f33bb84..0d893085 100644 --- a/libs/enemys.js +++ b/libs/enemys.js @@ -167,17 +167,30 @@ enemys.prototype._calSpecialContent = function (enemy, content) { ////// 获得某个点上某个怪物的某项属性 ////// enemys.prototype.getEnemyValue = function (enemy, name, x, y, floorId) { floorId = floorId || core.status.floorId; - if ((((flags.enemyOnPoint || {})[floorId] || {})[x + "," + y] || {})[name] != null) { - return flags.enemyOnPoint[floorId][x + "," + y][name]; + + const pointInfo = (((flags.enemyOnPoint || {})[floorId] || {})[x + "," + y] || {}); + + if (core.isset(name) && pointInfo[name] != null) { + return pointInfo[name]; } if (enemy == null) { var block = core.getBlock(x, y, floorId); - if (block == null) return null; + if (block == null) return null; // 无enemy且无x,y时返回null,无enemy有x,y将读取该点信息 enemy = core.material.enemys[block.event.id]; } - if (typeof enemy == 'string') enemy = core.material.enemys[enemy]; - if (enemy == null) return null; - return enemy[name]; + else if (typeof enemy == 'string') { + enemy = core.material.enemys[enemy]; + if (enemy == null) return null; + } + + if (!core.isset(name)) { // 仅name不填时返回该enemy的完整数据,有x,y将用该点信息覆盖core.material.enemys相应属性 + enemy = core.clone(enemy); + for (let status in pointInfo) { + if (pointInfo.hasOwnProperty(status)) enemy[status] = pointInfo[status]; + } + return enemy; + } + else return enemy[name]; } ////// 能否获胜 ////// diff --git a/project/floors/MT0.js b/project/floors/MT0.js index da474738..b03178b2 100644 --- a/project/floors/MT0.js +++ b/project/floors/MT0.js @@ -14,12 +14,12 @@ main.floors.MT0= [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [ 0, 0, 0, 0, 0, 0,201, 0, 0,201, 0, 0, 0], [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [ 0, 0, 0, 0, 0, 0, 0, 0, 0,201, 0, 0, 0], [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [ 0, 0, 0, 0, 0, 0, 12, 0, 0, 0, 0, 0, 0], - [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [ 0, 0, 0, 0, 0, 0, 0, 0, 0,201, 0, 0, 0], [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], @@ -56,7 +56,19 @@ main.floors.MT0= "afterOpenDoor": {}, "cannotMove": {}, "bgmap": [ - + [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [167,167,167,167,167,167,167,167,167,167,167,167,167], + [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] ], "fgmap": [ diff --git a/project/plugins.js b/project/plugins.js index 0d90682e..4b5bc4bc 100644 --- a/project/plugins.js +++ b/project/plugins.js @@ -1967,7 +1967,7 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = function canBattle(enemy, x, y) { const loc = `${x},${y}`; const floor = core.floors[core.status.floorId]; - const e = core.material.enemys[enemy]; + const e = core.getEnemyValue(enemy, null, x, y); const hasEvent = has(floor.afterBattle[loc]) || has(floor.beforeBattle[loc]) || has(e.beforeBattle) || has(e.afterBattle) diff --git a/runtime.d.ts b/runtime.d.ts index e354069f..5924ea2a 100644 --- a/runtime.d.ts +++ b/runtime.d.ts @@ -1426,8 +1426,15 @@ interface enemys { */ getSpecialHint(enemy: string | Enemy, special: number): string - /** 获得某个敌人的某项属性值 */ - getEnemyValue(enemy: string | Enemy, name: string, x?: number, y?: number, floorId?: string): any + /** + * 获得某个敌人的某项属性值 + * @param enemy 敌人id或敌人对象 + * @param name 要获取的属性名,不填时获取完整的该敌人数据 + * @param x 敌人的横坐标,可选,填写时该点属性覆盖core.material.enemys中相应属性 + * @param y 敌人的纵坐标,可选 + * @param floorId 敌人所在的地图,可选。 + */ + getEnemyValue(enemy: string | Enemy, name?: string, x?: number, y?: number, floorId?: string): any /** * 判定主角当前能否打败某只敌人