فهرست منبع

Merge pull request #14 from runhey/dev

Dev
huangrunheng 3 سال پیش
والد
کامیت
98826ee087
99فایلهای تغییر یافته به همراه2108 افزوده شده و 235 حذف شده
  1. 35 89
      README.md
  2. 56 0
      module/atom/ocr.py
  3. 5 1
      module/base/log_highlighter.py
  4. 5 3
      module/config/config_menu.py
  5. 3 1
      module/config/config_model.py
  6. 68 0
      module/config/config_modify.py
  7. 52 7
      module/dev_tools/assets_extract.py
  8. 5 4
      module/device/method/window.py
  9. 21 4
      module/gui/context/process_manager.py
  10. 1 1
      module/gui/qml/Component/Overview.qml
  11. 0 1
      module/gui/qml/Component/SplitPanel.qml
  12. 1 1
      module/gui/qml/Content/ClickRule.qml
  13. 1 1
      module/gui/qml/Content/ImageRule.qml
  14. 1 1
      module/gui/qml/Content/LongClickRule.qml
  15. 354 1
      module/gui/qml/Content/OcrRule.qml
  16. 2 2
      module/gui/qml/Content/SwipeRule.qml
  17. 220 0
      module/ocr/base_ocr.py
  18. 11 0
      module/ocr/models.py
  19. 56 0
      module/ocr/ppocr.py
  20. 192 0
      module/ocr/sub_ocr.py
  21. 23 0
      module/ocr/utils.py
  22. 2 1
      requirements-in.txt
  23. 18 6
      requirements.txt
  24. 1 0
      script.py
  25. 2 0
      tasks/AreaBoss/assets.py
  26. 1 1
      tasks/AreaBoss/config_boss.py
  27. 5 5
      tasks/AreaBoss/config_scheduler.py
  28. 1 0
      tasks/AreaBoss/script_task.py
  29. 25 0
      tasks/CoinChallenge/assets.py
  30. 65 0
      tasks/CoinChallenge/res/test_ocr.json
  31. 1 0
      tasks/DemonEncounter/assets.py
  32. 5 5
      tasks/DemonEncounter/config_scheduler.py
  33. 1 0
      tasks/EternitySea/assets.py
  34. 5 5
      tasks/EternitySea/config_scheduler.py
  35. 1 0
      tasks/ExperienceYoukai/assets.py
  36. 5 5
      tasks/ExperienceYoukai/config_scheduler.py
  37. 1 0
      tasks/FallenSun/assets.py
  38. 5 5
      tasks/FallenSun/config_scheduler.py
  39. 43 0
      tasks/GameUi/assets.py
  40. 44 0
      tasks/GameUi/game_ui.py
  41. 101 0
      tasks/GameUi/res/image.json
  42. 20 0
      tasks/GameUi/res/ocr.json
  43. BIN
      tasks/GameUi/res/res_back_blue.png
  44. BIN
      tasks/GameUi/res/res_home_collect.png
  45. BIN
      tasks/GameUi/res/res_home_concentric_team.png
  46. BIN
      tasks/GameUi/res/res_home_friend.png
  47. BIN
      tasks/GameUi/res/res_home_guild.png
  48. BIN
      tasks/GameUi/res/res_home_help.png
  49. BIN
      tasks/GameUi/res/res_home_mall.png
  50. BIN
      tasks/GameUi/res/res_home_omnyouji.png
  51. BIN
      tasks/GameUi/res/res_home_shikikami.png
  52. BIN
      tasks/GameUi/res/res_home_team.png
  53. BIN
      tasks/GameUi/res/res_home_tsk.png
  54. 1 0
      tasks/General/assets.py
  55. 10 0
      tasks/GeneralBattle/assets.py
  56. 15 34
      tasks/GeneralBattle/config_general_battle.py
  57. 56 6
      tasks/GeneralBattle/general_battle.py
  58. 0 0
      tasks/GeneralBattle/res/image.json
  59. BIN
      tasks/GeneralBattle/res/res_exit.png
  60. BIN
      tasks/GeneralBattle/res/res_exit_ensure.png
  61. 1 0
      tasks/GlobalGame/assets.py
  62. 1 0
      tasks/GoldYoukai/assets.py
  63. 5 5
      tasks/GoldYoukai/config_scheduler.py
  64. 1 0
      tasks/Hunt/assets.py
  65. 5 5
      tasks/Hunt/config_scheduler.py
  66. 1 0
      tasks/Nian/assets.py
  67. 5 5
      tasks/Nian/config_scheduler.py
  68. 1 0
      tasks/Orochi/assets.py
  69. 5 5
      tasks/Orochi/config_scheduler.py
  70. 1 0
      tasks/OrochiJudgement/assets.py
  71. 5 5
      tasks/OrochiJudgement/config_scheduler.py
  72. 1 0
      tasks/OrochiMoans/assets.py
  73. 5 5
      tasks/OrochiMoans/config_scheduler.py
  74. 42 1
      tasks/RealmRaid/assets.py
  75. 30 1
      tasks/RealmRaid/config.py
  76. 6 7
      tasks/RealmRaid/config_scheduler.py
  77. 137 0
      tasks/RealmRaid/res/image.json
  78. 20 0
      tasks/RealmRaid/res/ocr.json
  79. BIN
      tasks/RealmRaid/res/res_back_red.png
  80. BIN
      tasks/RealmRaid/res/res_fire.png
  81. BIN
      tasks/RealmRaid/res/res_fresh.png
  82. BIN
      tasks/RealmRaid/res/res_fresh_ensure.png
  83. BIN
      tasks/RealmRaid/res/res_lock.png
  84. BIN
      tasks/RealmRaid/res/res_medal_0.png
  85. BIN
      tasks/RealmRaid/res/res_medal_1.png
  86. BIN
      tasks/RealmRaid/res/res_medal_2.png
  87. BIN
      tasks/RealmRaid/res/res_medal_3.png
  88. BIN
      tasks/RealmRaid/res/res_medal_4.png
  89. BIN
      tasks/RealmRaid/res/res_medal_5.png
  90. BIN
      tasks/RealmRaid/res/res_realm_raid.png
  91. BIN
      tasks/RealmRaid/res/res_shikigami.png
  92. BIN
      tasks/RealmRaid/res/res_soul_raid.png
  93. BIN
      tasks/RealmRaid/res/res_unlock.png
  94. 175 0
      tasks/RealmRaid/script_task.py
  95. 1 0
      tasks/Restart/assets.py
  96. 1 0
      tasks/Script/assets.py
  97. 1 0
      tasks/Sougenbi/assets.py
  98. 5 5
      tasks/Sougenbi/config_scheduler.py
  99. 107 1
      tasks/base_task.py

+ 35 - 89
README.md

