From fe83c500c5129757e79c72931bd15b5295261bc6 Mon Sep 17 00:00:00 2001 From: yan Date: Sun, 18 Jan 2026 14:14:27 +0800 Subject: [PATCH] =?UTF-8?q?refactor(FullyAutoAndSemiAutoTools):=20?= =?UTF-8?q?=E9=87=8D=E6=9E=84=E9=98=9F=E4=BC=8D=E5=88=87=E6=8D=A2=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 提取队伍切换功能到独立的 switchTeamByIndex 函数中 - 添加详细的 JSDoc 注释说明函数用途和参数 - 简化主流程中的条件判断逻辑 - 将原有的队伍切换代码替换为函数调用 - 保留原有功能的同时提高代码可读性和维护性 - 为特定路径"有草神"添加专门的处理逻辑 --- repo/js/FullyAutoAndSemiAutoTools/main.js | 66 +++++++++++++++++------ 1 file changed, 50 insertions(+), 16 deletions(-) diff --git a/repo/js/FullyAutoAndSemiAutoTools/main.js b/repo/js/FullyAutoAndSemiAutoTools/main.js index e7d6521bc..41905a802 100644 --- a/repo/js/FullyAutoAndSemiAutoTools/main.js +++ b/repo/js/FullyAutoAndSemiAutoTools/main.js @@ -1383,7 +1383,35 @@ async function runPath(path) { } catch (error) { log.error("检查战斗需求失败: {error}", error.message); } - //切换队伍 + +/** + * 根据索引切换队伍 + * @param {number} index - 要切换的队伍在SevenElements数组中的索引 + * @returns {Promise} + */ + async function switchTeamByIndex(index) { + // 获取指定索引的队伍名称,如果索引超出范围或小于0则返回undefined + const teamName = team.SevenElements.length > index && index >= 0 ? team.SevenElements[index] : undefined; + // 检查队伍名称是否有效 + if (!teamName || teamName === "") { + // 如果没有设置队伍,记录调试日志并跳过切换 + log.debug(`[{mode}] 没有设置队伍: {teamName},跳过切换`, settings.mode, teamName); + } else if (team.current === teamName) { + // 如果当前已经是目标队伍,记录调试日志并跳过切换 + log.debug(`[{mode}] 当前队伍为: {teamName},无需切换`, settings.mode, teamName); + } else { + // 如果需要切换队伍,记录信息日志 + log.info(`[{mode}] 检测到需要: {key},切换至{val}`, settings.mode, key, teamName); + // 调用切换队伍的工具函数 + const teamSwitch = await switchUtil.SwitchPartyMain(teamName); + // 如果切换成功,更新当前队伍 + if (teamSwitch) { + team.current = teamSwitch; + } + } + } + +//切换队伍 if (team.fight) { if (!team.fightName) { log.error(`[{mode}] 路径需要配置好战斗策略: {path}`, settings.mode, path) @@ -1395,27 +1423,33 @@ async function runPath(path) { team.current = teamSwitch; } } - } else { + } + else if(path.includes("有草神")){ + const idx = SevenElement.SevenElements.indexOf('草'); + await switchTeamByIndex(idx); + } + else { const entry = [...SevenElement.SevenElementsMap.entries()].find(([key, val]) => { return val.some(item => path.includes(`\\${item}\\`)); }); if (entry) { const [key, val] = entry; const index = SevenElement.SevenElements.indexOf(key); - const teamName = team.SevenElements.length > index && index >= 0 ? - team.SevenElements[index] : undefined; - - if (!teamName || teamName === "") { - log.debug(`[{mode}] 没有设置队伍: {teamName},跳过切换`, settings.mode, teamName); - } else if (team.current === teamName) { - log.debug(`[{mode}] 当前队伍为: {teamName},无需切换`, settings.mode, teamName); - } else { - log.info(`[{mode}] 检测到需要: {key},切换至{val}`, settings.mode, key, teamName); - const teamSwitch = await switchUtil.SwitchPartyMain(teamName); - if (teamSwitch) { - team.current = teamSwitch; - } - } + await switchTeamByIndex(index); + // const teamName = team.SevenElements.length > index && index >= 0 ? + // team.SevenElements[index] : undefined; + // + // if (!teamName || teamName === "") { + // log.debug(`[{mode}] 没有设置队伍: {teamName},跳过切换`, settings.mode, teamName); + // } else if (team.current === teamName) { + // log.debug(`[{mode}] 当前队伍为: {teamName},无需切换`, settings.mode, teamName); + // } else { + // log.info(`[{mode}] 检测到需要: {key},切换至{val}`, settings.mode, key, teamName); + // const teamSwitch = await switchUtil.SwitchPartyMain(teamName); + // if (teamSwitch) { + // team.current = teamSwitch; + // } + // } } else if (team.current !== team.fightName) { const teamSwitch = await switchUtil.SwitchPartyMain(team.fightName); if (teamSwitch) {