JS 脚本: 修复无法加入和好友在忙等情况下会等待超时的问题 (#1116)

This commit is contained in:
ftnfurina
2025-06-16 18:07:47 +08:00
committed by GitHub
parent 04a7d9cbbc
commit bc13dc9958
2 changed files with 16 additions and 13 deletions

View File

@@ -14,26 +14,23 @@ function createTimer(timeout) {
} }
}); });
} }
async function isCoOpMode() {
await genshin.returnMainUi();
const gameRegion = captureGameRegion();
const ocrRegion = gameRegion.find(autoZoomOcr(343, 22, 45, 45));
const ocrText = ocrRegion.text.trim().toLocaleLowerCase();
return ocrText.includes("p") || ocrText !== "";
}
// 等待好友确认超时时间 25s // 等待好友确认超时时间 25s
const WAIT_FRIEND_CONFIRM_TIMEOUT = 25 * 1000; const WAIT_FRIEND_CONFIRM_TIMEOUT = 25 * 1000;
/**
* 是否在多人游戏中
*/
function inMultiplayerGame() {
const gameRegion = captureGameRegion();
const playerCountRegin = gameRegion.find(autoZoomOcr(340, 18, 53, 53));
const playerCountText = playerCountRegin.text.trim().toLocaleLowerCase();
return playerCountText.includes('p');
}
(async () => { (async () => {
try { try {
const uid = settings.uid?.trim(); const uid = settings.uid?.trim();
if (!uid) { if (!uid) {
throw new Error('UID 不能为空'); throw new Error('UID 不能为空');
} }
await genshin.returnMainUi(); if (await isCoOpMode()) {
if (inMultiplayerGame()) {
throw new Error('正在多人游戏中,无法加入好友世界'); throw new Error('正在多人游戏中,无法加入好友世界');
} }
log.info(`尝试加入好友世界(UID: ${uid})`); log.info(`尝试加入好友世界(UID: ${uid})`);
@@ -81,7 +78,13 @@ function inMultiplayerGame() {
if (requestText.endsWith('拒绝了多人游戏申请')) { if (requestText.endsWith('拒绝了多人游戏申请')) {
throw new Error('好友拒绝了多人游戏'); throw new Error('好友拒绝了多人游戏');
} }
if (inMultiplayerGame()) { else if (requestText.startsWith('无法进入')) {
throw new Error('无法进入好友世界');
}
else if (requestText.startsWith('世界主人暂忙')) {
throw new Error('好友正在忙,无法加入');
}
if (await isCoOpMode()) {
log.info('成功加入好友世界'); log.info('成功加入好友世界');
break; break;
} }

View File

@@ -2,7 +2,7 @@
"manifest_version": 1, "manifest_version": 1,
"name": "加入好友的世界", "name": "加入好友的世界",
"description": "快让我访问!", "description": "快让我访问!",
"version": "0.0.2", "version": "0.0.3",
"main": "index.js", "main": "index.js",
"settings_ui": "settings.json", "settings_ui": "settings.json",
"authors": [ "authors": [