j s 脚本:七圣召唤一条龙更新 (#617)
* Update main.js 添加检查是否挑战过的功能,以及识图追踪功能 * Update manifest.json
This commit is contained in:
@@ -1,5 +1,75 @@
|
|||||||
(async function () {
|
(async function () {
|
||||||
|
|
||||||
|
// 定义识别对象 - 玩家卡片图片
|
||||||
|
const cardPlayerRo = RecognitionObject.TemplateMatch( file.ReadImageMatSync("assets/cardPlayer.png"));
|
||||||
|
/**
|
||||||
|
* 检测指定点位是否有玩家卡片,发现后调用对应的函数
|
||||||
|
* @returns {Promise<boolean>} 是否找到并处理了卡片
|
||||||
|
*/
|
||||||
|
const detectCardPlayer = async () => {
|
||||||
|
// 定义要检测的6个点位及对应的处理函数
|
||||||
|
let i =0;
|
||||||
|
const checkPoints = [
|
||||||
|
{ x: 640, y: 750, action: async () => await gotoTable1() }, // 点位1
|
||||||
|
{ x: 810, y: 790, action: async () => await gotoTable2() }, // 点位2
|
||||||
|
{ x: 810, y: 600, action: async () => await gotoTable3() }, // 点位3
|
||||||
|
{ x: 610, y: 360, action: async () => await gotoTable4() }, // 点位4
|
||||||
|
{ x: 700, y: 5, action: async () => await gotoTable5() }, // 点位5
|
||||||
|
{ x: 290, y: 530, action: async () => await gotoTable6() } // 点位6
|
||||||
|
];
|
||||||
|
|
||||||
|
await openMap();
|
||||||
|
keyPress("M");
|
||||||
|
await sleep(1200);
|
||||||
|
click(48, 441);//放大地图
|
||||||
|
await sleep(500);
|
||||||
|
click(48, 441);//放大地图
|
||||||
|
await sleep(500);
|
||||||
|
click(48, 441);//放大地图
|
||||||
|
await sleep(500);
|
||||||
|
click(48, 441);//放大地图
|
||||||
|
await sleep(500);
|
||||||
|
click(48, 441);//放大地图
|
||||||
|
|
||||||
|
await sleep(500);
|
||||||
|
|
||||||
|
// 获取游戏区域截图
|
||||||
|
const captureRegion = captureGameRegion();
|
||||||
|
|
||||||
|
|
||||||
|
for (const point of checkPoints) {
|
||||||
|
i++;
|
||||||
|
// 遍历所有检测点位
|
||||||
|
const cropRegion = captureRegion.DeriveCrop(
|
||||||
|
point.x ,
|
||||||
|
point.y ,
|
||||||
|
160,
|
||||||
|
160
|
||||||
|
);
|
||||||
|
|
||||||
|
// 在裁剪区域中查找卡片
|
||||||
|
const result = cropRegion.Find(cardPlayerRo);
|
||||||
|
|
||||||
|
// 如果找到卡片
|
||||||
|
if (!result.IsEmpty()) {
|
||||||
|
log.info(`在点位${i}找到玩家卡片,执行对应操作`);
|
||||||
|
|
||||||
|
await sleep(1000);
|
||||||
|
keyPress("ESCAPE");
|
||||||
|
await sleep(1500);
|
||||||
|
await point.action(); // 调用该点位对应的函数
|
||||||
|
return true; // 返回true表示已找到并处理
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 所有点位都未找到
|
||||||
|
log.info("未在任何检测点找到玩家卡片");
|
||||||
|
textArray.length = 0;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// 存储识别到的文本信息
|
// 存储识别到的文本信息
|
||||||
let textArray = [];
|
let textArray = [];
|
||||||
|
|
||||||
@@ -14,9 +84,10 @@ async function captureAndStoreTexts() {
|
|||||||
{x: 1070, y: 620},
|
{x: 1070, y: 620},
|
||||||
{x: 1380, y: 620}
|
{x: 1380, y: 620}
|
||||||
];
|
];
|
||||||
|
|
||||||
// 截取区域大小
|
// 截取区域大小
|
||||||
const width = 210;
|
const width = 240;
|
||||||
const height = 60;
|
const height = 100;
|
||||||
await sleep(500);
|
await sleep(500);
|
||||||
keyPress("F6")
|
keyPress("F6")
|
||||||
await sleep(1000);
|
await sleep(1000);
|
||||||
@@ -28,20 +99,22 @@ async function captureAndStoreTexts() {
|
|||||||
// 遍历四个位置进行OCR识别
|
// 遍历四个位置进行OCR识别
|
||||||
for (const pos of positions) {
|
for (const pos of positions) {
|
||||||
// 创建OCR识别区域
|
// 创建OCR识别区域
|
||||||
const ocrRo = RecognitionObject.ocr(pos.x, pos.y, width, height);
|
const ocrRo = RecognitionObject.ocr(pos.x, pos.y, width, height);//挑战者名字区域
|
||||||
|
const ocrRo2 = RecognitionObject.ocr(pos.x, pos.y+100, width, height);//挑战是否完成
|
||||||
// 在指定区域进行OCR识别
|
// 在指定区域进行OCR识别
|
||||||
const result = captureRegion.find(ocrRo);
|
const result = captureRegion.find(ocrRo);
|
||||||
|
const result2 = captureRegion.find(ocrRo2);
|
||||||
if (!result.isEmpty() && result.text) {
|
if (!result.isEmpty() && result.text) {
|
||||||
// 存储识别结果和对应位置
|
// 存储识别结果和对应位置
|
||||||
|
if(result2.text == "追踪"){
|
||||||
|
log.info(`识别到文本: ${result.text} 位置: (${pos.x}, ${pos.y})`);
|
||||||
textArray.push({
|
textArray.push({
|
||||||
text: result.text.trim(),
|
text: result.text.trim(),
|
||||||
x: pos.x + width / 2, // 点击中心位置
|
x: pos.x + width / 2, // 点击中心位置
|
||||||
y: pos.y + height / 2
|
y: pos.y + height / 2
|
||||||
});
|
});}
|
||||||
|
|
||||||
log.info(`识别到文本: ${result.text} 位置: (${pos.x}, ${pos.y})`);
|
|
||||||
} else {
|
} else {
|
||||||
log.warn(`位置 (${pos.x}, ${pos.y}) 未识别到文本`);
|
log.warn(`位置 (${pos.x}, ${pos.y}) 未识别到文本`);
|
||||||
}
|
}
|
||||||
@@ -99,7 +172,7 @@ async function searchAndClickTexts() {
|
|||||||
|
|
||||||
//函数:打开地图前往猫尾酒馆
|
//函数:打开地图前往猫尾酒馆
|
||||||
async function gotoTavern() {
|
async function gotoTavern() {
|
||||||
log.info(`前往猫尾酒馆`);
|
|
||||||
await sleep(1000);
|
await sleep(1000);
|
||||||
keyPress("m");
|
keyPress("m");
|
||||||
await sleep(1500);
|
await sleep(1500);
|
||||||
@@ -139,6 +212,8 @@ click(1610,900 );//点击挑战
|
|||||||
await sleep(8000);
|
await sleep(8000);
|
||||||
await dispatcher.runTask(new SoloTask("AutoGeniusInvokation"));
|
await dispatcher.runTask(new SoloTask("AutoGeniusInvokation"));
|
||||||
await sleep(3000);
|
await sleep(3000);
|
||||||
|
click(960, 540);
|
||||||
|
await sleep(500);
|
||||||
click(1860,50 );//避免失败卡死:点击设置
|
click(1860,50 );//避免失败卡死:点击设置
|
||||||
await sleep(1000);
|
await sleep(1000);
|
||||||
click(1600,260 );//避免失败卡死:退出对局
|
click(1600,260 );//避免失败卡死:退出对局
|
||||||
@@ -157,7 +232,8 @@ await sleep(900);
|
|||||||
|
|
||||||
//前往一号桌
|
//前往一号桌
|
||||||
async function gotoTable1() {
|
async function gotoTable1() {
|
||||||
log.info(`前往1号桌`);
|
await gotoTavern();
|
||||||
|
log.info(`前往1号桌`);
|
||||||
keyDown("d");
|
keyDown("d");
|
||||||
await sleep(1500);
|
await sleep(1500);
|
||||||
keyUp("d");
|
keyUp("d");
|
||||||
@@ -173,6 +249,7 @@ await sleep(700);
|
|||||||
}
|
}
|
||||||
//前往二号桌
|
//前往二号桌
|
||||||
async function gotoTable2() {
|
async function gotoTable2() {
|
||||||
|
await gotoTavern();
|
||||||
log.info(`前往2号桌`);
|
log.info(`前往2号桌`);
|
||||||
keyDown("d");
|
keyDown("d");
|
||||||
await sleep(1500);
|
await sleep(1500);
|
||||||
@@ -192,6 +269,7 @@ await sleep(700);
|
|||||||
}
|
}
|
||||||
//前往三号桌
|
//前往三号桌
|
||||||
async function gotoTable3() {
|
async function gotoTable3() {
|
||||||
|
await gotoTavern();
|
||||||
log.info(`前往3号桌`);
|
log.info(`前往3号桌`);
|
||||||
keyDown("w");
|
keyDown("w");
|
||||||
await sleep(2000);
|
await sleep(2000);
|
||||||
@@ -206,6 +284,7 @@ await sleep(700);
|
|||||||
}
|
}
|
||||||
//前往四号桌
|
//前往四号桌
|
||||||
async function gotoTable4() {
|
async function gotoTable4() {
|
||||||
|
await gotoTavern();
|
||||||
log.info(`前往4号桌`);
|
log.info(`前往4号桌`);
|
||||||
keyDown("w");
|
keyDown("w");
|
||||||
await sleep(2000);
|
await sleep(2000);
|
||||||
@@ -226,6 +305,7 @@ await sleep(700);
|
|||||||
}
|
}
|
||||||
//前往一号包间
|
//前往一号包间
|
||||||
async function gotoTable5() {
|
async function gotoTable5() {
|
||||||
|
await gotoTavern();
|
||||||
log.info(`前往1号包间`);
|
log.info(`前往1号包间`);
|
||||||
keyDown("w");
|
keyDown("w");
|
||||||
await sleep(2500);
|
await sleep(2500);
|
||||||
@@ -245,6 +325,7 @@ await sleep(700);
|
|||||||
}
|
}
|
||||||
//前往二号包间
|
//前往二号包间
|
||||||
async function gotoTable6() {
|
async function gotoTable6() {
|
||||||
|
await gotoTavern();
|
||||||
log.info(`前往2号包间`);
|
log.info(`前往2号包间`);
|
||||||
await sleep(1500);
|
await sleep(1500);
|
||||||
keyDown("d");
|
keyDown("d");
|
||||||
@@ -272,38 +353,38 @@ await sleep(500);
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function openMap() {
|
||||||
|
await gotoTavern();
|
||||||
|
keyDown("w");
|
||||||
|
await sleep(2000);
|
||||||
|
keyUp("w");
|
||||||
|
keyDown("d");
|
||||||
|
await sleep(5000);
|
||||||
|
keyUp("d");
|
||||||
|
await sleep(700);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//主流程
|
//主流程
|
||||||
await genshin.returnMainUi();
|
await genshin.returnMainUi();
|
||||||
await gotoTavern();
|
await gotoTavern();
|
||||||
await sleep(4000);
|
await sleep(4000);
|
||||||
await captureAndStoreTexts();
|
await captureAndStoreTexts();
|
||||||
for (let i = 0;i < 6; i++) {
|
for (let i = 0;i < 6; i++) {//六次循环兜底,避免多次挑战不过
|
||||||
|
|
||||||
|
if (textArray.length === 0) break;
|
||||||
|
await detectCardPlayer();
|
||||||
|
await searchAndClickTexts();
|
||||||
|
|
||||||
if (textArray.length === 0) break;
|
|
||||||
if (i != 0)await gotoTavern();
|
|
||||||
await gotoTable1();
|
|
||||||
await searchAndClickTexts();
|
|
||||||
if (textArray.length === 0) break;
|
|
||||||
await gotoTavern();
|
|
||||||
await gotoTable2();
|
|
||||||
await searchAndClickTexts();
|
|
||||||
if (textArray.length === 0) break;
|
|
||||||
await gotoTavern();
|
|
||||||
await gotoTable3();
|
|
||||||
await searchAndClickTexts();
|
|
||||||
if (textArray.length === 0) break;
|
|
||||||
await gotoTavern();
|
|
||||||
await gotoTable4();
|
|
||||||
await searchAndClickTexts();
|
|
||||||
if (textArray.length === 0) break;
|
|
||||||
await gotoTavern();
|
|
||||||
await gotoTable5();
|
|
||||||
await searchAndClickTexts();
|
|
||||||
if (textArray.length === 0) break;
|
|
||||||
await gotoTavern();
|
|
||||||
await gotoTable6();
|
|
||||||
await searchAndClickTexts();
|
|
||||||
if (textArray.length === 0) break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await genshin.returnMainUi();
|
||||||
|
await sleep(500);
|
||||||
|
keyPress("F6")
|
||||||
|
await sleep(1000);
|
||||||
|
click(300, 370);//点击七日历练
|
||||||
|
await sleep(1000);
|
||||||
|
log.info(`打牌结束`);
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
{
|
{
|
||||||
"manifest_version": 1,
|
"manifest_version": 1,
|
||||||
"name": "打牌一条龙",
|
"name": "打牌一条龙",
|
||||||
"version": "1.0",
|
"version": "1.1",
|
||||||
"description": "不依靠分层地图的一条龙打牌(无奈.jpg), 所以什么时候加上?另外只靠一个牌组的话,胜率还是太低了,所以有没有既简单又强势的卡组推荐下呢?",
|
"description": "只靠一个牌组的话,胜率还是太低了,所以有没有既简单又强势的卡组推荐下呢?",
|
||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
"name": "柒叶子",
|
"name": "柒叶子",
|
||||||
|
|||||||
Reference in New Issue
Block a user