diff --git a/repo/js/JoinFriendsWorld/index.js b/repo/js/JoinFriendsWorld/index.js index 52d7f6b1..e459f253 100644 --- a/repo/js/JoinFriendsWorld/index.js +++ b/repo/js/JoinFriendsWorld/index.js @@ -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 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 () => { try { const uid = settings.uid?.trim(); if (!uid) { throw new Error('UID 不能为空'); } - await genshin.returnMainUi(); - if (inMultiplayerGame()) { + if (await isCoOpMode()) { throw new Error('正在多人游戏中,无法加入好友世界'); } log.info(`尝试加入好友世界(UID: ${uid})`); @@ -81,7 +78,13 @@ function inMultiplayerGame() { if (requestText.endsWith('拒绝了多人游戏申请')) { throw new Error('好友拒绝了多人游戏'); } - if (inMultiplayerGame()) { + else if (requestText.startsWith('无法进入')) { + throw new Error('无法进入好友世界'); + } + else if (requestText.startsWith('世界主人暂忙')) { + throw new Error('好友正在忙,无法加入'); + } + if (await isCoOpMode()) { log.info('成功加入好友世界'); break; } diff --git a/repo/js/JoinFriendsWorld/manifest.json b/repo/js/JoinFriendsWorld/manifest.json index 9b3ee2d9..6d75b0ed 100644 --- a/repo/js/JoinFriendsWorld/manifest.json +++ b/repo/js/JoinFriendsWorld/manifest.json @@ -2,7 +2,7 @@ "manifest_version": 1, "name": "加入好友的世界", "description": "快让我访问!", - "version": "0.0.2", + "version": "0.0.3", "main": "index.js", "settings_ui": "settings.json", "authors": [