fix: 修复开战前等待,修复错误终止任务
This commit is contained in:
@@ -1,20 +1,20 @@
|
||||
{
|
||||
"info": {
|
||||
"name": "盗宝团",
|
||||
"type": "collect",
|
||||
"author": "HZYgrandma",
|
||||
"version": "1.0",
|
||||
"description": "",
|
||||
"bgi_version": "0.43.4"
|
||||
},
|
||||
"positions": [
|
||||
{
|
||||
"id": 1,
|
||||
"x": -2756.67,
|
||||
"y": -3467.63,
|
||||
"type": "path",
|
||||
"move_mode": "dash",
|
||||
"action": ""
|
||||
}
|
||||
]
|
||||
}
|
||||
"info": {
|
||||
"name": "盗宝团",
|
||||
"type": "collect",
|
||||
"author": "HZYgrandma",
|
||||
"version": "1.0",
|
||||
"description": "",
|
||||
"bgi_version": "0.43.4"
|
||||
},
|
||||
"positions": [
|
||||
{
|
||||
"id": 1,
|
||||
"x": -2756.67,
|
||||
"y": -3467.63,
|
||||
"type": "path",
|
||||
"move_mode": "dash",
|
||||
"action": ""
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"info": {
|
||||
"name": "盗宝团",
|
||||
"name": "触发点",
|
||||
"type": "collect",
|
||||
"author": "HZYgrandma",
|
||||
"version": "1.0",
|
||||
@@ -24,14 +24,6 @@
|
||||
"move_mode": "walk",
|
||||
"action": "exit_and_relogin"
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"x": -2739.71,
|
||||
"y": -3399.06,
|
||||
"type": "path",
|
||||
"move_mode": "dash",
|
||||
"action": ""
|
||||
},
|
||||
{
|
||||
"id": 4,
|
||||
"x": -2738.67,
|
||||
|
||||
@@ -2,7 +2,7 @@ const DEFAULT_RUNS = 10;
|
||||
const DEFAULT_PERIOD = 25;
|
||||
const DEFAULT_BASE_RUNS = 50;
|
||||
const BENCHMARK_HOUR = "T04:00:00";
|
||||
const DEFAULT_OCR_TIMEOUT_SECONDS = 10;
|
||||
const DEFAULT_OCR_TIMEOUT_SECONDS = 30;
|
||||
const DEFAULT_FIGHT_TIMEOUT_SECONDS = 120;
|
||||
|
||||
(async function () {
|
||||
@@ -77,7 +77,6 @@ async function AutoPath(locationName) {
|
||||
} catch (error) {
|
||||
log.error(`执行 ${locationName} 路径时发生错误: ${error.message}`);
|
||||
}
|
||||
await sleep(2000);
|
||||
}
|
||||
|
||||
// 计算运行时长
|
||||
@@ -106,6 +105,10 @@ async function AutoFriendshipDev(times, ocrTimeout, fightTimeout) {
|
||||
let startFirstTime = Date.now();
|
||||
for (let i = 0; i < times; i++) {
|
||||
await AutoPath('触发点');
|
||||
// 启动路径导航任务
|
||||
let pathTaskPromise = AutoPath('盗宝团');
|
||||
|
||||
// OCR检测
|
||||
let ocrStatus = false;
|
||||
let ocrStartTime = Date.now();
|
||||
while (Date.now() - ocrStartTime < ocrTimeout * 1000 && !ocrStatus) {
|
||||
@@ -119,16 +122,54 @@ async function AutoFriendshipDev(times, ocrTimeout, fightTimeout) {
|
||||
|| res.text.includes("鬼鬼祟祟")
|
||||
|| res.text.includes("盗宝团")) {
|
||||
ocrStatus = true;
|
||||
log.info("检测到突发任务触发");
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!ocrStatus) {
|
||||
await sleep(1000);
|
||||
}
|
||||
}
|
||||
|
||||
if(ocrStatus){
|
||||
log.info("检测到突发任务触发")
|
||||
await AutoPath('盗宝团');
|
||||
const cts = new CancellationTokenSource();
|
||||
try {
|
||||
const cts = new CancellationTokenSource();
|
||||
// 设置最大等待时间为15秒
|
||||
const maxWaitTime = 15000;
|
||||
const waitStartTime = Date.now();
|
||||
|
||||
// 校验距离,如果距离小于10米,则认为已经到达目的地
|
||||
const targetX = -2756.67;
|
||||
const targetY = -3467.63;
|
||||
const maxDistance = 10; // 10米距离判定
|
||||
|
||||
// 等待角色到达指定位置附近
|
||||
let isNearTarget = false;
|
||||
let pathTaskFinished = false;
|
||||
|
||||
// 简单监控路径任务完成
|
||||
pathTaskPromise.then(() => {
|
||||
pathTaskFinished = true;
|
||||
log.info("路径任务已完成");
|
||||
}).catch(error => {
|
||||
pathTaskFinished = true;
|
||||
log.error(`路径任务出错: ${error}`);
|
||||
});
|
||||
|
||||
// 等待角色到达目标位置或超时
|
||||
while (!isNearTarget && !pathTaskFinished && (Date.now() - waitStartTime < maxWaitTime)) {
|
||||
const pos = genshin.getPositionFromMap();
|
||||
if (pos) {
|
||||
const distance = Math.sqrt(Math.pow(pos.x - targetX, 2) + Math.pow(pos.y - targetY, 2));
|
||||
if (distance <= maxDistance) {
|
||||
isNearTarget = true;
|
||||
log.info(`已到达目标点附近,距离: ${distance.toFixed(2)}米`);
|
||||
break;
|
||||
}
|
||||
}
|
||||
await sleep(1000);
|
||||
}
|
||||
|
||||
log.info("开始战斗...");
|
||||
const battleTask = dispatcher.RunTask(new SoloTask("AutoFight"), cts);
|
||||
|
||||
@@ -136,6 +177,7 @@ async function AutoFriendshipDev(times, ocrTimeout, fightTimeout) {
|
||||
log.info(`战斗任务已结束,战斗结果:${fightResult}`);
|
||||
cts.cancel();
|
||||
} catch (error) {
|
||||
cts.cancel();
|
||||
log.error(`执行过程中出错: ${error}`);
|
||||
}
|
||||
const estimatedCompletion = CalculateEstimatedCompletion(startFirstTime, i + 1, times);
|
||||
@@ -148,7 +190,6 @@ async function AutoFriendshipDev(times, ocrTimeout, fightTimeout) {
|
||||
log.info(`未识别到突发任务(岛上无贼),盗宝团好感结束`);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
log.info('盗宝团好感已完成');
|
||||
}
|
||||
@@ -207,36 +248,46 @@ async function waitForBattleResult(timeout = 2 * 60 * 1000) {
|
||||
const failureKeywords = ["失败"];
|
||||
const eventKeyword = ["岛上", "无贼","消灭","鬼鬼祟祟","盗宝团"];
|
||||
let notFind = 0;
|
||||
|
||||
while (Date.now() - fightStartTime < timeout) {
|
||||
try {
|
||||
// 简化OCR检测,只使用一个try-catch块
|
||||
let result = captureGameRegion().find(RecognitionObject.ocr(850, 150, 200, 80));
|
||||
let result2 = captureGameRegion().find(RecognitionObject.ocr(0, 200, 300, 300));
|
||||
let text = result.text;
|
||||
let text2 = result2.text;
|
||||
|
||||
// 检查成功关键词
|
||||
for (let keyword of successKeywords) {
|
||||
if (text.includes(keyword)) {
|
||||
log.info("检测到战斗成功关键词: {0}", keyword);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// 检查失败关键词
|
||||
for (let keyword of failureKeywords) {
|
||||
if (text.includes(keyword)) {
|
||||
log.warn("检测到战斗失败关键词: {0}", keyword);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// 检查事件关键词
|
||||
let find = 0;
|
||||
for(let keyword of eventKeyword) {
|
||||
if (text2.includes(keyword)) {
|
||||
find++;
|
||||
}
|
||||
}
|
||||
|
||||
if(find === 0) {
|
||||
notFind++;
|
||||
log.info("未检测到任务触发关键词:{0} 次", notFind);
|
||||
}else{
|
||||
notFind = 0;
|
||||
}
|
||||
|
||||
if (notFind > 10) {
|
||||
log.warn("不在任务触发区域,战斗失败");
|
||||
return false;
|
||||
@@ -244,9 +295,13 @@ async function waitForBattleResult(timeout = 2 * 60 * 1000) {
|
||||
}
|
||||
catch (error) {
|
||||
log.error("OCR过程中出错: {0}", error);
|
||||
// 出错后继续循环,不进行额外嵌套处理
|
||||
}
|
||||
await sleep(1000); // 检查间隔
|
||||
|
||||
// 统一的检查间隔
|
||||
await sleep(1000);
|
||||
}
|
||||
|
||||
log.warn("在超时时间内未检测到战斗结果");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"manifest_version": 1,
|
||||
"name": "盗宝团好感:自动好感度&刷盗宝团&卡时间",
|
||||
"version": "1.2.1",
|
||||
"version": "1.2.2",
|
||||
"tags": ["好感", "盗宝团", "突发事件"],
|
||||
"description": "通过突发事件【岛上无贼】刷好感度,刷盗宝团材料,小怪锄地,卡时间等,请配合战斗脚本使用。在 HZYgrandma & 愚溪的原始脚本上改编。当前版本可能无法以任意方式拾取掉落物,如果有拾取掉落物需求,请勿更新。",
|
||||
"authors": [
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
{
|
||||
"name": "qiuQiuRen",
|
||||
"type": "checkbox",
|
||||
"label": "是否清理丘丘人【默认否,选是会清理丘丘人之后再开始盗宝团好感】"
|
||||
"label": "是否清理丘丘人\n【默认否,选是会清理丘丘人之后再开始盗宝团好感】"
|
||||
},
|
||||
{
|
||||
"name": "partyName",
|
||||
@@ -12,31 +12,31 @@
|
||||
{
|
||||
"name": "runTimes",
|
||||
"type": "input-text",
|
||||
"label": "(选填)运行次数【默认10次,卡时间模式默认50次】"
|
||||
"label": "(选填)运行次数\n【默认10次,卡时间模式默认50次】"
|
||||
},
|
||||
{
|
||||
"name": "waitTimeMode",
|
||||
"type": "checkbox",
|
||||
"label": "卡时间模式【基于运行次数、基准日期、周期确定需要运行次数】"
|
||||
"label": "卡时间模式\n【基于运行次数、基准日期、周期确定需要运行次数】"
|
||||
},
|
||||
{
|
||||
"name": "waitTimeModeDay",
|
||||
"type": "input-text",
|
||||
"label": "卡时间模式基准日期【格式参考:2025-01-01】"
|
||||
"label": "卡时间模式基准日期\n【格式参考:2025-01-01】"
|
||||
},
|
||||
{
|
||||
"name": "waitTimeModePeriod",
|
||||
"type": "input-text",
|
||||
"label": "(选填)卡时间模式周期【默认:25天】"
|
||||
"label": "(选填)卡时间模式周期\n【默认:25天】"
|
||||
},
|
||||
{
|
||||
"name": "ocrTimeout",
|
||||
"type": "input-text",
|
||||
"label": "OCR超时时间(选填,默认为10秒)"
|
||||
"label": "OCR超时时间\n【选填,默认为30秒,如果经常提前判定未识别到任务,请适当调大】"
|
||||
},
|
||||
{
|
||||
"name": "fightTimeOut",
|
||||
"type": "input-text",
|
||||
"label": "战斗超时时间(选填,默认为120秒)"
|
||||
"label": "战斗超时时间\n【选填,默认为120秒】"
|
||||
}
|
||||
]
|
||||
Reference in New Issue
Block a user