diff --git a/repo/js/AutoLeyLineOutcrop/utils/attemptReward.js b/repo/js/AutoLeyLineOutcrop/utils/attemptReward.js index 423c548f..ba4059a1 100644 --- a/repo/js/AutoLeyLineOutcrop/utils/attemptReward.js +++ b/repo/js/AutoLeyLineOutcrop/utils/attemptReward.js @@ -1,3 +1,40 @@ +/** + * 带验证的单击函数 + * @param {number} x - X坐标 + * @param {number} y - Y坐标 + * @param {string} targetText - 需要验证消失的目标文字 + * @param {number} maxRetries - 最大重试次数,默认为10 + * @returns {Promise} 是否成功 + */ +this.clickWithVerification = async function(x, y, targetText, maxRetries = 20) { + for (let i = 0; i < maxRetries; i++) { + click(x, y); + await sleep(400); + + // 验证目标文字是否消失 + let resList = captureGameRegion().findMulti(ocrRoThis); + let textFound = false; + + if (resList && resList.count > 0) { + for (let j = 0; j < resList.count; j++) { + if (resList[j].text.includes(targetText)) { + textFound = true; + break; + } + } + } + + // 如果文字消失了,说明点击成功 + if (!textFound) { + return true; + } + + } + + log.warn(`经过${maxRetries}次点击,文字"${targetText}"仍未消失`); + return false; +} + /** * 尝试领取地脉花奖励 * @returns {Promise} @@ -41,18 +78,28 @@ async function () { isValid = true; dobuleReward = true; } - } - - // 处理不同的树脂情况 + } // 处理不同的树脂情况 if (originalResin && dobuleReward == true) { log.info("选择使用原粹树脂,获得双倍产出"); - click(Math.round(originalResin.x + originalResin.width / 2), Math.round(originalResin.y + originalResin.height / 2)); + await clickWithVerification( + Math.round(originalResin.x + originalResin.width / 2), + Math.round(originalResin.y + originalResin.height / 2), + "树脂" + ); } else if (condensedResin) { log.info("选择使用浓缩树脂"); - click(Math.round(condensedResin.x + condensedResin.width / 2), Math.round(condensedResin.y + condensedResin.height / 2)); + await clickWithVerification( + Math.round(condensedResin.x + condensedResin.width / 2), + Math.round(condensedResin.y + condensedResin.height / 2), + "树脂" + ); } else if (originalResin) { log.info("选择使用原粹树脂"); - click(Math.round(originalResin.x + originalResin.width / 2), Math.round(originalResin.y + originalResin.height / 2)); + await clickWithVerification( + Math.round(originalResin.x + originalResin.width / 2), + Math.round(originalResin.y + originalResin.height / 2), + "树脂" + ); } else if (isResinEmpty) { log.error("识别到补充原粹树脂,看来树脂用完了呢"); keyPress("VK_ESCAPE");