JS脚本:兽肉好感核心函数完善 (#663)

* fix: 默认延迟时间

* fix: 无法跳出while循环

* impr: 修改核心函数逻辑
This commit is contained in:
起个名字好难的喵
2025-04-28 23:08:10 +08:00
committed by GitHub
parent 292d9ee657
commit f6e3468ecc
3 changed files with 53 additions and 41 deletions

View File

@@ -71,7 +71,7 @@
}
// 好感核心函数
async function AutoFriendship(runTimes, statueTimes, GetMeatMode, delayTime, startTime, ocrTimeout) {
async function AutoFriendship(runTimes, statueTimes, getMeatMode, delayTime, startTime, ocrTimeout) {
for (let i = 0; i < runTimes; i++) {
if ((i + 1) % statueTimes === 0) { // 判断当前循环次数否达到去神像设置值
await genshin.tpToStatueOfTheSeven();
@@ -80,48 +80,60 @@
log.info(`导航至突发任务(张牙舞爪的恶党)触发位置(二净甸)`);
await AutoPath(`好感-张牙舞爪的恶党-触发位置(二净甸)`);
await sleep(delayTime);
notification.send(`已抵达突发任务张牙舞爪的恶党触发位置`);
notification.send(`已抵达突发任务张牙舞爪的恶党触发位置`);
}
await genshin.relogin();
// OCR识别是否触发任务默认30秒超时
let ocrStatus = false;
let ocrStartTime = Date.now();
while (Date.now() - ocrStartTime < ocrTimeout) {
let captureRegion = captureGameRegion();
let resList = captureRegion.findMulti(RecognitionObject.ocr(0, 200, 300, 300));
for (let o = 0; o < resList.count; o++) {
let res = resList[o];
if (res.text.includes("张牙") || res.text.includes("舞爪") || res.text.includes("恶党") || res.text.includes("打倒") || res.text.includes("所有") || res.text.includes("鳄鱼")) {
ocrStatus = true;
break;
// 判断游戏重上后是否在任务触发位置如果在就进行OCR如果不在则退回次数并重新执行触发路线
if (await comparePosition()) {
// OCR识别是否触发任务默认30秒超时
let ocrStatus = false;
let ocrStartTime = Date.now();
while (Date.now() - ocrStartTime < ocrTimeout && !ocrStatus) {
let captureRegion = captureGameRegion();
let resList = captureRegion.findMulti(RecognitionObject.ocr(0, 200, 300, 300));
for (let o = 0; o < resList.count; o++) {
let res = resList[o];
if (res.text.includes("张牙") || res.text.includes("舞爪") || res.text.includes("恶党") || res.text.includes("打倒") || res.text.includes("所有") || res.text.includes("鳄鱼")) {
ocrStatus = true;
break;
}
}
}
}
if (ocrStatus) {
log.info(`当前次数:${i + 1}/${runTimes}`);
// 开启急速拾取
dispatcher.addTimer(new RealtimeTimer("AutoPick", {
"forceInteraction": true
}));
await AutoPath(`好感-张牙舞爪的恶党-循环${GetMeatMode ? '(二净甸刷肉版)' : '(二净甸)'}`);
// 关闭急速拾取
dispatcher.addTimer(new RealtimeTimer("AutoPick", {
"forceInteraction": false
}));
// 判定本轮循环是否执行完毕
if (await comparePosition()) {
log.info(`已完成次数:${i + 1}/${runTimes}`);
if (ocrStatus) {
log.info(`当前次数:${i + 1}/${runTimes}`);
// 开启急速拾取
dispatcher.addTimer(new RealtimeTimer("AutoPick", {
"forceInteraction": true
}));
await AutoPath(`好感-张牙舞爪的恶党-循环${getMeatMode ? '(二净甸刷肉版)' : '(二净甸)'}`);
// 关闭急速拾取
dispatcher.addTimer(new RealtimeTimer("AutoPick", {
"forceInteraction": false
}));
// 根据是否回到触发位置,判定本轮循环是否执行完毕
if (await comparePosition()) {
log.info(`已完成次数:${i + 1}/${runTimes}`);
} else {
i = i - 1; // 退回这次次数
log.warn(`判定本轮循环执行失败,退回本轮执行次数:${i + 1}/${runTimes}`);
}
} else {
i = i - 1; // 退回这次次数
log.warn(`判定本轮循环执行失败,退回本轮执行次数:${i + 1}/${runTimes}`);
notification.send(`未识别到突发任务(张牙舞爪的恶党),兽肉好感结束`);
break;
}
} else {
notification.send(`未识别到突发任务(张牙舞爪的恶党),兽肉好感结束`);
break;
i = i - 1; // 退回这次次数
log.warn(`判定本轮循环执行失败,退回本轮执行次数:${i + 1}/${runTimes}`);
}
const estimatedCompletion = calculateEstimatedCompletion(startTime, i + 1, runTimes);
logTimeTaken(startTime);
log.info(`预计完成时间:${estimatedCompletion}`);
@@ -130,14 +142,14 @@
}
// 刷肉相关参数
let GetMeatMode = settings.GetMeatMode ? settings.GetMeatMode : false;
let getMeatMode = settings.getMeatMode ? settings.getMeatMode : false;
let inputValue = settings.inputValue ? settings.inputValue : 300;
let runTimes = GetMeatMode ? (isNaN(inputValue) ? 50 : Math.ceil(inputValue / 6)) : 10;
let runTimes = getMeatMode ? (isNaN(inputValue) ? 50 : Math.ceil(inputValue / 6)) : 10;
// 神像相关参数
let goStatue = settings.goStatue ? settings.goStatue : false;
let statueTimes = goStatue ? (isNaN(settings.statueTimes) ? 5 : settings.statueTimes) : 0;
// 延迟相关
let delayTime = settings.delayTime ? settings.delayTime * 1000 : 0;
let delayTime = settings.delayTime ? settings.delayTime * 1000 : 10000;
let ocrTimeout = settings.ocrTimeout ? settings.ocrTimeout * 1000 : 30000;
// 卡时间相关参数
if (settings.waitTimeMode) {
@@ -195,6 +207,6 @@
}
const startTime = Date.now();
await AutoFriendship(runTimes, statueTimes, GetMeatMode, delayTime, startTime, ocrTimeout);
await AutoFriendship(runTimes, statueTimes, getMeatMode, delayTime, startTime, ocrTimeout);
})();

View File

@@ -1,7 +1,7 @@
{
"manifest_version": 1,
"name": "兽肉好感:自动好感度&刷两只鳄鱼兽肉&卡时间",
"version": "1.3.5",
"version": "1.3.6",
"bgi_version": "0.44.6",
"description": "通过突发事件:张牙舞爪的恶党刷兽肉并顺带获取好感度好感度超过10次后不再获取请使用满员好感度队伍并为全体队伍角色配置相应的战斗策略",
"authors": [

View File

@@ -2,10 +2,10 @@
{
"name": "partyName",
"type": "input-text",
"label": "需要切换的队伍名称(选填)"
"label": "需要切换的队伍名称选填"
},
{
"name": "GetMeatMode",
"name": "getMeatMode",
"type": "checkbox",
"label": "开启刷兽肉模式【勾选才拾取兽肉】"
},
@@ -17,7 +17,7 @@
{
"name": "waitTimeMode",
"type": "checkbox",
"label": "卡时间模式基于运行次数、基准日期、周期确定需要运行次数"
"label": "卡时间模式基于运行次数、基准日期、周期确定需要运行次数"
},
{
"name": "waitTimeModeDay",
@@ -47,7 +47,7 @@
{
"name": "delayTime",
"type": "input-text",
"label": "到达触发地点后的延迟时间(秒)"
"label": "到达触发地点后的延迟时间(选填默认为10秒)"
},
{
"name": "ocrTimeout",