@@ -25,15 +25,10 @@ async function scrollPage(totalDistance, stepDistance = 10, delayMs = 5) {
|
||||
[460, 538],
|
||||
[792, 538],
|
||||
[1130, 538],
|
||||
[1462, 538]
|
||||
[1462, 538],
|
||||
];
|
||||
|
||||
const positionSettings = [
|
||||
settings.position1,
|
||||
settings.position2,
|
||||
settings.position3,
|
||||
settings.position4
|
||||
];
|
||||
const positionSettings = [settings.position1, settings.position2, settings.position3, settings.position4];
|
||||
|
||||
// 识别对象定义
|
||||
const roTeamConfig = RecognitionObject.TemplateMatch(file.ReadImageMatSync(`Assets/RecognitionObject/队伍配置.png`), 0, 0, 1920, 1080);
|
||||
@@ -43,6 +38,13 @@ async function scrollPage(totalDistance, stepDistance = 10, delayMs = 5) {
|
||||
let openPairingTries = 0;
|
||||
let totalOpenPairingTries = 0;
|
||||
|
||||
// 在进入角色切换逻辑前进行检测,如果所有角色设置均为空则直接退出
|
||||
if (positionSettings.every((item) => !item || item.trim() === "")) {
|
||||
log.info("未设置任何角色,跳过切换队伍步骤");
|
||||
await genshin.returnMainUi();
|
||||
return;
|
||||
}
|
||||
|
||||
async function openPairingInterface() {
|
||||
while (openPairingTries < 3) {
|
||||
keyPress("l");
|
||||
@@ -60,26 +62,28 @@ async function scrollPage(totalDistance, stepDistance = 10, delayMs = 5) {
|
||||
openPairingTries = 0;
|
||||
return openPairingInterface();
|
||||
} else {
|
||||
log.error('无法打开配对界面,任务结束');
|
||||
log.error("无法打开配对界面,任务结束");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!await openPairingInterface()) {
|
||||
if (!(await openPairingInterface())) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 角色切换逻辑
|
||||
for (let i = 0; i < positionSettings.length; i++) {
|
||||
let rolenum = i+1;
|
||||
let rolenum = i + 1;
|
||||
const selectedCharacter = positionSettings[i];
|
||||
if (selectedCharacter === "") {
|
||||
log.info(`未设置${rolenum}号位角色,跳过`);
|
||||
if (!selectedCharacter || selectedCharacter.trim() === "") {
|
||||
log.info(`未设置${rolenum}号位角色,跳过`);
|
||||
continue;
|
||||
}
|
||||
const [x, y] = positionCoordinates[i];
|
||||
click(x, y);
|
||||
log.info(`开始设置${rolenum}号位角色`);
|
||||
await sleep(1000);
|
||||
|
||||
await sleep(1000);
|
||||
|
||||
let characterFound = false;
|
||||
let pageTries = 0;
|
||||
@@ -88,12 +92,15 @@ async function scrollPage(totalDistance, stepDistance = 10, delayMs = 5) {
|
||||
while (pageTries < 20) {
|
||||
// 尝试识别所有可能的角色文件名
|
||||
for (let num = 1; ; num++) {
|
||||
const paddedNum = num.toString().padStart(2, '0');
|
||||
const paddedNum = num.toString().padStart(2, "0");
|
||||
const characterFileName = `${selectedCharacter}${paddedNum}`;
|
||||
try {
|
||||
const characterRo = RecognitionObject.TemplateMatch(
|
||||
file.ReadImageMatSync(`Assets/characterimage/${characterFileName}.png`),
|
||||
0, 0, 1920, 1080
|
||||
file.ReadImageMatSync(`Assets/characterimage/${characterFileName}.png`),
|
||||
0,
|
||||
0,
|
||||
1920,
|
||||
1080
|
||||
);
|
||||
const characterResult = captureGameRegion().find(characterRo);
|
||||
if (characterResult.isExist()) {
|
||||
@@ -101,11 +108,11 @@ async function scrollPage(totalDistance, stepDistance = 10, delayMs = 5) {
|
||||
// 计算向右偏移70像素、向下偏移70像素的位置
|
||||
const targetX = characterResult.x + 35;
|
||||
const targetY = characterResult.y + 35;
|
||||
|
||||
|
||||
// 边界检查,确保坐标在屏幕范围内
|
||||
const safeX = Math.min(Math.max(targetX, 0), 1920);
|
||||
const safeY = Math.min(Math.max(targetY, 0), 1080);
|
||||
|
||||
|
||||
click(safeX, safeY);
|
||||
await sleep(500); // 点击角色后等待0.5秒
|
||||
characterFound = true;
|
||||
@@ -120,7 +127,7 @@ async function scrollPage(totalDistance, stepDistance = 10, delayMs = 5) {
|
||||
if (characterFound) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
// 如果不是最后一次尝试,尝试滚动页面
|
||||
if (pageTries < 15) {
|
||||
log.info("当前页面没有目标角色,滚动页面");
|
||||
@@ -128,7 +135,7 @@ async function scrollPage(totalDistance, stepDistance = 10, delayMs = 5) {
|
||||
}
|
||||
pageTries++;
|
||||
}
|
||||
|
||||
|
||||
if (!characterFound) {
|
||||
log.error(`未找到【${selectedCharacter}】`);
|
||||
continue;
|
||||
@@ -137,18 +144,18 @@ async function scrollPage(totalDistance, stepDistance = 10, delayMs = 5) {
|
||||
// 识别"更换"或"加入"按钮
|
||||
const replaceResult = captureGameRegion().find(roReplace);
|
||||
const joinResult = captureGameRegion().find(roJoin);
|
||||
|
||||
|
||||
if (replaceResult.isExist() || joinResult.isExist()) {
|
||||
await sleep(300);
|
||||
await sleep(300);
|
||||
click(68, 1020);
|
||||
keyPress("VK_LBUTTON");
|
||||
await sleep(500);
|
||||
await sleep(500);
|
||||
} else {
|
||||
log.error(`该角色已在队伍中,无需切换`);
|
||||
}
|
||||
await sleep(500);
|
||||
await sleep(500);
|
||||
}
|
||||
|
||||
// 返回主界面
|
||||
await genshin.returnMainUi();
|
||||
})();
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user