diff --git a/libs/control.js b/libs/control.js index 5423504f..3fd82d62 100644 --- a/libs/control.js +++ b/libs/control.js @@ -1120,6 +1120,26 @@ control.prototype.updateCheckBlock = function (floorId) { } ////// 检查并执行领域、夹击、阻击事件 ////// + +control.prototype.battleWithChase = function () { + const [hx, hy] = [core.getHeroLoc('x'), core.getHeroLoc('y')]; + const scan = core.utils.scan; + const actions = []; + for (const dir in scan) { + const [nx, ny] = [hx + scan[dir].x, hy + scan[dir].y]; + const blockId = core.getBlockId(nx, ny); + if (core.hasSpecial(blockId, 28)) { + actions.push({ + "type": "function", "function": "function() { " + + "core.battle('" + blockId + "', " + nx + "," + ny + ", true, core.doAction); " + + "}", "async": true + }); + } + } + if (actions.length > 0) core.insertAction(actions); + core.doAction(); +} + control.prototype.checkBlock = function () { var x = core.getHeroLoc('x'), y = core.getHeroLoc('y'), loc = x + "," + y; var damage = core.status.checkBlock.damage[loc]; @@ -1139,8 +1159,22 @@ control.prototype.checkBlock = function () { core.updateStatusBar(false, true); } } - this._checkBlock_ambush(core.status.checkBlock.ambush[loc]); - this._checkBlock_repulse(core.status.checkBlock.repulse[loc]); + let actions = []; + + const ambushAction = this._checkBlock_ambush(core.status.checkBlock.ambush[loc]); + if (ambushAction.length > 0) core.push(actions, ambushAction); + + const repulseAction =this._checkBlock_repulse(core.status.checkBlock.repulse[loc]); + if (repulseAction.length > 0) core.push(actions, repulseAction); + + const chaseAction = this._checkBlock_chase(core.status.checkBlock.chase[loc]); + if (chaseAction.length > 0) core.push(actions, chaseAction); + + if (repulseAction.length > 0 || chaseAction.length > 0) core.push(actions, { "type": "waitAsync" }); + if (chaseAction.length > 0) core.push(actions, + { "type": "function", "async": true, "function": "function(){\ncore.battleWithChase();\n}" } + ); + if (actions.length > 0) core.insertAction(actions); } control.prototype._checkBlock_disableQuickShop = function () { @@ -1154,22 +1188,21 @@ control.prototype._checkBlock_disableQuickShop = function () { ////// 阻击 ////// control.prototype._checkBlock_repulse = function (repulse) { - if (!repulse || repulse.length == 0) return; + if (!repulse || repulse.length == 0) return []; var actions = []; repulse.forEach(function (t) { - actions.push({ "type": "move", "loc": [t[0], t[1]], "steps": [t[3]], "time": 250, "keep": true, "async": true }); + actions.push({ "type": "move", "loc": [t[0], t[1]], "steps": [t[3]], "time": 100, "keep": true, "async": true }); }); - actions.push({ "type": "waitAsync" }); - core.insertAction(actions); + return actions; } ////// 捕捉 ////// control.prototype._checkBlock_ambush = function (ambush) { - if (!ambush || ambush.length == 0) return; + if (!ambush || ambush.length == 0) return []; // 捕捉效果 - var actions = []; + let actions = []; ambush.forEach(function (t) { - actions.push({ "type": "move", "loc": [t[0], t[1]], "steps": [t[3]], "time": 250, "keep": false, "async": true }); + actions.push({ "type": "move", "loc": [t[0], t[1]], "steps": [t[3]], "time": 100, "keep": false, "async": true }); }); actions.push({ "type": "waitAsync" }); // 强制战斗 @@ -1180,7 +1213,18 @@ control.prototype._checkBlock_ambush = function (ambush) { "}", "async": true }); }); - core.insertAction(actions); + return actions; +} + +////// 追猎 ////// +control.prototype._checkBlock_chase = function (chase) { + if (!chase || chase.length == 0) return []; + var actions = []; + chase.forEach(function (info) { + const { x, y, dir } = info; + actions.push({ "type": "move", "loc": [x, y], "time": 100, "keep": true, "async": true, "steps": [dir + ":1"] }); + }); + return actions; } ////// 更新全地图显伤 ////// diff --git a/project/functions.js b/project/functions.js index 6a212eb4..bc7238d1 100644 --- a/project/functions.js +++ b/project/functions.js @@ -1270,7 +1270,7 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a = // 计算血网和领域、阻击、激光的伤害,计算捕捉信息 for (var loc in blocks) { - var block = blocks[loc], + const block = blocks[loc], x = block.x, y = block.y, id = block.event.id, @@ -1375,113 +1375,32 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a = } } - // 追猎 - if (enemy && core.hasSpecial(enemy.special, 41)) { - for (var nx = x; nx >= 0; nx++) { - if (nx == x) continue - if (nx >= core.bigmap.width) break; - if (core.noPass(nx, y)) break - var currloc = nx + "," + y; - if (nx != x) { - var dir; - if (nx < x) { - //if (x - nx == 1) continue; - dir = "left"; - } else { - //if (nx - x == 1) continue; - dir = "right"; - } - // 检查下一个点是否存在事件(从而判定是否移动) - var rnx = x + core.utils.scan[dir].x; - var rny = y + core.utils.scan[dir].y; - if (rnx >= 0 && rnx < width && rny >= 0 && rny < height && - (core.getBlock(rnx, rny, floorId) == null || core.getBlockCls(rnx, rny, floorId) == "items")) { - chase[currloc] = (chase[currloc] || []).concat([ - [x, y, id, dir] - ]); - } - } - } - for (var nx = x; nx < width; nx--) { - if (nx == x) continue - if (nx < 0) break; - if (core.noPass(nx, y)) break - var currloc = nx + "," + y; - if (nx != x) { - var dir; - if (nx < x) { - //if (x - nx == 1) continue; - dir = "left"; - } else { - //if (nx - x == 1) continue; - dir = "right"; - } - // 检查下一个点是否存在事件(从而判定是否移动) - var rnx = x + core.utils.scan[dir].x; - var rny = y + core.utils.scan[dir].y; - if (rnx >= 0 && rnx < width && rny >= 0 && rny < height && - (core.getBlock(rnx, rny, floorId) == null || core.getBlockCls(rnx, rny, floorId) == "items")) { - chase[currloc] = (chase[currloc] || []).concat([ - [x, y, id, dir] - ]); - } - } - } - for (var ny = y; ny >= 0; ny++) { - if (ny == y) continue - if (ny >= core.bigmap.width) break; - if (core.noPass(x, ny)) break - //console.log(x, ny) - var currloc = x + "," + ny; - if (ny != y) { - var dir; - if (ny < y) { - //if (y - ny == 1) continue; - dir = "up"; - } else { - //if (ny - y == 1) continue; - dir = "down"; - } - //检查下一个点是否存在事件(从而判定是否移动) - var rnx = x + core.utils.scan[dir].x; - var rny = y + core.utils.scan[dir].y; - if (rnx >= 0 && rnx < width && rny >= 0 && rny < height && - (core.getBlock(rnx, rny, floorId) == null || core.getBlockCls(rnx, rny, floorId) == "items")) { - chase[currloc] = (chase[currloc] || []).concat([ - [x, y, id, dir] - ]); - } - } - } - for (var ny = y; ny < height; ny--) { - if (ny == y) continue - if (ny < 0) break; - if (core.noPass(x, ny)) break; - //console.log(x, ny) - var currloc = x + "," + ny; - if (ny != y) { - var dir; - if (ny < y) { - //if (y - ny == 1) continue; - dir = "up"; - } else { - //if (ny - y == 1) continue; - dir = "down"; - } - //检查下一个点是否存在事件(从而判定是否移动) - var rnx = x + core.utils.scan[dir].x; - var rny = y + core.utils.scan[dir].y; - if (rnx >= 0 && rnx < width && rny >= 0 && rny < height && - (core.getBlock(rnx, rny, floorId) == null || core.getBlockCls(rnx, rny, floorId) == "items")) { - chase[currloc] = (chase[currloc] || []).concat([ - [x, y, id, dir] - ]); - } - } - } - + /** + * 追猎的视野能否通过该格子 + */ + function canSeeThrough(x, y) { + const block = core.getBlock(x, y); + // 空地和道具,敌人(不含普通事件)可被穿过 + if (block === null || + (['items', 'enemys', 'enemy48'].includes(block.event.cls) && !block.event.data)) return true; + return false; } + // 追猎 + if (enemy && core.hasSpecial(enemy.special, 28)) { + let scan = core.utils.scan; + for (const dir in scan) { + for (let i = 1; ; i++) { + const [nx, ny] = [x + i * scan[dir].x, y + i * scan[dir].y]; + const currloc = nx + "," + ny; + if (nx < 0 || nx > core.__SIZE__ - 1 || ny < 0 || ny > core.__SIZE__ - 1) break; + if (!canSeeThrough(nx, ny)) break; + if (i === 1) continue; // 离勇士一格以内的追猎怪不需要移动 + if (!chase[currloc]) chase[currloc] = []; + chase[currloc].push({ x, y, dir }); + } + } + } // 夹击;在这里提前计算所有可能的夹击点,具体计算逻辑在下面 // 如果要防止夹击伤害,可以简单的将 flag:no_betweenAttack 设为true @@ -1504,7 +1423,7 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a = // 对每个可能的夹击点计算夹击伤害 for (var loc in betweenAttackLocs) { - var xy = loc.split(","), + let xy = loc.split(","), x = parseInt(xy[0]), y = parseInt(xy[1]); // 夹击怪物的ID @@ -1565,6 +1484,7 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a = type: type, repulse: repulse, ambush: ambush, + chase: chase, needCache: needCache, cache: {} // clear cache };