From 22f89277086bab52268b636739d312ef28ffb944 Mon Sep 17 00:00:00 2001 From: ckcz123 Date: Fri, 24 May 2019 11:34:55 +0800 Subject: [PATCH] getEnemyInfo query cache --- project/functions.js | 112 +++++++++++++++++++++++-------------------- 1 file changed, 60 insertions(+), 52 deletions(-) diff --git a/project/functions.js b/project/functions.js index 9ff2e15b..8e84d5e4 100644 --- a/project/functions.js +++ b/project/functions.js @@ -513,64 +513,72 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a = mon_def = hero_atk - 1; } - // 光环检查 - // 从V2.5.4开始,对光环效果增加缓存,以解决多次重复计算的问题,从而大幅提升运行效率。 - // 检查当前楼层所有光环怪物(数字25) - var hp_buff = 0, - atk_buff = 0, - def_buff = 0, - cnt = 0; // ------ 支援 ------ var guards = []; - // 检查光环缓存 - var index = x != null && y != null ? (x + "," + y) : "floor"; - if (!core.status.checkBlock) core.status.checkBlock = {}; - if (!core.status.checkBlock.cache) core.status.checkBlock.cache = {}; - var cache = core.status.checkBlock.cache[index]; - if (!cache) { - // 没有该点的缓存,则遍历每个图块 - core.status.maps[floorId].blocks.forEach(function (block) { - if (!block.disable) { - // 获得该图块的ID - var id = block.event.id, - enemy = core.material.enemys[id]; - // 检查是不是怪物,且是否拥有该特殊属性 - if (enemy && core.hasSpecial(enemy.special, 25)) { - // 检查是否可叠加 - if (enemy.add || cnt == 0) { - hp_buff += enemy.value || 0; - atk_buff += enemy.atkValue || 0; - def_buff += enemy.defValue || 0; - cnt++; - } - } - // 检查【支援】技能 - if (enemy && core.hasSpecial(enemy.special, 26) && - // 检查支援条件,坐标存在,距离为1,且不能是自己 - // 其他类型的支援怪,比如十字之类的话.... 看着做是一样的 - x != null && y != null && Math.abs(block.x - x) <= 1 && Math.abs(block.y - y) <= 1 && !(x == block.x && y == block.y)) { - // 记录怪物的x,y,ID - guards.push([block.x, block.y, id]); - } - // TODO:如果有其他类型光环怪物在这里仿照添加检查 - } - }); - - core.status.checkBlock.cache[index] = { "hp_buff": hp_buff, "atk_buff": atk_buff, "def_buff": def_buff, "guards": guards }; - } else { - // 直接使用缓存数据 - hp_buff = cache.hp_buff; - atk_buff = cache.atk_buff; - def_buff = cache.def_buff; - guards = cache.guards; + // 光环检查 + // 在这里判定是否需要遍历全图(由于光环需要遍历全图,应尽可能不需要以减少计算量,尤其是大地图) + var query = function () { + var floorIds = ["MTx"]; // 在这里给出所有需要遍历的楼层(即有光环或支援等) + return core.inArray(floorIds, floorId); // 也可以写其他的判定条件 } - // 增加比例;如果要增加数值可以直接在这里修改 - mon_hp *= (1 + hp_buff / 100); - mon_atk *= (1 + atk_buff / 100); - mon_def *= (1 + def_buff / 100); + if (query()) { + // 从V2.5.4开始,对光环效果增加缓存,以解决多次重复计算的问题,从而大幅提升运行效率。 + // 检查当前楼层所有光环怪物(数字25) + var hp_buff = 0, + atk_buff = 0, + def_buff = 0, + cnt = 0; + // 检查光环缓存 + var index = x != null && y != null ? (x + "," + y) : "floor"; + if (!core.status.checkBlock) core.status.checkBlock = {}; + if (!core.status.checkBlock.cache) core.status.checkBlock.cache = {}; + var cache = core.status.checkBlock.cache[index]; + if (!cache) { + // 没有该点的缓存,则遍历每个图块 + core.status.maps[floorId].blocks.forEach(function (block) { + if (!block.disable) { + // 获得该图块的ID + var id = block.event.id, + enemy = core.material.enemys[id]; + // 检查是不是怪物,且是否拥有该特殊属性 + if (enemy && core.hasSpecial(enemy.special, 25)) { + // 检查是否可叠加 + if (enemy.add || cnt == 0) { + hp_buff += enemy.value || 0; + atk_buff += enemy.atkValue || 0; + def_buff += enemy.defValue || 0; + cnt++; + } + } + // 检查【支援】技能 + if (enemy && core.hasSpecial(enemy.special, 26) && + // 检查支援条件,坐标存在,距离为1,且不能是自己 + // 其他类型的支援怪,比如十字之类的话.... 看着做是一样的 + x != null && y != null && Math.abs(block.x - x) <= 1 && Math.abs(block.y - y) <= 1 && !(x == block.x && y == block.y)) { + // 记录怪物的x,y,ID + guards.push([block.x, block.y, id]); + } + // TODO:如果有其他类型光环怪物在这里仿照添加检查 + } + }); + + core.status.checkBlock.cache[index] = { "hp_buff": hp_buff, "atk_buff": atk_buff, "def_buff": def_buff, "guards": guards }; + } else { + // 直接使用缓存数据 + hp_buff = cache.hp_buff; + atk_buff = cache.atk_buff; + def_buff = cache.def_buff; + guards = cache.guards; + } + + // 增加比例;如果要增加数值可以直接在这里修改 + mon_hp *= (1 + hp_buff / 100); + mon_atk *= (1 + atk_buff / 100); + mon_def *= (1 + def_buff / 100); + } // TODO:可以在这里新增其他的怪物数据变化 // 比如仿攻(怪物攻击不低于勇士攻击):