mirror of
https://github.com/babalae/bettergi-scripts-list.git
synced 2026-05-06 00:16:03 +08:00
* refactor(ActivitySwitchNotice): 优化通知配置构建逻辑 - 将 configNotice 变量改为 let 声明以支持动态更新 - 新增 async 函数 buildConfigNotice 用于构建通知配置 - 在 sendNotice 函数中调用 buildConfigNotice 确保配置最新 - 在 sendText 函数中添加 buildConfigNotice 调用保证配置同步 * refactor(utils): 导出工具函数并移除全局挂载 - 将 activity.js 中的 activityMain 函数改为导出函数 - 将 campaignArea.js 中的 ocrDailyCommission、ocrWeeklyCount、campaignAreaMain、dailyCommissionMain 函数改为导出函数 - 将 mapMission.js 中的 ocrMapMission、openMap、mapMission 函数改为导出函数 - 将 tool.js 中的 findTextAndClick、getDayOfWeek 函数改为导出函数 - 将 uid.js 中的 saveOnlyNumber、ocrUID、compareUid、checkUid、check 函数改为导出函数 - 将 ws.js 中的 send、sendText 函数改为导出函数 - 移除所有 utils 文件中对 this 对象的挂载操作 - 在 main.js 中导入新的工具函数并移除重复定义的函数 * fix(ActivitySwitchNotice): 修复圣遗物空间检查功能中的显示和逻辑问题 - 修正圣遗物空间不足提醒消息中的标点符号格式 - 修复圣遗物空间阈值错误日志中的数字格式 - 移除不必要的延时操作以优化执行效率 - 调整代码结构以提高运行性能 fix(ActivitySwitchNotice): 修复圣遗物空间检查功能中的显示和逻辑问题 - 修正圣遗物空间不足提醒消息中的标点符号格式 - 修复圣遗物空间阈值错误日志中的数字格式 - 移除不必要的延时操作以优化执行效率 - 调整代码结构以提高运行性能 refactor(ActivitySwitchNotice): 优化圣遗物检查功能中的延迟配置 - 将硬编码的延迟时间替换为可配置的常量 - 统一延迟时间管理,提高代码可维护性 - 保持原有功能逻辑不变的情况下提升代码质量 feat(ActivitySwitchNotice): 更新版本并新增圣遗物空间检测提醒功能 - 将插件版本从 0.1.3 更新至 0.1.5 - 新增圣遗物剩余空间检测提醒功能 - 在版本历史中添加 0.1.5 版本记录 fix(ActivitySwitchNotice): 修复圣遗物剩余空间阈值解析错误 - 添加 try-catch 块处理 parseInt 异常情况 - 当阈值格式错误时默认使用 400 的阈值 - 添加警告日志记录格式错误的阈值设置 - 确保程序在无效配置下仍能正常运行 feat(bag): 添加圣遗物背包空间检查功能 - 新增 HolyRelics.js 工具模块实现圣遗物数量检查逻辑 - 集成 OCR 识别功能用于获取圣遗物数量信息 - 添加背包空间不足提醒功能,可自定义阈值 - 在 main.js 中集成圣遗物检查流程 - 添加新的配置选项包括打开背包按键和圣遗物阈值设置 - 扩展工具类增加 findText、findImg 和 OcrFind 等通用识别方法 - 实现自动打开背包并处理过期物品弹窗功能 * fix(HolyRelics): 修复圣遗物背包空间检测功能 - 添加了进入圣遗物背包的点击状态验证,避免无法进入时继续执行 - 增强了OCR文本解析逻辑,添加了字符串分割长度验证和数值解析校验 - 优化了阈值参数解析,在main.js中添加了更安全的数值转换和错误处理 - 修复了工具函数中资源释放问题,在isInMainUI函数中使用try-finally确保资源被正确释放 - 更新了提醒消息文本,明确标识阈值设置参数
194 lines
7.7 KiB
JavaScript
194 lines
7.7 KiB
JavaScript
import {findTextAndClick,getDayOfWeek} from "./tool";
|
||
import {sendText} from "./notice";
|
||
import {ocrUID} from "./uid";
|
||
function settingsParseInt(str, defaultValue) {
|
||
try {
|
||
return str ? parseInt('' + str) : defaultValue;
|
||
} catch (e) {
|
||
log.warn(`settingsParseInt error:${e}`)
|
||
return defaultValue;
|
||
}
|
||
}
|
||
|
||
function settingsParseStr(str, defaultValue) {
|
||
return '' + (str ? str : defaultValue);
|
||
}
|
||
|
||
const config = {
|
||
campaignAreaKey: settingsParseStr(settings.campaignAreaKey, 'F1'),
|
||
// campaignAreaReminderDay: settingsParseInt(settings.campaignAreaReminderDay, 0),//征讨领域提醒日
|
||
campaignAreaReminderDays: Array.from(settings.campaignAreaReminderDays)
|
||
}
|
||
const ocrRegionConfig = {
|
||
weeklyCount: {x: 809, y: 258, width: 277, height: 37},//征讨领域减半次数识别区域坐标和尺寸
|
||
campaignArea:{x:433, y:215, width:306, height:697},//征讨领域识别区域
|
||
dailyCommission: {x: 630, y: 312, width: 105, height: 118},//每日委托识别区域坐标和尺寸
|
||
}
|
||
const xyConfig = {
|
||
campaignArea: {x: 493, y: 537},//征讨领域坐标
|
||
secretRealm: {x: 304, y: 448},//秘境坐标
|
||
dailyCommission: {x: 266, y: 318},//委托坐标 x=266, y=318, width=69, height=44
|
||
}
|
||
|
||
/**
|
||
* 每日委托OCR识别函数
|
||
* @param {Object} ocrRegion - OCR识别区域配置,默认为ocrRegionConfig.dailyCommission
|
||
* @returns {Object} 返回包含每日委托和体力使用情况的对象
|
||
*/
|
||
export async function ocrDailyCommission(ocrRegion = ocrRegionConfig.dailyCommission) {
|
||
let captureRegion = captureGameRegion(); // 获取游戏区域截图
|
||
try {
|
||
const ocrObject = RecognitionObject.Ocr(ocrRegion.x, ocrRegion.y, ocrRegion.width, ocrRegion.height); // 创建OCR识别对象
|
||
// ocrObject.threshold = 1.0;
|
||
let resList = captureRegion.findMulti(ocrObject); // 在指定区域进行OCR识别
|
||
let dailyCommission = resList[0].text?.trim();
|
||
const lastName = dailyCommission.at(dailyCommission.length - 1);
|
||
|
||
if (dailyCommission.lastIndexOf('1') === 1) {
|
||
// 0/4 被识别成==>014
|
||
dailyCommission = dailyCommission.replace('1' + lastName, '/' + lastName)
|
||
}
|
||
const dailyCommissionSplit = dailyCommission.split('/');
|
||
|
||
// physical
|
||
let physical = resList[1].text?.trim();
|
||
const physicalSplit = physical.split('/');
|
||
return {
|
||
daily: {
|
||
total: parseInt(dailyCommissionSplit[1]),
|
||
use: parseInt(dailyCommissionSplit[0]),
|
||
},
|
||
physical: {
|
||
total: parseInt(physicalSplit[1]),
|
||
use: parseInt(physicalSplit[0]),
|
||
},
|
||
}
|
||
} finally {
|
||
captureRegion.dispose(); // 释放截图资源
|
||
}
|
||
}
|
||
|
||
/**
|
||
* OCR识别周计数函数
|
||
* @param {Object} ocrRegion - OCR识别区域配置,默认为ocrRegionConfig.weeklyCount
|
||
* @returns {Object} 返回包含周计数信息的JSON对象,包含text、total和count属性
|
||
* @throws {Error} 当OCR识别失败时抛出错误
|
||
*/
|
||
export async function ocrWeeklyCount(ocrRegion = ocrRegionConfig.weeklyCount) {
|
||
let captureRegion = captureGameRegion(); // 获取游戏区域截图
|
||
try {
|
||
const ocrObject = RecognitionObject.Ocr(ocrRegion.x, ocrRegion.y, ocrRegion.width, ocrRegion.height); // 创建OCR识别对象
|
||
// ocrObject.threshold = 1.0;
|
||
let res = captureRegion.find(ocrObject); // 在指定区域进行OCR识别
|
||
if (!res.isExist()) {
|
||
log.error(`ocrWeeklyCount not found`) // 记录错误日志
|
||
throw new Error(`ocrWeeklyCount not found`) // 抛出错误异常
|
||
}
|
||
let weekJson = { // 初始化周计数JSON对象
|
||
text: res.text,
|
||
total: 3,
|
||
count: 3,
|
||
}
|
||
let weekCountText = res.text // 获取OCR识别的文本结果
|
||
let result = weekCountText.match(/[0-9/]+/g)?.join('') || ''; // 使用正则表达式提取数字和斜杠
|
||
|
||
log.debug(`识别结果:{weekCountText}`, weekCountText) // 记录原始识别结果
|
||
log.debug(`处理结果:{result}`, result) // 记录处理后的结果
|
||
const numbers = result.split('/').map((item) => parseInt(item)); // 分割字符串并转换为数字数组
|
||
weekJson.total = numbers[1] // 设置总数
|
||
weekJson.count = numbers[0] // 设置当前计数
|
||
log.debug(`Json:{weekJson}`, weekJson) // 记录最终JSON结果
|
||
return weekJson // 返回处理后的周计数JSON对象
|
||
} finally {
|
||
captureRegion.dispose(); // 释放截图资源
|
||
}
|
||
}
|
||
|
||
|
||
/**
|
||
* 执行秘境征讨剩余次数提醒的主函数
|
||
* 该函数会在每周日执行,检查秘境征讨的剩余次数并发送提醒
|
||
*/
|
||
export async function campaignAreaMain(openKey = true) {
|
||
// 获取当前星期信息
|
||
let dayOfWeek = await getDayOfWeek();
|
||
// 如果不是周日(0代表周日),则直接返回
|
||
// const bool = dayOfWeek.day != config.campaignAreaReminderDay;
|
||
log.info(`秘境征讨提醒日:{0}`,JSON.stringify(config.campaignAreaReminderDays))
|
||
const bool =!config.campaignAreaReminderDays.includes(dayOfWeek.dayOfWeek)
|
||
// log.info(`bool={0}`,bool)
|
||
// 记录开始执行秘境征讨提醒的日志
|
||
log.info(`[{dayOfWeek.dayOfWeek}],${bool ? "跳过" : "开始"}执行秘境征讨剩余次数提醒`, dayOfWeek.dayOfWeek)
|
||
if (bool) {
|
||
return
|
||
}
|
||
// 设置操作间隔时间(毫秒)
|
||
let ms = 600
|
||
if (openKey) {
|
||
// 等待一段时间
|
||
await sleep(ms)
|
||
// 按下配置的热键
|
||
await keyPress(config.campaignAreaKey)
|
||
}
|
||
await sleep(ms * 2)
|
||
// 点击秘境入口坐标
|
||
await click(xyConfig.secretRealm.x, xyConfig.secretRealm.y)
|
||
await sleep(ms * 2)
|
||
// 点击秘境征讨坐标
|
||
// await click(xyConfig.campaignArea.x, xyConfig.campaignArea.y)
|
||
const find = await findTextAndClick("征讨领域");
|
||
if (find===null){
|
||
log.warn("未找到征讨领域")
|
||
return
|
||
}
|
||
await sleep(ms * 2)
|
||
// 使用OCR识别本周秘境征讨剩余次数
|
||
let weekJson = await ocrWeeklyCount();
|
||
|
||
// 如果有剩余次数,则记录日志并发送通知
|
||
if (weekJson.count > 0) {
|
||
let uid = await ocrUID()
|
||
log.info(`本周剩余消耗减半次数:${weekJson.count}`)
|
||
await sendText(`>|本周剩余消耗减半次数:${weekJson.count}`, `UID:${uid}\n秘境征讨`)
|
||
}
|
||
|
||
}
|
||
|
||
/**
|
||
* 每日委托主函数
|
||
* @param {boolean} openKey - 是否开启热键功能,默认为true
|
||
* @returns {Promise<void>}
|
||
*/
|
||
export async function dailyCommissionMain(openKey = true) {
|
||
// 获取当前星期信息
|
||
let dayOfWeek = await getDayOfWeek();
|
||
// 如果不是周日(0代表周日),
|
||
// const bool = dayOfWeek.day != config.campaignAreaReminderDay;
|
||
const bool =config.campaignAreaReminderDays.includes(dayOfWeek.dayOfWeek)
|
||
// 设置操作间隔时间(毫秒)
|
||
let ms = 600
|
||
// 等待一段时间
|
||
await sleep(ms)
|
||
if (openKey || bool) {
|
||
// 按下配置的热键
|
||
await keyPress(config.campaignAreaKey)
|
||
}
|
||
await sleep(ms * 2)
|
||
// 点击秘境入口坐标
|
||
await click(xyConfig.dailyCommission.x, xyConfig.dailyCommission.y)
|
||
await sleep(ms * 2)
|
||
const re = await ocrDailyCommission();
|
||
log.debug(`dailyCommission:{re}`, re)
|
||
// 如果有每日未完成/领取,则记录日志并发送通知
|
||
if (re.daily.total > re.daily.use
|
||
|| re.physical.total > re.physical.use
|
||
) {
|
||
let uid = await ocrUID()
|
||
await sendText(`>|每日委托奖励:${re.daily.use}/${re.daily.total}\n>|原粹树脂消耗:${re.physical.use}/${re.physical.total}`, `UID:${uid}\n每日委托`)
|
||
}
|
||
}
|
||
|
||
// export {
|
||
// campaignAreaMain,
|
||
// dailyCommissionMain,
|
||
// }
|