解决偶发性“登陆其他账号”识别不到问题 (#2239)

* Update README.md

* Update main.js

解决循环无法跳出

* Update README.md

增加更新记录

* Update README.md

* Update manifest.json

* 解决偶发性识别不到“登陆其他账号”的问题

* Add files via upload

---------

Co-authored-by: 起个名字好难 <25520958+MisakaAldrich@users.noreply.github.com>
This commit is contained in:
彩虹QQ人
2025-10-25 11:52:34 +08:00
committed by GitHub
parent 0721e9fcb4
commit 6f5f4ad7ac
2 changed files with 37 additions and 12 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

View File

@@ -18,7 +18,7 @@ const out_account = {
name: "out_account.png"
};
const login_other_account = {
template:RecognitionObject.TemplateMatch(file.ReadImageMatSync("assets/login_other_account.png")),
template:RecognitionObject.TemplateMatch(file.ReadImageMatSync("assets/login_other_account_1.png")),
name: "login_other_account.png"
};
const input_phone_or_email = {
@@ -53,6 +53,7 @@ async function matchImgAndClick(obj, desc, timeout = 8000) {
let status = false; // 用于记录是否匹配成功
try {
while (Date.now() - start < timeout && !status) {
await sleep(300);
let result = captureGameRegion().Find(obj.template);
await sleep(500); // 短暂延迟,避免过快循环
if (result.isExist()) {
@@ -61,7 +62,7 @@ async function matchImgAndClick(obj, desc, timeout = 8000) {
status = true; // 设置匹配成功状态
return {success: true, x: clickResult.x, y: clickResult.y};
}
await sleep(200); // 短暂延迟,避免过快循环
// await sleep(200); // 短暂延迟,避免过快循环
log.info(`【IMG】第${retryCount++}次识别并点击 ${desc} 失败 | 耗时: ${Date.now() - start}ms`);
}
} catch (error) {
@@ -107,10 +108,21 @@ async function recognizeTextAndClick(targetText, ocrRegion, timeout = 8000) {
setGameMetrics(1920, 1080, 1);
// 如果切换账号是第一个脚本,则有可能出现月卡选项
await genshin.blessingOfTheWelkinMoon();
await sleep(1000);
await genshin.blessingOfTheWelkinMoon();
await sleep(1000);
//防止genshin.blessingOfTheWelkinMoon();方法失效,先使用物理点击。
try {
keyDown("VK_MENU");
await sleep(500);
for(let i = 0; i<=4; i++){
await click(genshin.width / 2.0, genshin.height * 0.8);
await sleep(1000);
}
}finally {
keyUp("VK_MENU");
}
//await genshin.blessingOfTheWelkinMoon();
//await sleep(1000);
//await genshin.blessingOfTheWelkinMoon();
//await sleep(1000);
await genshin.returnMainUi();
await keyPress("VK_ESCAPE");
@@ -151,20 +163,33 @@ async function recognizeTextAndClick(targetText, ocrRegion, timeout = 8000) {
*/
await sleep(8000);
await recognizeTextAndClick("点击进入", RecognitionObject.Ocr(862, 966, 206, 104), 960, 540, 5000);
await sleep(12000);
await sleep(15000);
//可能登录账号的时候出现月卡提醒,则先点击一次月卡。
await genshin.blessingOfTheWelkinMoon();
await sleep(1000);
await genshin.blessingOfTheWelkinMoon();
//await genshin.blessingOfTheWelkinMoon();
//await sleep(1000);
//await genshin.blessingOfTheWelkinMoon();
//await sleep(1000);
//防止genshin.blessingOfTheWelkinMoon();方法失效,先使用物理点击。
await sleep(2000);
keyDown("VK_MENU");
await sleep(500);
for(let i = 0; i<=4; i++){
await click(genshin.width / 2.0, genshin.height * 0.8);
await sleep(1000);
}
//keyUp("VK_MENU");
await genshin.returnMainUi();
await sleep(1000);
// 如果配置了通知
notification.send("【UID" + settings.UID + "】切换成功");
notification.send("账号【" + settings.UID + "】切换成功");
}catch (error) {
log.error(`${script_name}脚本执行过程中发生错误:${error.message}`);
//如果发生错误,则发送通知
notification.error(`${script_name}脚本执行过程中发生错误:${error.message}`);
throw new Error(`${script_name}脚本执行过程中发生错误:${error.message}`);
}finally {
keyUp("VK_MENU");
}
})();
})();