Files
bettergi-scripts-list/js/提瓦特百货商店/main.js
小鹰划船不用桨 4c2e1157a4 JS脚本:提瓦特百货商店(新建) (#1031)
* feature: 更新第一版提瓦特商店,在OCR买菜基础上进行大规模重构,补充了蒙德,璃月和稻妻的商人,增加了时间重试机制,增加了售罄检测

* Update repo/js/提瓦特百货商店/assets/Pathing/蒙德杂货商人-布兰琪.json

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update repo/js/提瓦特百货商店/assets/Pathing/璃月万民堂老板-卯师傅.json

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* feature: 更新第一版提瓦特商店,在OCR买菜基础上进行大规模重构,补充了蒙德,璃月和稻妻的商人,增加了时间重试机制,增加了售罄检测

---------

Co-authored-by: 秋云 <physligl@gmail.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-06-23 20:38:02 +08:00

101 lines
4.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 检查 F 图标和右边水平对齐的文字
async function checkNpcAndFAlignment(npcName, fDialogueRo) {
try {
let ra = captureGameRegion();
let fRes = ra.find(fDialogueRo);
if (!fRes.isExist()) {
let f_attempts = 0; // 初始化为0而不是null
while (f_attempts < 5) {
f_attempts++;
log.info(`当前尝试次数:${f_attempts}`);
if (f_attempts <= 3) {
await keyMouseScript.runFile(`assets/滚轮下翻.json`);
await sleep(1000);
} else if (f_attempts === 4) {
log.warn("尝试调整游戏时间");
// 先调整到8点
await setGameTime(8);
await sleep(2000);
// 8点时进行3次滚轮下滑和NPC检测
log.info("8点时执行滚轮下滑和NPC检测循环");
for (let i = 0; i < 3; i++) {
await keyMouseScript.runFile(`assets/滚轮下翻.json`);
await sleep(1000);
// 检查F图标和NPC是否对齐
if (await checkAlignment()) {
log.info(`在8点第${i + 1}次滚动后找到对齐的NPC: ${npcName}`);
return true;
}
}
// 如果8点没找到调整到18点
await setGameTime(18);
await sleep(2000);
// 18点时进行3次滚轮下滑和NPC检测
log.info("18点时执行滚轮下滑和NPC检测循环");
for (let i = 0; i < 3; i++) {
await keyMouseScript.runFile(`assets/滚轮下翻.json`);
await sleep(1000);
// 检查F图标和NPC是否对齐
if (await checkAlignment()) {
log.info(`在18点第${i + 1}次滚动后找到对齐的NPC: ${npcName}`);
return true;
}
}
// 如果都没找到,重新加载路径文件
log.info("重新加载路径文件");
await pathingScript.runFile(filePath);
await sleep(500);
} else {
log.warn("尝试次数已达上限");
break;
}
fRes = ra.find(fDialogueRo);
if (fRes.isExist()) {
log.info("找到 F 图标");
// 找到F图标后立即检查对齐情况
if (await checkAlignment()) {
return true;
}
}
log.warn(`尝试 ${f_attempts}:寻找 F 图标`);
}
if (!fRes.isExist()) {
log.warn("经过多次尝试后仍未找到 F 图标");
return false;
}
}
// 如果已经找到F图标检查对齐情况
return await checkAlignment();
} catch (err) {
log.warn(`检查NPC和F对齐失败: ${err}`);
return false;
}
// 内部函数检查F图标和NPC是否对齐
async function checkAlignment() {
let ra = captureGameRegion();
let fRes = ra.find(fDialogueRo);
if (!fRes.isExist()) return false;
let centerYF = fRes.y + fRes.height / 2;
let ocrResult = await performOcr(npcName, npcxRange, { min: fRes.y, max: fRes.y + fRes.height }, tolerance);
if (!ocrResult.success) {
return false;
}
let centerYnpcName = ocrResult.y + ocrResult.height / 2;
let isAligned = Math.abs(centerYnpcName - centerYF) <= npctolerance;
if (isAligned) {
log.info(`NPC '${npcName}' 和 F 图标水平对齐NPC: ${centerYnpcName}, F 图标: ${centerYF}`);
}
return isAligned;
}
}