From 2bcb120670d9b5d4fe3b2036e923e42835fa705a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=89=E5=90=89=E5=96=B5?= Date: Mon, 20 Oct 2025 22:30:03 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=A8=A1=E5=9D=97=E4=B8=8D?= =?UTF-8?q?=E9=80=82=E9=85=8D=E7=9A=84bug=20(#2195)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 其他模块适配 --- repo/js/背包材料统计/lib/backStats.js | 46 +--------------- repo/js/背包材料统计/lib/region.js | 76 --------------------------- 2 files changed, 1 insertion(+), 121 deletions(-) diff --git a/repo/js/背包材料统计/lib/backStats.js b/repo/js/背包材料统计/lib/backStats.js index 76320e18c..d60db7a51 100644 --- a/repo/js/背包材料统计/lib/backStats.js +++ b/repo/js/背包材料统计/lib/backStats.js @@ -3,8 +3,6 @@ eval(file.readTextSync("lib/region.js")); const holdX = Math.min(1920, Math.max(0, Math.floor(Number(settings.HoldX) || 1050))); const holdY = Math.min(1080, Math.max(0, Math.floor(Number(settings.HoldY) || 750))); const totalPageDistance = Math.max(10, Math.floor(Number(settings.PageScrollDistance) || 711)); -const targetCount = Math.min(9999, Math.max(0, Math.floor(Number(settings.TargetCount) || 5000))); // 设定的目标数量 -const exceedCount = Math.min(9999, Math.max(0, Math.floor(Number(settings.ExceedCount) || 5000))); // 设定的超量目标数量 const imageDelay = Math.min(1000, Math.max(0, Math.floor(Number(settings.ImageDelay) || 0))); // 识图基准时长 await sleep(imageDelay); // 配置参数 @@ -58,7 +56,7 @@ const materialPriority = { // log.info(`材料分类: ${materialsCategory}, 菜单偏移值: ${menuOffset}, 计算出的点击 X 坐标: ${menuClickX}`); // OCR识别文本 -async function recognizeText(ocrRegion, timeout = 1000, retryInterval = 20, maxAttempts = 10, maxFailures = 3, ra = null) { +async function recognizeText(ocrRegion, timeout = 100, retryInterval = 20, maxAttempts = 10, maxFailures = 3, ra = null) { let startTime = Date.now(); let retryCount = 0; let failureCount = 0; // 用于记录连续失败的次数 @@ -509,48 +507,6 @@ const MaterialsRo = RecognitionObject.TemplateMatch(file.ReadImageMatSync("asset const CultivationItemsRo = RecognitionObject.TemplateMatch(file.ReadImageMatSync("assets/CultivationItems.png"), 749, 30, 38, 38); const FoodRo = RecognitionObject.TemplateMatch(file.ReadImageMatSync("assets/Food.png"), 845, 31, 38, 38); -const specialMaterials = [ - "水晶块", "魔晶块", "星银矿石", "紫晶块", "萃凝晶", "虹滴晶", "铁块", "白铁块", - "精锻用魔矿", "精锻用良矿", "精锻用杂矿" -]; -var excessMaterialNames = []; // 超量材料名单 - -function filterLowCountMaterials(pathingMaterialCounts, materialCategoryMap) { - // 新增:超量阈值(普通材料9999,矿石处理后也是9999) - const EXCESS_THRESHOLD = exceedCount; - // 新增:临时存储本次超量材料 - const tempExcess = []; - - // 原逻辑:提取所有需要扫描的材料 - const allMaterials = Object.values(materialCategoryMap).flat(); - - const filteredMaterials = pathingMaterialCounts - .filter(item => - allMaterials.includes(item.name) && - (item.count < targetCount || item.count === "?") - ) - .map(item => { - // 原逻辑:矿石数量÷10 - let processedCount = item.count; - if (specialMaterials.includes(item.name) && item.count !== "?") { - processedCount = Math.floor(Number(item.count) / 10); - } - - // 新增:判断是否超量(用处理后数量对比阈值) - if (item.count !== "?" && processedCount >= EXCESS_THRESHOLD) { - tempExcess.push(item.name); // 记录超量材料名 - } - - return { ...item, count: processedCount }; - }); - - tempExcess.push("OCR启动"); // 新增:添加特殊标记,用于终止OCR等待 - // 新增:更新全局超量名单(去重) - excessMaterialNames = [...new Set(tempExcess)]; - log.info(`【超量材料更新】共${excessMaterialNames.length}种:${excessMaterialNames.join("、")}`); - - return filteredMaterials; // 原返回值不变 -} function dynamicMaterialGrouping(materialCategoryMap) { // 初始化动态分组对象 diff --git a/repo/js/背包材料统计/lib/region.js b/repo/js/背包材料统计/lib/region.js index 9d4a6d4f1..dd5461684 100644 --- a/repo/js/背包材料统计/lib/region.js +++ b/repo/js/背包材料统计/lib/region.js @@ -73,79 +73,3 @@ async function recognizeImage( usedNewScreenshot: useNewScreenshot }; } - -// 定义一个异步函数来绘制红框并延时清除 -async function drawAndClearRedBox(searchRegion, ra, delay = 500) { - let drawRegion = null; - try { - // 创建绘制区域 - drawRegion = ra.DeriveCrop( - searchRegion.x, searchRegion.y, - searchRegion.width, searchRegion.height - ); - drawRegion.DrawSelf("icon"); // 绘制红框 - - // 等待指定时间 - await sleep(delay); - - // 清除红框 - 使用更可靠的方式 - if (drawRegion && typeof drawRegion.DrawSelf === 'function') { - // 可能需要使用透明绘制来清除,或者绘制一个0大小的区域 - ra.DeriveCrop(0, 0, 0, 0).DrawSelf("icon"); - } - } catch (e) { - log.error("红框绘制异常:" + e.message); - } finally { - // 正确释放资源,如果dispose方法存在的话 - if (drawRegion && typeof drawRegion.dispose === 'function') { - drawRegion.dispose(); - } - } -} - -// 截图保存函数 -function imageSaver(mat, saveFile) { - // 获取当前时间并格式化为 "YYYY-MM-DD_HH-MM-SS" - const now = new Date(); - const timestamp = `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, '0')}-${String(now.getDate()).padStart(2, '0')}_${String(now.getHours()).padStart(2, '0')}-${String(now.getMinutes()).padStart(2, '0')}-${String(now.getSeconds()).padStart(2, '0')}`; - - // 获取当前脚本所在的目录 - const scriptDir = getScriptDirPath(); - if (!scriptDir) { - log.error("无法获取脚本目录"); - return; - } - - // 构建完整的目标目录路径和文件名 - const savePath = `${scriptDir}/${saveFile}/screenshot_${timestamp}.png`; - const tempFilePath = `${scriptDir}/${saveFile}`; - - // 检查临时文件是否存在,如果不存在则创建目录 - try { - // 尝试读取临时文件 - file.readPathSync(tempFilePath); - log.info("目录存在,继续执行保存图像操作"); - } catch (error) { - log.error(`确保目录存在时出错: ${error}`); - return; - } - - // 保存图像 - try { - mat.saveImage(savePath); - // log.info(`图像已成功保存到: ${savePath}`); - } catch (error) { - log.error(`保存图像失败: ${error}`); - } -} - -// 获取脚本目录 -function getScriptDirPath() { - try { - file.readTextSync(`temp-${Math.random()}.txt`); - } catch (e) { - const match = e.toString().match(/'([^']+)'/); - return match ? match[1].replace(/\\[^\\]+$/, "") : null; - } - return null; -} \ No newline at end of file