From a0bfe339ea529ba5b98e27c580c84943a1ce4ee0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B7=E4=B8=AA=E5=90=8D=E5=AD=97=E5=A5=BD=E9=9A=BE?= =?UTF-8?q?=E7=9A=84=E5=96=B5?= <25520958+MisakaAldrich@users.noreply.github.com> Date: Tue, 29 Jul 2025 22:13:42 +0800 Subject: [PATCH] =?UTF-8?q?JS=E8=84=9A=E6=9C=AC:=20=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E4=BC=90=E6=9C=A8=E8=B7=AF=E5=BE=84=E8=BF=BD=E8=B8=AA=E7=89=88?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E4=BC=AA=E9=80=A0=E6=97=A5=E5=BF=97=EF=BC=8C?= =?UTF-8?q?=E9=A2=84=E8=AE=A1=E7=94=A8=E6=97=B6=20(#1438)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- repo/js/AutoWoodcutting-Pathing/main.js | 105 +++++++++++++++++- repo/js/AutoWoodcutting-Pathing/manifest.json | 2 +- 2 files changed, 100 insertions(+), 7 deletions(-) diff --git a/repo/js/AutoWoodcutting-Pathing/main.js b/repo/js/AutoWoodcutting-Pathing/main.js index d6ef1585..072eccbe 100644 --- a/repo/js/AutoWoodcutting-Pathing/main.js +++ b/repo/js/AutoWoodcutting-Pathing/main.js @@ -82,7 +82,9 @@ if (pathing.fileName.length > 1 && pathing.fileName[0].includes('大循环')) { try { log.info(`正在执行 ${pathingName} 大循环路径`); + await fakeLog(`${pathing.fileName}`, false, true, 0); await pathingScript.runFile(filePath); + await fakeLog(`${pathing.fileName}`, false, false, 0); await sleep(1); log.info(`完成 ${pathingName} 大循环路径, 获得${woodCountToStr(woodCount)}`); woodCount.forEach((value, key) => { woodNumberMap.set(key, woodNumberMap.get(key) - value) }); @@ -108,23 +110,27 @@ } await sleep(1); try { + const currentWoodStartTime = Date.now(); for (let i = 0; i < runTimes; i++) { log.info(`正在执行 ${pathingName} 第 ${i + 1}/${runTimes} 次循环`); for (let k = j; k < pathing.fileName.length; k++) { filePath = filePathPre + pathing.fileName[k] + filePathSuf; + await fakeLog(`${pathing.fileName}`, false, true, 0); await pathingScript.runFile(filePath); + await fakeLog(`${pathing.fileName}`, false, false, 0); await sleep(1); } + const jsTimeTaken = logTimeTaken(startTime); + const estimatedCompletion = calculateEstimatedCompletion(currentWoodStartTime, i + 1, runTimes); log.info(`${pathingName} 第 ${i + 1}/${runTimes} 次循环执行完成`); - logTimeTaken(startTime); + log.info(`${pathingName} 预计完成时间: ${estimatedCompletion}, ${jsTimeTaken}`) } - log.info(`完成 ${pathingName} 循环路径, 获得${woodCountToStr(woodCount, runTimes)}`); - logTimeTaken(startTime); + const jsTimeTaken = logTimeTaken(startTime); + log.info(`完成 ${pathingName} 循环路径, 获得${woodCountToStr(woodCount, runTimes)}, ${jsTimeTaken}`); woodCount.forEach((value, key) => { woodNumberMap.set(key, woodNumberMap.get(key) - value * runTimes); }); - log.info(`${pathingName} 伐木完成,将执行下一个`); - logTimeTaken(startTime); + log.info(`${pathingName} 伐木完成, 将执行下一个`); logRemainingItems(); } catch (error) { log.error(`在砍伐 ${pathingName} 时发生错误: ${error}`); @@ -248,7 +254,94 @@ const minutes = Math.floor(totalTimeInSeconds / 60); const seconds = totalTimeInSeconds % 60; const formattedTime = `${minutes}分${seconds.toFixed(0).padStart(2, '0')}秒`; - log.info(`当前运行总时长:${formattedTime}`); + return `当前运行总时长: ${formattedTime}`; + } + + function calculateEstimatedCompletion(startTime, current, total) { + if (current === 0) return "计算中..."; + const elapsedTime = Date.now() - startTime; + const timePerTask = elapsedTime / current; + const remainingTasks = total - current; + const remainingTime = timePerTask * remainingTasks; + const completionDate = new Date(Date.now() + remainingTime); + return `${completionDate.toLocaleTimeString()}, 约 ${Math.round(remainingTime / 60000)} 分钟`; + } + + async function fakeLog(name, isJs, isStart, duration) { + await sleep(10); + const currentTime = Date.now(); + // 参数检查 + if (typeof name !== 'string') { + log.error("参数 'name' 必须是字符串类型!"); + return; + } + if (typeof isJs !== 'boolean') { + log.error("参数 'isJs' 必须是布尔型!"); + return; + } + if (typeof isStart !== 'boolean') { + log.error("参数 'isStart' 必须是布尔型!"); + return; + } + if (typeof currentTime !== 'number' || !Number.isInteger(currentTime)) { + log.error("参数 'currentTime' 必须是整数!"); + return; + } + if (typeof duration !== 'number' || !Number.isInteger(duration)) { + log.error("参数 'duration' 必须是整数!"); + return; + } + + // 将 currentTime 转换为 Date 对象并格式化为 HH:mm:ss.sss + const date = new Date(currentTime); + const hours = String(date.getHours()).padStart(2, '0'); + const minutes = String(date.getMinutes()).padStart(2, '0'); + const seconds = String(date.getSeconds()).padStart(2, '0'); + const milliseconds = String(date.getMilliseconds()).padStart(3, '0'); + const formattedTime = `${hours}:${minutes}:${seconds}.${milliseconds}`; + + // 将 duration 转换为分钟和秒,并保留三位小数 + const durationInSeconds = duration / 1000; // 转换为秒 + const durationMinutes = Math.floor(durationInSeconds / 60); + const durationSeconds = (durationInSeconds % 60).toFixed(3); // 保留三位小数 + + // 使用四个独立的 if 语句处理四种情况 + if (isJs && isStart) { + // 处理 isJs = true 且 isStart = true 的情况 + const logMessage = `正在伪造js开始的日志记录\n\n` + + `[${formattedTime}] [INF] BetterGenshinImpact.Service.ScriptService\n` + + `------------------------------\n\n` + + `[${formattedTime}] [INF] BetterGenshinImpact.Service.ScriptService\n` + + `→ 开始执行JS脚本: "${name}"`; + log.debug(logMessage); + } + if (isJs && !isStart) { + // 处理 isJs = true 且 isStart = false 的情况 + const logMessage = `正在伪造js结束的日志记录\n\n` + + `[${formattedTime}] [INF] BetterGenshinImpact.Service.ScriptService\n` + + `→ 脚本执行结束: "${name}", 耗时: ${durationMinutes}分${durationSeconds}秒\n\n` + + `[${formattedTime}] [INF] BetterGenshinImpact.Service.ScriptService\n` + + `------------------------------`; + log.debug(logMessage); + } + if (!isJs && isStart) { + // 处理 isJs = false 且 isStart = true 的情况 + const logMessage = `正在伪造地图追踪开始的日志记录\n\n` + + `[${formattedTime}] [INF] BetterGenshinImpact.Service.ScriptService\n` + + `------------------------------\n\n` + + `[${formattedTime}] [INF] BetterGenshinImpact.Service.ScriptService\n` + + `→ 开始执行地图追踪任务: "${name}"`; + log.debug(logMessage); + } + if (!isJs && !isStart) { + // 处理 isJs = false 且 isStart = false 的情况 + const logMessage = `正在伪造地图追踪结束的日志记录\n\n` + + `[${formattedTime}] [INF] BetterGenshinImpact.Service.ScriptService\n` + + `→ 脚本执行结束: "${name}", 耗时: ${durationMinutes}分${durationSeconds}秒\n\n` + + `[${formattedTime}] [INF] BetterGenshinImpact.Service.ScriptService\n` + + `------------------------------`; + log.debug(logMessage); + } } // Set game environment settings diff --git a/repo/js/AutoWoodcutting-Pathing/manifest.json b/repo/js/AutoWoodcutting-Pathing/manifest.json index 5c1c5f81..af6ab0f2 100644 --- a/repo/js/AutoWoodcutting-Pathing/manifest.json +++ b/repo/js/AutoWoodcutting-Pathing/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 1, "name": "自动伐木-地图追踪版", - "version": "1.1.0", + "version": "1.1.2", "description": "基于地图追踪的自动伐木,已支持5.7版本前的全部木材\n默认砍伐全部支持木材至2000上限\n自定义设置:\n-可更改砍伐木材种类和数量\n-可以单独设置每个木材数量\n-可设置队伍中是否包含一斗,按保底20%,计算砍伐数量时会除以1.2", "tags": [ "伐木",