From 8d88cc4d01eb16a9068a0052cb06e8837be035ea Mon Sep 17 00:00:00 2001 From: oc Date: Mon, 25 Feb 2019 01:40:21 +0800 Subject: [PATCH] Fix openDoor replay Bug --- _docs/api.md | 1 + libs/core.js | 2 +- libs/events.js | 20 ++++++++++++-------- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/_docs/api.md b/_docs/api.md index 68606a04..88697135 100644 --- a/_docs/api.md +++ b/_docs/api.md @@ -176,6 +176,7 @@ core.openDoor(id, x, y, needKey, callback) [异步] 尝试开门操作。id为目标点的ID,x和y为坐标,needKey表示是否需要使用钥匙,callback为开门完毕后的回调函数。 id可为null代表使用地图上的值。 例如:core.openDoor('yellowDoor', 10, 3, false, function() {console.log("1")}) +此函数返回true代表成功开门,并将执行callback回调;返回false代表无法开门,且不会执行回调函数。 core.battle(id, x, y, force, callback) [异步] diff --git a/libs/core.js b/libs/core.js index f62fb9ce..0092ac83 100644 --- a/libs/core.js +++ b/libs/core.js @@ -623,7 +623,7 @@ core.prototype.nearHero = function (x, y) { ////// 开门 ////// core.prototype.openDoor = function (id, x, y, needKey, callback) { - core.events.openDoor(id, x, y, needKey, callback); + return core.events.openDoor(id, x, y, needKey, callback); } ////// 战斗 ////// diff --git a/libs/events.js b/libs/events.js index 3cad299e..d351f2e5 100644 --- a/libs/events.js +++ b/libs/events.js @@ -864,11 +864,15 @@ events.prototype.doAction = function() { y = core.calValue(data.loc[1], prefix); } var floorId=data.floorId || core.status.floorId; - if (floorId==core.status.floorId) - core.openDoor(null, x, y, data.needKey, function() { + if (floorId==core.status.floorId) { + var _callback = function () { core.lockControl(); core.events.doAction(); - }) + } + if (!core.openDoor(null, x, y, data.needKey, _callback)) { + _callback(); + } + } else { core.removeBlock(x, y, floorId); this.doAction(); @@ -1423,8 +1427,7 @@ events.prototype.openDoor = function (id, x, y, needKey, callback) { // 是否存在门 if (!core.terrainExists(x, y, id) || !(id.endsWith("Door") || id.endsWith("Wall")) || !core.isset(core.material.icons.animates[id])) { - if (core.isset(callback)) callback(); - return; + return false; } if (core.status.automaticRoute.moveStepBeforeStop.length==0) { core.status.automaticRoute.moveStepBeforeStop=core.status.automaticRoute.autoStepRoutes.slice(core.status.automaticRoute.autoStep-1,core.status.automaticRoute.autoStepRoutes.length); @@ -1440,8 +1443,7 @@ events.prototype.openDoor = function (id, x, y, needKey, callback) { core.drawTip("你没有" + ((core.material.items[key]||{}).name||"钥匙")); else core.drawTip("无法开启此门"); core.clearContinueAutomaticRoute(); - if (core.isset(callback)) callback(); - return; + return false; } core.autosave(true); core.removeItem(key); @@ -1469,7 +1471,9 @@ events.prototype.openDoor = function (id, x, y, needKey, callback) { } core.clearMap('event', 32 * x, 32 * y, 32, 32); core.drawImage('event', core.material.images.animates, 32 * state, 32 * door, 32, 32, 32 * x, 32 * y, 32, 32); - }, speed / core.status.replay.speed) + }, speed / core.status.replay.speed); + + return true; } ////// 战斗 //////