diff --git a/libs/maps.js b/libs/maps.js index 060f74ff..e700f469 100644 --- a/libs/maps.js +++ b/libs/maps.js @@ -82,6 +82,12 @@ maps.prototype._getNumberById = function (id) { return 0; } +maps.prototype.getBlockByNumber = function (number) { + core.status.number2Block = core.status.number2Block || {}; + if (core.status.number2Block[number] != null) return core.status.number2Block[number]; + return core.status.number2Block[number] = this.initBlock(null, null, number, true); +} + ////// 数字和ID的对应关系 ////// maps.prototype.initBlock = function (x, y, id, addInfo, eventFloor) { var disable = null; @@ -481,7 +487,7 @@ maps.prototype._canMoveHero_checkCannotInOut = function (number, name, direction } return false; } - return core.inArray((this.initBlock(0, 0, number).event || {})[name], direction); + return core.inArray((this.getBlockByNumber(number).event || {})[name], direction); } ////// 能否瞬间移动 ////// @@ -1331,7 +1337,7 @@ maps.prototype.getBlockInfo = function (block) { } if (typeof block == 'number') { // 参数是数字 if (block == 0) return null; - block = this.initBlock(0, 0, block, true); + block = this.getBlockByNumber(block); } var number = block.id, id = block.event.id, cls = block.event.cls, name = block.event.name, image = null, posX = 0, posY = 0, animate = block.event.animate, @@ -1367,7 +1373,7 @@ maps.prototype.getBlockInfo = function (block) { ////// 搜索某个图块出现的所有位置 ////// maps.prototype.searchBlock = function (id, floorId, showDisable) { - if (typeof id == 'number') id = this.initBlock(0, 0, id).event.id; + if (typeof id == 'number') id = this.getBlockByNumber(id).event.id; floorId = floorId || core.status.floorId; var result = []; if (floorId instanceof Array) { @@ -1610,7 +1616,7 @@ maps.prototype.replaceBlock = function (fromNumber, toNumber, floorId) { }); return; } - var toBlock = this.initBlock(0, 0, toNumber, true); + var toBlock = this.getBlockByNumber(toNumber, true); core.status.maps[floorId].blocks.forEach(function (block) { if (block.id == fromNumber) { block.id = toNumber; diff --git a/libs/utils.js b/libs/utils.js index c221a5b8..9fa75957 100644 --- a/libs/utils.js +++ b/libs/utils.js @@ -1093,7 +1093,7 @@ utils.prototype._export = function (floorIds) { content += arr.map(function (x) { // check monster x.forEach(function (t) { - var block = core.maps.initBlock(null, null, t); + var block = core.maps.getBlockByNumber(t); if (block.event.cls.indexOf("enemy") == 0) { monsterMap[t] = block.event.id; }