@@ -1,112 +1,58 @@
-![image-20230605215659764](https://runhey-img-stg1.oss-cn-chengdu.aliyuncs.com/img2/202306052157563.png)
+<div align="center">
 
-## 设计思路(其实大部分就是alas的设计)
+<br><br>
 
-<details>
-<summary></summary>
+# OnmyojiAutoScript
 
-### 核心
+<br>
 
-- 多实例化:简单理解为不同的模拟器配置或者是不同的任务配置,每个实例由一个config.json文件来驱动。Config来管理任务的调度,配置任务的不同的参数。
-- 全程接管:阴阳师已经走过了颠覆时期,三次元痒痒鼠玩家本应游戏中畅行无阻,而游戏世界7x24永续航。
-- 游戏通用:我们在参考Alas时发现其同碧蓝航线有很强的耦合性,于此设计该项目将减少同阴阳师的耦合,因此你可以fork该项目使用到你的游戏脚本上
-- 操作格式化:对于每个任务的执行过程就是比较常规的截图+控制,我们选择同[早期的设计](https://github.com/runhey/Uowl)一致,设计一个原子化的模块化的配置信息。比如说要识别某个图片会添加一份json数据来设置识图的范围、方式、识别的图片。点击的话也会有一份json数据配置点击的随机概率、范围等等。每一个操作都一份可格式化的配置信息,而不是同alas一样将识别图片和点击一起抽象成一个button。
+<div>
+    <img alt="python" src="https://img.shields.io/badge/python-3.10-%233776AB?logo=python">
+</div>
+<div>
+    <img alt="platform" src="https://img.shields.io/badge/platform-Windows-blueviolet">
+</div>
+<div>
+    <img alt="license" src="https://img.shields.io/github/license/runhey/OnmyojiAutoScript">
+    <img alt="GitHub repo size" src="https://img.shields.io/github/repo-size/runhey/OnmyojiAutoScript">
+    <img alt="GitHub all releases" src="https://img.shields.io/github/downloads/runhey/OnmyojiAutoScript/total">
+    <img alt="stars" src="https://img.shields.io/github/stars/runhey/OnmyojiAutoScript?style=social">
+</div>
+<br>
 
+阴阳师 自动化 脚本 
 
+基于图像识别技术,一键托管
 
-### 设计架构
+绝赞更新中✿✿ヽ(°▽°)ノ✿<br>
 
-- 部署方式:batchfile + python(env+pip) + git 。具体的说就是,需要先下载一个安装包里面包含一个最小python和git环境,运行后下拉仓库,完事后安装依赖,再完事后启动gui。
+### [文档](https://runhey.github.io/OnmyojiAutoScript-website/)
 
-- GUI实现:  用的是这个库[FluentUI for QML ](https://github.com/zhuzichu520/FluentUI).是用的qml来写,我想懂这个语言的人不多吧,跟python通信一个是靠注入上下文,另一个是靠zerorpc。
+</div>
 
-- 程序入口:  有两个根目录下的gui.py和script.py。而gui.py会根据配置文件config.json来实例化不同的script,script就是某个具体的脚本过程。
 
-- 脚本进程:  gui启动自带一个进程,每有一个script就会继续多一个进程,单独建一个进程来提供ocr服务。一般用zerorpc来进程通信。
+## 许可证 LICENSE
 
-- 运行过程:  gui 按钮点击后就会开始从script上启动服务。script持有一个设备device,一个配置config,一个任务task。这个时候调度器(其实就是config)会更新出running、pending and waiting tasks。选择runing的去执行,任务的执行过程就是一个大的状态机。
+This project is licensed under the GNU General Public License v3.0.
 
+## 声明 Announcement
+本软件开源、免费,仅供学习交流使用。开发者团队拥有本项目的最终解释权。使用本软件产生的所有问题与本项目与开发者团队无关。
 
-### 模块设计
+## 鸣谢 Acknowledgements
 
+感谢所有参与到开发/测试中的朋友们
 
-</details>    
+[![Contributors](https://contributors-img.web.app/image?repo=runhey/OnmyojiAutoScript)](https://github.com/runhey/OnmyojiAutoScript/graphs/contributors)
 
+<div align="center">
 
+## Star History
 
-## SETUP
+[![Star History Chart](https://api.star-history.com/svg?repos=runhey/OnmyojiAutoScript&type=Date)](https://star-history.com/#runhey/OnmyojiAutoScript&Date)
 
-oas目前还在开发中,我们期待你的加入,Q群: 465946275
 
-### 浅尝即可
+## ⚡ Visitor count
 
-如果单纯了解本项目,你可以下载[最新发布](https://github.com/runhey/OnmyojiAutoScript/releases),会自动安装环境。
+![](https://profile-counter.glitch.me/runhey-OnmyojiAutoScript/count.svg)
 
-具体为:下载->解压->打开`oas.exe`, 稍等一两分钟待环境安装好后即可启动
-
-### 参与开发
-
-1. 打开本项目[主仓库](https://github.com/runhey/OnmyojiAutoScript/tree/master), 点击右上角的 `Fork`,然后点击下面绿色的 `Create fork`
-
-2. 进入自己账号下的 oas仓库,并 `clone` 其中的 `dev` 分支到本地
-	```
-	git clone url -b dev
-	```
-
-3. 下载[最新环境包](https://github.com/runhey/OnmyojiAutoScript/releases), 解压复制`toolkit`,`deploy`两个文件夹和`console.bat`到本地的仓库根目录,`toolkit`里面包含python最小环境、git环境和GUI启动环境。
-
-3. 安装pip库, 安装后你可以执行`gui.py`启动进行测试
-
-   ```
-   ./toolkit/python.exe -m pip install -r requirements.txt 
-   ```
-   
-5. 此时你可以进行开发了,建议完成所有功能/任务后,再提交 `commit`, 别忘了按照下面的 `统一格式` 写上 `message`
-
-   ```
-   git commit -m 'message'
-   ```
-   >`message`的统一格式
-   >```
-   >doc(your part): your changes
-   >feat(module name): your add
-   >fix(module name): your fix
-   >```
-
-6. 完成开发后,推送本地分支到自己的仓库
-
-   ```
-   git push -u origin
-   ```
-
-   > 第一次 `push` 代码需要按照提示设置上传流(`--set-upstream`)
-
-5. 打开 [主仓库](https://github.com/runhey/OnmyojiAutoScript/tree/master)。提交一个 `pull request` (会自动携带你 `commit` 的信息),等待管理员通过。注意:要提交到 `dev` 分支上,别提交到 `master` 分支去了
-
-### 开发IDE
-
-- Pycharm
-- QtCreator:  用于qml开发
-- Linguist: Qt家的翻译器
-
-## NEXT
-
-| 进度表                                                       |
-| :----------------------------------------------------------- |
-| ✔自动化部署                                                  |
-| ✔GUI引入工程                                                 |
-| ✔config读写参数字段                                          |
-| ✔优化window截图+控制                                         |
-| ✔投屏到OAS                                                   |
-| 🔨操作格式化json生成工具:可以从用户界面简单操作生成维护数据(包括✔图片匹配,✔点击操作,✔长按操作,✔滑动操作,ocr识别等等) |
-| ✔Atom: 对于上一条数据的接口                                  |
-| 📆实现ocr单独进程                                             |
-| 🔨到此我们可以(读参数)、(对游戏截屏控制)、(操控数据)。实现第一个脚本任务如挖土 |
-| 📆重写device(从alas复制过来需要解耦)                          |
-|                                                              |
-
-| **更多**        | 难题             |
-| --------------- | ---------------- |
-| 📆实现更多的任务 | 如何输出Log到GUI |
-| 📆建立任务调度   | 优化速度         |
-|                 |                  |
+</div>

+ 56 - 0
module/atom/ocr.py

@@ -1,3 +1,59 @@
 # This Python file uses the following encoding: utf-8
 # @author runhey
 # github https://github.com/runhey
+
+import numpy as np
+import cv2
+
+from module.ocr.base_ocr import BaseCor, OcrMode, OcrMethod
+from module.ocr.sub_ocr import Full, Single, Digit, DigitCounter, Duration
+from module.logger import logger
+
+
+
+class RuleOcr(Digit, DigitCounter, Duration, Single, Full):
+
+    def __init__(self, *args, **kwargs):
+        super().__init__(*args, **kwargs)
+
+
+    def after_process(self, result):
+        match self.mode:
+            case OcrMode.FULL: return Full.after_process(self, result)
+            case OcrMode.SINGLE: return Single.after_process(self, result)
+            case OcrMode.DIGIT: return Digit.after_process(self, result)
+            case OcrMode.DIGITCOUNTER: return DigitCounter.after_process(self, result)
+            case OcrMode.DURATION: return Duration.after_process(self, result)
+            case _: return result
+
+    def ocr(self, image, keyword=None):
+
+        match self.mode:
+            case OcrMode.FULL: return Full.ocr_full(self, image, keyword)
+            case OcrMode.SINGLE: return Single.ocr_single(self, image)
+            case OcrMode.DIGIT: return Digit.ocr_digit(self, image)
+            case OcrMode.DIGITCOUNTER: return DigitCounter.ocr_digit_counter(self, image)
+            case OcrMode.DURATION: return Duration.ocr_duration(self, image)
+            case _: return None
+
+    def coord(self) -> tuple:
+        """
+        获取一个区域,随机返回一个坐标
+        :return:
+        """
+        area = None
+        if self.mode == OcrMode.FULL:
+            area = self.area
+        else:
+            area = self.roi
+
+        x, y, w, h = self.area
+        x = np.random.randint(x, x + w)
+        y = np.random.randint(y, y + h)
+        return x, y
+
+
+
+if __name__ == "__main__":
+    pass
+

+ 5 - 1
module/base/log_highlighter.py

@@ -4,6 +4,10 @@
 import re
 from html import escape
 
+def replace_newline_with_br(input_text):
+    replaced_text = input_text.replace('\n', '<br>')
+    return replaced_text
+
 def highlight_text(input_text):
     color_mapping = {
         r'\d{2}:\d{2}:\d{2}\.\d{3}': 'cyan',
@@ -19,7 +23,7 @@ def highlight_text(input_text):
     for pattern, color in color_mapping.items():
         input_text = re.sub(pattern, f'<span style="color: {color}">\\g<0></span>', input_text)
 
-    return input_text + '<br>'
+    return replace_newline_with_br(input_text)
 
 # 测试
 # input_string = 'The time is 13:20:36.411. Is it True or False? DEBUG: This is a debug message. INFO: This is an info message. WARNING: This is a warning message. ERROR: This is an error message. CRITICAL: This is a critical message.'

+ 5 - 3
module/config/config_menu.py

@@ -16,12 +16,14 @@ class ConfigMenu:
         self.menu["Overview"] = []
         # 脚本设置
         self.menu['Script'] = ['Script', 'General', 'Restart', 'GlobalGame']
-        # 开发工具
-        self.menu["Tools"] = ['Image Rule', 'Ocr Rule', 'Click Rule', 'Long Click Rule', 'Swipe Rule']
         # 刷御魂
         self.menu["Soul Zones"] = ['Orochi', 'OrochiMoans', 'OrochiJudgement', 'Sougenbi', 'FallenSun', 'EternitySea']
         # 日常的任务
-        self.menu["Daily Task"] = ['AreaBoss', 'GoldYoukai', 'ExperienceYoukai', 'Nian']
+        self.menu["Daily Task"] = ['AreaBoss', 'GoldYoukai', 'ExperienceYoukai', 'Nian', 'RealmRaid']
+
+        # 开发工具
+        self.menu["Tools"] = ['Image Rule', 'Ocr Rule', 'Click Rule', 'Long Click Rule', 'Swipe Rule']
+
     @cached_property
     def gui_menu(self) -> str:
         """

+ 3 - 1
module/config/config_model.py

@@ -23,6 +23,7 @@ from tasks.OrochiJudgement.config import OrochiJudgement
 from tasks.Sougenbi.config import Sougenbi
 from tasks.FallenSun.config import FallenSun
 from tasks.EternitySea.config import EternitySea
+from tasks.RealmRaid.config import RealmRaid
 
 
 
@@ -34,11 +35,12 @@ class ConfigModel(BaseModel):
     restart: Restart = Field(default_factory=Restart)
     global_game: GlobalGame = Field(default_factory=GlobalGame)
 
-    # 这些是每日人物的
+    # 这些是每日任务的
     area_boss: AreaBoss = Field(default_factory=AreaBoss)
     experience_youkai: ExperienceYoukai = Field(default_factory=ExperienceYoukai)
     gold_youkai: GoldYoukai = Field(default_factory=GoldYoukai)
     nian: Nian = Field(default_factory=Nian)
+    realm_raid: RealmRaid = Field(default_factory=RealmRaid)
 
     # 这些是刷御魂的
     orochi: Orochi = Field(default_factory=Orochi)

+ 68 - 0
module/config/config_modify.py

@@ -0,0 +1,68 @@
+# This Python file uses the following encoding: utf-8
+# @author runhey
+# github https://github.com/runhey
+from module.config.config import Config
+from module.config.utils import convert_to_underscore
+from module.config.config_model import ConfigModel
+
+from module.logger import logger
+from pydantic import BaseModel, ValidationError
+
+
+
+class ConfigModify(Config):
+    """
+    这个类的出现是为了修补一个架构问题:
+    不同于Alas,我默认用户在GUI界面点击的时候就启动了脚本进程,初始化会直接同时初始化一个config和一个device
+    如果用户配置不对这个进程直接挂掉了,用户甚至没有修改config的机会,即时重启了也会由于没有修改config而再次挂掉
+
+    因此这个类的出现是为了在脚本进程挂掉的时候,用户可以修改config,然后再次启动脚本进程
+
+
+    """
+
+    def __init__(self, config: str) -> None:
+        super().__init__(config)
+
+
+    def gui_args(self, task: str) -> str:
+        """
+        获取给gui显示的参数
+        :return:
+        """
+        return super().gui_args(task=task)
+
+    def gui_task(self, task: str) -> str:
+        """
+        获取给gui显示的任务 的参数的具体值
+        :return:
+        """
+        return self.model.gui_task(task=task)
+
+    def gui_set_task(self, task: str, group: str, argument: str, value) -> bool:
+        """
+        设置给gui显示的任务 的参数的具体值
+        :return:
+        """
+        task = convert_to_underscore(task)
+        group = convert_to_underscore(group)
+        argument = convert_to_underscore(argument)
+
+        path = f'{task}.{group}.{argument}'
+        task_object = getattr(self.model, task, None)
+        group_object = getattr(task_object, group, None)
+        argument_object = getattr(group_object, argument, None)
+
+        if argument_object is None:
+            logger.error(f'gui_set_task {task}.{group}.{argument}.{value} failed')
+            return False
+
+        try:
+            setattr(group_object, argument, value)
+            argument_object = getattr(group_object, argument, None)
+            logger.info(f'gui_set_task {task}.{group}.{argument}.{argument_object}')
+            super().save()  # 我是没有想到什么方法可以使得属性改变自动保存的
+            return True
+        except ValidationError as e:
+            logger.error(e)
+            return False

+ 52 - 7
module/dev_tools/assets_extract.py

@@ -17,6 +17,7 @@ from module.atom.image import RuleImage
 from module.atom.click import RuleClick
 from module.atom.long_click import RuleLongClick
 from module.atom.swipe import RuleSwipe
+from module.atom.ocr import RuleOcr
 
 # This file was automatically generated by module/dev_tools/assets_extract.py.
 # Don't modify it manually.
@@ -49,7 +50,7 @@ class ImageExtractor:
         self.file = str(Path(file).resolve().relative_to((Path.cwd()).resolve()).as_posix())
         self.image_path = Path(self.file).parent.as_posix()
 
-        self._result = '\n\t# Image Rule Assets\n'
+        self._result = '\n\n\t# Image Rule Assets\n'
         for item in data:
             self._result += self.extract_item(item)
 
@@ -80,7 +81,7 @@ class ClickExtractor:
         click rule 提取
         :param data:  json解析后的数据
         """
-        self._result = '\t# Click Rule Assets\n'
+        self._result = '\n\n\t# Click Rule Assets\n'
         for item in data:
             self._result += self.extract_item(item)
 
@@ -108,7 +109,7 @@ class LongClickExtractor:
         long click rule 提取
         :param data:  json解析后的数据
         """
-        self._result = '\t# Long Click Rule Assets\n'
+        self._result = '\n\n\t# Long Click Rule Assets\n'
         for item in data:
             self._result += self.extract_item(item)
 
@@ -137,7 +138,7 @@ class SwipeExtractor:
         swipe rule 提取
         :param data:  json解析后的数据
         """
-        self._result = '\t# Swipe Rule Assets\n'
+        self._result = '\n\n\t# Swipe Rule Assets\n'
         for item in data:
             self._result += self.extract_item(item)
 
@@ -159,6 +160,36 @@ class SwipeExtractor:
                     f'name="{item["itemName"]}")\n'
         return description + name
 
+class OcrExtractor:
+    def __init__(self, file: str, data: list) -> None:
+        """
+        swipe rule 提取
+        :param data:  json解析后的数据
+        """
+        self._result = '\n\n\t# Ocr Rule Assets\n'
+        for item in data:
+            self._result += self.extract_item(item)
+
+    @property
+    def result(self) -> str:
+        return self._result
+
+    @classmethod
+    def extract_item(cls, item) -> str:
+        """
+        解析每一项,返回字符串
+        :param item:
+        :return:
+        """
+        description: str = f'\t# {item["description"]} \n'
+        name: str = f'\tO_{name_transform(item["itemName"])} = RuleOcr(' \
+                    f'roi=({item["roiFront"]}), ' \
+                    f'area=({item["roiBack"]}), ' \
+                    f'mode="{item["mode"]}", ' \
+                    f'method="{item["method"]}", ' \
+                    f'keyword="{item["keyword"]}", ' \
+                    f'name="{item["itemName"]}")\n'
+        return description + name
 
 class AssetsExtractor:
 
@@ -237,12 +268,24 @@ class AssetsExtractor:
     @classmethod
     def is_swipe_file(cls, data: list) -> bool:
         """
-        判断是不是swiperule 文件
+        判断是不是swipe rule 文件
+        :param data: 解析后的json数据,是list
+        :return:
+        """
+        item = data[0]
+        if 'mode' in item and len(item) == 5:
+            return True
+        return False
+
+    @classmethod
+    def is_ocr_file(cls, data: list) -> bool:
+        """
+        判断是不是ocr 文件
         :param data: 解析后的json数据,是list
         :return:
         """
         item = data[0]
-        if 'mode' in item:
+        if 'keyword' in item:
             return True
         return False
 
@@ -272,6 +315,8 @@ class AssetsExtractor:
                 result += LongClickExtractor(file, data).result
             elif self.is_swipe_file(data):
                 result += SwipeExtractor(file, data).result
+            elif self.is_ocr_file(data):
+                result += OcrExtractor(file, data).result
 
         if result == '':
             logger.error(f'There are no resource files under the {self.task_name} task')
@@ -300,6 +345,6 @@ class AllAssetsExtractor:
 
 
 if __name__ == "__main__":
-    # c = AssetsExtractor('GeneralBattle')
+    # c = AssetsExtractor('CoinChallenge')
     # c.extract()
     AllAssetsExtractor()

+ 5 - 4
module/device/method/window.py

@@ -132,23 +132,24 @@ class Window(Handle):
 
         x = int(x / self.window_scale_rate)
         y = int(y / self.window_scale_rate)
+        mumu_head_height = int(36/self.window_scale_rate)
         # print(f"我点击的x:{x}, y:{y}")
         emulator_type = len(self.control_handle_list)
         if emulator_type == 2:  # mumu模拟器
-            SendMessage(self.control_handle_list[0], WM_LBUTTONDOWN, 0, MAKELONG(x, y))  # 模拟鼠标按下 先是父窗口 上面的框高度是57
-            time.sleep((random.randint(200, 400)) / 1000.0)  # 点击弹起改为随机,时间100ms-200ms
+            SendMessage(self.control_handle_list[0], WM_LBUTTONDOWN, 0, MAKELONG(x, y+mumu_head_height))  # 模拟鼠标按下 先是父窗口 上面的框高度是57
+            time.sleep((random.randint(100, 200)) / 1000.0)  # 点击弹起改为随机,时间100ms-200ms
             SendMessage(self.control_handle_list[1], WM_LBUTTONUP, 0, MAKELONG(x, y))  # 模拟鼠标弹起 后是子窗口
         elif emulator_type > 2:  # 夜神模拟器
             SendMessage(self.control_handle_list[0], WM_LBUTTONDOWN, 0, MAKELONG(x, y))  # 模拟鼠标按下 先是父窗口 上面的框高度是57
             SendMessage(self.control_handle_list[1], WM_LBUTTONDOWN, 0, MAKELONG(x, y))
             SendMessage(self.control_handle_list[2], WM_LBUTTONDOWN, 0, MAKELONG(x, y))
             SendMessage(self.control_handle_list[3], WM_LBUTTONDOWN, 0, MAKELONG(x, y))
-            time.sleep((random.randint(200, 400)) / 1000.0)  # 点击弹起改为随机,时间100ms-200ms
+            time.sleep((random.randint(100, 200)) / 1000.0)  # 点击弹起改为随机,时间100ms-200ms
             SendMessage(self.control_handle_list[3], WM_LBUTTONUP, 0, MAKELONG(x, y))  # 模拟鼠标弹起 后是子窗口
         elif emulator_type == 1:  # 雷电模拟器
             clickPos = MAKELONG(x, y)
             SendMessage(self.control_handle_list[0], WM_LBUTTONDOWN, 0, clickPos)  # 模拟鼠标按下
-            time.sleep((random.randint(200, 400)) / 1000.0)  # 点击弹起改为随机,时间100ms-200ms
+            time.sleep((random.randint(100, 300)) / 1000.0)  # 点击弹起改为随机,时间100ms-200ms
             SendMessage(self.control_handle_list[0], WM_LBUTTONUP, 0, clickPos)  # 模拟鼠标弹起
 
     def long_click_window_message(self, x: int, y: int, duration: float):

+ 21 - 4
module/gui/context/process_manager.py

@@ -24,6 +24,7 @@ from threading import Thread
 from module.base.log_highlighter import highlight_text
 from module.gui.process.script_process import ScriptProcess
 from module.config.config_menu import ConfigMenu
+from module.config.config_modify import ConfigModify
 from module.gui.context.add import Add
 from module.logger import logger
 
@@ -63,6 +64,7 @@ class ProcessManager(QObject):
         """
         super().__init__()
         self.processes: Dict[str, ScriptProcess] = {}  # 持有所有的进程
+        self.configs: Dict[str, ConfigModify] = {}  # 持有所有的配置, 权宜之计
         self.ports: Dict[str, int] = {}  # 持有所有的端口
         self.clients = {}  # zerorpc连接的客户端
 
@@ -145,7 +147,7 @@ class ProcessManager(QObject):
         """
         if config in self.processes:
             if not self.processes[config].is_alive():  # 如果进程已经死亡,那么就重新启动
-                logger.info(f'restart script {config}')
+                logger.info(f'{config} process is dead, restart it')
 
 
             self.processes[config].terminate()  # 强制结束进程
@@ -208,6 +210,21 @@ class ProcessManager(QObject):
         menu = ConfigMenu()
         return menu.gui_menu
 
+    def check_script(self, config: str):
+        """
+        检查脚本是否存在
+        :param config:
+        :return:
+        """
+        if config in self.processes and self.processes[config].is_alive():  # 如果脚本进程存在
+            if config in self.configs:
+                del self.configs[config]
+            return self.clients[config]
+        else:
+            if config not in self.configs:
+                self.configs[config] = ConfigModify(config)  # 初始化一个
+            return self.configs[config]
+
     @Slot(str, str, result="QString")
     def gui_args(self, config: str, task: str) -> str:
         """
@@ -218,7 +235,7 @@ class ProcessManager(QObject):
         """
         if config in self.clients:
             logger.info(f'gui get args of {config} {task}')
-            return self.clients[config].gui_args(task)
+            return self.check_script(config).gui_args(task)
         else:
             logger.info(f'script {config} is not running')
             return None
@@ -233,7 +250,7 @@ class ProcessManager(QObject):
         """
         if config in self.clients:
             logger.info(f'gui get value of {config} {task}')
-            return self.clients[config].gui_task(task)
+            return self.check_script(config).gui_task(task)
         else:
             logger.info(f'script {config} is not running')
             return None
@@ -251,7 +268,7 @@ class ProcessManager(QObject):
         """
         if config in self.clients:
             logger.info(f'gui set value of {config} {task}')
-            if self.clients[config].gui_set_task(task, group, arg, value):
+            if self.check_script(config).gui_set_task(task, group, arg, value):
                 return True
             else:
                 return False

+ 1 - 1
module/gui/qml/Component/Overview.qml

@@ -296,7 +296,7 @@ Item {
             anchors.fill: parent
         FluText{
             id: textLog
-            width: parent.width
+            width: parent.width-10
             padding: 10
             clip: true
             wrapMode: Text.WordWrap // 设置自动换行模式

+ 0 - 1
module/gui/qml/Component/SplitPanel.qml

@@ -38,7 +38,6 @@ Item {
 
         onLoaded: {
             if(typeof contentDefalut.item.splitPanel === "undefined"){
-                console.debug('还没有属性')
                 return
             }
 

+ 1 - 1
module/gui/qml/Content/ClickRule.qml

@@ -313,7 +313,7 @@ Item {
             data.push(itemData)
         }
 
-        ruleFile.rule_file.write_file(ruleFile.file, JSON.stringify(data))
+        ruleFile.rule_file.write_file(ruleFile.file, JSON.stringify(data, null, "  "))
         showSuccess("Save file")
 
     }

+ 1 - 1
module/gui/qml/Content/ImageRule.qml

@@ -341,7 +341,7 @@ Item {
             data.push(itemData)
         }
 
-        ruleFile.rule_file.write_file(ruleFile.file, JSON.stringify(data))
+        ruleFile.rule_file.write_file(ruleFile.file, JSON.stringify(data, null, "  "))
         showSuccess("Save file")
 
     }

+ 1 - 1
module/gui/qml/Content/LongClickRule.qml

@@ -272,7 +272,7 @@ Item {
             data.push(itemData)
         }
 
-        ruleFile.rule_file.write_file(ruleFile.file, JSON.stringify(data))
+        ruleFile.rule_file.write_file(ruleFile.file, JSON.stringify(data, null, "  "))
         showSuccess("Save file")
 
     }

+ 354 - 1
module/gui/qml/Content/OcrRule.qml

@@ -1,5 +1,358 @@
-import QtQuick 2.0
+import QtQuick
+import QtQuick.Controls
+import FluentUI
+import "../Component"
 
 Item {
 
+    MirrorImage{
+        id: mirrorImage
+        anchors{
+            left: parent.left
+            top: parent.top
+        }
+        width: 1280
+        height: 720 + 50
+        imageWidth: 1280
+        imageHeight: 720
+
+        onRoi_red_changed: function(roi){
+            if(typeof ruleFile.currentItem === "undefined"){
+                return
+            }
+            ruleFile.currentItem.roiFront = roi
+        }
+
+        onRoi_green_changed: function(roi){
+            if(typeof ruleFile.currentItem === "undefined"){
+                return
+            }
+            ruleFile.currentItem.roiBack = roi
+        }
+    }
+    RuleFile{
+        id: ruleFile
+        anchors{
+            left: mirrorImage.right
+            leftMargin: 10
+            right: parent.right
+            top: parent.top
+        }
+        height: 600
+        addFunc: add
+        editFunc: edit
+        saveFunc: save
+
+        onCurrentItemChanged: {
+            if(currentItem === "" || typeof currentItem === "undefined"){
+                return
+            }
+            var [x, y, width, height] = currentItem.roiFront.split(',')
+            mirrorImage.roiRed_x = parseInt(x)
+            mirrorImage.roiRed_y = parseInt(y)
+            mirrorImage.roiRed_width = parseInt(width)
+            mirrorImage.roiRed_height = parseInt(height)
+            var [x, y, width, height] = currentItem.roiBack.split(',')
+            mirrorImage.roiGreen_x = parseInt(x)
+            mirrorImage.roiGreen_y = parseInt(y)
+            mirrorImage.roiGreen_width = parseInt(width)
+            mirrorImage.roiGreen_height = parseInt(height)
+
+        }
+    }
+
+    FluArea {
+        id: ruleArea
+        anchors{
+            left: mirrorImage.right
+            leftMargin: 10
+            right: parent.right
+            top: ruleFile.bottom
+            topMargin: 12
+            bottom: parent.bottom
+        }
+        Column{
+            id: coi
+            anchors{
+                top: parent.top
+                bottom: parent.bottom
+                left: parent.left
+                leftMargin: 20
+                right: parent.right
+                rightMargin: 20
+            }
+            spacing: 5
+            //头
+            Item{
+                width: coi.width
+                height: 40
+                FluText{
+                    anchors.left: parent.left
+                    anchors.verticalCenter: parent.verticalCenter
+                    text: "Editing rule"
+                    font: FluTextStyle.Subtitle
+                }
+            }
+            //item name 这个参数项的名称
+            Item{
+                width: coi.width
+                height: 40
+                FluText{
+                    anchors.left: parent.left
+                    anchors.verticalCenter: parent.verticalCenter
+                    text: "Item name"
+                    font: FluTextStyle.BodyStrong
+                }
+                FluTextBox{
+                    id: itemName
+                    anchors{
+                        right: parent.right
+                        verticalCenter: parent.verticalCenter
+                    }
+                    placeholderText:"单行输入框"
+                    disabled: true
+                    text: (typeof ruleFile.currentItem === "undefined")? "" : ruleFile.currentItem.itemName
+                    width: 200
+                }
+            }
+
+            // roi front
+            Item{
+                width: coi.width
+                height: 40
+                FluText{
+                    anchors.left: parent.left
+                    anchors.verticalCenter: parent.verticalCenter
+                    text: "Roi front"
+                    font: FluTextStyle.BodyStrong
+                }
+                FluTextBox{
+                    id: roiFront
+                    anchors{
+                        right: parent.right
+                        verticalCenter: parent.verticalCenter
+                    }
+                    disabled: true
+                    text:(typeof ruleFile.currentItem === "undefined")? "" : ruleFile.currentItem.roiFront
+                    placeholderText:"0,0,100,100"
+                    width: 200
+                }
+            }
+            //roi back
+            Item{
+                width: coi.width
+                height: 40
+                FluText{
+                    anchors.left: parent.left
+                    anchors.verticalCenter: parent.verticalCenter
+                    text: "Roi Back"
+                    font: FluTextStyle.BodyStrong
+                }
+                FluTextBox{
+                    id: roiBack
+                    anchors{
+                        right: parent.right
+                        verticalCenter: parent.verticalCenter
+                    }
+                    disabled: true
+                    text:(typeof ruleFile.currentItem === "undefined")? "" : ruleFile.currentItem.roiBack
+                    placeholderText:"0,0,100,100"
+                    width: 200
+
+
+                }
+            }
+            //ocr 模式
+            Item{
+                width: coi.width
+                height: 40
+                FluText{
+                    anchors.left: parent.left
+                    anchors.verticalCenter: parent.verticalCenter
+                    text: "Mode"
+                    font: FluTextStyle.BodyStrong
+                }
+                FComboBox{
+                    id: mode
+                    anchors{
+                        right: parent.right
+                        verticalCenter: parent.verticalCenter
+                    }
+                    width: 200
+                    model: ["Single", "Full", "Digit", "DigitCounter", "Duration"]
+                    currentIndex: if(typeof ruleFile.currentItem !== "undefined"){
+                                     if(ruleFile.currentItem.mode === "Single"){
+                                         return 0
+                                     }else if(ruleFile.currentItem.mode === "Full"){
+                                         return 1
+                                     }else if(ruleFile.currentItem.mode === "Digit"){
+                                         return 2
+                                     }else if(ruleFile.currentItem.mode === "DigitCounter"){
+                                         return 3
+                                     }else if(ruleFile.currentItem.mode === "Duration"){
+                                         return 4
+                                     }
+                                  }else{return 0}
+                    onActivated: {
+                        if(currentIndex === 0){
+                            ruleFile.currentItem.mode = "Single"
+                        }
+                        else if(currentIndex === 1){
+                            ruleFile.currentItem.mode = "Full"
+                        }
+                        else if(currentIndex === 2){
+                            ruleFile.currentItem.mode = "Digit"
+                        }
+                        else if(currentIndex === 3){
+                            ruleFile.currentItem.mode = "DigitCounter"
+                        }
+                        else if(currentIndex === 4){
+                            ruleFile.currentItem.mode = "Duration"
+                        }
+                    }
+                }
+            }
+            // ocr 方法
+            Item{
+                width: coi.width
+                height: 40
+                FluText{
+                    anchors.left: parent.left
+                    anchors.verticalCenter: parent.verticalCenter
+                    text: "Method"
+                    font: FluTextStyle.BodyStrong
+                }
+                FComboBox{
+                    id: method
+                    anchors{
+                        right: parent.right
+                        verticalCenter: parent.verticalCenter
+                    }
+                    width: 200
+                    currentIndex: 0
+                    model: ["Default"]
+                    onActivated: {
+
+                    }
+                }
+            }
+            //keyword 匹配字段
+            Item{
+                width: coi.width
+                height: 40
+                FluText{
+                    anchors.left: parent.left
+                    anchors.verticalCenter: parent.verticalCenter
+                    text: "Keyword"
+                    font: FluTextStyle.BodyStrong
+                }
+                FluTextBox{
+                    id: keyword
+                    anchors{
+                        right: parent.right
+                        verticalCenter: parent.verticalCenter
+                    }
+                    width: 200
+                    text:(typeof ruleFile.currentItem === "undefined")? "" : ruleFile.currentItem.keyword
+                    placeholderText:""
+                    onEditingFinished: {
+                        if(typeof ruleFile.currentItem === "undefined"){
+                            return
+                        }
+                        ruleFile.currentItem.keyword = text
+                    }
+                }
+            }
+
+            //描述 description
+            Item{
+                width: coi.width
+                height: 40
+                FluText{
+                    anchors.left: parent.left
+                    anchors.verticalCenter: parent.verticalCenter
+                    text: "Description"
+                    font: FluTextStyle.BodyStrong
+                }
+                FluTextBox{
+                    id: description
+                    anchors{
+                        right: parent.right
+                        verticalCenter: parent.verticalCenter
+                    }
+                    width: 200
+                    text:(typeof ruleFile.currentItem === "undefined")? "" : ruleFile.currentItem.description
+                    placeholderText:"input your description"
+                    onEditingFinished: {
+                        if(typeof ruleFile.currentItem === "undefined"){
+                            return
+                        }
+                        ruleFile.currentItem.description = text
+                    }
+                }
+            }
+
+        }
+
+    }
+
+    // 帮助
+    FluArea{
+        id: ruleHelp
+        anchors{
+            left: parent.left
+            right: ruleArea.left
+            rightMargin: 10
+            top: mirrorImage.bottom
+            topMargin: 10
+            bottom: parent.bottom
+        }
+        FluText{
+            leftPadding: 12
+            topPadding: 12
+            text: "红色的框(Roi front = roi)表示这一个项OCR识别的默认范围,绿色的框(Roi Back = area)表示如果识别到会点击的的范围。
+在移动边框时右边的roi并不会实时显示,当切换软件的焦点时更新显示,但是具体的数值是更新的。
+投屏的设置最上边点击即可"
+        }
+
+    }
+
+    function add(){
+        const item ={}
+        item["itemName"] = "new"
+        item["roiFront"] = "0,0,100,100"
+        item["roiBack"] = "0,0,100,100"
+        item["mode"] = "Single"
+        item["method"] = "Default"
+        item["keyword"] = ""
+        item["description"] = "Ocr-description"
+        showSuccess("Add new item")
+        return item
+    }
+
+    function edit(model){
+
+    }
+
+    function save(){
+        const data = []
+        for(var i=0; i<ruleFile.list_model.count; i++){
+            const item = ruleFile.list_model.get(i)
+            const itemData = {}
+            itemData["itemName"] = item["itemName"]
+            itemData["roiFront"] = item["roiFront"]
+            itemData["roiBack"] = item["roiBack"]
+            itemData["mode"] = item["mode"]
+            itemData["method"] = item["method"]
+            itemData["keyword"] = item["keyword"]
+            itemData["description"] = item["description"]
+            data.push(itemData)
+        }
+
+        ruleFile.rule_file.write_file(ruleFile.file, JSON.stringify(data, null, "  "))
+        showSuccess("Save file")
+
+    }
+
+
 }

+ 2 - 2
module/gui/qml/Content/SwipeRule.qml

@@ -163,7 +163,7 @@ Item {
 
                 }
             }
-            //长按的时间间隔
+            //滑动模式
             Item{
                 width: coi.width
                 height: 40
@@ -282,7 +282,7 @@ Item {
             data.push(itemData)
         }
 
-        ruleFile.rule_file.write_file(ruleFile.file, JSON.stringify(data))
+        ruleFile.rule_file.write_file(ruleFile.file, JSON.stringify(data, null, "  "))
         showSuccess("Save file")
 
     }

+ 220 - 0
module/ocr/base_ocr.py

@@ -0,0 +1,220 @@
+# This Python file uses the following encoding: utf-8
+# @author runhey
+# github https://github.com/runhey
+import time
+import cv2
+import numpy as np
+
+from ppocronnx.predict_system import BoxedResult
+from enum import Enum
+
+
+from module.base.decorator import cached_property
+from module.base.utils import area_pad, crop, float2str
+from module.ocr.ppocr import TextSystem
+from module.ocr.models import OCR_MODEL
+from module.exception import ScriptError
+from module.logger import logger
+
+
+class OcrMode(Enum):
+    FULL = 1  # str: "Full"
+    SINGLE = 2  # str: "Single"
+    DIGIT = 3  # str: "Digit"
+    DIGITCOUNTER = 4  # str: "DigitCounter"
+    DURATION = 5  # str: "Duration"
+
+class OcrMethod(Enum):
+    DEFAULT = 1  # str: "Default"
+
+class BaseCor:
+
+    lang: str = "ch"
+    score: float = 0.6  # 阈值默认为0.5
+
+    name: str = "ocr"
+    mode: OcrMode = OcrMode.FULL
+    method: OcrMethod = OcrMethod.DEFAULT  # 占位符
+    roi: list = []  # [x, y, width, height]
+    area: list = []  # [x, y, width, height]
+    keyword: str = ""  # 默认为空
+
+
+    def __init__(self,
+                 name: str,
+                 mode: str,
+                 method: str,
+                 roi: tuple,
+                 area: tuple,
+                 keyword: str) -> None:
+        """
+
+        :param name:
+        :param mode:
+        :param method:
+        :param roi:
+        :param area:
+        :param keyword:
+        """
+        self.name = name
+        if isinstance(mode, str):
+            self.mode = OcrMode[mode.upper()]
+        elif isinstance(mode, OcrMode):
+            self.mode = mode
+        if isinstance(method, str):
+            self.method = OcrMethod[method.upper()]
+        elif isinstance(method, OcrMethod):
+            self.method = method
+        self.roi: list = list(roi)
+        self.area: list = list(area)
+        self.keyword = keyword
+
+    @cached_property
+    def model(self) -> TextSystem:
+        return OCR_MODEL.__getattribute__(self.lang)
+
+    def pre_process(self, image):
+        """
+        重写
+        :param image:
+        :return:
+        """
+        return image
+
+    def after_process(self, result):
+        """
+        重写
+        :param result:
+        :return:
+        """
+        return result
+
+    @classmethod
+    def crop(cls, image: np.array, roi: tuple) -> np.array:
+        """
+        截取图片
+        :param roi:
+        :param image:
+        :return:
+        """
+        x, y, w, h = roi
+        return image[y:y + h, x:x + w]
+
+    def ocr_item(self, image):
+        """
+        这个函数区别于ocr_single_line,这个函数不对图片进行裁剪,是什么就是什么的
+        :param image:
+        :return:
+        """
+        # pre process
+        start_time = time.time()
+        image = self.pre_process(image)
+        # ocr
+        result, score = self.model.ocr_single_line(image)
+        if score < self.score:
+            result = ""
+        # after proces
+        result = self.after_process(result)
+        logger.info("ocr result score: %s%s" % (result,score))
+        logger.attr(name='%s %ss' % (self.name, float2str(time.time() - start_time)),
+                    text=f'[{result}]')
+        return result
+
+    def ocr_single_line(self, image):
+        """
+        只支持横方向的单行ocr,不支持竖方向的单行ocr
+        注意:这里使用了预处理和后处理
+        :param image:
+        :return:
+        """
+        # pre process
+        start_time = time.time()
+        image = self.crop(image, self.roi)
+        image = self.pre_process(image)
+        # ocr
+        result, score = self.model.ocr_single_line(image)
+        if score < self.score:
+            result = ""
+        # after proces
+        result = self.after_process(result)
+        logger.info("ocr result score: %s" % score)
+        logger.attr(name='%s %ss' % (self.name, float2str(time.time() - start_time)),
+                    text=f'[{result}]')
+        return result
+
+    def detect_and_ocr(self, image) -> list[BoxedResult]:
+        """
+        注意:这里使用了预处理和后处理
+        :param image:
+        :return:
+        """
+        # pre process
+        start_time = time.time()
+        image = self.crop(image, self.roi)
+        image = self.pre_process(image)
+
+        # ocr
+        boxed_results: list[BoxedResult] = self.model.detect_and_ocr(image)
+        results = []
+        # after proces
+        for result in boxed_results:
+            logger.info("ocr result score: %s" % result.score)
+            if result.score < self.score:
+                continue
+            result.ocr_text = self.after_process(result.ocr_text)
+            results.append(result)
+
+        logger.attr(name='%s %ss' % (self.name, float2str(time.time() - start_time)),
+                    text=str([result.ocr_text for result in results]))
+        return results
+
+    def match(self, result: str, included: bool=False) -> bool:
+        """
+        使用ocr获取结果后和keyword进行匹配
+        :param result:
+        :param included:  ocr结果和keyword是否包含关系, 要么是包含关系,要么是相等关系
+        :return:
+        """
+        if included:
+            return self.keyword in result
+        else:
+            return self.keyword == result
+
+
+    def filter(self, boxed_results: list[BoxedResult], keyword: str=None) -> list:
+        """
+        使用ocr获取结果后和keyword进行匹配. 返回匹配的index list
+        :param keyword: 如果不指定默认适用对象的keyword
+        :param boxed_results:
+        :return:
+        """
+        # 首先先将所有的ocr的str顺序拼接起来, 然后再进行匹配
+        result = None
+        strings = [boxed_result.ocr_text for boxed_result in boxed_results]
+        concatenated_string = "".join(strings)
+        if keyword is None:
+            keyword = self.keyword
+        if keyword in concatenated_string:
+            result = [index for index, _ in enumerate(strings)]
+        else:
+            result = None
+
+        if result is not None:
+            # logger.info("Filter result: %s" % result)
+            return result
+
+        # 如果适用顺序拼接还是没有匹配到,那可能是竖排的,使用单个字节的keyword进行匹配
+        indices = []
+        for index, char in enumerate(keyword):
+            for i, string in enumerate(strings):
+                if char not in string:
+                    break
+                if i == len(strings) - 1:
+                    indices.append(index)
+        if indices:
+            return indices
+        else:
+            indices = None
+            return indices
+
+

+ 11 - 0
module/ocr/models.py

@@ -0,0 +1,11 @@
+from module.base.decorator import cached_property
+from module.ocr.ppocr import TextSystem
+
+
+class OcrModel:
+    @cached_property
+    def ch(self):
+        return TextSystem()
+
+
+OCR_MODEL = OcrModel()

+ 56 - 0
module/ocr/ppocr.py

@@ -0,0 +1,56 @@
+import ppocronnx.predict_system
+
+
+class TextSystem(ppocronnx.predict_system.TextSystem):
+    def __init__(
+            self,
+            use_angle_cls=False,
+            box_thresh=0.6,
+            unclip_ratio=1.6,
+            rec_model_path=None,
+            det_model_path=None,
+            ort_providers=None
+    ):
+        super().__init__(
+            use_angle_cls=use_angle_cls,
+            box_thresh=box_thresh,
+            unclip_ratio=unclip_ratio,
+            rec_model_path=rec_model_path,
+            det_model_path=det_model_path,
+            ort_providers=ort_providers
+        )
+
+    # def ocr_single_line(self, img):
+    #     img = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)
+    #     return super().ocr_single_line(img)
+    #
+    # def detect_and_ocr(self, img: np.ndarray,**kwargs):
+    #     img = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)
+    #     return super().detect_and_ocr(img, **kwargs)
+
+
+def sorted_boxes(dt_boxes):
+    """
+    Sort text boxes in order from top to bottom, left to right
+    args:
+        dt_boxes(array):detected text boxes with shape [4, 2]
+    return:
+        sorted boxes(array) with shape [4, 2]
+    """
+    num_boxes = dt_boxes.shape[0]
+    sorted_boxes = sorted(dt_boxes, key=lambda x: (x[0][1], x[0][0]))
+    _boxes = list(sorted_boxes)
+
+    for i in range(num_boxes - 1):
+        for j in range(i, -1, -1):
+            if abs(_boxes[j + 1][0][1] - _boxes[j][0][1]) < 10 and \
+                    (_boxes[j + 1][0][0] < _boxes[j][0][0]):
+                tmp = _boxes[j]
+                _boxes[j] = _boxes[j + 1]
+                _boxes[j + 1] = tmp
+            else:
+                break
+    return _boxes
+
+# sorted_boxes() from PaddleOCR 2.6, newer and better than the one in ppocr-onnx
+ppocronnx.predict_system.sorted_boxes = sorted_boxes

+ 192 - 0
module/ocr/sub_ocr.py

@@ -0,0 +1,192 @@
+# This Python file uses the following encoding: utf-8
+# @author runhey
+# github https://github.com/runhey
+
+import cv2
+import re
+
+from datetime import timedelta
+
+from module.ocr.ppocr import TextSystem
+from module.exception import ScriptError
+from module.base.utils import area_pad, crop, float2str
+from module.ocr.base_ocr import BaseCor, OcrMode, OcrMethod
+from module.ocr.utils import merge_area
+from module.logger import logger
+
+
+class Full(BaseCor):
+    """
+    这个类适用于大ROI范围的文本识别。可以支持多条文本识别, 默认不支持竖方向的文本识别
+    """
+    def after_process(self, result):
+        return result
+
+    def ocr_full(self, image, keyword: str=None) -> tuple:
+        """
+        检测整个图片的文本,并对结果进行过滤。返回的是匹配到的keyword的左边。如果没有匹配到返回(0, 0, 0, 0)
+        :param image:
+        :param keyword:
+        :return:
+        """
+        if keyword is None:
+            keyword = self.keyword
+
+        boxed_results = self.detect_and_ocr(image)
+        if not boxed_results:
+            return 0, 0, 0, 0
+
+        index_list = self.filter(boxed_results, keyword)
+        # 如果一个都没有匹配到
+        if not index_list:
+            return 0, 0, 0, 0
+
+        # 如果匹配到了多个,则合并所有的坐标,返回合并后的坐标
+        if len(index_list) > 1:
+            area_list = [(
+                boxed_results[index].box[0, 0],  # x
+                boxed_results[index].box[0, 1],  # y
+                boxed_results[index].box[1, 0] - boxed_results[index].box[0, 0],     # width
+                boxed_results[index].box[2, 1] - boxed_results[index].box[0, 1],     # height
+            ) for index in index_list]
+            box = merge_area(area_list)
+            self.area = box[0]+self.roi[0], box[1]+self.roi[1], box[2], box[3]
+        else:
+            box = boxed_results[index_list[0]].box
+            self.area = box[0, 0]+self.roi[0], box[0, 1]+self.roi[1], box[1, 0] - box[0, 0], box[2, 1] - box[0, 1]
+
+        logger.info(f"OCR [{self.name}: {keyword}] detected in {self.area}")
+        return self.area
+
+class Single(BaseCor):
+    """
+    这个类使用于单行文本识别(所识别的ROI不会动)
+    """
+    def after_process(self, result):
+        return result
+
+    def ocr_single(self, image) -> str:
+        """
+        检测某个固定位置的roi的文本。可以是横方向也可以是竖方向
+        :param image:
+        :return:
+        """
+        if self.roi:
+            result = self.ocr_single_line(image)
+            if result != "":
+                return result
+
+            # 如果没有识别到,这个时候考虑到可能是竖方向的文本, 使用detect_and_ocr来进行识别
+            logger.info(f"OCR {self.name}: No text detected in ROI, try to detect vertically")
+            result = self.detect_and_ocr(image)
+            if result[0].ocr_text != "" and result[0].score > self.score:
+                return result[0].ocr_text
+
+            # 如果还是没有识别到。那可能就是真的没有识别到了
+            return ""
+        else:
+            raise ScriptError("Roi is empty")
+
+class Digit(Single):
+
+    def after_process(self, result):
+        result = super().after_process(result)
+        result = result.replace('I', '1').replace('D', '0').replace('S', '5')
+        result = result.replace('B', '8')
+
+        prev = result
+        result = int(result) if result else 0
+        if str(result) != prev:
+            logger.warning(f'OCR {self.name}: Result "{prev}" is revised to "{result}"')
+
+        return result
+
+    def ocr_digit(self, image) -> int:
+        """
+        返回数字
+        :param image:
+        :return:
+        """
+        result = self.ocr_single(image)
+
+        if result == "":
+            return 0
+        else:
+            return int(result)
+
+class DigitCounter(Single):
+    def after_process(self, result):
+        result = super().after_process(result)
+        result = result.replace('I', '1').replace('D', '0').replace('S', '5')
+        result = result.replace('B', '8')
+        return result
+
+    @classmethod
+    def ocr_str_digit_counter(cls, result: str) -> tuple[int, int, int]:
+        result = re.search(r'(\d+)/(\d+)', result)
+        if result:
+            result = [int(s) for s in result.groups()]
+            current, total = int(result[0]), int(result[1])
+            current = min(current, total)
+            return current, total - current, total
+        else:
+            logger.warning(f'Unexpected ocr result: {result}')
+            return 0, 0, 0
+
+
+    def ocr_digit_counter(self, image) -> tuple[int, int, int]:
+        """
+        获取计数的结果
+        :param image:
+        :return: 例如 14/15,返回 (14, 1, 15) 。如果没有识别到,返回 (0, 0, 0)
+        """
+        result = self.ocr_single(image)
+        if result == "":
+            return 0, 0, 0
+        return self.ocr_str_digit_counter(result)
+
+class Duration(Single):
+    def after_process(self, result):
+        result = super().after_process(result)
+        result = result.replace('I', '1').replace('D', '0').replace('S', '5')
+        result = result.replace('B', '8')
+        return result
+
+    @staticmethod
+    def parse_time(string):
+        """
+        Args:
+            string (str): `01:30:00`
+
+        Returns:
+            datetime.timedelta:
+        """
+        result = re.search(r'(\d{1,2}):?(\d{2}):?(\d{2})', string)
+        if result:
+            result = [int(s) for s in result.groups()]
+            return timedelta(hours=result[0], minutes=result[1], seconds=result[2])
+        else:
+            logger.warning(f'Invalid duration: {string}')
+            return timedelta(hours=0, minutes=0, seconds=0)
+
+    def ocr_duration(self, image) -> timedelta:
+        """
+
+        :param image:
+        :return:
+        """
+        result = self.ocr_single(image)
+
+        if result == "":
+            return timedelta(hours=0, minutes=0, seconds=0)
+
+        return self.parse_time(result)
+
+
+if __name__ == '__main__':
+    d = DigitCounter.ocr_str_digit_counter('14/77')
+    print(d)
+
+    u = Duration.parse_time('01:30:00')
+    print(u)
+

+ 23 - 0
module/ocr/utils.py

@@ -0,0 +1,23 @@
+# This Python file uses the following encoding: utf-8
+# @author runhey
+# github https://github.com/runhey
+
+
+def _merge_area(area1, area2):
+    xa1, ya1, xa2, ya2 = area1
+    xb1, yb1, xb2, yb2 = area2
+    return min(xa1, xb1), min(ya1, yb1), max(xa2, xb2), max(ya2, yb2)
+
+def merge_area(areas: list[tuple]) -> tuple:
+    """
+    合并多个区域
+    :param areas:
+    :return:
+    """
+    if not areas:
+        return 0, 0, 0, 0
+    area = areas[0]
+    for i in range(1, len(areas)):
+        area = _merge_area(area, areas[i])
+    return area
+

+ 2 - 1
requirements-in.txt

@@ -13,4 +13,5 @@ zerorpc==0.6.3
 wrapt==1.15.0
 pydantic==1.10.7
 inflection==0.5.1
-tqdm==4.65.0
+tqdm==4.65.0
+ppocr-onnx==0.0.3.9

+ 18 - 6
requirements.txt

@@ -15,43 +15,55 @@ certifi==2023.5.7         # via requests
 cffi==1.15.1              # via gevent
 charset-normalizer==3.1.0  # via requests
 cigam==0.0.3              # via apkutils2
-colorama==0.4.6           # via logzero
+colorama==0.4.6           # via logzero, tqdm
+coloredlogs==15.0.1       # via onnxruntime
 decorator==5.1.1          # via retry
 deprecated==1.2.13        # via uiautomator2
 deprecation==2.1.0        # via adbutils
 filelock==3.12.0          # via uiautomator2
+flatbuffers==23.5.26      # via onnxruntime
 future==0.18.3            # via zerorpc
 gevent==22.10.2           # via zerorpc
 greenlet==2.0.2           # via gevent
+humanfriendly==10.0       # via coloredlogs
 idna==3.4                 # via requests
 inflection==0.5.1         # via -r requirements-in.txt
 logzero==1.7.0            # via uiautomator2
 lxml==4.9.2               # via uiautomator2
 markdown-it-py==2.2.0     # via rich
 mdurl==0.1.2              # via markdown-it-py
+mpmath==1.3.0             # via sympy
 msgpack==1.0.5            # via zerorpc
-numpy==1.24.3             # via -r requirements-in.txt, opencv-python
-opencv-python==4.7.0.72   # via -r requirements-in.txt
-packaging==20.9           # via deprecation, uiautomator2
-pillow==9.5.0             # via uiautomator2
+numpy==1.24.3             # via -r requirements-in.txt, onnxruntime, opencv-python, ppocr-onnx, shapely
+onnxruntime==1.15.0       # via ppocr-onnx
+opencv-python==4.7.0.72   # via -r requirements-in.txt, ppocr-onnx
+packaging==20.9           # via deprecation, onnxruntime, uiautomator2
+pillow==9.5.0             # via ppocr-onnx, uiautomator2
+ppocr-onnx==0.0.3.9       # via -r requirements-in.txt
 progress==1.6             # via uiautomator2
+protobuf==4.23.3          # via onnxruntime
 py==1.11.0                # via retry
+pyclipper==1.3.0.post4    # via ppocr-onnx
 pycparser==2.21           # via cffi
 pydantic==1.10.7          # via -r requirements-in.txt
 pyelftools==0.29          # via apkutils2
 pygments==2.15.1          # via rich
 pyparsing==3.0.9          # via packaging
+pyreadline3==3.4.1        # via humanfriendly
 pyside6==6.4.3            # via -r requirements-in.txt
 pyside6-addons==6.4.3     # via pyside6
 pyside6-essentials==6.4.3  # via pyside6, pyside6-addons
 pywin32==306              # via -r requirements-in.txt
 pyyaml==6.0               # via -r requirements-in.txt
 pyzmq==25.0.2             # via zerorpc
-requests==2.30.0          # via adbutils, uiautomator2
+requests==2.30.0          # via adbutils, ppocr-onnx, uiautomator2
 retry==0.9.2              # via adbutils, uiautomator2
 rich==13.3.5              # via -r requirements-in.txt
+shapely==2.0.1            # via ppocr-onnx
 shiboken6==6.4.3          # via pyside6, pyside6-addons, pyside6-essentials
 six==1.16.0               # via adbutils, anytree, uiautomator2
+sympy==1.12               # via onnxruntime
+tqdm==4.65.0              # via -r requirements-in.txt
 typing-extensions==4.5.0  # via pydantic
 uiautomator2==2.16.17     # via -r requirements-in.txt
 urllib3==2.0.2            # via requests

+ 1 - 0
script.py

@@ -445,3 +445,4 @@ if __name__ == "__main__":
     script = Script("oas1")
     print(script.get_next_task())
     script.run("AreaBoss")
+    # script.run('RealmRaid')

+ 2 - 0
tasks/AreaBoss/assets.py

@@ -2,11 +2,13 @@ from module.atom.image import RuleImage
 from module.atom.click import RuleClick
 from module.atom.long_click import RuleLongClick
 from module.atom.swipe import RuleSwipe
+from module.atom.ocr import RuleOcr
 
 # This file was automatically generated by module/dev_tools/assets_extract.py.
 # Don't modify it manually.
 class AreaBossAssets: 
 
+
 	# Image Rule Assets
 	# 探索图标 
 	I_EXPLORE = RuleImage(roi_front=(758,122,66,77), roi_back=(339,104,836,120), threshold=0.8, method="Template matching", file="./tasks/AreaBoss/res/res_explore.png")

+ 1 - 1
tasks/AreaBoss/config_boss.py

@@ -8,5 +8,5 @@ from pydantic import BaseModel, ValidationError, validator, Field
 class Boss(BaseModel):
     boss_number: int = Field(title='Boss Number',
                              default=3,
-                             description='只可选范围1~3',
+                             description='[Boss数量]:默认为3\n 可选[1-3]',
                              ge=1, le=3)

+ 5 - 5
tasks/AreaBoss/config_scheduler.py

@@ -6,10 +6,10 @@ from datetime import datetime, time
 from pydantic import BaseModel, ValidationError, validator, Field
 
 class Scheduler(BaseModel):
-    enable: bool = Field(default=False,
-                         description='none')
+    enable: bool = Field(default=False, description='[是否启用]:默认为False')
     next_run: datetime = Field(default="2023-01-01 00:00:00",
-                               description='none')
-    priority: int = Field(default=3,
-                          description='已经弃置,不生效')
+                               description='[下次执行时间]:默认为2023-01-01 00:00:00\n 清空后回车设置当前的时间')
+    interval_days: int = Field(default=1, description='[间隔天数]:默认为1\n 可选0-7')
+    interval_hours: int = Field(default=0, description='[间隔小时]:默认为0\n 可选0-23')
+    interval_minutes: int = Field(default=0, description='[间隔分钟]:默认为0\n 可选0-59')
 

+ 1 - 0
tasks/AreaBoss/script_task.py

@@ -166,6 +166,7 @@ class ScriptTask(GeneralBattle, AreaBossAssets):
 
         # 退出
         self.go_back()
+        self.set_next_run(task='AreaBoss')
 
         # 以抛出异常的形式结束
         raise TaskEnd

+ 25 - 0
tasks/CoinChallenge/assets.py

@@ -2,11 +2,13 @@ from module.atom.image import RuleImage
 from module.atom.click import RuleClick
 from module.atom.long_click import RuleLongClick
 from module.atom.swipe import RuleSwipe
+from module.atom.ocr import RuleOcr
 
 # This file was automatically generated by module/dev_tools/assets_extract.py.
 # Don't modify it manually.
 class CoinChallengeAssets: 
 
+
 	# Image Rule Assets
 	# description 
 	I_NEW1 = RuleImage(roi_front=(157,240,70,79), roi_back=(41,185,279,207), threshold=0.8, method="Template matching", file="./tasks/CoinChallenge/res/res_new1.png")
@@ -14,6 +16,8 @@ class CoinChallengeAssets:
 	I_NEW2 = RuleImage(roi_front=(362,243,100,100), roi_back=(803,101,100,100), threshold=0.8, method="Template matching", file="./tasks/CoinChallenge/res/res_new2.png")
 	# desc55 
 	I_NEW3 = RuleImage(roi_front=(568,212,240,220), roi_back=(0,0,100,100), threshold=0.9, method="Template matching", file="./tasks/CoinChallenge/res/res_new3.png")
+
+
 	# Click Rule Assets
 	# description 
 	C_NEW1 = RuleClick(roi_front=(268,268,100,100), roi_back=(614,214,100,100), name="new1")
@@ -21,6 +25,8 @@ class CoinChallengeAssets:
 	C_NEW2 = RuleClick(roi_front=(171,236,100,100), roi_back=(554,225,100,100), name="new2")
 	# desc444n 
 	C_NEW3 = RuleClick(roi_front=(180,150,100,100), roi_back=(596,247,100,100), name="new3")
+
+
 	# Long Click Rule Assets
 	# description 
 	L_NEW1 = RuleLongClick(roi_front=(208,151,100,100), roi_back=(542,279,100,100), duration=1500, name="new1")
@@ -28,6 +34,25 @@ class CoinChallengeAssets:
 	L_NEW2 = RuleLongClick(roi_front=(355,191,100,100), roi_back=(526,323,100,100), duration=1500, name="new2")
 	# de66666n 
 	L_NEW3 = RuleLongClick(roi_front=(112,156,100,100), roi_back=(469,200,100,100), duration=1000, name="new3")
+
+
+	# Ocr Rule Assets
+	# Ocr-description 
+	O_NEW_FULL = RuleOcr(roi=(255,129,628,100), area=(637,418,100,100), mode="Full", method="Default", keyword="探索", name="new_full")
+	# Ocr-description 
+	O_NEW_SINGLE_V = RuleOcr(roi=(564,255,105,159), area=(0,0,100,100), mode="Single", method="Default", keyword="式神育成", name="new_single_v")
+	# Ocr-description 
+	O_NEW_SINGLE_H = RuleOcr(roi=(78,19,143,63), area=(314,169,100,100), mode="Single", method="Default", keyword="式神育成", name="new_single_h")
+	# Ocr-description 
+	O_DIGIT = RuleOcr(roi=(434,173,25,43), area=(0,0,100,100), mode="Digit", method="Default", keyword="", name="digit")
+	# Ocr-description 
+	O_DIGIT_COUNTER = RuleOcr(roi=(1134,6,100,56), area=(0,0,100,100), mode="DigitCounter", method="Default", keyword="", name="digit_counter")
+	# Ocr-description 
+	O_DURATION = RuleOcr(roi=(923,256,100,46), area=(0,0,100,100), mode="Duration", method="Default", keyword="育成_结界卡剩余时间", name="duration")
+	# Ocr-description 
+	O_NEW_DUR_00 = RuleOcr(roi=(848,624,76,37), area=(0,0,100,100), mode="Duration", method="Default", keyword="", name="new_dur_00")
+
+
 	# Swipe Rule Assets
 	# description 
 	S_NEW1 = RuleSwipe(roi_front=(253,212,100,100), roi_back=(652,292,100,100), mode="default", name="new1")

+ 65 - 0
tasks/CoinChallenge/res/test_ocr.json

@@ -0,0 +1,65 @@
+[
+  {
+    "itemName": "new_full",
+    "roiFront": "255,129,628,100",
+    "roiBack": "637,418,100,100",
+    "mode": "Full",
+    "method": "Default",
+    "keyword": "探索",
+    "description": "Ocr-description"
+  },
+  {
+    "itemName": "new_single_v",
+    "roiFront": "564,255,105,159",
+    "roiBack": "0,0,100,100",
+    "mode": "Single",
+    "method": "Default",
+    "keyword": "式神育成",
+    "description": "Ocr-description"
+  },
+  {
+    "itemName": "new_single_h",
+    "roiFront": "78,19,143,63",
+    "roiBack": "314,169,100,100",
+    "mode": "Single",
+    "method": "Default",
+    "keyword": "式神育成",
+    "description": "Ocr-description"
+  },
+  {
+    "itemName": "digit",
+    "roiFront": "434,173,25,43",
+    "roiBack": "0,0,100,100",
+    "mode": "Digit",
+    "method": "Default",
+    "keyword": "",
+    "description": "Ocr-description"
+  },
+  {
+    "itemName": "digit_counter",
+    "roiFront": "1134,6,100,56",
+    "roiBack": "0,0,100,100",
+    "mode": "DigitCounter",
+    "method": "Default",
+    "keyword": "",
+    "description": "Ocr-description"
+  },
+  {
+    "itemName": "duration",
+    "roiFront": "923,256,100,46",
+    "roiBack": "0,0,100,100",
+    "mode": "Duration",
+    "method": "Default",
+    "keyword": "育成_结界卡剩余时间",
+    "description": "Ocr-description"
+  },
+  {
+    "itemName": "new_dur_00",
+    "roiFront": "848,624,76,37",
+    "roiBack": "0,0,100,100",
+    "mode": "Duration",
+    "method": "Default",
+    "keyword": "",
+    "description": "Ocr-description"
+  }
+]

+ 1 - 0
tasks/DemonEncounter/assets.py

@@ -2,6 +2,7 @@ from module.atom.image import RuleImage
 from module.atom.click import RuleClick
 from module.atom.long_click import RuleLongClick
 from module.atom.swipe import RuleSwipe
+from module.atom.ocr import RuleOcr
 
 # This file was automatically generated by module/dev_tools/assets_extract.py.
 # Don't modify it manually.

+ 5 - 5
tasks/DemonEncounter/config_scheduler.py

@@ -6,10 +6,10 @@ from datetime import datetime, time
 from pydantic import BaseModel, ValidationError, validator, Field
 
 class Scheduler(BaseModel):
-    enable: bool = Field(default=False,
-                         description='none')
+    enable: bool = Field(default=False, description='[是否启用]:默认为False')
     next_run: datetime = Field(default="2023-01-01 00:00:00",
-                               description='none')
-    priority: int = Field(default=3,
-                          description='default 3')
+                               description='[下次执行时间]:默认为2023-01-01 00:00:00\n 清空后回车设置当前的时间')
+    interval_days: int = Field(default=1, description='[间隔天数]:默认为1\n 可选0-7')
+    interval_hours: int = Field(default=0, description='[间隔小时]:默认为0\n 可选0-23')
+    interval_minutes: int = Field(default=0, description='[间隔分钟]:默认为0\n 可选0-59')
 

+ 1 - 0
tasks/EternitySea/assets.py

@@ -2,6 +2,7 @@ from module.atom.image import RuleImage
 from module.atom.click import RuleClick
 from module.atom.long_click import RuleLongClick
 from module.atom.swipe import RuleSwipe
+from module.atom.ocr import RuleOcr
 
 # This file was automatically generated by module/dev_tools/assets_extract.py.
 # Don't modify it manually.

+ 5 - 5
tasks/EternitySea/config_scheduler.py

@@ -6,10 +6,10 @@ from datetime import datetime, time
 from pydantic import BaseModel, ValidationError, validator, Field
 
 class Scheduler(BaseModel):
-    enable: bool = Field(default=False,
-                         description='none')
+    enable: bool = Field(default=False, description='[是否启用]:默认为False')
     next_run: datetime = Field(default="2023-01-01 00:00:00",
-                               description='none')
-    priority: int = Field(default=3,
-                          description='default 3')
+                               description='[下次执行时间]:默认为2023-01-01 00:00:00\n 清空后回车设置当前的时间')
+    interval_days: int = Field(default=1, description='[间隔天数]:默认为1\n 可选0-7')
+    interval_hours: int = Field(default=0, description='[间隔小时]:默认为0\n 可选0-23')
+    interval_minutes: int = Field(default=0, description='[间隔分钟]:默认为0\n 可选0-59')
 

+ 1 - 0
tasks/ExperienceYoukai/assets.py

@@ -2,6 +2,7 @@ from module.atom.image import RuleImage
 from module.atom.click import RuleClick
 from module.atom.long_click import RuleLongClick
 from module.atom.swipe import RuleSwipe
+from module.atom.ocr import RuleOcr
 
 # This file was automatically generated by module/dev_tools/assets_extract.py.
 # Don't modify it manually.

+ 5 - 5
tasks/ExperienceYoukai/config_scheduler.py

@@ -6,10 +6,10 @@ from datetime import datetime, time
 from pydantic import BaseModel, ValidationError, validator, Field
 
 class Scheduler(BaseModel):
-    enable: bool = Field(default=False,
-                         description='none')
+    enable: bool = Field(default=False, description='[是否启用]:默认为False')
     next_run: datetime = Field(default="2023-01-01 00:00:00",
-                               description='none')
-    priority: int = Field(default=3,
-                          description='default 3')
+                               description='[下次执行时间]:默认为2023-01-01 00:00:00\n 清空后回车设置当前的时间')
+    interval_days: int = Field(default=1, description='[间隔天数]:默认为1\n 可选0-7')
+    interval_hours: int = Field(default=0, description='[间隔小时]:默认为0\n 可选0-23')
+    interval_minutes: int = Field(default=0, description='[间隔分钟]:默认为0\n 可选0-59')
 

+ 1 - 0
tasks/FallenSun/assets.py

@@ -2,6 +2,7 @@ from module.atom.image import RuleImage
 from module.atom.click import RuleClick
 from module.atom.long_click import RuleLongClick
 from module.atom.swipe import RuleSwipe
+from module.atom.ocr import RuleOcr
 
 # This file was automatically generated by module/dev_tools/assets_extract.py.
 # Don't modify it manually.

+ 5 - 5
tasks/FallenSun/config_scheduler.py

@@ -6,10 +6,10 @@ from datetime import datetime, time
 from pydantic import BaseModel, ValidationError, validator, Field
 
 class Scheduler(BaseModel):
-    enable: bool = Field(default=False,
-                         description='none')
+    enable: bool = Field(default=False, description='[是否启用]:默认为False')
     next_run: datetime = Field(default="2023-01-01 00:00:00",
-                               description='none')
-    priority: int = Field(default=3,
-                          description='default 3')
+                               description='[下次执行时间]:默认为2023-01-01 00:00:00\n 清空后回车设置当前的时间')
+    interval_days: int = Field(default=1, description='[间隔天数]:默认为1\n 可选0-7')
+    interval_hours: int = Field(default=0, description='[间隔小时]:默认为0\n 可选0-23')
+    interval_minutes: int = Field(default=0, description='[间隔分钟]:默认为0\n 可选0-59')
 

+ 43 - 0
tasks/GameUi/assets.py

@@ -0,0 +1,43 @@
+from module.atom.image import RuleImage
+from module.atom.click import RuleClick
+from module.atom.long_click import RuleLongClick
+from module.atom.swipe import RuleSwipe
+from module.atom.ocr import RuleOcr
+
+# This file was automatically generated by module/dev_tools/assets_extract.py.
+# Don't modify it manually.
+class GameUiAssets: 
+
+
+	# Image Rule Assets
+	# 左上角蓝色的返回 
+	I_BACK_BLUE = RuleImage(roi_front=(32,31,50,53), roi_back=(1,2,139,120), threshold=0.8, method="Template matching", file="./tasks/GameUi/res/res_back_blue.png")
+	# 式神录 
+	I_HOME_SHIKIKAMI = RuleImage(roi_front=(1092,611,73,41), roi_back=(1092,611,73,41), threshold=0.8, method="Template matching", file="./tasks/GameUi/res/res_home_shikikami.png")
+	# 阴阳术 
+	I_HOME_OMNYOUJI = RuleImage(roi_front=(989,613,59,58), roi_back=(989,613,59,58), threshold=0.8, method="Template matching", file="./tasks/GameUi/res/res_home_omnyouji.png")
+	# description 
+	I_HOME_FRIEND = RuleImage(roi_front=(876,619,60,53), roi_back=(876,619,60,53), threshold=0.8, method="Template matching", file="./tasks/GameUi/res/res_home_friend.png")
+	# 花合战 
+	I_HOME_TSK = RuleImage(roi_front=(764,608,66,56), roi_back=(764,608,66,56), threshold=0.8, method="Template matching", file="./tasks/GameUi/res/res_home_tsk.png")
+	# 商店 
+	I_HOME_MALL = RuleImage(roi_front=(654,620,51,55), roi_back=(654,620,51,55), threshold=0.8, method="Template matching", file="./tasks/GameUi/res/res_home_mall.png")
+	# 阴阳寮 
+	I_HOME_GUILD = RuleImage(roi_front=(540,607,53,50), roi_back=(540,607,53,50), threshold=0.8, method="Template matching", file="./tasks/GameUi/res/res_home_guild.png")
+	# 组队 
+	I_HOME_TEAM = RuleImage(roi_front=(430,616,49,61), roi_back=(430,616,49,61), threshold=0.8, method="Template matching", file="./tasks/GameUi/res/res_home_team.png")
+	# 同心队 
+	I_HOME_CONCENTRIC_TEAM = RuleImage(roi_front=(310,618,67,60), roi_back=(310,618,67,60), threshold=0.8, method="Template matching", file="./tasks/GameUi/res/res_home_concentric_team.png")
+	# 珍旅居 
+	I_HOME_HELP = RuleImage(roi_front=(201,617,56,57), roi_back=(201,617,56,57), threshold=0.8, method="Template matching", file="./tasks/GameUi/res/res_home_help.png")
+	# 图鉴 
+	I_HOME_COLLECT = RuleImage(roi_front=(92,607,48,74), roi_back=(92,607,48,74), threshold=0.8, method="Template matching", file="./tasks/GameUi/res/res_home_collect.png")
+
+
+	# Ocr Rule Assets
+	# 庭院到探索 
+	O_HOME_EXPLORE = RuleOcr(roi=(310,105,858,194), area=(0,0,100,100), mode="Full", method="Default", keyword="探索", name="home_explore")
+	# Ocr-description 
+	O_NEW = RuleOcr(roi=(0,0,100,100), area=(0,0,100,100), mode="Single", method="Default", keyword="", name="new")
+
+

+ 44 - 0
tasks/GameUi/game_ui.py

@@ -0,0 +1,44 @@
+# This Python file uses the following encoding: utf-8
+# @author runhey
+# github https://github.com/runhey
+import time
+
+from tasks.GameUi.assets import GameUiAssets
+from tasks.base_task import BaseTask
+from tasks.GeneralBattle.general_battle import GeneralBattle
+from tasks.AreaBoss.assets import AreaBossAssets
+from module.logger import logger
+
+
+class GameUi(BaseTask, GameUiAssets):
+
+    def home_explore(self) -> bool:
+        """
+        使用ocr识别到探索按钮并点击
+        :return:
+        """
+        while 1:
+            self.screenshot()
+            if self.ocr_appear_click(self.O_HOME_EXPLORE, interval=2):
+                continue
+            if self.appear(self.I_BACK_BLUE, threshold=0.6):
+                break
+        logger.info(f'Click {self.O_HOME_EXPLORE.name}')
+        return True
+
+    def explore_home(self) -> bool:
+        """
+
+        :return:
+        """
+        while 1:
+            self.screenshot()
+            if self.appear_then_click(self.I_BACK_BLUE, threshold=0.6, interval=2):
+                continue
+            if self.appear(self.I_HOME_SHIKIKAMI, threshold=0.6):
+                break
+        logger.info(f'Click {self.I_HOME_SHIKIKAMI.name}')
+        return True
+
+
+

+ 101 - 0
tasks/GameUi/res/image.json

@@ -0,0 +1,101 @@
+[
+  {
+    "itemName": "back_blue",
+    "imageName": "res_back_blue.png",
+    "roiFront": "32,31,50,53",
+    "roiBack": "1,2,139,120",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "左上角蓝色的返回"
+  },
+  {
+    "itemName": "home_shikikami",
+    "imageName": "res_home_shikikami.png",
+    "roiFront": "1092,611,73,41",
+    "roiBack": "1092,611,73,41",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "式神录"
+  },
+  {
+    "itemName": "home_omnyouji",
+    "imageName": "res_home_omnyouji.png",
+    "roiFront": "989,613,59,58",
+    "roiBack": "989,613,59,58",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "阴阳术"
+  },
+  {
+    "itemName": "home_friend",
+    "imageName": "res_home_friend.png",
+    "roiFront": "876,619,60,53",
+    "roiBack": "876,619,60,53",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "home_tsk",
+    "imageName": "res_home_tsk.png",
+    "roiFront": "764,608,66,56",
+    "roiBack": "764,608,66,56",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "花合战"
+  },
+  {
+    "itemName": "home_mall",
+    "imageName": "res_home_mall.png",
+    "roiFront": "654,620,51,55",
+    "roiBack": "654,620,51,55",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "商店"
+  },
+  {
+    "itemName": "home_guild",
+    "imageName": "res_home_guild.png",
+    "roiFront": "540,607,53,50",
+    "roiBack": "540,607,53,50",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "阴阳寮"
+  },
+  {
+    "itemName": "home_team",
+    "imageName": "res_home_team.png",
+    "roiFront": "430,616,49,61",
+    "roiBack": "430,616,49,61",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "组队"
+  },
+  {
+    "itemName": "home_concentric_team",
+    "imageName": "res_home_concentric_team.png",
+    "roiFront": "310,618,67,60",
+    "roiBack": "310,618,67,60",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "同心队"
+  },
+  {
+    "itemName": "home_help",
+    "imageName": "res_home_help.png",
+    "roiFront": "201,617,56,57",
+    "roiBack": "201,617,56,57",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "珍旅居"
+  },
+  {
+    "itemName": "home_collect",
+    "imageName": "res_home_collect.png",
+    "roiFront": "92,607,48,74",
+    "roiBack": "92,607,48,74",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "图鉴"
+  }
+]

+ 20 - 0
tasks/GameUi/res/ocr.json

@@ -0,0 +1,20 @@
+[
+  {
+    "itemName": "home_explore",
+    "roiFront": "310,105,858,194",
+    "roiBack": "0,0,100,100",
+    "mode": "Full",
+    "method": "Default",
+    "keyword": "探索",
+    "description": "庭院到探索"
+  },
+  {
+    "itemName": "new",
+    "roiFront": "0,0,100,100",
+    "roiBack": "0,0,100,100",
+    "mode": "Single",
+    "method": "Default",
+    "keyword": "",
+    "description": "Ocr-description"
+  }
+]

BIN
tasks/GameUi/res/res_back_blue.png


BIN
tasks/GameUi/res/res_home_collect.png


BIN
tasks/GameUi/res/res_home_concentric_team.png


BIN
tasks/GameUi/res/res_home_friend.png


BIN
tasks/GameUi/res/res_home_guild.png


BIN
tasks/GameUi/res/res_home_help.png


BIN
tasks/GameUi/res/res_home_mall.png


BIN
tasks/GameUi/res/res_home_omnyouji.png


BIN
tasks/GameUi/res/res_home_shikikami.png


BIN
tasks/GameUi/res/res_home_team.png


BIN
tasks/GameUi/res/res_home_tsk.png


+ 1 - 0
tasks/General/assets.py

@@ -2,6 +2,7 @@ from module.atom.image import RuleImage
 from module.atom.click import RuleClick
 from module.atom.long_click import RuleLongClick
 from module.atom.swipe import RuleSwipe
+from module.atom.ocr import RuleOcr
 
 # This file was automatically generated by module/dev_tools/assets_extract.py.
 # Don't modify it manually.

+ 10 - 0
tasks/GeneralBattle/assets.py

@@ -2,10 +2,13 @@ from module.atom.image import RuleImage
 from module.atom.click import RuleClick
 from module.atom.long_click import RuleLongClick
 from module.atom.swipe import RuleSwipe
+from module.atom.ocr import RuleOcr
 
 # This file was automatically generated by module/dev_tools/assets_extract.py.
 # Don't modify it manually.
 class GeneralBattleAssets: 
+
+
 	# Click Rule Assets
 	# 预设队伍1 
 	C_PRESET_TEAM_1 = RuleClick(roi_front=(196,234,464,114), roi_back=(196,234,464,114), name="preset_team_1")
@@ -44,6 +47,7 @@ class GeneralBattleAssets:
 	# 战斗的时候有一定的概率随机点击 
 	C_RANDOM_CLICK = RuleClick(roi_front=(104,79,1050,507), roi_back=(255,65,100,100), name="random_click")
 
+
 	# Image Rule Assets
 	# 奖励,就是那个魂 
 	I_REWARD = RuleImage(roi_front=(547,518,172,96), roi_back=(547,518,172,96), threshold=0.8, method="Template matching", file="./tasks/GeneralBattle/res/res_reward.png")
@@ -77,6 +81,12 @@ class GeneralBattleAssets:
 	I_LOCAL = RuleImage(roi_front=(25,563,30,34), roi_back=(25,563,30,34), threshold=0.8, method="Template matching", file="./tasks/GeneralBattle/res/res_local.png")
 	# description 
 	I_STATISTICS = RuleImage(roi_front=(61,644,33,28), roi_back=(61,644,33,28), threshold=0.8, method="Template matching", file="./tasks/GeneralBattle/res/res_statistics.png")
+	# 左上角的退出 
+	I_EXIT = RuleImage(roi_front=(14,12,43,41), roi_back=(14,12,43,41), threshold=0.8, method="Template matching", file="./tasks/GeneralBattle/res/res_exit.png")
+	# 退出确认 
+	I_EXIT_ENSURE = RuleImage(roi_front=(674,388,135,63), roi_back=(674,388,135,63), threshold=0.8, method="Template matching", file="./tasks/GeneralBattle/res/res_exit_ensure.png")
+
+
 	# Swipe Rule Assets
 	# description 
 	S_BATTLE_RANDOM_LEFT = RuleSwipe(roi_front=(122,155,480,426), roi_back=(667,147,461,427), mode="default", name="battle_random_left")

+ 15 - 34
tasks/GeneralBattle/config_general_battle.py

@@ -16,54 +16,35 @@ class GreenMarkType(str, Enum):
 class GeneralBattleConfig(BaseModel):
 
     # 是否锁定阵容, 有些的战斗是外边的锁定阵容甚至有些的战斗没有锁定阵容的
-    lock_team_enable: bool = Field(default=False,
-                                   description='default is false')
+    lock_team_enable: bool = Field(default=False, description='[锁定阵容]:默认为False \n如果锁定阵容将无法启用预设队伍、加成功能')
 
     # 是否启动 预设队伍
-    preset_enable: bool = Field(default=False,
-                                description='default is false')
+    preset_enable: bool = Field(default=False, description='[启用预设]:默认为False')
     # 选哪一个预设组
-    preset_group: int = Field(default=1,
-                              description='default is 1, max is 7, min is 1',
-                              ge=1, le=7)
+    preset_group: int = Field(default=1, description='[设置预设组]:默认为1, 可选[1-7]', ge=1, le=7)
     # 选哪一个队伍
-    preset_team: int = Field(default=1,
-                             description='default is 1, min is 1, max is 4',
-                             ge=1, le=4)
-
+    preset_team: int = Field(default=1, description='[设置预设队伍]:默认为1, 可选[1-5]', ge=1, le=5)
     # 是否启动开启buff
-    buff_enable: bool = Field(default=False,
-                               description='default is false')
+    buff_enable: bool = Field(default=False, description='[启用加成]:默认为False')
     # 是否点击觉醒Buff
-    buff_awake_click: bool = Field(default=False,
-                                   description='default is false')
+    buff_awake_click: bool = Field(default=False, description='[觉醒加成]:默认为False')
     # 是否点击御魂buff
-    buff_soul_click: bool = Field(default=False,
-                                  description='default is false')
+    buff_soul_click: bool = Field(default=False, description='[御魂加成]:默认为False')
     # 是否点击金币50buff
-    buff_gold_50_click: bool = Field(default=False,
-                                    description='default is false')
+    buff_gold_50_click: bool = Field(default=False, description='[金币50加成]:默认为False')
     # 是否点击金币100buff
-    buff_gold_100_click: bool = Field(default=False,
-                                        description='default is false')
+    buff_gold_100_click: bool = Field(default=False, description='[金币100加成]:默认为False')
     # 是否点击经验50buff
-    buff_exp_50_click: bool = Field(default=False,
-                                    description='default is false')
+    buff_exp_50_click: bool = Field(default=False, description='[经验50加成]:默认为False')
     # 是否点击经验100buff
-    buff_exp_100_click: bool = Field(default=False,
-                                    description='default is false')
+    buff_exp_100_click: bool = Field(default=False, description='[经验100加成]:默认为False')
 
     # 是否开启绿标
-    green_enable: bool = Field(default=False,
-                                 description='default is false')
+    green_enable: bool = Field(default=False, description='[启用绿标]:默认为False')
     # 选哪一个绿标
-    green_mark: GreenMarkType = Field(default=GreenMarkType.GREEN_LEFT1,
-                                        description='default is GREEN_LEFT1')
+    green_mark: GreenMarkType = Field(default=GreenMarkType.GREEN_LEFT1, description='[设置绿标]:默认为左一 \n可选[左一, 左二, 左三, 左四, 左五, 主阴阳师]')
 
     # 是否启动战斗时随机点击或者随机滑动
-    random_click_swipt_enable: bool = Field(default=False,
-                                        description='default is false')
-    # 是否启动战斗时随机滑动
-    # random_swipe_enable: bool = Field(default=False,
-    #                                     description='default is false')
+    random_click_swipt_enable: bool = Field(default=False, description='[战斗时随机点击或滑动]:默认为False \n防封优化,请注意这个与绿标功能冲突,可能会乱点绿标')
+
 

+ 56 - 6
tasks/GeneralBattle/general_battle.py

@@ -30,12 +30,12 @@ class GeneralBattle(BaseTask, GeneralBattleAssets):
 
         # 如果没有锁定队伍。那么可以根据配置设定队伍
         if not config.lock_team_enable:
-            logger.info("lock team is not enable")
+            logger.info("Lock team is not enable")
             # 如果启动更换队伍
             if config.preset_enable:
-                logger.info("preset is enable")
+                logger.info("Preset is enable")
                 # 点击预设按钮
-                logger.info("click preset button")
+                logger.info("Click preset button")
                 while 1:
                     self.screenshot()
                     if self.appear_then_click(self.I_PRESET, threshold=0.8):
@@ -90,20 +90,20 @@ class GeneralBattle(BaseTask, GeneralBattleAssets):
 
             # 点击准备按钮
             self.wait_until_appear(self.I_PREPARE_HIGHLIGHT)
-            logger.info("click prepare button")
             while 1:
                 self.screenshot()
                 if self.appear_then_click(self.I_PREPARE_HIGHLIGHT, interval=1.5):
                     continue
-                if not self.appear(self.I_PRESET):
+                if not self.appear(self.I_BUFF):
                     break
+            logger.info("Click prepare ensure button")
 
             # 照顾一下某些模拟器慢的
             time.sleep(0.1)
 
         # 绿标
         if config.green_enable:
-            logger.info("green is enable")
+            logger.info("Green is enable")
             x, y = None, None
             match config.green_mark:
                 case GreenMarkType.GREEN_LEFT1: x, y = self.C_GREEN_LEFT_1.coord()
@@ -185,3 +185,53 @@ class GeneralBattle(BaseTask, GeneralBattleAssets):
         else:
             return False
 
+
+    def run_general_battle_back(self, config: dict=None) -> bool:
+        """
+        进入挑战然后直接返回
+        :param config:
+        :return:
+        """
+        # 如果没有锁定队伍那么在点击准备后才退出的
+        if not config.lock_team_enable:
+            # 点击准备按钮
+            self.wait_until_appear(self.I_PREPARE_HIGHLIGHT)
+            while 1:
+                self.screenshot()
+                if self.appear_then_click(self.I_PREPARE_HIGHLIGHT, interval=1.5):
+                    continue
+                if not self.appear(self.I_PRESET):
+                    break
+            logger.info(f"Click {self.I_PREPARE_HIGHLIGHT.name}")
+
+        # 点击返回
+        while 1:
+            self.screenshot()
+            if self.appear_then_click(self.I_EXIT, interval=1.5):
+                continue
+            if self.appear(self.I_EXIT_ENSURE):
+                break
+        logger.info(f"Click {self.I_EXIT.name}")
+
+        # 点击返回确认
+        while 1:
+            self.screenshot()
+            if self.appear_then_click(self.I_EXIT_ENSURE, interval=1.5):
+                continue
+            if self.appear(self.I_FALSE):
+                break
+        logger.info(f"Click {self.I_EXIT_ENSURE.name}")
+
+        # 点击失败确认
+        self.wait_until_appear(self.I_FALSE)
+        while 1:
+            self.screenshot()
+            if self.appear_then_click(self.I_FALSE, interval=1.5):
+                continue
+            if not self.appear(self.I_FALSE):
+                break
+        logger.info(f"Click {self.I_FALSE.name}")
+
+        return True
+
+

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 0 - 0
tasks/GeneralBattle/res/image.json


BIN
tasks/GeneralBattle/res/res_exit.png


BIN
tasks/GeneralBattle/res/res_exit_ensure.png


+ 1 - 0
tasks/GlobalGame/assets.py

@@ -2,6 +2,7 @@ from module.atom.image import RuleImage
 from module.atom.click import RuleClick
 from module.atom.long_click import RuleLongClick
 from module.atom.swipe import RuleSwipe
+from module.atom.ocr import RuleOcr
 
 # This file was automatically generated by module/dev_tools/assets_extract.py.
 # Don't modify it manually.

+ 1 - 0
tasks/GoldYoukai/assets.py

@@ -2,6 +2,7 @@ from module.atom.image import RuleImage
 from module.atom.click import RuleClick
 from module.atom.long_click import RuleLongClick
 from module.atom.swipe import RuleSwipe
+from module.atom.ocr import RuleOcr
 
 # This file was automatically generated by module/dev_tools/assets_extract.py.
 # Don't modify it manually.

+ 5 - 5
tasks/GoldYoukai/config_scheduler.py

@@ -6,10 +6,10 @@ from datetime import datetime, time
 from pydantic import BaseModel, ValidationError, validator, Field
 
 class Scheduler(BaseModel):
-    enable: bool = Field(default=False,
-                         description='none')
+    enable: bool = Field(default=False, description='[是否启用]:默认为False')
     next_run: datetime = Field(default="2023-01-01 00:00:00",
-                               description='none')
-    priority: int = Field(default=3,
-                          description='default 3')
+                               description='[下次执行时间]:默认为2023-01-01 00:00:00\n 清空后回车设置当前的时间')
+    interval_days: int = Field(default=1, description='[间隔天数]:默认为1\n 可选0-7')
+    interval_hours: int = Field(default=0, description='[间隔小时]:默认为0\n 可选0-23')
+    interval_minutes: int = Field(default=0, description='[间隔分钟]:默认为0\n 可选0-59')
 

+ 1 - 0
tasks/Hunt/assets.py

@@ -2,6 +2,7 @@ from module.atom.image import RuleImage
 from module.atom.click import RuleClick
 from module.atom.long_click import RuleLongClick
 from module.atom.swipe import RuleSwipe
+from module.atom.ocr import RuleOcr
 
 # This file was automatically generated by module/dev_tools/assets_extract.py.
 # Don't modify it manually.

+ 5 - 5
tasks/Hunt/config_scheduler.py

@@ -6,10 +6,10 @@ from datetime import datetime, time
 from pydantic import BaseModel, ValidationError, validator, Field
 
 class Scheduler(BaseModel):
-    enable: bool = Field(default=False,
-                         description='none')
+    enable: bool = Field(default=False, description='[是否启用]:默认为False')
     next_run: datetime = Field(default="2023-01-01 00:00:00",
-                               description='none')
-    priority: int = Field(default=3,
-                          description='default 3')
+                               description='[下次执行时间]:默认为2023-01-01 00:00:00\n 清空后回车设置当前的时间')
+    interval_days: int = Field(default=1, description='[间隔天数]:默认为1\n 可选0-7')
+    interval_hours: int = Field(default=0, description='[间隔小时]:默认为0\n 可选0-23')
+    interval_minutes: int = Field(default=0, description='[间隔分钟]:默认为0\n 可选0-59')
 

+ 1 - 0
tasks/Nian/assets.py

@@ -2,6 +2,7 @@ from module.atom.image import RuleImage
 from module.atom.click import RuleClick
 from module.atom.long_click import RuleLongClick
 from module.atom.swipe import RuleSwipe
+from module.atom.ocr import RuleOcr
 
 # This file was automatically generated by module/dev_tools/assets_extract.py.
 # Don't modify it manually.

+ 5 - 5
tasks/Nian/config_scheduler.py

@@ -6,10 +6,10 @@ from datetime import datetime, time
 from pydantic import BaseModel, ValidationError, validator, Field
 
 class Scheduler(BaseModel):
-    enable: bool = Field(default=False,
-                         description='none')
+    enable: bool = Field(default=False, description='[是否启用]:默认为False')
     next_run: datetime = Field(default="2023-01-01 00:00:00",
-                               description='none')
-    priority: int = Field(default=3,
-                          description='default 3')
+                               description='[下次执行时间]:默认为2023-01-01 00:00:00\n 清空后回车设置当前的时间')
+    interval_days: int = Field(default=1, description='[间隔天数]:默认为1\n 可选0-7')
+    interval_hours: int = Field(default=0, description='[间隔小时]:默认为0\n 可选0-23')
+    interval_minutes: int = Field(default=0, description='[间隔分钟]:默认为0\n 可选0-59')
 

+ 1 - 0
tasks/Orochi/assets.py

@@ -2,6 +2,7 @@ from module.atom.image import RuleImage
 from module.atom.click import RuleClick
 from module.atom.long_click import RuleLongClick
 from module.atom.swipe import RuleSwipe
+from module.atom.ocr import RuleOcr
 
 # This file was automatically generated by module/dev_tools/assets_extract.py.
 # Don't modify it manually.

+ 5 - 5
tasks/Orochi/config_scheduler.py

@@ -6,10 +6,10 @@ from datetime import datetime, time
 from pydantic import BaseModel, ValidationError, validator, Field
 
 class Scheduler(BaseModel):
-    enable: bool = Field(default=False,
-                         description='none')
+    enable: bool = Field(default=False, description='[是否启用]:默认为False')
     next_run: datetime = Field(default="2023-01-01 00:00:00",
-                               description='none')
-    priority: int = Field(default=3,
-                          description='default 3')
+                               description='[下次执行时间]:默认为2023-01-01 00:00:00\n 清空后回车设置当前的时间')
+    interval_days: int = Field(default=1, description='[间隔天数]:默认为1\n 可选0-7')
+    interval_hours: int = Field(default=0, description='[间隔小时]:默认为0\n 可选0-23')
+    interval_minutes: int = Field(default=0, description='[间隔分钟]:默认为0\n 可选0-59')
 

+ 1 - 0
tasks/OrochiJudgement/assets.py

@@ -2,6 +2,7 @@ from module.atom.image import RuleImage
 from module.atom.click import RuleClick
 from module.atom.long_click import RuleLongClick
 from module.atom.swipe import RuleSwipe
+from module.atom.ocr import RuleOcr
 
 # This file was automatically generated by module/dev_tools/assets_extract.py.
 # Don't modify it manually.

+ 5 - 5
tasks/OrochiJudgement/config_scheduler.py

@@ -6,10 +6,10 @@ from datetime import datetime, time
 from pydantic import BaseModel, ValidationError, validator, Field
 
 class Scheduler(BaseModel):
-    enable: bool = Field(default=False,
-                         description='none')
+    enable: bool = Field(default=False, description='[是否启用]:默认为False')
     next_run: datetime = Field(default="2023-01-01 00:00:00",
-                               description='none')
-    priority: int = Field(default=3,
-                          description='default 3')
+                               description='[下次执行时间]:默认为2023-01-01 00:00:00\n 清空后回车设置当前的时间')
+    interval_days: int = Field(default=1, description='[间隔天数]:默认为1\n 可选0-7')
+    interval_hours: int = Field(default=0, description='[间隔小时]:默认为0\n 可选0-23')
+    interval_minutes: int = Field(default=0, description='[间隔分钟]:默认为0\n 可选0-59')
 

+ 1 - 0
tasks/OrochiMoans/assets.py

@@ -2,6 +2,7 @@ from module.atom.image import RuleImage
 from module.atom.click import RuleClick
 from module.atom.long_click import RuleLongClick
 from module.atom.swipe import RuleSwipe
+from module.atom.ocr import RuleOcr
 
 # This file was automatically generated by module/dev_tools/assets_extract.py.
 # Don't modify it manually.

+ 5 - 5
tasks/OrochiMoans/config_scheduler.py

@@ -6,10 +6,10 @@ from datetime import datetime, time
 from pydantic import BaseModel, ValidationError, validator, Field
 
 class Scheduler(BaseModel):
-    enable: bool = Field(default=False,
-                         description='none')
+    enable: bool = Field(default=False, description='[是否启用]:默认为False')
     next_run: datetime = Field(default="2023-01-01 00:00:00",
-                               description='none')
-    priority: int = Field(default=3,
-                          description='default 3')
+                               description='[下次执行时间]:默认为2023-01-01 00:00:00\n 清空后回车设置当前的时间')
+    interval_days: int = Field(default=1, description='[间隔天数]:默认为1\n 可选0-7')
+    interval_hours: int = Field(default=0, description='[间隔小时]:默认为0\n 可选0-23')
+    interval_minutes: int = Field(default=0, description='[间隔分钟]:默认为0\n 可选0-59')
 

+ 42 - 1
tasks/RealmRaid/assets.py

@@ -2,9 +2,50 @@ from module.atom.image import RuleImage
 from module.atom.click import RuleClick
 from module.atom.long_click import RuleLongClick
 from module.atom.swipe import RuleSwipe
+from module.atom.ocr import RuleOcr
 
 # This file was automatically generated by module/dev_tools/assets_extract.py.
 # Don't modify it manually.
 class RealmRaidAssets: 
-	pass
+
+
+	# Image Rule Assets
+	# 点击结界突破的图片 
+	I_REALM_RAID = RuleImage(roi_front=(246,628,63,64), roi_back=(246,628,63,64), threshold=0.8, method="Template matching", file="./tasks/RealmRaid/res/res_realm_raid.png")
+	# 五个勋章 
+	I_MEDAL_5 = RuleImage(roi_front=(238,205,212,53), roi_back=(216,187,919,364), threshold=0.9, method="Template matching", file="./tasks/RealmRaid/res/res_medal_5.png")
+	# description 
+	I_MEDAL_4 = RuleImage(roi_front=(241,483,193,46), roi_back=(228,178,899,362), threshold=0.9, method="Template matching", file="./tasks/RealmRaid/res/res_medal_4.png")
+	# description 
+	I_MEDAL_3 = RuleImage(roi_front=(240,210,193,41), roi_back=(229,189,894,345), threshold=0.9, method="Template matching", file="./tasks/RealmRaid/res/res_medal_3.png")
+	# description 
+	I_MEDAL_2 = RuleImage(roi_front=(572,478,198,48), roi_back=(217,193,923,354), threshold=0.9, method="Template matching", file="./tasks/RealmRaid/res/res_medal_2.png")
+	# description 
+	I_MEDAL_1 = RuleImage(roi_front=(570,206,199,52), roi_back=(237,198,892,336), threshold=0.9, method="Template matching", file="./tasks/RealmRaid/res/res_medal_1.png")
+	# 没有勋章的 
+	I_MEDAL_0 = RuleImage(roi_front=(510,336,202,51), roi_back=(231,200,898,336), threshold=0.9, method="Template matching", file="./tasks/RealmRaid/res/res_medal_0.png")
+	# 右上角红色的关闭 
+	I_BACK_RED = RuleImage(roi_front=(1178,101,57,64), roi_back=(1178,101,57,64), threshold=0.8, method="Template matching", file="./tasks/RealmRaid/res/res_back_red.png")
+	# 没有锁的状态图标 
+	I_UNLOCK = RuleImage(roi_front=(818,579,38,42), roi_back=(818,579,38,42), threshold=0.8, method="Template matching", file="./tasks/RealmRaid/res/res_unlock.png")
+	# 以锁的状态图片 
+	I_LOCK = RuleImage(roi_front=(818,579,36,41), roi_back=(818,579,36,41), threshold=0.8, method="Template matching", file="./tasks/RealmRaid/res/res_lock.png")
+	# 刷新按钮 
+	I_FRESH = RuleImage(roi_front=(957,564,182,66), roi_back=(957,564,182,66), threshold=0.8, method="Template matching", file="./tasks/RealmRaid/res/res_fresh.png")
+	# 点击的式神录 
+	I_SHIKIGAMI = RuleImage(roi_front=(1206,608,54,51), roi_back=(1206,608,54,51), threshold=0.8, method="Template matching", file="./tasks/RealmRaid/res/res_shikigami.png")
+	# 进攻 
+	I_FIRE = RuleImage(roi_front=(982,494,136,63), roi_back=(140,129,1024,584), threshold=0.8, method="Template matching", file="./tasks/RealmRaid/res/res_fire.png")
+	# 打完个后出现的领取奖励 
+	I_SOUL_RAID = RuleImage(roi_front=(577,502,100,100), roi_back=(577,502,100,100), threshold=0.8, method="Template matching", file="./tasks/RealmRaid/res/res_soul_raid.png")
+	# 刷新确认 
+	I_FRESH_ENSURE = RuleImage(roi_front=(672,403,173,59), roi_back=(672,403,173,59), threshold=0.8, method="Template matching", file="./tasks/RealmRaid/res/res_fresh_ensure.png")
+
+
+	# Ocr Rule Assets
+	# 刷新的时间 
+	O_FRESH_TIME = RuleOcr(roi=(1042,582,85,36), area=(0,0,100,100), mode="Duration", method="Default", keyword="", name="fresh_time")
+	# 右上角 突破卷的数量 
+	O_NUMBER = RuleOcr(roi=(1139,13,91,39), area=(0,0,100,100), mode="DigitCounter", method="Default", keyword="", name="number")
+
 

+ 30 - 1
tasks/RealmRaid/config.py

@@ -2,5 +2,34 @@
 # @author runhey
 # github https://github.com/runhey
 from pydantic import BaseModel, Field
+from enum import Enum
+
+from tasks.RealmRaid.config_scheduler import Scheduler
+from tasks.GeneralBattle.config_general_battle import GeneralBattleConfig
+
+
+class RaidMode(str, Enum):
+    NORMAL = 'retreat_four_attack_nine'
+    ATTACK_ALL = 'attack_all'
+
+class AttackNumber(str, Enum):
+    NINE = 'nine'
+    ALL = 'all'
+
+class RaidConfig(BaseModel):
+    raid_mode: RaidMode = Field(title='Raid Mode', default=RaidMode.NORMAL,
+                                description='[挑战模式]:默认为退四打九\n 退四打九指每次执行前都会退出四次,然后在进攻九次')
+    attack_number: AttackNumber = Field(title='Attack Number', default=AttackNumber.ALL,
+                                        description='[挑战次数]:默认为all,一直打到没有\n nine为打九次')
+
+class RealmRaid(BaseModel):
+    scheduler: Scheduler = Field(default_factory=Scheduler)
+    raid_config: RaidConfig = Field(default_factory=RaidConfig)
+    general_battle_config: GeneralBattleConfig = Field(default_factory=GeneralBattleConfig)
+
+
+
+
+
+
 
-from tasks.RealmRaid.config_scheduler import Scheduler

+ 6 - 7
tasks/RealmRaid/config_scheduler.py

@@ -2,14 +2,13 @@
 # @author runhey
 # github https://github.com/runhey
 from enum import Enum
-from datetime import datetime, time
+from datetime import datetime, timedelta
 from pydantic import BaseModel, ValidationError, validator, Field
 
 class Scheduler(BaseModel):
-    enable: bool = Field(default=False,
-                         description='none')
-    next_run: datetime = Field(default="2023-01-01 00:00:00",
-                               description='none')
-    priority: int = Field(default=3,
-                          description='default 3')
+    enable: bool = Field(default=False, description='[是否启用]:默认为False')
+    next_run: datetime = Field(default="2023-01-01 00:00:00", description='[下次执行时间]:默认为2023-01-01 00:00:00\n 清空后回车设置当前的时间')
+    interval_days: int = Field(default=1, description='[间隔天数]:默认为1\n 可选0-7')
+    interval_hours: int = Field(default=0, description='[间隔小时]:默认为0\n 可选0-23')
+    interval_minutes: int = Field(default=0, description='[间隔分钟]:默认为0\n 可选0-59')
 

+ 137 - 0
tasks/RealmRaid/res/image.json

@@ -0,0 +1,137 @@
+[
+  {
+    "itemName": "realm_raid",
+    "imageName": "res_realm_raid.png",
+    "roiFront": "246,628,63,64",
+    "roiBack": "246,628,63,64",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "点击结界突破的图片"
+  },
+  {
+    "itemName": "medal_5",
+    "imageName": "res_medal_5.png",
+    "roiFront": "238,205,212,53",
+    "roiBack": "216,187,919,364",
+    "method": "Template matching",
+    "threshold": 0.9,
+    "description": "五个勋章"
+  },
+  {
+    "itemName": "medal_4",
+    "imageName": "res_medal_4.png",
+    "roiFront": "241,483,193,46",
+    "roiBack": "228,178,899,362",
+    "method": "Template matching",
+    "threshold": 0.9,
+    "description": "description"
+  },
+  {
+    "itemName": "medal_3",
+    "imageName": "res_medal_3.png",
+    "roiFront": "240,210,193,41",
+    "roiBack": "229,189,894,345",
+    "method": "Template matching",
+    "threshold": 0.9,
+    "description": "description"
+  },
+  {
+    "itemName": "medal_2",
+    "imageName": "res_medal_2.png",
+    "roiFront": "572,478,198,48",
+    "roiBack": "217,193,923,354",
+    "method": "Template matching",
+    "threshold": 0.9,
+    "description": "description"
+  },
+  {
+    "itemName": "medal_1",
+    "imageName": "res_medal_1.png",
+    "roiFront": "570,206,199,52",
+    "roiBack": "237,198,892,336",
+    "method": "Template matching",
+    "threshold": 0.9,
+    "description": "description"
+  },
+  {
+    "itemName": "medal_0",
+    "imageName": "res_medal_0.png",
+    "roiFront": "510,336,202,51",
+    "roiBack": "231,200,898,336",
+    "method": "Template matching",
+    "threshold": 0.9,
+    "description": "没有勋章的"
+  },
+  {
+    "itemName": "back_red",
+    "imageName": "res_back_red.png",
+    "roiFront": "1178,101,57,64",
+    "roiBack": "1178,101,57,64",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "右上角红色的关闭"
+  },
+  {
+    "itemName": "unlock",
+    "imageName": "res_unlock.png",
+    "roiFront": "818,579,38,42",
+    "roiBack": "818,579,38,42",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "没有锁的状态图标"
+  },
+  {
+    "itemName": "lock",
+    "imageName": "res_lock.png",
+    "roiFront": "818,579,36,41",
+    "roiBack": "818,579,36,41",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "以锁的状态图片"
+  },
+  {
+    "itemName": "fresh",
+    "imageName": "res_fresh.png",
+    "roiFront": "957,564,182,66",
+    "roiBack": "957,564,182,66",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "刷新按钮"
+  },
+  {
+    "itemName": "shikigami",
+    "imageName": "res_shikigami.png",
+    "roiFront": "1206,608,54,51",
+    "roiBack": "1206,608,54,51",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "点击的式神录"
+  },
+  {
+    "itemName": "fire",
+    "imageName": "res_fire.png",
+    "roiFront": "982,494,136,63",
+    "roiBack": "140,129,1024,584",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "进攻"
+  },
+  {
+    "itemName": "soul_raid",
+    "imageName": "res_soul_raid.png",
+    "roiFront": "577,502,100,100",
+    "roiBack": "577,502,100,100",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "打完个后出现的领取奖励"
+  },
+  {
+    "itemName": "fresh_ensure",
+    "imageName": "res_fresh_ensure.png",
+    "roiFront": "672,403,173,59",
+    "roiBack": "672,403,173,59",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "刷新确认"
+  }
+]

+ 20 - 0
tasks/RealmRaid/res/ocr.json

@@ -0,0 +1,20 @@
+[
+  {
+    "itemName": "fresh_time",
+    "roiFront": "1042,582,85,36",
+    "roiBack": "0,0,100,100",
+    "mode": "Duration",
+    "method": "Default",
+    "keyword": "",
+    "description": "刷新的时间"
+  },
+  {
+    "itemName": "number",
+    "roiFront": "1139,13,91,39",
+    "roiBack": "0,0,100,100",
+    "mode": "DigitCounter",
+    "method": "Default",
+    "keyword": "",
+    "description": "右上角 突破卷的数量"
+  }
+]

BIN
tasks/RealmRaid/res/res_back_red.png


BIN
tasks/RealmRaid/res/res_fire.png


BIN
tasks/RealmRaid/res/res_fresh.png


BIN
tasks/RealmRaid/res/res_fresh_ensure.png


BIN
tasks/RealmRaid/res/res_lock.png


BIN
tasks/RealmRaid/res/res_medal_0.png


BIN
tasks/RealmRaid/res/res_medal_1.png


BIN
tasks/RealmRaid/res/res_medal_2.png


BIN
tasks/RealmRaid/res/res_medal_3.png


BIN
tasks/RealmRaid/res/res_medal_4.png


BIN
tasks/RealmRaid/res/res_medal_5.png


BIN
tasks/RealmRaid/res/res_realm_raid.png


BIN
tasks/RealmRaid/res/res_shikigami.png


BIN
tasks/RealmRaid/res/res_soul_raid.png


BIN
tasks/RealmRaid/res/res_unlock.png


+ 175 - 0
tasks/RealmRaid/script_task.py

@@ -0,0 +1,175 @@
+# This Python file uses the following encoding: utf-8
+# @author runhey
+# github https://github.com/runhey
+import time
+
+from tasks.base_task import BaseTask
+from tasks.GeneralBattle.general_battle import GeneralBattle
+from tasks.GameUi.game_ui import GameUi
+from tasks.RealmRaid.assets import RealmRaidAssets
+from tasks.RealmRaid.config import RealmRaid, RaidMode, AttackNumber
+from module.logger import logger
+from module.exception import TaskEnd
+
+class ScriptTask(GeneralBattle, GameUi, RealmRaidAssets):
+
+    def run(self):
+        """
+        执行
+        :return:
+        """
+        config = self.config.realm_raid
+        self.home_explore()
+
+        # 点击突破
+        while 1:
+            self.screenshot()
+            if self.appear_then_click(self.I_REALM_RAID, interval=1):
+                continue
+            if self.appear(self.I_BACK_RED, threshold=0.6):
+                break
+        logger.info(f'Click {self.I_REALM_RAID.name}')
+
+        # 判断是不是锁定阵容
+        if config.general_battle_config.lock_team_enable:
+            while 1:
+                self.screenshot()
+                if self.appear_then_click(self.I_UNLOCK, interval=1):
+                    continue
+                if self.appear(self.I_LOCK, threshold=0.9):
+                    break
+            logger.info(f'Click {self.I_UNLOCK.name}')
+        else:
+            while 1:
+                self.screenshot()
+                if self.appear_then_click(self.I_LOCK, interval=1):
+                    continue
+                if self.appear(self.I_UNLOCK, threshold=0.9):
+                    break
+            logger.info(f'Click {self.I_LOCK.name}')
+
+        # 判断是只打九次还是打完去
+        if config.raid_config.attack_number == AttackNumber.NINE:
+            self.execute_round(config)
+        else:
+            while 1:
+                if self.execute_round(config):
+                    continue
+                else:
+                    break
+
+        # 点击 右上角的关闭
+        while 1:
+            self.screenshot()
+            if self.appear_then_click(self.I_BACK_RED, interval=1):
+                continue
+            if self.appear(self.I_REALM_RAID, threshold=0.6):
+                break
+        logger.info(f'Click {self.I_BACK_RED.name}')
+
+        # 点击左上角的关闭
+        self.explore_home()
+
+        self.set_next_run(task='RealmRaid')
+        raise TaskEnd
+
+
+    def is_ticket(self) -> bool:
+        """
+        如果没有票了,那么就返回False
+        :return:
+        """
+        self.screenshot()
+        cu, res, total = self.O_NUMBER.ocr(self.device.image)
+        if cu == 0 and cu+res == total:
+            logger.warning(f'Execute round failed, no ticket')
+            return False
+        return True
+
+    def medal_fire(self) -> bool:
+        """
+        点击勋章
+        :return:
+        """
+        # 点击勋章的挑战 和挑战
+        is_click = False
+        while 1:
+            self.screenshot()
+
+            if self.appear(self.I_FIRE, threshold=0.8):
+                break
+
+            if self.appear_then_click(self.I_SOUL_RAID, interval=1.5):
+                while 1:
+                    self.screenshot()
+                    if self.appear_then_click(self.I_SOUL_RAID, interval=1.5):
+                        continue
+                    if not self.appear(self.I_SOUL_RAID, threshold=0.6):
+                        break
+                continue
+
+            if is_click:
+                continue
+            if self.appear_then_click(self.I_MEDAL_5, interval=1.5):
+                is_click = True
+                continue
+            if self.appear_then_click(self.I_MEDAL_4, interval=1.5):
+                is_click = True
+                continue
+            if self.appear_then_click(self.I_MEDAL_3, interval=1.5):
+                is_click = True
+                continue
+            if self.appear_then_click(self.I_MEDAL_2, interval=1.5):
+                is_click = True
+                continue
+            if self.appear_then_click(self.I_MEDAL_1, interval=1.5):
+                is_click = True
+                continue
+            if self.appear_then_click(self.I_MEDAL_0, interval=1.5):
+                is_click = True
+                continue
+        logger.info(f'Click Medal')
+
+        # 点击挑战
+        self.wait_until_appear(self.I_FIRE)
+        while 1:
+            self.screenshot()
+            if self.appear_then_click(self.I_FIRE, interval=2):
+                continue
+            if not self.appear(self.I_FIRE, threshold=0.8):
+                break
+        logger.info(f'Click {self.I_FIRE.name}')
+
+    def execute_round(self, config: RealmRaid) -> bool:
+        """
+        执行一轮 除非票不够,一直到到九次
+        :return:
+        """
+        # 如果没有票了,就退出
+        if not self.is_ticket():
+            return False
+
+        # 判断是退四打九还是全部打
+        if config.raid_config.raid_mode == RaidMode.NORMAL:
+            logger.info(f'Execute round, retreat four attack nine')
+            self.medal_fire()
+            self.run_general_battle_back(config.general_battle_config)
+
+            self.medal_fire()
+            self.run_general_battle_back(config.general_battle_config)
+
+            self.medal_fire()
+            self.run_general_battle_back(config.general_battle_config)
+
+            self.medal_fire()
+            self.run_general_battle_back(config.general_battle_config)
+
+        # 打九次
+        for i in range(9):
+            if not self.is_ticket():
+                return False
+            self.medal_fire()
+            self.run_general_battle(config.general_battle_config)
+            self.wait_until_appear(self.I_BACK_RED)
+
+        return True

+ 1 - 0
tasks/Restart/assets.py

@@ -2,6 +2,7 @@ from module.atom.image import RuleImage
 from module.atom.click import RuleClick
 from module.atom.long_click import RuleLongClick
 from module.atom.swipe import RuleSwipe
+from module.atom.ocr import RuleOcr
 
 # This file was automatically generated by module/dev_tools/assets_extract.py.
 # Don't modify it manually.

+ 1 - 0
tasks/Script/assets.py

@@ -2,6 +2,7 @@ from module.atom.image import RuleImage
 from module.atom.click import RuleClick
 from module.atom.long_click import RuleLongClick
 from module.atom.swipe import RuleSwipe
+from module.atom.ocr import RuleOcr
 
 # This file was automatically generated by module/dev_tools/assets_extract.py.
 # Don't modify it manually.

+ 1 - 0
tasks/Sougenbi/assets.py

@@ -2,6 +2,7 @@ from module.atom.image import RuleImage
 from module.atom.click import RuleClick
 from module.atom.long_click import RuleLongClick
 from module.atom.swipe import RuleSwipe
+from module.atom.ocr import RuleOcr
 
 # This file was automatically generated by module/dev_tools/assets_extract.py.
 # Don't modify it manually.

+ 5 - 5
tasks/Sougenbi/config_scheduler.py

@@ -6,10 +6,10 @@ from datetime import datetime, time
 from pydantic import BaseModel, ValidationError, validator, Field
 
 class Scheduler(BaseModel):
-    enable: bool = Field(default=False,
-                         description='none')
+    enable: bool = Field(default=False, description='[是否启用]:默认为False')
     next_run: datetime = Field(default="2023-01-01 00:00:00",
-                               description='none')
-    priority: int = Field(default=3,
-                          description='default 3')
+                               description='[下次执行时间]:默认为2023-01-01 00:00:00\n 清空后回车设置当前的时间')
+    interval_days: int = Field(default=1, description='[间隔天数]:默认为1\n 可选0-7')
+    interval_hours: int = Field(default=0, description='[间隔小时]:默认为0\n 可选0-23')
+    interval_minutes: int = Field(default=0, description='[间隔分钟]:默认为0\n 可选0-59')
 

+ 107 - 1
tasks/base_task.py

@@ -1,18 +1,24 @@
 # This Python file uses the following encoding: utf-8
 # @author runhey
 # github https://github.com/runhey
-from datetime import datetime
+import numpy as np
+
+from datetime import datetime, timedelta
 from typing import Union
 
+from module.config.utils import convert_to_underscore
 from module.atom.image import RuleImage
 from module.atom.click import RuleClick
 from module.atom.long_click import RuleLongClick
 from module.atom.swipe import RuleSwipe
+from module.atom.ocr import RuleOcr
+from module.ocr.base_ocr import OcrMode, OcrMethod
 from module.logger import logger
 from module.base.timer import Timer
 from module.config.config import Config
 from module.device.device import Device
 
+
 class BaseTask:
     config: Config = None
     device: Device = None
@@ -30,6 +36,8 @@ class BaseTask:
 
         self.interval_timer = {}  # 这个是用来记录每个匹配的运行间隔的,用于控制运行频率
 
+        self.start_time = datetime.now()  # 启动的时间
+
 
 
 
@@ -239,3 +247,101 @@ class BaseTask:
         # 执行后,如果有限制时间,则重置限制时间
         if interval:
             self.interval_timer[click.name].reset()
+
+    def ocr_appear(self, target: RuleOcr, interval: float=None) -> bool:
+        """
+        ocr识别目标
+        :param interval:
+        :param target:
+        :return: 如果target有keyword或者是keyword存在,返回是True,否则返回False
+                 但是没有指定keyword,返回的是匹配到的值,具体取决于target的mode
+        """
+        if not isinstance(target, RuleOcr):
+            return None
+
+        if interval:
+            if target.name in self.interval_timer:
+                # 如果传入的限制时间不一样,则替换限制新的传入的时间
+                if self.interval_timer[target.name].limit != interval:
+                    self.interval_timer[target.name] = Timer(interval)
+            else:
+                # 如果没有限制时间,则创建限制时间
+                self.interval_timer[target.name] = Timer(interval)
+            # 如果时间还没到达,则不执行
+            if not self.interval_timer[target.name].reached():
+                return None
+
+        result = target.ocr(self.device.image)
+        appear = False
+
+
+        if not target.keyword or target.keyword == '':
+            appear = False
+        match target.mode:
+            case OcrMode.FULL:  # 全匹配
+                appear = result != (0, 0, 0, 0)
+            case OcrMode.SINGLE:
+                appear = result == target.keyword
+            case OcrMode.DIGIT:
+                appear = result == int(target.keyword)
+            case OcrMode.DIGITCOUNTER:
+                appear = result == target.ocr_str_digit_counter(target.keyword)
+            case OcrMode.DURATION:
+                appear = result == target.parse_time(target.keyword)
+
+        if interval and appear:
+            self.interval_timer[target.name].reset()
+
+        return appear
+
+    def ocr_appear_click(self,
+                         target: RuleOcr,
+                         action: Union[RuleClick, RuleLongClick]=None,
+                         interval: float=None,
+                         duration: float = None) -> bool:
+        """
+        ocr识别目标,如果目标存在,则触发动作
+        :param target:
+        :param action:
+        :param interval:
+        :param duration:
+        :return:
+        """
+        appear = self.ocr_appear(target, interval)
+
+        if not appear:
+            return False
+
+        if action:
+            x, y = action.coord()
+            self.click(action, interval)
+        else:
+            x, y = target.coord()
+            self.device.click(x=x, y=y, control_name=target.name)
+
+
+    def set_next_run(self, task: str, finish: bool=False) -> None:
+        """
+        设置下次运行时间  当然这个也是可以重写的
+        :param task: 任务名称,大驼峰的
+        :param finish: 是完成任务后的时间为基准还是开始任务的时间为基准
+        :return:
+        """
+        task = convert_to_underscore(task)
+        task_object = getattr(self.config.model, task, None)
+        if not task_object:
+            logger.warning(f'No task named {task}')
+            return
+
+        if finish:
+            start_time = datetime.now()
+        else:
+            start_time = self.start_time
+        delta = timedelta(days=task_object.scheduler.interval_days,
+                          hours=task_object.scheduler.interval_hours,
+                          minutes=task_object.scheduler.interval_minutes,)
+        next_run = start_time + delta
+
+        task_object.scheduler.next_run = next_run
+        self.config.save()
+

برخی فایل ها در این مقایسه diff نمایش داده نمی شوند زیرا تعداد فایل ها بسیار زیاد است