Browse Source

Merge pull request #55 from runhey/dev

Dev
huangrunheng 3 years ago
parent
commit
9578461914
56 changed files with 1032 additions and 233 deletions
  1. 9 1
      module/config/argument/setting-template.json
  2. 4 5
      module/config/config.py
  3. BIN
      module/config/i18n/zh_CN.qm
  4. 17 0
      module/config/i18n/zh_CN.ts
  5. 29 27
      module/gui/context/process_manager.py
  6. 28 49
      module/gui/qml/Component/Overview.qml
  7. 14 6
      module/gui/qml/Global/MainEvent.qml
  8. 6 0
      module/gui/qml/Page/ScriptView.qml
  9. 21 8
      module/logger.py
  10. 18 0
      module/ocr/base_ocr.py
  11. 1 1
      module/ocr/models.py
  12. 11 2
      script.py
  13. 4 0
      tasks/Component/GeneralBattle/assets.py
  14. BIN
      tasks/Component/GeneralBattle/gb/gb_reward_gold.png
  15. BIN
      tasks/Component/GeneralBattle/gb/gb_reward_statistics.png
  16. 18 0
      tasks/Component/GeneralBattle/gb/image.json
  17. 56 19
      tasks/Component/GeneralBattle/general_battle.py
  18. 19 2
      tasks/Component/GeneralInvite/config_invite.py
  19. 18 1
      tasks/Component/config_base.py
  20. 6 4
      tasks/GameUi/game_ui.py
  21. BIN
      tasks/KekkaiActivation/a/a_a_harvest_kaiko_3.png
  22. BIN
      tasks/KekkaiActivation/a/a_a_harvest_kaiko_4.png
  23. 18 0
      tasks/KekkaiActivation/a/image.json
  24. 4 0
      tasks/KekkaiActivation/assets.py
  25. 3 1
      tasks/KekkaiActivation/script_task.py
  26. 6 2
      tasks/KekkaiUtilize/assets.py
  27. 9 0
      tasks/KekkaiUtilize/realm/image.json
  28. BIN
      tasks/KekkaiUtilize/realm/realm_box_exp_max.png
  29. 21 8
      tasks/KekkaiUtilize/script_task.py
  30. 2 2
      tasks/KekkaiUtilize/utilize/image.json
  31. 9 0
      tasks/KekkaiUtilize/utilize/ocr.json
  32. BIN
      tasks/KekkaiUtilize/utilize/utilize_u_fish_3.png
  33. BIN
      tasks/KekkaiUtilize/utilize/utilize_u_moon_6.png
  34. BIN
      tasks/KekkaiUtilize/utilize/utilize_u_taiko_6.png
  35. 8 1
      tasks/Orochi/assets.py
  36. 9 0
      tasks/Orochi/o/image.json
  37. BIN
      tasks/Orochi/o/o_pet_present.png
  38. 1 1
      tasks/Orochi/res/list.json
  39. 11 0
      tasks/Orochi/res/ocr.json
  40. 34 6
      tasks/Orochi/script_task.py
  41. 50 0
      tasks/RealmRaid/assets.py
  42. 16 4
      tasks/RealmRaid/config.py
  43. 38 0
      tasks/RealmRaid/res/image2.json
  44. 81 0
      tasks/RealmRaid/res/ocr.json
  45. 56 0
      tasks/RealmRaid/res/partition.json
  46. BIN
      tasks/RealmRaid/res/res_frog_medal.png
  47. BIN
      tasks/RealmRaid/res/res_frog_raid.png
  48. BIN
      tasks/RealmRaid/res/res_rr_person.png
  49. BIN
      tasks/RealmRaid/res/res_rr_three.png
  50. 342 75
      tasks/RealmRaid/script_task.py
  51. 4 0
      tasks/Restart/assets.py
  52. 5 4
      tasks/Restart/login.py
  53. 9 0
      tasks/Restart/login/image.json
  54. BIN
      tasks/Restart/login/login_login_specific_serve.png
  55. 9 0
      tasks/Restart/login/ocr.json
  56. 8 4
      tasks/base_task.py

+ 9 - 1
module/config/argument/setting-template.json

@@ -1 +1,9 @@
-{"displayMode":1,"darkMode":2,"primaryColor":"Yellow","nativeText":true,"language":"简体中文","dpiStrategy":"default"}
+{
+    "displayMode": 1,
+    "darkMode": 2,
+    "primaryColor": "Yellow",
+    "nativeText": true,
+    "language": "简体中文",
+    "dpiStrategy": "default",
+    "branch": "master"
+}

+ 4 - 5
module/config/config.py

@@ -115,7 +115,8 @@ class Config(ConfigState, ConfigManual, ConfigWatcher, ConfigMenu):
         try:
         try:
             return getattr(self.model, name)
             return getattr(self.model, name)
         except AttributeError:
         except AttributeError:
-            logger.error(f'can not ask this variable {name}')
+            # 这个导致 大量的无用log
+            # logger.error(f'can not ask this variable {name}')
             return None  # 或者抛出异常,或者返回其他默认值
             return None  # 或者抛出异常,或者返回其他默认值
 
 
     def gui_args(self, task: str) -> str:
     def gui_args(self, task: str) -> str:
@@ -243,7 +244,7 @@ class Config(ConfigState, ConfigManual, ConfigWatcher, ConfigMenu):
             return False
             return False
 
 
     def task_delay(self, task: str, start_time: datetime = None,
     def task_delay(self, task: str, start_time: datetime = None,
-                   success: bool=None, server: bool=True, target: timedelta=None) -> None:
+                   success: bool=None, server: bool=True, target: datetime=None) -> None:
         """
         """
         设置下次运行时间  当然这个也是可以重写的
         设置下次运行时间  当然这个也是可以重写的
         :param target: 可以自定义的下次运行时间
         :param target: 可以自定义的下次运行时间
@@ -329,10 +330,8 @@ class Config(ConfigState, ConfigManual, ConfigWatcher, ConfigMenu):
 if __name__ == '__main__':
 if __name__ == '__main__':
     config = Config(config_name='oas1')
     config = Config(config_name='oas1')
     config.update_scheduler()
     config.update_scheduler()
-    print(config.pending_task)
     print(config.waiting_task)
     print(config.waiting_task)
-    config.update_scheduler()
-    print(config.pending_task)
+
     # print(config.get_next())
     # print(config.get_next())
 
 
 
 

BIN
module/config/i18n/zh_CN.qm


+ 17 - 0
module/config/i18n/zh_CN.ts

@@ -520,4 +520,21 @@ mode_3策略是刷到五个契灵后开始结契,选择高级、中级盘来
 	<message><source>Notify Config</source><translation>推送配置</translation></message>	
 	<message><source>Notify Config</source><translation>推送配置</translation></message>	
 	<message><source>notify_config_help</source><translation>输入为yaml格式,":"冒号后有一个空格,具体请翻阅文档[消息推送]</translation></message>	
 	<message><source>notify_config_help</source><translation>输入为yaml格式,":"冒号后有一个空格,具体请翻阅文档[消息推送]</translation></message>	
 </context>		
 </context>		
+<context>
+    <name>Args</name>
+	<message><source>Number Attack</source><translation>挑战次数</translation></message>	
+	<message><source>Exit Four</source><translation>当进攻到左上角第一个的时候先退四次再进攻</translation></message>	
+	<message><source>Order Attack</source><translation>挑战顺序</translation></message>
+	<message><source>WhenAttackFail</source><translation>挑战失败时</translation></message>
+	<message><source>Three Refresh</source><translation>每三次就刷新</translation></message>
+	<message><source>Number Base</source><translation>突破卷数量大于等于 X 时才会挑战</translation></message>
+	<message><source>number_attack_help</source><translation>默认30,可选范围[1~30],没有挑战卷自动退出任务(标记为成功)</translation></message>
+	<message><source>exit_four_help</source><translation>为了支持打九退四,保证稳定57级</translation></message>	
+	<message><source>order_attack_help</source><translation>使用过滤器,保持默认即可</translation></message>
+	<message><source>when_attack_fail_help</source><translation>Exit:直接退出任务,标记为失败
+Continue:挑战其他的直至没有可挑战的才刷新
+Refresh:直接刷新,如果刷新操作进入CD,将标记为失败并退出</translation></message>
+	<message><source>three_refresh_help</source><translation>挑战进度到三,领取奖励后就刷新,如果刷新操作进入CD,将标记为失败并退出</translation></message>
+	<message><source>number_base_help</source><translation>旨在检查突破卷数量,如果当前的数量没有大于等于这个值,将标记为成功并退出</translation></message>
+</context>	
 </TS>
 </TS>

+ 29 - 27
module/gui/context/process_manager.py

@@ -40,10 +40,10 @@ def is_port_in_use(ip, port) -> bool:
     try:
     try:
         s.connect((ip, port))
         s.connect((ip, port))
         s.shutdown(2)
         s.shutdown(2)
-        logger.info(f'port {port} is in use')
+        logger.info(f'Port {port} is in use')
         return True
         return True
     except:
     except:
-        logger.info(f'port {port} is not in use')
+        logger.info(f'Port {port} is not in use')
         return False
         return False
 
 
 
 
@@ -77,7 +77,9 @@ class ProcessManager(QObject):
         self.update_thread: Thread = None  # 更新线程
         self.update_thread: Thread = None  # 更新线程
         self.start_update_tasks()  # 启动更新线程
         self.start_update_tasks()  # 启动更新线程
 
 
-        self.event_loop = asyncio.get_event_loop()  # 事件循环
+        # self.event_loop = asyncio.get_event_loop()  # 事件循环
+
+
 
 
     @Slot()
     @Slot()
     def create_all(self) -> None:
     def create_all(self) -> None:
@@ -110,17 +112,17 @@ class ProcessManager(QObject):
             self.log_thread[config].start()
             self.log_thread[config].start()
 
 
             # 下面是启动 zerorpc 客户端
             # 下面是启动 zerorpc 客户端
-            logger.info(f'create script {config} on port {port}')
+            logger.info(f'Create script {config} on port {port}')
             try:
             try:
                 self.clients[config] = zerorpc.Client()
                 self.clients[config] = zerorpc.Client()
                 self.clients[config].connect(f'tcp://127.0.0.1:{self.ports[config]}')
                 self.clients[config].connect(f'tcp://127.0.0.1:{self.ports[config]}')
             except:
             except:
-                logger.exception(f'connect to script {config} error')
+                logger.exception(f'Connect to script {config} error')
                 raise
                 raise
             self.processes[config].start()
             self.processes[config].start()
-            logger.info(f'add script {config}')
+            logger.info(f'Add script {config}')
         else:
         else:
-            logger.info(f'script {config} is already running')
+            logger.info(f'Script {config} is already running')
 
 
     def remove(self, config: str) -> None:
     def remove(self, config: str) -> None:
         """
         """
@@ -133,10 +135,10 @@ class ProcessManager(QObject):
             del self.processes[config]
             del self.processes[config]
             del self.ports[config]
             del self.ports[config]
             del self.clients[config]
             del self.clients[config]
-            logger.info(f'remove script {config}')
-            logger.info(f'port {config} is released')
+            logger.info(f'Remove script {config}')
+            logger.info(f'Port {config} is released')
         else:
         else:
-            logger.info(f'script {config} is not running')
+            logger.info(f'Script {config} is not running')
 
 
     @Slot(str)
     @Slot(str)
     def restart(self, config: str) -> None:
     def restart(self, config: str) -> None:
@@ -166,9 +168,9 @@ class ProcessManager(QObject):
                                                    log_queue=self.log_queue[config],
                                                    log_queue=self.log_queue[config],
                                                    update_queue=self.update_queue)
                                                    update_queue=self.update_queue)
             self.processes[config].start()
             self.processes[config].start()
-            logger.info(f'restart script {config}')
+            logger.info(f'Restart script {config}')
         else:
         else:
-            logger.info(f'script {config} is not running')
+            logger.info(f'Script {config} is not running')
 
 
     def stop_all(self) -> None:
     def stop_all(self) -> None:
         """
         """
@@ -177,7 +179,7 @@ class ProcessManager(QObject):
         """
         """
         for config in self.processes:
         for config in self.processes:
             self.processes[config].stop()
             self.processes[config].stop()
-        logger.info(f'stop all script')
+        logger.info(f'Stop all script')
 
 
     def restart_all(self) -> None:
     def restart_all(self) -> None:
         """
         """
@@ -186,7 +188,7 @@ class ProcessManager(QObject):
         """
         """
         for config in self.processes:
         for config in self.processes:
             self.processes[config].restart()
             self.processes[config].restart()
-        logger.info(f'restart all script')
+        logger.info(f'Restart all script')
 
 
     def get_client(self, config: str) -> zerorpc.Client:
     def get_client(self, config: str) -> zerorpc.Client:
         """
         """
@@ -197,7 +199,7 @@ class ProcessManager(QObject):
         if config in self.clients:
         if config in self.clients:
             return self.clients[config]
             return self.clients[config]
         else:
         else:
-            logger.info(f'script {config} is not running')
+            logger.info(f'Script {config} is not running')
             return None
             return None
 
 
     @Slot(result="QString")
     @Slot(result="QString")
@@ -234,10 +236,10 @@ class ProcessManager(QObject):
         :return:
         :return:
         """
         """
         if config in self.clients:
         if config in self.clients:
-            logger.info(f'gui get args of {config} {task}')
+            logger.info(f'Gui get args of {config} {task}')
             return self.check_script(config).gui_args(task)
             return self.check_script(config).gui_args(task)
         else:
         else:
-            logger.info(f'script {config} is not running')
+            logger.info(f'Script {config} is not running')
             return None
             return None
 
 
     @Slot(str, str, result="QString")
     @Slot(str, str, result="QString")
@@ -249,10 +251,10 @@ class ProcessManager(QObject):
         :return:
         :return:
         """
         """
         if config in self.clients:
         if config in self.clients:
-            logger.info(f'gui get value of {config} {task}')
+            logger.info(f'Gui get value of {config} {task}')
             return self.check_script(config).gui_task(task)
             return self.check_script(config).gui_task(task)
         else:
         else:
-            logger.info(f'script {config} is not running')
+            logger.info(f'Script {config} is not running')
             return None
             return None
 
 
     @Slot(str, str, str, str, str, result="bool")
     @Slot(str, str, str, str, str, result="bool")
@@ -267,13 +269,13 @@ class ProcessManager(QObject):
         :return:
         :return:
         """
         """
         if config in self.clients:
         if config in self.clients:
-            logger.info(f'gui set value of {config} {task}')
+            logger.info(f'Gui set value of {config} {task}')
             if self.check_script(config).gui_set_task(task, group, arg, value):
             if self.check_script(config).gui_set_task(task, group, arg, value):
                 return True
                 return True
             else:
             else:
                 return False
                 return False
         else:
         else:
-            logger.info(f'script {config} is not running')
+            logger.info(f'Script {config} is not running')
             return False
             return False
 
 
     @Slot(str, str, str, str, bool, result="bool")
     @Slot(str, str, str, str, bool, result="bool")
@@ -288,13 +290,13 @@ class ProcessManager(QObject):
         :return:
         :return:
         """
         """
         if config in self.clients:
         if config in self.clients:
-            logger.info(f'gui set value of {config} {task}')
+            logger.info(f'Gui set value of {config} {task}')
             if self.check_script(config).gui_set_task(task, group, arg, value):
             if self.check_script(config).gui_set_task(task, group, arg, value):
                 return True
                 return True
             else:
             else:
                 return False
                 return False
         else:
         else:
-            logger.info(f'script {config} is not running')
+            logger.info(f'Script {config} is not running')
             return False
             return False
 
 
     @Slot(str, str, str, str, float, result="bool")
     @Slot(str, str, str, str, float, result="bool")
@@ -309,13 +311,13 @@ class ProcessManager(QObject):
         :return:
         :return:
         """
         """
         if config in self.clients:
         if config in self.clients:
-            logger.info(f'gui set value of {config} {task}')
+            logger.info(f'Gui set value of {config} {task}')
             if self.check_script(config).gui_set_task(task, group, arg, value):
             if self.check_script(config).gui_set_task(task, group, arg, value):
                 return True
                 return True
             else:
             else:
                 return False
                 return False
         else:
         else:
-            logger.info(f'script {config} is not running')
+            logger.info(f'Script {config} is not running')
             return False
             return False
 
 
     @Slot(str, result="QImage")
     @Slot(str, result="QImage")
@@ -325,7 +327,7 @@ class ProcessManager(QObject):
         :return:
         :return:
         """
         """
         if config in self.clients:
         if config in self.clients:
-            logger.info(f'gui get mirror image of {config}')
+            logger.info(f'Gui get mirror image of {config}')
             # 接收流对象
             # 接收流对象
             stream = self.clients[config].gui_mirror_image()
             stream = self.clients[config].gui_mirror_image()
             # 创建 BytesIO 对象来存储图像数据
             # 创建 BytesIO 对象来存储图像数据
@@ -344,7 +346,7 @@ class ProcessManager(QObject):
 
 
 
 
         else:
         else:
-            logger.info(f'script {config} is not running')
+            logger.info(f'Script {config} is not running')
             return None
             return None
 
 
 
 

+ 28 - 49
module/gui/qml/Component/Overview.qml

@@ -175,41 +175,6 @@ Item {
                     }
                     }
                 }
                 }
             }
             }
-
-//            ColumnLayout{
-//                width: parent.width
-//                spacing: 8
-//                FluText{
-//                    text: 'Pending'
-//                    Layout.leftMargin: 16
-//                    Layout.topMargin: 6
-//                    font: FluTextStyle.Subtitle
-//                }
-//                Rectangle{
-//                    // 这个是一条横线
-//                    width: schedulerRunning.width - 20
-//                    height: 2
-//                    Layout.alignment: Qt.AlignHCenter
-//                    color: FluTheme.dark ? Qt.rgba(64/255, 68/255, 75/255, 1) : Qt.rgba(234/255, 236/255, 239/255, 1)
-//                    radius: 2
-//                }
-//                ListView{
-//                    id: pendingListView
-//                    Layout.alignment: Qt.AlignHCenter
-//                    width: 225
-//                    height: 200
-//                    spacing: 8
-//                    model: ListModel{
-//                        id: pendingListModel
-//                    }
-//                    delegate: Component{
-//                        Taskmini{
-//                            name: model.name
-//                            nextRun: model.next_run
-//                        }
-//                    }
-//                }
-//            }
         }
         }
         FluArea{
         FluArea{
             id: schedulerWaiting
             id: schedulerWaiting
@@ -219,28 +184,42 @@ Item {
             anchors.bottomMargin: 0
             anchors.bottomMargin: 0
             width: parent.width                  
             width: parent.width                  
 
 
-            ColumnLayout{
-                width: parent.width
-                spacing: 8
-                FluText{
-                    Layout.fillHeight: false
-                    text: 'Waiting'
-                    Layout.leftMargin: 16
-                    Layout.topMargin: 6
-                    font: FluTextStyle.Subtitle
+//            ColumnLayout{
+//                width: parent.width
+//                spacing: 8
+            FluText{
+                id: waitingText
+                anchors{
+                    top: parent.top
+                    topMargin: 6
+
                 }
                 }
+                width: parent.width
+                text: 'Waiting'
+                leftPadding: 16
+                font: FluTextStyle.Subtitle
+            }
                 Rectangle{
                 Rectangle{
-                    Layout.fillHeight: false
+                    id: lineWaiting
+                    anchors{
+                        top: waitingText.bottom
+                        topMargin: 8
+                        horizontalCenter: parent.horizontalCenter
+                    }
                     width: schedulerPending.width - 20
                     width: schedulerPending.width - 20
                     height: 2
                     height: 2
-                    Layout.alignment: Qt.AlignHCenter
                     color: FluTheme.dark ? Qt.rgba(64/255, 68/255, 75/255, 1) : Qt.rgba(234/255, 236/255, 239/255, 1)
                     color: FluTheme.dark ? Qt.rgba(64/255, 68/255, 75/255, 1) : Qt.rgba(234/255, 236/255, 239/255, 1)
                     radius: 2
                     radius: 2
                 }
                 }
                 ListView{
                 ListView{
                     id: waitingListView
                     id: waitingListView
-                    Layout.fillHeight: true
-                    Layout.alignment: Qt.AlignHCenter
+                    anchors{
+                        top: lineWaiting.bottom
+                        topMargin: 8
+                        bottom: parent.bottom
+                        bottomMargin: 8
+                        horizontalCenter: parent.horizontalCenter
+                    }
                     width: 225
                     width: 225
                     clip: true
                     clip: true
                     spacing: 8
                     spacing: 8
@@ -257,7 +236,7 @@ Item {
                         }
                         }
                     }
                     }
                 }
                 }
-            }
+//            }
         }
         }
     }
     }
 
 

+ 14 - 6
module/gui/qml/Global/MainEvent.qml

@@ -24,6 +24,7 @@ QtObject {
     property bool nativeText: true
     property bool nativeText: true
     property string language: ""
     property string language: ""
     property string dpiStrategy: ""
     property string dpiStrategy: ""
+    property string branch: ""
 
 
     property int runStatus: MainEvent.RunStatus.Empty
     property int runStatus: MainEvent.RunStatus.Empty
     property string menuTitle: ""
     property string menuTitle: ""
@@ -53,6 +54,13 @@ QtObject {
         mainEvent.nativeText = set["nativeText"]
         mainEvent.nativeText = set["nativeText"]
         mainEvent.language = set["language"]
         mainEvent.language = set["language"]
         mainEvent.dpiStrategy = set["dpiStrategy"]
         mainEvent.dpiStrategy = set["dpiStrategy"]
+        if ('branch' in set){
+            mainEvent.branch = set['branch']
+        }else{
+            mainEvent.branch = "master"
+            mainEvent.settings["branch"] = mainEvent.branch
+            setting.update(JSON.stringify(mainEvent.settings, null, "  "))
+        }
 
 
         var primary_color = set["primaryColor"]
         var primary_color = set["primaryColor"]
         if(primary_color === "Yellow"){mainEvent.primaryColor = FluColors.Yellow}
         if(primary_color === "Yellow"){mainEvent.primaryColor = FluColors.Yellow}
@@ -76,7 +84,7 @@ QtObject {
         if(settingInit){
         if(settingInit){
             return
             return
         }
         }
-        setting.update(JSON.stringify(mainEvent.settings))
+        setting.update(JSON.stringify(mainEvent.settings, null, "  "))
     }
     }
     onDarkModeChanged: {
     onDarkModeChanged: {
 
 
@@ -88,7 +96,7 @@ QtObject {
         if(settingInit){
         if(settingInit){
             return
             return
         }
         }
-        setting.update(JSON.stringify(mainEvent.settings))
+        setting.update(JSON.stringify(mainEvent.settings, null, "  "))
     }
     }
     onPrimaryColorChanged: {
     onPrimaryColorChanged: {
         if(mainEvent.settings === ""){
         if(mainEvent.settings === ""){
@@ -112,7 +120,7 @@ QtObject {
         if(settingInit){
         if(settingInit){
             return
             return
         }
         }
-        setting.update(JSON.stringify(mainEvent.settings))
+        setting.update(JSON.stringify(mainEvent.settings, null, "  "))
     }
     }
     onNativeTextChanged: {
     onNativeTextChanged: {
 
 
@@ -125,7 +133,7 @@ QtObject {
         if(settingInit){
         if(settingInit){
             return
             return
         }
         }
-        setting.update(JSON.stringify(mainEvent.settings))
+        setting.update(JSON.stringify(mainEvent.settings, null, "  "))
     }
     }
     onLanguageChanged: {
     onLanguageChanged: {
         if(mainEvent.settings === ""){
         if(mainEvent.settings === ""){
@@ -137,7 +145,7 @@ QtObject {
         if(settingInit){
         if(settingInit){
             return
             return
         }
         }
-        setting.update(JSON.stringify(mainEvent.settings))
+        setting.update(JSON.stringify(mainEvent.settings, null, "  "))
 
 
     }
     }
     onDpiStrategyChanged: {
     onDpiStrategyChanged: {
@@ -149,6 +157,6 @@ QtObject {
         if(settingInit){
         if(settingInit){
             return
             return
         }
         }
-        setting.update(JSON.stringify(mainEvent.settings))
+        setting.update(JSON.stringify(mainEvent.settings, null, "  "))
     }
     }
 }
 }

+ 6 - 0
module/gui/qml/Page/ScriptView.qml

@@ -107,6 +107,12 @@ SplitPanel{
 
 
         //创建左边的菜单
         //创建左边的菜单
         const data = JSON.parse(process_manager.gui_menu())
         const data = JSON.parse(process_manager.gui_menu())
+        if(MainEvent.branch == 'master'){
+            if('Tools' in data){
+                delete data['Tools']
+            }
+        }
+
         create(data)
         create(data)
 
 
         // 点击的时候顺带创建 python 进程
         // 点击的时候顺带创建 python 进程

+ 21 - 8
module/logger.py

@@ -10,7 +10,7 @@ import traceback
 from io import TextIOBase
 from io import TextIOBase
 from typing import Callable, List
 from typing import Callable, List
 
 
-from rich.console import Console, ConsoleOptions, ConsoleRenderable, NewLine
+from rich.console import Console, ConsoleOptions, ConsoleRenderable, NewLine, RenderResult
 from rich.highlighter import RegexHighlighter, NullHighlighter
 from rich.highlighter import RegexHighlighter, NullHighlighter
 from rich.logging import RichHandler
 from rich.logging import RichHandler
 from rich.text import Text
 from rich.text import Text
@@ -108,7 +108,7 @@ class RichRenderableHandler(RichHandler):
         # 这个message_renderable是一个Text对象
         # 这个message_renderable是一个Text对象
         # traceback是表示异常的对象
         # traceback是表示异常的对象
         # Directly put renderable into function
         # Directly put renderable into function
-        self._func(message_renderable)
+        self._func(log_renderable)
 
 
     def handle(self, record: logging.LogRecord) -> bool:
     def handle(self, record: logging.LogRecord) -> bool:
         if not self._func:
         if not self._func:
@@ -190,7 +190,7 @@ logger_debug = False
 logger = logging.getLogger('oas')
 logger = logging.getLogger('oas')
 logger.setLevel(logging.DEBUG if logger_debug else logging.INFO)
 logger.setLevel(logging.DEBUG if logger_debug else logging.INFO)
 file_formatter = logging.Formatter(
 file_formatter = logging.Formatter(
-    fmt='%(asctime)s.%(msecs)03d | %(levelname)s | %(message)s', datefmt='%Y-%m-%d %H:%M:%S')
+    fmt='%(asctime)s.%(msecs)03d | %(levelname)8s | %(message)s', datefmt='%Y-%m-%d %H:%M:%S')
 console_formatter = logging.Formatter(
 console_formatter = logging.Formatter(
     fmt='%(asctime)s.%(msecs)03d │ %(message)s', datefmt='%Y-%m-%d %H:%M:%S')
     fmt='%(asctime)s.%(msecs)03d │ %(message)s', datefmt='%Y-%m-%d %H:%M:%S')
 web_formatter = logging.Formatter(
 web_formatter = logging.Formatter(
@@ -203,6 +203,9 @@ web_formatter = logging.Formatter(
 # logger.addHandler(console)
 # logger.addHandler(console)
 
 
 # Add rich console logger
 # Add rich console logger
+# ======================================================================================================================
+#            设置控制台的
+# ======================================================================================================================
 stdout_console = console = Console()
 stdout_console = console = Console()
 console_hdlr = RichHandler(
 console_hdlr = RichHandler(
     show_path=False,
     show_path=False,
@@ -252,7 +255,7 @@ def set_file_logger(name=pyw_name):
         file=file,
         file=file,
         no_color=True,
         no_color=True,
         highlight=False,
         highlight=False,
-        width=119,
+        width=120,
     )
     )
 
 
     hdlr = RichFileHandler(
     hdlr = RichFileHandler(
@@ -263,6 +266,7 @@ def set_file_logger(name=pyw_name):
         rich_tracebacks=True,
         rich_tracebacks=True,
         tracebacks_show_locals=True,
         tracebacks_show_locals=True,
         tracebacks_extra_lines=3,
         tracebacks_extra_lines=3,
+        tracebacks_width=80,
         highlighter=NullHighlighter(),
         highlighter=NullHighlighter(),
     )
     )
     hdlr.setFormatter(file_formatter)
     hdlr.setFormatter(file_formatter)
@@ -278,9 +282,11 @@ def set_func_logger(func):
     stream = LogStream(func=func)
     stream = LogStream(func=func)
     file_console = Console(
     file_console = Console(
         file=stream,
         file=stream,
+        force_terminal=False,
+        force_interactive=False,
         no_color=True,
         no_color=True,
         highlight=False,
         highlight=False,
-        width=160,
+        width=120,
     )
     )
     hdlr = RichStreamHandler(
     hdlr = RichStreamHandler(
         console=file_console,
         console=file_console,
@@ -329,10 +335,16 @@ def print(*objects: ConsoleRenderable, **kwargs):
         elif isinstance(hdlr, RichHandler):
         elif isinstance(hdlr, RichHandler):
             hdlr.console.print(*objects)
             hdlr.console.print(*objects)
 
 
+class GuiRule(Rule):
+    def __rich_console__(
+            self, console: Console, options: ConsoleOptions
+    ) -> RenderResult:
+        options.max_width = 80
+        return super().__rich_console__(console, options)
 
 
 def rule(title="", *, characters="─", style="rule.line", end="\n", align="center"):
 def rule(title="", *, characters="─", style="rule.line", end="\n", align="center"):
-    rule = Rule(title=title, characters=characters,
-                style=style, end=end, align=align)
+    rule = GuiRule(title=title, characters=characters,
+                style=style, end=end)
     print(rule)
     print(rule)
 
 
 
 
@@ -348,7 +360,7 @@ def hr(title, level=3):
         logger.info(f"[bold]<<< {title} >>>[/bold]", extra={"markup": True})
         logger.info(f"[bold]<<< {title} >>>[/bold]", extra={"markup": True})
     if level == 0:
     if level == 0:
         logger.rule(characters='═')
         logger.rule(characters='═')
-        logger.rule(title, characters=' ')
+        logger.rule(title, characters='-')
         logger.rule(characters='═')
         logger.rule(characters='═')
 
 
 
 
@@ -404,3 +416,4 @@ logger.log_file: str
 logger.set_file_logger()
 logger.set_file_logger()
 logger.hr('Start', level=0)
 logger.hr('Start', level=0)
 
 
+

+ 18 - 0
module/ocr/base_ocr.py

@@ -17,6 +17,22 @@ from module.exception import ScriptError
 from module.logger import logger
 from module.logger import logger
 
 
 
 
+
+def enlarge_canvas(image):
+    """
+    copy from https://github.com/LmeSzinc/StarRailCopilot
+    Enlarge image into a square fill with black background. In the structure of PaddleOCR,
+    image with w:h=1:1 is the best while 3:1 rectangles takes three times as long.
+    Also enlarge into the integer multiple of 32 cause PaddleOCR will downscale images to 1/32.
+    """
+    height, width = image.shape[:2]
+    length = int(max(width, height) // 32 * 32 + 32)
+    border = (0, length - height, 0, length - width)
+    if sum(border) > 0:
+        image = cv2.copyMakeBorder(image, *border, borderType=cv2.BORDER_CONSTANT, value=(0, 0, 0))
+    return image
+
+
 class OcrMode(Enum):
 class OcrMode(Enum):
     FULL = 1  # str: "Full"
     FULL = 1  # str: "Full"
     SINGLE = 2  # str: "Single"
     SINGLE = 2  # str: "Single"
@@ -142,6 +158,7 @@ class BaseCor:
                     text=f'[{result}]')
                     text=f'[{result}]')
         return result
         return result
 
 
+
     def detect_and_ocr(self, image) -> list[BoxedResult]:
     def detect_and_ocr(self, image) -> list[BoxedResult]:
         """
         """
         注意:这里使用了预处理和后处理
         注意:这里使用了预处理和后处理
@@ -152,6 +169,7 @@ class BaseCor:
         start_time = time.time()
         start_time = time.time()
         image = self.crop(image, self.roi)
         image = self.crop(image, self.roi)
         image = self.pre_process(image)
         image = self.pre_process(image)
+        image = enlarge_canvas(image)
 
 
         # ocr
         # ocr
         boxed_results: list[BoxedResult] = self.model.detect_and_ocr(image)
         boxed_results: list[BoxedResult] = self.model.detect_and_ocr(image)

+ 1 - 1
module/ocr/models.py

@@ -22,7 +22,7 @@ if __name__ == "__main__":
     # 引入ocr 会导致非常巨大的内存开销
     # 引入ocr 会导致非常巨大的内存开销
     @profile
     @profile
     def test_memory():
     def test_memory():
-        for i in range(10):
+        for i in range(2):
             start_time = time.time()
             start_time = time.time()
             result = model.detect_and_ocr(image)
             result = model.detect_and_ocr(image)
             print(result)
             print(result)

+ 11 - 2
script.py

@@ -155,9 +155,18 @@ class Script:
         设置给gui显示的任务 的参数的具体值
         设置给gui显示的任务 的参数的具体值
         :return:
         :return:
         """
         """
+        # 验证参数
         task = convert_to_underscore(task)
         task = convert_to_underscore(task)
         group = convert_to_underscore(group)
         group = convert_to_underscore(group)
         argument = convert_to_underscore(argument)
         argument = convert_to_underscore(argument)
+        # pandtic验证
+        if isinstance(value, str):
+            if len(value) == 8:
+                try:
+                    value = datetime.strptime(value, '%H:%M:%S').time()
+                except ValueError:
+                    pass
+
 
 
         path = f'{task}.{group}.{argument}'
         path = f'{task}.{group}.{argument}'
         task_object = getattr(self.config.model, task, None)
         task_object = getattr(self.config.model, task, None)
@@ -165,13 +174,13 @@ class Script:
         argument_object = getattr(group_object, argument, None)
         argument_object = getattr(group_object, argument, None)
 
 
         if argument_object is None:
         if argument_object is None:
-            logger.error(f'gui_set_task {task}.{group}.{argument}.{value} failed')
+            logger.error(f'Set arg {task}.{group}.{argument}.{value} failed')
             return False
             return False
 
 
         try:
         try:
             setattr(group_object, argument, value)
             setattr(group_object, argument, value)
             argument_object = getattr(group_object, argument, None)
             argument_object = getattr(group_object, argument, None)
-            logger.info(f'gui_set_task {task}.{group}.{argument}.{argument_object}')
+            logger.info(f'Set arg {task}.{group}.{argument}.{argument_object}')
             self.config.save()  # 我是没有想到什么方法可以使得属性改变自动保存的
             self.config.save()  # 我是没有想到什么方法可以使得属性改变自动保存的
             return True
             return True
         except ValidationError as e:
         except ValidationError as e:

+ 4 - 0
tasks/Component/GeneralBattle/assets.py

@@ -103,6 +103,10 @@ class GeneralBattleAssets:
 	I_EXIT_ENSURE = RuleImage(roi_front=(674,388,135,63), roi_back=(674,388,135,63), threshold=0.8, method="Template matching", file="./tasks/Component/GeneralBattle/gb/gb_exit_ensure.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/Component/GeneralBattle/gb/gb_exit_ensure.png")
 	# 左上角好友图标 
 	# 左上角好友图标 
 	I_FRIENDS = RuleImage(roi_front=(89,14,36,36), roi_back=(89,14,36,36), threshold=0.8, method="Template matching", file="./tasks/Component/GeneralBattle/gb/gb_friends.png")
 	I_FRIENDS = RuleImage(roi_front=(89,14,36,36), roi_back=(89,14,36,36), threshold=0.8, method="Template matching", file="./tasks/Component/GeneralBattle/gb/gb_friends.png")
+	# 结算时左下角统计图标 
+	I_REWARD_STATISTICS = RuleImage(roi_front=(51,629,54,59), roi_back=(51,629,54,59), threshold=0.8, method="Template matching", file="./tasks/Component/GeneralBattle/gb/gb_reward_statistics.png")
+	# 结算金币 
+	I_REWARD_GOLD = RuleImage(roi_front=(943,312,97,69), roi_back=(943,312,97,69), threshold=0.8, method="Template matching", file="./tasks/Component/GeneralBattle/gb/gb_reward_gold.png")
 
 
 
 
 	# Image Rule Assets
 	# Image Rule Assets

BIN
tasks/Component/GeneralBattle/gb/gb_reward_gold.png


BIN
tasks/Component/GeneralBattle/gb/gb_reward_statistics.png


+ 18 - 0
tasks/Component/GeneralBattle/gb/image.json

@@ -169,5 +169,23 @@
     "method": "Template matching",
     "method": "Template matching",
     "threshold": 0.8,
     "threshold": 0.8,
     "description": "左上角好友图标"
     "description": "左上角好友图标"
+  },
+  {
+    "itemName": "reward_statistics",
+    "imageName": "gb_reward_statistics.png",
+    "roiFront": "51,629,54,59",
+    "roiBack": "51,629,54,59",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "结算时左下角统计图标"
+  },
+  {
+    "itemName": "reward_gold",
+    "imageName": "gb_reward_gold.png",
+    "roiFront": "943,312,97,69",
+    "roiBack": "943,312,97,69",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "结算金币"
   }
   }
 ]
 ]

+ 56 - 19
tasks/Component/GeneralBattle/general_battle.py

@@ -26,7 +26,7 @@ class GeneralBattle(BaseTask, GeneralBattleAssets):
         self.current_count += 1
         self.current_count += 1
         logger.info(f"Current count: {self.current_count}")
         logger.info(f"Current count: {self.current_count}")
         if config is None:
         if config is None:
-            config = GeneralBattleConfig().dict()
+            config = GeneralBattleConfig()
 
 
 
 
         # 如果没有锁定队伍。那么可以根据配置设定队伍
         # 如果没有锁定队伍。那么可以根据配置设定队伍
@@ -36,20 +36,6 @@ class GeneralBattle(BaseTask, GeneralBattleAssets):
             if self.current_count == 1:
             if self.current_count == 1:
                 self.switch_preset_team(config.preset_enable, config.preset_group, config.preset_team)
                 self.switch_preset_team(config.preset_enable, config.preset_group, config.preset_team)
 
 
-            # 检测是否已经在战斗中
-            if self.is_in_battle():
-                while 1:
-                    self.screenshot()
-                    if self.appear_then_click(self.I_PREPARE_HIGHLIGHT, interval=1.5):
-                        continue
-                    if not self.appear(self.I_BUFF):
-                        break
-                win = self.battle_wait(config.random_click_swipt_enable)
-                if win:
-                    return True
-                else:
-                    return False
-
             # 点击准备按钮
             # 点击准备按钮
             self.wait_until_appear(self.I_PREPARE_HIGHLIGHT)
             self.wait_until_appear(self.I_PREPARE_HIGHLIGHT)
             while 1:
             while 1:
@@ -64,7 +50,9 @@ class GeneralBattle(BaseTask, GeneralBattleAssets):
             time.sleep(0.1)
             time.sleep(0.1)
 
 
         # 绿标
         # 绿标
-        self.green_mark(config.green_enable, config.green_mark)
+        self.wait_until_disappear(self.I_BUFF)
+        if self.is_in_battle(False):
+            self.green_mark(config.green_enable, config.green_mark)
 
 
         win = self.battle_wait(config.random_click_swipt_enable)
         win = self.battle_wait(config.random_click_swipt_enable)
         if win:
         if win:
@@ -73,7 +61,7 @@ class GeneralBattle(BaseTask, GeneralBattleAssets):
             return False
             return False
 
 
 
 
-    def run_general_battle_back(self, config: dict=None) -> bool:
+    def run_general_battle_back(self, config: GeneralBattleConfig=None) -> bool:
         """
         """
         进入挑战然后直接返回
         进入挑战然后直接返回
         :param config:
         :param config:
@@ -186,6 +174,11 @@ class GeneralBattle(BaseTask, GeneralBattleAssets):
             if self.appear(self.I_REWARD, threshold=0.6):
             if self.appear(self.I_REWARD, threshold=0.6):
                 win = True
                 win = True
                 break
                 break
+
+            # 如果领奖励出现金币
+            if self.appear(self.I_REWARD_GOLD, threshold=0.8):
+                win = True
+                break
             # 如果开启战斗过程随机滑动
             # 如果开启战斗过程随机滑动
             if random_click_swipt_enable:
             if random_click_swipt_enable:
                 self.random_click_swipt()
                 self.random_click_swipt()
@@ -215,9 +208,10 @@ class GeneralBattle(BaseTask, GeneralBattleAssets):
             self.screenshot()
             self.screenshot()
             # 如果出现领奖励
             # 如果出现领奖励
             action_click = random.choice([self.C_REWARD_1, self.C_REWARD_2, self.C_REWARD_3])
             action_click = random.choice([self.C_REWARD_1, self.C_REWARD_2, self.C_REWARD_3])
-            if self.appear_then_click(self.I_REWARD, action=action_click ,interval=1.5):
+            if self.appear_then_click(self.I_REWARD, action=action_click ,interval=1.5) or \
+                    self.appear_then_click(self.I_REWARD_GOLD, action=action_click ,interval=1.5):
                 continue
                 continue
-            if not self.appear(self.I_REWARD):
+            if not self.appear(self.I_REWARD) and not self.appear(self.I_REWARD_GOLD):
                 break
                 break
 
 
         return win
         return win
@@ -364,6 +358,49 @@ class GeneralBattle(BaseTask, GeneralBattleAssets):
         else:
         else:
             return False
             return False
 
 
+    def is_in_prepare(self, is_screenshot: bool = True) -> bool:
+        """
+        判断是否在准备中
+        :return:
+        """
+        if is_screenshot:
+            self.screenshot()
+        if self.appear(self.I_BUFF):
+            return True
+        elif self.appear(self.I_PREPARE_HIGHLIGHT):
+            return True
+        elif self.appear(self.I_PREPARE_DARK):
+            return True
+        elif self.appear(self.I_PRESET):
+            return True
+        else:
+            return False
+
+    def check_take_over_battle(self, is_screenshot: bool, config: GeneralBattleConfig) -> bool or None:
+        """
+        中途接入战斗,并且接管
+        :return:  赢了返回True, 输了返回False, 不是在战斗中返回None
+        """
+        if is_screenshot:
+            self.screenshot()
+        if not self.is_in_battle():
+            return None
+
+        if self.is_in_prepare(False):
+            while 1:
+                self.screenshot()
+                if self.appear_then_click(self.I_PREPARE_HIGHLIGHT, interval=1.5):
+                    continue
+                if not self.appear(self.I_BUFF):
+                    break
+
+            # 被接管的战斗,只有准备阶段才可以点绿标。
+            # 因为如果是战斗中,无法保证点击的时候是否出现动画
+            self.wait_until_disappear(self.I_BUFF)
+            self.green_mark(config.green_enable, config.green_mark)
+
+        return self.battle_wait(config.random_click_swipt_enable)
+
 
 
 
 
 
 

+ 19 - 2
tasks/Component/GeneralInvite/config_invite.py

@@ -5,6 +5,8 @@ from enum import Enum
 from datetime import datetime, time
 from datetime import datetime, time
 from pydantic import BaseModel, ValidationError, validator, Field
 from pydantic import BaseModel, ValidationError, validator, Field
 
 
+from tasks.Component.config_base import Time
+
 class InviteNumber(str, Enum):
 class InviteNumber(str, Enum):
     ONE = 'one'
     ONE = 'one'
     TWO = 'two'
     TWO = 'two'
@@ -19,8 +21,23 @@ class InviteConfig(BaseModel):
     friend_1: str = Field(default='', description='friend_name_help')
     friend_1: str = Field(default='', description='friend_name_help')
     friend_2: str = Field(default='', description='friend_2_name_help')
     friend_2: str = Field(default='', description='friend_2_name_help')
     find_mode: FindMode = Field(default=FindMode.AUTO_FIND, description='find_mode_help')
     find_mode: FindMode = Field(default=FindMode.AUTO_FIND, description='find_mode_help')
-    wait_time: time = Field(default=time(minute=1), description='wait_time_help')
+    wait_time: time = Field(default=time(minute=2), description='wait_time_help')
     default_invite: bool = Field(default=True, description='default_invite_help')
     default_invite: bool = Field(default=True, description='default_invite_help')
 
 
-    # recent_friend, guild_friend, friend, other_friend
+    # @validator('wait_time', pre=False, always=False)
+    # def parse_time(cls, value):
+    #     print('parse_time', value)
+    #     if isinstance(value, str):
+    #         try:
+    #             return datetime.strptime(value, '%H:%M:%S').time()
+    #         except ValueError:
+    #             raise ValueError('Invalid time value. Expected format: HH:MM:SS')
+    #     return value
+
+if __name__ == "__main__":
+    i = InviteConfig()
+    print(isinstance(i.wait_time, time))
+    i.wait_time = "00:05:00"
+    print(i.wait_time)
+    print(isinstance(i.wait_time, time))
 
 

+ 18 - 1
tasks/Component/config_base.py

@@ -3,7 +3,7 @@
 # github https://github.com/runhey
 # github https://github.com/runhey
 from typing import Any
 from typing import Any
 from collections.abc import Callable, Generator
 from collections.abc import Callable, Generator
-from datetime import timedelta
+from datetime import timedelta, time
 
 
 from pydantic import BaseModel, datetime_parse
 from pydantic import BaseModel, datetime_parse
 from pydantic.fields import ModelField
 from pydantic.fields import ModelField
@@ -47,4 +47,21 @@ class MultiLine(str):
         if field:
         if field:
             field_schema['type'] = 'multi_line'
             field_schema['type'] = 'multi_line'
 
 
+class Time(time):
+    """
+    尝试将字符串转换为time对象, 但是不生效
+    """
+    @classmethod
+    def __get_validators__(cls):
+        yield cls.validate
 
 
+    @classmethod
+    def validate(cls, value):
+        print('validate', value)
+        if isinstance(value, str):
+            hour, minute, second = map(int, value.split(":"))
+            return cls(hour, minute, second)
+        elif isinstance(value, time):
+            return value
+        else:
+            raise ValueError("Invalid time format")

+ 6 - 4
tasks/GameUi/game_ui.py

@@ -212,10 +212,10 @@ class GameUi(BaseTask, GameUiAssets):
                     for button in page.additional:
                     for button in page.additional:
                         if isinstance(button, RuleImage) and self.appear_then_click(button, interval=1):
                         if isinstance(button, RuleImage) and self.appear_then_click(button, interval=1):
                             sleep(0.4)
                             sleep(0.4)
-                            logger.info(f'Page {page} additional button {button} clicked')
+                            logger.info(f'Page {page} AB {button} clicked')
                         if isinstance(button, RuleOcr) and self.ocr_appear_click(button, interval=1):
                         if isinstance(button, RuleOcr) and self.ocr_appear_click(button, interval=1):
                             sleep(0.4)
                             sleep(0.4)
-                            logger.info(f'Page {page} additional button {button} clicked')
+                            logger.info(f'Page {page} AB {button} clicked')
 
 
                 # 获取当前页面的要点击的按钮
                 # 获取当前页面的要点击的按钮
                 if self.appear(page.check_button, interval=4):
                 if self.appear(page.check_button, interval=4):
@@ -245,5 +245,7 @@ if __name__ == '__main__':
     c = Config('oas1')
     c = Config('oas1')
     d = Device(c)
     d = Device(c)
     game = GameUi(config=c, device=d)
     game = GameUi(config=c, device=d)
-    game.ui_get_current_page(skip_first_screenshot=True)
-    game.ui_goto(page_shikigami_records)
+
+    game.screenshot()
+    print(game.appear(game.I_CHECK_AREA_BOSS))
+    print(game.appear(game.I_RECORDS_CLOSE))

BIN
tasks/KekkaiActivation/a/a_a_harvest_kaiko_3.png


BIN
tasks/KekkaiActivation/a/a_a_harvest_kaiko_4.png


+ 18 - 0
tasks/KekkaiActivation/a/image.json

@@ -151,5 +151,23 @@
     "method": "Template matching",
     "method": "Template matching",
     "threshold": 0.8,
     "threshold": 0.8,
     "description": "description"
     "description": "description"
+  },
+  {
+    "itemName": "a_harvest_kaiko_4",
+    "imageName": "a_a_harvest_kaiko_4.png",
+    "roiFront": "894,164,48,41",
+    "roiBack": "867,132,100,100",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "太鼓4"
+  },
+  {
+    "itemName": "a_harvest_kaiko_3",
+    "imageName": "a_a_harvest_kaiko_3.png",
+    "roiFront": "893,163,47,42",
+    "roiBack": "865,136,100,100",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
   }
   }
 ]
 ]

+ 4 - 0
tasks/KekkaiActivation/assets.py

@@ -62,6 +62,10 @@ class KekkaiActivationAssets:
 	I_A_EMPTY = RuleImage(roi_front=(677,255,353,128), roi_back=(677,255,353,128), threshold=0.8, method="Template matching", file="./tasks/KekkaiActivation/a/a_a_empty.png")
 	I_A_EMPTY = RuleImage(roi_front=(677,255,353,128), roi_back=(677,255,353,128), threshold=0.8, method="Template matching", file="./tasks/KekkaiActivation/a/a_a_empty.png")
 	# description 
 	# description 
 	I_A_CHECK_CARD = RuleImage(roi_front=(513,32,260,49), roi_back=(513,32,260,49), threshold=0.8, method="Template matching", file="./tasks/KekkaiActivation/a/a_a_check_card.png")
 	I_A_CHECK_CARD = RuleImage(roi_front=(513,32,260,49), roi_back=(513,32,260,49), threshold=0.8, method="Template matching", file="./tasks/KekkaiActivation/a/a_a_check_card.png")
+	# 太鼓4 
+	I_A_HARVEST_KAIKO_4 = RuleImage(roi_front=(894,164,48,41), roi_back=(867,132,100,100), threshold=0.8, method="Template matching", file="./tasks/KekkaiActivation/a/a_a_harvest_kaiko_4.png")
+	# description 
+	I_A_HARVEST_KAIKO_3 = RuleImage(roi_front=(893,163,47,42), roi_back=(865,136,100,100), threshold=0.8, method="Template matching", file="./tasks/KekkaiActivation/a/a_a_harvest_kaiko_3.png")
 
 
 
 
 	# Image Rule Assets
 	# Image Rule Assets

+ 3 - 1
tasks/KekkaiActivation/script_task.py

@@ -117,7 +117,7 @@ class ScriptTask(KU, KekkaiActivationAssets):
                 logger.info('Card is selected but not using')
                 logger.info('Card is selected but not using')
                 while 1:
                 while 1:
                     self.screenshot()
                     self.screenshot()
-                    if self.appear(self.I_A_INVITE):
+                    if self.appear(self.I_A_INVITE, threshold=0.7):
                         logger.info('Card is activated')
                         logger.info('Card is activated')
                         break
                         break
                     if self.appear_then_click(self.I_UI_CONFIRM, interval=0.6):
                     if self.appear_then_click(self.I_UI_CONFIRM, interval=0.6):
@@ -356,6 +356,8 @@ class ScriptTask(KU, KekkaiActivationAssets):
         """
         """
         self.appear_then_click(self.I_A_HARVEST_EXP)
         self.appear_then_click(self.I_A_HARVEST_EXP)
         self.appear_then_click(self.I_A_HARVEST_FISH4)  # 斗鱼的如果一直没有领的话
         self.appear_then_click(self.I_A_HARVEST_FISH4)  # 斗鱼的如果一直没有领的话
+        self.appear_then_click(self.I_A_HARVEST_KAIKO_4)
+        self.appear_then_click(self.I_A_HARVEST_KAIKO_3)
 
 
 if __name__ == "__main__":
 if __name__ == "__main__":
     from module.config.config import Config
     from module.config.config import Config

+ 6 - 2
tasks/KekkaiUtilize/assets.py

@@ -48,6 +48,8 @@ class KekkaiUtilizeAssets:
 	I_AP_EXTRACT = RuleImage(roi_front=(592,501,100,75), roi_back=(592,501,100,75), threshold=0.8, method="Template matching", file="./tasks/KekkaiUtilize/realm/realm_ap_extract.png")
 	I_AP_EXTRACT = RuleImage(roi_front=(592,501,100,75), roi_back=(592,501,100,75), threshold=0.8, method="Template matching", file="./tasks/KekkaiUtilize/realm/realm_ap_extract.png")
 	# 提取 
 	# 提取 
 	I_EXP_EXTRACT = RuleImage(roi_front=(592,448,100,73), roi_back=(592,448,100,73), threshold=0.8, method="Template matching", file="./tasks/KekkaiUtilize/realm/realm_exp_extract.png")
 	I_EXP_EXTRACT = RuleImage(roi_front=(592,448,100,73), roi_back=(592,448,100,73), threshold=0.8, method="Template matching", file="./tasks/KekkaiUtilize/realm/realm_exp_extract.png")
+	# 盒子经验满 
+	I_BOX_EXP_MAX = RuleImage(roi_front=(886,425,61,64), roi_back=(886,425,61,64), threshold=0.7, method="Template matching", file="./tasks/KekkaiUtilize/realm/realm_box_exp_max.png")
 
 
 
 
 	# Image Rule Assets
 	# Image Rule Assets
@@ -64,9 +66,9 @@ class KekkaiUtilizeAssets:
 	# description 
 	# description 
 	I_U_TAIKO_5 = RuleImage(roi_front=(544,201,59,52), roi_back=(538,179,79,426), threshold=0.8, method="Template matching", file="./tasks/KekkaiUtilize/utilize/utilize_u_taiko_5.png")
 	I_U_TAIKO_5 = RuleImage(roi_front=(544,201,59,52), roi_back=(538,179,79,426), threshold=0.8, method="Template matching", file="./tasks/KekkaiUtilize/utilize/utilize_u_taiko_5.png")
 	# description 
 	# description 
-	I_U_TAIKO_6 = RuleImage(roi_front=(544,265,60,45), roi_back=(533,156,87,450), threshold=0.8, method="Template matching", file="./tasks/KekkaiUtilize/utilize/utilize_u_taiko_6.png")
+	I_U_TAIKO_6 = RuleImage(roi_front=(545,313,60,45), roi_back=(533,156,87,450), threshold=0.8, method="Template matching", file="./tasks/KekkaiUtilize/utilize/utilize_u_taiko_6.png")
 	# description 
 	# description 
-	I_U_FISH_3 = RuleImage(roi_front=(551,325,41,33), roi_back=(543,178,69,412), threshold=0.8, method="Template matching", file="./tasks/KekkaiUtilize/utilize/utilize_u_fish_3.png")
+	I_U_FISH_3 = RuleImage(roi_front=(552,216,41,33), roi_back=(543,178,69,412), threshold=0.8, method="Template matching", file="./tasks/KekkaiUtilize/utilize/utilize_u_fish_3.png")
 	# description 
 	# description 
 	I_U_FISH_4 = RuleImage(roi_front=(549,310,51,50), roi_back=(542,177,73,401), threshold=0.8, method="Template matching", file="./tasks/KekkaiUtilize/utilize/utilize_u_fish_4.png")
 	I_U_FISH_4 = RuleImage(roi_front=(549,310,51,50), roi_back=(542,177,73,401), threshold=0.8, method="Template matching", file="./tasks/KekkaiUtilize/utilize/utilize_u_fish_4.png")
 	# description 
 	# description 
@@ -107,6 +109,8 @@ class KekkaiUtilizeAssets:
 	# Ocr Rule Assets
 	# Ocr Rule Assets
 	# 这个寄养的剩余时间 
 	# 这个寄养的剩余时间 
 	O_UTILIZE_RES_TIME = RuleOcr(roi=(1140,117,100,30), area=(1140,117,100,30), mode="Duration", method="Default", keyword="", name="utilize_res_time")
 	O_UTILIZE_RES_TIME = RuleOcr(roi=(1140,117,100,30), area=(1140,117,100,30), mode="Duration", method="Default", keyword="", name="utilize_res_time")
+	# 今日以领取经验 
+	O_BOX_EXP = RuleOcr(roi=(654,538,179,39), area=(654,538,179,39), mode="DigitCounter", method="Default", keyword="", name="box_exp")
 
 
 
 
 	# Swipe Rule Assets
 	# Swipe Rule Assets

+ 9 - 0
tasks/KekkaiUtilize/realm/image.json

@@ -88,5 +88,14 @@
     "method": "Template matching",
     "method": "Template matching",
     "threshold": 0.8,
     "threshold": 0.8,
     "description": "提取"
     "description": "提取"
+  },
+  {
+    "itemName": "box_exp_max",
+    "imageName": "realm_box_exp_max.png",
+    "roiFront": "886,425,61,64",
+    "roiBack": "886,425,61,64",
+    "method": "Template matching",
+    "threshold": 0.7,
+    "description": "盒子经验满"
   }
   }
 ]
 ]

BIN
tasks/KekkaiUtilize/realm/realm_box_exp_max.png


+ 21 - 8
tasks/KekkaiUtilize/script_task.py

@@ -3,7 +3,7 @@
 # github https://github.com/runhey
 # github https://github.com/runhey
 import time
 import time
 from cached_property import cached_property
 from cached_property import cached_property
-from datetime import timedelta
+from datetime import timedelta, datetime
 
 
 from module.base.timer import Timer
 from module.base.timer import Timer
 from module.atom.image_grid import ImageGrid
 from module.atom.image_grid import ImageGrid
@@ -32,7 +32,7 @@ class ScriptTask(GameUi, ReplaceShikigami, KekkaiUtilizeAssets):
         # 进入寮结界
         # 进入寮结界
         self.goto_realm()
         self.goto_realm()
         # 顺带收体力盒子或者是经验盒子
         # 顺带收体力盒子或者是经验盒子
-        time.sleep(0.5)
+        time.sleep(1)
         self.check_box_ap_or_exp(con.box_ap_enable, con.box_exp_enable, con.box_exp_waste)
         self.check_box_ap_or_exp(con.box_ap_enable, con.box_exp_enable, con.box_exp_waste)
 
 
         # 收菜看看
         # 收菜看看
@@ -43,12 +43,13 @@ class ScriptTask(GameUi, ReplaceShikigami, KekkaiUtilizeAssets):
         if not self.appear(self.I_UTILIZE_ADD):
         if not self.appear(self.I_UTILIZE_ADD):
             remaining_time = self.O_UTILIZE_RES_TIME.ocr(self.device.image)
             remaining_time = self.O_UTILIZE_RES_TIME.ocr(self.device.image)
             if not isinstance(remaining_time, timedelta):
             if not isinstance(remaining_time, timedelta):
-                logger.warning('ocr remaining time error')
+                logger.warning('Ocr remaining time error')
             logger.info(f'Utilize remaining time: {remaining_time}')
             logger.info(f'Utilize remaining time: {remaining_time}')
             # 执行失败,推出下一次执行为失败的时间间隔
             # 执行失败,推出下一次执行为失败的时间间隔
             logger.info('Utilize failed, exit')
             logger.info('Utilize failed, exit')
             self.back_guild()
             self.back_guild()
-            self.set_next_run(task='KekkaiUtilize', success=False, finish=True)
+            next_time = datetime.now() + remaining_time
+            self.set_next_run(task='KekkaiUtilize', success=False, finish=True, target=next_time)
             raise TaskEnd
             raise TaskEnd
         if not self.grown_goto_utilize():
         if not self.grown_goto_utilize():
             logger.info('Utilize failed, exit')
             logger.info('Utilize failed, exit')
@@ -174,15 +175,16 @@ class ScriptTask(GameUi, ReplaceShikigami, KekkaiUtilizeAssets):
             while 1:
             while 1:
                 self.screenshot()
                 self.screenshot()
 
 
-                if self.appear_then_click(self.I_BOX_EXP, interval=1):
+                if self.appear_then_click(self.I_BOX_EXP, threshold=0.6, interval=1):
                     continue
                     continue
                 if self.appear_then_click(self.I_EXP_EXTRACT, interval=1):
                 if self.appear_then_click(self.I_EXP_EXTRACT, interval=1):
                     continue
                     continue
 
 
                 # 如果出现结界皮肤, 表示收取好了
                 # 如果出现结界皮肤, 表示收取好了
-                if self.appear(self.I_REALM_SHIN) and not self.appear(self.I_BOX_EXP):
+                if self.appear(self.I_REALM_SHIN) and not self.appear(self.I_BOX_EXP, threshold=0.6):
                     break
                     break
 
 
+
                 # 如果出现收取确认,表明进入到了有满级的
                 # 如果出现收取确认,表明进入到了有满级的
                 if self.appear(self.I_UI_CONFIRM):
                 if self.appear(self.I_UI_CONFIRM):
                     self.screenshot()
                     self.screenshot()
@@ -201,6 +203,15 @@ class ScriptTask(GameUi, ReplaceShikigami, KekkaiUtilizeAssets):
                             continue
                             continue
                     break
                     break
 
 
+                if self.appear(self.I_EXP_EXTRACT):
+                    # 如果达到今日领取的最大,就不领取了
+                    cur, res, totol = self.O_BOX_EXP.ocr(self.device.image)
+                    if cur == res == totol == 0:
+                        continue
+                    if cur == totol and cur + res == totol:
+                        logger.info('Exp box reach max do not collect')
+                        break
+
                 if time_exp.reached():
                 if time_exp.reached():
                     logger.warning('Extract exp box timeout')
                     logger.warning('Extract exp box timeout')
                     break
                     break
@@ -208,7 +219,7 @@ class ScriptTask(GameUi, ReplaceShikigami, KekkaiUtilizeAssets):
 
 
         self.screenshot()
         self.screenshot()
         box_ap = self.appear(self.I_BOX_AP)
         box_ap = self.appear(self.I_BOX_AP)
-        box_exp = self.appear(self.I_BOX_EXP, threshold=0.6)
+        box_exp = self.appear(self.I_BOX_EXP, threshold=0.6) or self.appear(self.I_BOX_EXP_MAX, threshold=0.6)
         if ap_enable:
         if ap_enable:
             _check_ap_box(box_ap)
             _check_ap_box(box_ap)
         if exp_enable:
         if exp_enable:
@@ -450,6 +461,8 @@ if __name__ == "__main__":
     t = ScriptTask(c, d)
     t = ScriptTask(c, d)
 
 
     t.run()
     t.run()
-
+    # t.screenshot()
+    # print(t.appear(t.I_BOX_EXP, threshold=0.6))
+    # print(t.appear(t.I_BOX_EXP_MAX, threshold=0.6))
 
 
 
 

+ 2 - 2
tasks/KekkaiUtilize/utilize/image.json

@@ -56,7 +56,7 @@
   {
   {
     "itemName": "u_taiko_6",
     "itemName": "u_taiko_6",
     "imageName": "utilize_u_taiko_6.png",
     "imageName": "utilize_u_taiko_6.png",
-    "roiFront": "544,265,60,45",
+    "roiFront": "545,313,60,45",
     "roiBack": "533,156,87,450",
     "roiBack": "533,156,87,450",
     "method": "Template matching",
     "method": "Template matching",
     "threshold": 0.8,
     "threshold": 0.8,
@@ -65,7 +65,7 @@
   {
   {
     "itemName": "u_fish_3",
     "itemName": "u_fish_3",
     "imageName": "utilize_u_fish_3.png",
     "imageName": "utilize_u_fish_3.png",
-    "roiFront": "551,325,41,33",
+    "roiFront": "552,216,41,33",
     "roiBack": "543,178,69,412",
     "roiBack": "543,178,69,412",
     "method": "Template matching",
     "method": "Template matching",
     "threshold": 0.8,
     "threshold": 0.8,

+ 9 - 0
tasks/KekkaiUtilize/utilize/ocr.json

@@ -7,5 +7,14 @@
     "method": "Default",
     "method": "Default",
     "keyword": "",
     "keyword": "",
     "description": "这个寄养的剩余时间"
     "description": "这个寄养的剩余时间"
+  },
+  {
+    "itemName": "box_exp",
+    "roiFront": "654,538,179,39",
+    "roiBack": "654,538,179,39",
+    "mode": "DigitCounter",
+    "method": "Default",
+    "keyword": "",
+    "description": "今日以领取经验"
   }
   }
 ]
 ]

BIN
tasks/KekkaiUtilize/utilize/utilize_u_fish_3.png


BIN
tasks/KekkaiUtilize/utilize/utilize_u_moon_6.png


BIN
tasks/KekkaiUtilize/utilize/utilize_u_taiko_6.png


+ 8 - 1
tasks/Orochi/assets.py

@@ -25,11 +25,18 @@ class OrochiAssets:
 	I_SHI_RECORDS = RuleImage(roi_front=(821,638,48,45), roi_back=(821,638,48,45), threshold=0.8, method="Template matching", file="./tasks/Orochi/o/o_shi_records.png")
 	I_SHI_RECORDS = RuleImage(roi_front=(821,638,48,45), roi_back=(821,638,48,45), threshold=0.8, method="Template matching", file="./tasks/Orochi/o/o_shi_records.png")
 	# description 
 	# description 
 	I_OROCHI_MATCHING = RuleImage(roi_front=(62,568,44,114), roi_back=(62,568,44,114), threshold=0.8, method="Template matching", file="./tasks/Orochi/o/o_orochi_matching.png")
 	I_OROCHI_MATCHING = RuleImage(roi_front=(62,568,44,114), roi_back=(62,568,44,114), threshold=0.8, method="Template matching", file="./tasks/Orochi/o/o_orochi_matching.png")
+	# 小小宠物,发现宝藏 
+	I_PET_PRESENT = RuleImage(roi_front=(873,184,62,147), roi_back=(873,184,62,147), threshold=0.8, method="Template matching", file="./tasks/Orochi/o/o_pet_present.png")
 
 
 
 
 	# List Rule Assets
 	# List Rule Assets
 	# 这个是御魂界面选择不同层数的 
 	# 这个是御魂界面选择不同层数的 
-	L_LAYER_LIST = RuleList(folder="./tasks/Orochi/res", direction="vertical", mode="ocr", roi_back=(276,130,52,500), size=(45, 88), 
+	L_LAYER_LIST = RuleList(folder="./tasks/Orochi/res", direction="vertical", mode="ocr", roi_back=(138,130,359,500), size=(45, 88), 
 					 array=["壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖", "拾", "悲", "神"])
 					 array=["壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖", "拾", "悲", "神"])
 
 
 
 
+	# Ocr Rule Assets
+	# Ocr-description 
+	O_O_TEST_OCR = RuleOcr(roi=(126,136,360,491), area=(126,136,360,491), mode="Full", method="Default", keyword="", name="o_test_ocr")
+
+

+ 9 - 0
tasks/Orochi/o/image.json

@@ -61,5 +61,14 @@
     "method": "Template matching",
     "method": "Template matching",
     "threshold": 0.8,
     "threshold": 0.8,
     "description": "description"
     "description": "description"
+  },
+  {
+    "itemName": "pet_present",
+    "imageName": "o_pet_present.png",
+    "roiFront": "873,184,62,147",
+    "roiBack": "873,184,62,147",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "小小宠物,发现宝藏"
   }
   }
 ]
 ]

BIN
tasks/Orochi/o/o_pet_present.png


+ 1 - 1
tasks/Orochi/res/list.json

@@ -2,7 +2,7 @@
   "name": "layer_list",
   "name": "layer_list",
   "direction": "vertical",
   "direction": "vertical",
   "type": "ocr",
   "type": "ocr",
-  "roiBack": "276,130,52,500",
+  "roiBack": "138,130,359,500",
   "description": "这个是御魂界面选择不同层数的",
   "description": "这个是御魂界面选择不同层数的",
   "list": [
   "list": [
     {
     {

+ 11 - 0
tasks/Orochi/res/ocr.json

@@ -0,0 +1,11 @@
+[
+  {
+    "itemName": "o_test_ocr",
+    "roiFront": "126,136,360,491",
+    "roiBack": "126,136,360,491",
+    "mode": "Full",
+    "method": "Default",
+    "keyword": "",
+    "description": "Ocr-description"
+  }
+]

+ 34 - 6
tasks/Orochi/script_task.py

@@ -113,13 +113,12 @@ class ScriptTask(GeneralBattle, GeneralInvite, GeneralBuff, GeneralRoom, GameUi,
 
 
 
 
 
 
-
     def run_leader(self):
     def run_leader(self):
         logger.info('Start run leader')
         logger.info('Start run leader')
         self.ui_get_current_page()
         self.ui_get_current_page()
         self.ui_goto(page_soul_zones)
         self.ui_goto(page_soul_zones)
         self.orochi_enter()
         self.orochi_enter()
-        layer = self.config.orochi.orochi_config.layer[0]
+        layer = self.config.orochi.orochi_config.layer
         self.check_layer(layer)
         self.check_layer(layer)
         self.check_lock(self.config.orochi.general_battle_config.lock_team_enable)
         self.check_lock(self.config.orochi.general_battle_config.lock_team_enable)
         # 创建队伍
         # 创建队伍
@@ -146,6 +145,10 @@ class ScriptTask(GeneralBattle, GeneralInvite, GeneralBuff, GeneralRoom, GameUi,
             if self.check_and_invite(self.config.orochi.invite_config.default_invite):
             if self.check_and_invite(self.config.orochi.invite_config.default_invite):
                 continue
                 continue
 
 
+            # 检查猫咪奖励
+            if self.appear_then_click(self.I_PET_PRESENT, action=self.C_WIN_3, interval=1):
+                continue
+
             if self.current_count >= self.limit_count:
             if self.current_count >= self.limit_count:
                 if self.is_in_room():
                 if self.is_in_room():
                     logger.info('Orochi count limit out')
                     logger.info('Orochi count limit out')
@@ -214,9 +217,14 @@ class ScriptTask(GeneralBattle, GeneralInvite, GeneralBuff, GeneralRoom, GameUi,
         # self.check_lock(self.config.orochi.general_battle_config.lock_team_enable)
         # self.check_lock(self.config.orochi.general_battle_config.lock_team_enable)
 
 
         # 进入战斗流程
         # 进入战斗流程
+        self.device.stuck_record_add('BATTLE_STATUS_S')
         while 1:
         while 1:
             self.screenshot()
             self.screenshot()
 
 
+            # 检查猫咪奖励
+            if self.appear_then_click(self.I_PET_PRESENT, action=self.C_WIN_3, interval=1):
+                continue
+
             if self.current_count >= self.limit_count:
             if self.current_count >= self.limit_count:
                 logger.info('Orochi count limit out')
                 logger.info('Orochi count limit out')
                 break
                 break
@@ -228,13 +236,14 @@ class ScriptTask(GeneralBattle, GeneralInvite, GeneralBuff, GeneralRoom, GameUi,
                 continue
                 continue
 
 
             if self.is_in_room():
             if self.is_in_room():
+                self.device.stuck_record_clear()
                 if self.wait_battle(wait_time=self.config.orochi.invite_config.wait_time):
                 if self.wait_battle(wait_time=self.config.orochi.invite_config.wait_time):
                     self.run_general_battle(config=self.config.orochi.general_battle_config)
                     self.run_general_battle(config=self.config.orochi.general_battle_config)
                 else:
                 else:
                     break
                     break
             # 队长秒开的时候,检测是否进入到战斗中
             # 队长秒开的时候,检测是否进入到战斗中
-            elif self.is_in_battle():
-                self.run_general_battle(config=self.config.orochi.general_battle_config)
+            elif self.check_take_over_battle(False, config=self.config.orochi.general_battle_config):
+                continue
 
 
         while 1:
         while 1:
             # 有一种情况是本来要退出的,但是队长邀请了进入的战斗的加载界面
             # 有一种情况是本来要退出的,但是队长邀请了进入的战斗的加载界面
@@ -257,7 +266,7 @@ class ScriptTask(GeneralBattle, GeneralInvite, GeneralBuff, GeneralRoom, GameUi,
         self.ui_get_current_page()
         self.ui_get_current_page()
         self.ui_goto(page_soul_zones)
         self.ui_goto(page_soul_zones)
         self.orochi_enter()
         self.orochi_enter()
-        layer = self.config.orochi.orochi_config.layer[0]
+        layer = self.config.orochi.orochi_config.layer
         self.check_layer(layer)
         self.check_layer(layer)
         self.check_lock(self.config.orochi.general_battle_config.lock_team_enable)
         self.check_lock(self.config.orochi.general_battle_config.lock_team_enable)
 
 
@@ -269,6 +278,10 @@ class ScriptTask(GeneralBattle, GeneralInvite, GeneralBuff, GeneralRoom, GameUi,
         while 1:
         while 1:
             self.screenshot()
             self.screenshot()
 
 
+            # 检查猫咪奖励
+            if self.appear_then_click(self.I_PET_PRESENT, action=self.C_WIN_3, interval=1):
+                continue
+
             if not is_in_orochi():
             if not is_in_orochi():
                 continue
                 continue
 
 
@@ -314,12 +327,27 @@ class ScriptTask(GeneralBattle, GeneralInvite, GeneralBuff, GeneralRoom, GameUi,
 if __name__ == '__main__':
 if __name__ == '__main__':
     from module.config.config import Config
     from module.config.config import Config
     from module.device.device import Device
     from module.device.device import Device
+    from memory_profiler import profile
     c = Config('oas1')
     c = Config('oas1')
     d = Device(c)
     d = Device(c)
     t = ScriptTask(c, d)
     t = ScriptTask(c, d)
 
 
     # t.run()
     # t.run()
-    t.check_layer("拾")
+
+    # t.check_layer('悲')
+
+    from module.base.timer import timer
+
+    @timer
+    @profile
+    def test_memory():
+        t.screenshot()
+        print(t.ocr_appear(t.O_O_TEST_OCR))
+        print(t.L_LAYER_LIST.image_appear(t.device.image, '悲'))
+    for i in range(4):
+        test_memory()
+        print('=====================')
+
 
 
 
 
 
 

+ 50 - 0
tasks/RealmRaid/assets.py

@@ -53,10 +53,60 @@ class RealmRaidAssets:
 	I_MEDAL_3_3 = RuleImage(roi_front=(902,479,201,50), roi_back=(902,479,201,50), threshold=0.8, method="Template matching", file="./tasks/RealmRaid/res/res_medal_3_3.png")
 	I_MEDAL_3_3 = RuleImage(roi_front=(902,479,201,50), roi_back=(902,479,201,50), threshold=0.8, method="Template matching", file="./tasks/RealmRaid/res/res_medal_3_3.png")
 
 
 
 
+	# Image Rule Assets
+	# 出现呱太勋章 
+	I_FROG_MEDAL = RuleImage(roi_front=(912,12,32,35), roi_back=(912,12,32,35), threshold=0.8, method="Template matching", file="./tasks/RealmRaid/res/res_frog_medal.png")
+	# 已经进攻三次了 
+	I_RR_THREE = RuleImage(roi_front=(346,584,42,44), roi_back=(346,584,42,44), threshold=0.8, method="Template matching", file="./tasks/RealmRaid/res/res_rr_three.png")
+	# 呱太入侵, 第一次进入结界时候出现 
+	I_FROG_RAID = RuleImage(roi_front=(511,301,282,100), roi_back=(511,301,282,100), threshold=0.8, method="Template matching", file="./tasks/RealmRaid/res/res_frog_raid.png")
+	# 个人 
+	I_RR_PERSON = RuleImage(roi_front=(1203,236,56,100), roi_back=(1203,236,56,100), threshold=0.8, method="Template matching", file="./tasks/RealmRaid/res/res_rr_person.png")
+
+
 	# Ocr Rule Assets
 	# 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_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=(1143,13,80,39), area=(0,0,100,100), mode="DigitCounter", method="Default", keyword="", name="number")
 	O_NUMBER = RuleOcr(roi=(1143,13,80,39), area=(0,0,100,100), mode="DigitCounter", method="Default", keyword="", name="number")
+	# Ocr-description 
+	O_FROG_1 = RuleOcr(roi=(158,168,42,33), area=(158,168,42,33), mode="Digit", method="Default", keyword="", name="frog_1")
+	# Ocr-description 
+	O_FROG_2 = RuleOcr(roi=(491,170,34,32), area=(491,170,34,32), mode="Digit", method="Default", keyword="", name="frog_2")
+	# Ocr-description 
+	O_FROG_3 = RuleOcr(roi=(824,170,34,32), area=(824,170,34,32), mode="Digit", method="Default", keyword="", name="frog_3")
+	# Ocr-description 
+	O_FROG_4 = RuleOcr(roi=(158,303,38,35), area=(158,303,38,35), mode="Digit", method="Default", keyword="", name="frog_4")
+	# Ocr-description 
+	O_FROG_5 = RuleOcr(roi=(489,304,35,35), area=(489,304,35,35), mode="Digit", method="Default", keyword="", name="frog_5")
+	# Ocr-description 
+	O_FROG_6 = RuleOcr(roi=(824,305,35,33), area=(824,305,35,33), mode="Digit", method="Default", keyword="", name="frog_6")
+	# Ocr-description 
+	O_FROG_7 = RuleOcr(roi=(160,439,31,33), area=(160,439,31,33), mode="Digit", method="Default", keyword="", name="frog_7")
+	# Ocr-description 
+	O_FROG_8 = RuleOcr(roi=(494,441,31,31), area=(494,441,31,31), mode="Digit", method="Default", keyword="", name="frog_8")
+	# Ocr-description 
+	O_FROG_9 = RuleOcr(roi=(825,440,33,33), area=(825,440,33,33), mode="Digit", method="Default", keyword="", name="frog_9")
+
+
+	# Click Rule Assets
+	# 用来分割不同的挑战位置 
+	C_PARTITION_1 = RuleClick(roi_front=(220,147,242,120), roi_back=(220,147,242,120), name="partition_1")
+	# 用来分割不同的挑战位置 
+	C_PARTITION_2 = RuleClick(roi_front=(554,148,249,115), roi_back=(554,148,249,115), name="partition_2")
+	# 用来分割不同的挑战位置 
+	C_PARTITION_3 = RuleClick(roi_front=(885,147,242,116), roi_back=(885,147,242,116), name="partition_3")
+	# 用来分割不同的挑战位置 
+	C_PARTITION_4 = RuleClick(roi_front=(220,283,245,124), roi_back=(220,283,245,124), name="partition_4")
+	# 用来分割不同的挑战位置 
+	C_PARTITION_5 = RuleClick(roi_front=(564,280,237,120), roi_back=(564,280,237,120), name="partition_5")
+	# 用来分割不同的挑战位置 
+	C_PARTITION_6 = RuleClick(roi_front=(894,282,237,120), roi_back=(894,282,237,120), name="partition_6")
+	# 用来分割不同的挑战位置 
+	C_PARTITION_7 = RuleClick(roi_front=(225,416,244,121), roi_back=(225,416,244,121), name="partition_7")
+	# 用来分割不同的挑战位置 
+	C_PARTITION_8 = RuleClick(roi_front=(560,413,237,124), roi_back=(560,413,237,124), name="partition_8")
+	# 用来分割不同的挑战位置 
+	C_PARTITION_9 = RuleClick(roi_front=(893,418,234,116), roi_back=(893,418,234,116), name="partition_9")
 
 
 
 

+ 16 - 4
tasks/RealmRaid/config.py

@@ -17,11 +17,23 @@ class AttackNumber(str, Enum):
     NINE = 'nine'
     NINE = 'nine'
     ALL = 'all'
     ALL = 'all'
 
 
+class WhenAttackFail(str, Enum):
+    EXIT: str = 'Exit'
+    CONTINUE: str = 'Continue'
+    REFRESH: str = 'Refresh'
+
 class RaidConfig(BaseModel):
 class RaidConfig(BaseModel):
-    raid_mode: RaidMode = Field(title='Raid Mode', default=RaidMode.NORMAL,
-                                description='raid_mode_help')
-    attack_number: AttackNumber = Field(title='Attack Number', default=AttackNumber.ALL,
-                                        description='')
+    # raid_mode: RaidMode = Field(title='Raid Mode', default=RaidMode.NORMAL,
+    #                             description='raid_mode_help')
+    # attack_number: AttackNumber = Field(title='Attack Number', default=AttackNumber.ALL,
+    #                                     description='')
+
+    number_attack: int = Field(title='Number Attack', default=30, le=30, ge=1, description='number_attack_help')
+    number_base: int = Field(title='Number Base', default=0, le=20, ge=0, description='number_base_help')
+    exit_four: bool = Field(title='Exit Four', default=True, description='exit_four_help')
+    order_attack: str = Field(title='Order Attack', default='5 > 4 > 3 > 2 > 1 > 0', description='order_attack_help')
+    three_refresh: bool = Field(title='Three Refresh', default=False, description='three_refresh_help')
+    when_attack_fail: WhenAttackFail = Field(title='WhenAttackFail', default=WhenAttackFail.REFRESH, description='when_attack_fail_help')
 
 
 class RealmRaid(ConfigBase):
 class RealmRaid(ConfigBase):
     scheduler: Scheduler = Field(default_factory=Scheduler)
     scheduler: Scheduler = Field(default_factory=Scheduler)

+ 38 - 0
tasks/RealmRaid/res/image2.json

@@ -0,0 +1,38 @@
+[
+  {
+    "itemName": "frog_medal",
+    "imageName": "res_frog_medal.png",
+    "roiFront": "912,12,32,35",
+    "roiBack": "912,12,32,35",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "出现呱太勋章"
+  },
+  {
+    "itemName": "rr_three",
+    "imageName": "res_rr_three.png",
+    "roiFront": "346,584,42,44",
+    "roiBack": "346,584,42,44",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "已经进攻三次了"
+  },
+  {
+    "itemName": "frog_raid",
+    "imageName": "res_frog_raid.png",
+    "roiFront": "511,301,282,100",
+    "roiBack": "511,301,282,100",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "呱太入侵, 第一次进入结界时候出现"
+  },
+  {
+    "itemName": "rr_person",
+    "imageName": "res_rr_person.png",
+    "roiFront": "1203,236,56,100",
+    "roiBack": "1203,236,56,100",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "个人"
+  }
+]

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

@@ -16,5 +16,86 @@
     "method": "Default",
     "method": "Default",
     "keyword": "",
     "keyword": "",
     "description": "右上角 突破卷的数量"
     "description": "右上角 突破卷的数量"
+  },
+  {
+    "itemName": "frog_1",
+    "roiFront": "158,168,42,33",
+    "roiBack": "158,168,42,33",
+    "mode": "Digit",
+    "method": "Default",
+    "keyword": "",
+    "description": "Ocr-description"
+  },
+  {
+    "itemName": "frog_2",
+    "roiFront": "491,170,34,32",
+    "roiBack": "491,170,34,32",
+    "mode": "Digit",
+    "method": "Default",
+    "keyword": "",
+    "description": "Ocr-description"
+  },
+  {
+    "itemName": "frog_3",
+    "roiFront": "824,170,34,32",
+    "roiBack": "824,170,34,32",
+    "mode": "Digit",
+    "method": "Default",
+    "keyword": "",
+    "description": "Ocr-description"
+  },
+  {
+    "itemName": "frog_4",
+    "roiFront": "158,303,38,35",
+    "roiBack": "158,303,38,35",
+    "mode": "Digit",
+    "method": "Default",
+    "keyword": "",
+    "description": "Ocr-description"
+  },
+  {
+    "itemName": "frog_5",
+    "roiFront": "489,304,35,35",
+    "roiBack": "489,304,35,35",
+    "mode": "Digit",
+    "method": "Default",
+    "keyword": "",
+    "description": "Ocr-description"
+  },
+  {
+    "itemName": "frog_6",
+    "roiFront": "824,305,35,33",
+    "roiBack": "824,305,35,33",
+    "mode": "Digit",
+    "method": "Default",
+    "keyword": "",
+    "description": "Ocr-description"
+  },
+  {
+    "itemName": "frog_7",
+    "roiFront": "160,439,31,33",
+    "roiBack": "160,439,31,33",
+    "mode": "Digit",
+    "method": "Default",
+    "keyword": "",
+    "description": "Ocr-description"
+  },
+  {
+    "itemName": "frog_8",
+    "roiFront": "494,441,31,31",
+    "roiBack": "494,441,31,31",
+    "mode": "Digit",
+    "method": "Default",
+    "keyword": "",
+    "description": "Ocr-description"
+  },
+  {
+    "itemName": "frog_9",
+    "roiFront": "825,440,33,33",
+    "roiBack": "825,440,33,33",
+    "mode": "Digit",
+    "method": "Default",
+    "keyword": "",
+    "description": "Ocr-description"
   }
   }
 ]
 ]

+ 56 - 0
tasks/RealmRaid/res/partition.json

@@ -0,0 +1,56 @@
+[
+  {
+    "itemName": "partition_1",
+    "roiFront": "220,147,242,120",
+    "roiBack": "220,147,242,120",
+    "description": "用来分割不同的挑战位置"
+  },
+  {
+    "itemName": "partition_2",
+    "roiFront": "554,148,249,115",
+    "roiBack": "554,148,249,115",
+    "description": "用来分割不同的挑战位置"
+  },
+  {
+    "itemName": "partition_3",
+    "roiFront": "885,147,242,116",
+    "roiBack": "885,147,242,116",
+    "description": "用来分割不同的挑战位置"
+  },
+  {
+    "itemName": "partition_4",
+    "roiFront": "220,283,245,124",
+    "roiBack": "220,283,245,124",
+    "description": "用来分割不同的挑战位置"
+  },
+  {
+    "itemName": "partition_5",
+    "roiFront": "564,280,237,120",
+    "roiBack": "564,280,237,120",
+    "description": "用来分割不同的挑战位置"
+  },
+  {
+    "itemName": "partition_6",
+    "roiFront": "894,282,237,120",
+    "roiBack": "894,282,237,120",
+    "description": "用来分割不同的挑战位置"
+  },
+  {
+    "itemName": "partition_7",
+    "roiFront": "225,416,244,121",
+    "roiBack": "225,416,244,121",
+    "description": "用来分割不同的挑战位置"
+  },
+  {
+    "itemName": "partition_8",
+    "roiFront": "560,413,237,124",
+    "roiBack": "560,413,237,124",
+    "description": "用来分割不同的挑战位置"
+  },
+  {
+    "itemName": "partition_9",
+    "roiFront": "893,418,234,116",
+    "roiBack": "893,418,234,116",
+    "description": "用来分割不同的挑战位置"
+  }
+]

BIN
tasks/RealmRaid/res/res_frog_medal.png


BIN
tasks/RealmRaid/res/res_frog_raid.png


BIN
tasks/RealmRaid/res/res_rr_person.png


BIN
tasks/RealmRaid/res/res_rr_three.png


+ 342 - 75
tasks/RealmRaid/script_task.py

@@ -2,94 +2,29 @@
 # @author runhey
 # @author runhey
 # github https://github.com/runhey
 # github https://github.com/runhey
 import time
 import time
+import re
+from cached_property import cached_property
 
 
 from tasks.base_task import BaseTask
 from tasks.base_task import BaseTask
 from tasks.Component.GeneralBattle.general_battle import GeneralBattle
 from tasks.Component.GeneralBattle.general_battle import GeneralBattle
 from tasks.GameUi.game_ui import GameUi
 from tasks.GameUi.game_ui import GameUi
 from tasks.GameUi.page import page_realm_raid, page_main
 from tasks.GameUi.page import page_realm_raid, page_main
 from tasks.RealmRaid.assets import RealmRaidAssets
 from tasks.RealmRaid.assets import RealmRaidAssets
-from tasks.RealmRaid.config import RealmRaid, RaidMode, AttackNumber
+from tasks.RealmRaid.config import RealmRaid, RaidMode, AttackNumber, WhenAttackFail
+
+
 from module.logger import logger
 from module.logger import logger
 from module.exception import TaskEnd
 from module.exception import TaskEnd
 from module.atom.image_grid import ImageGrid
 from module.atom.image_grid import ImageGrid
+from module.atom.image import RuleImage
+from module.atom.click import RuleClick
 
 
-class ScriptTask(GeneralBattle, GameUi, RealmRaidAssets):
 
 
+class ScriptTask(GeneralBattle, GameUi, RealmRaidAssets):
     medal_grid: ImageGrid = None
     medal_grid: ImageGrid = None
 
 
     def run(self):
     def run(self):
-        """
-        执行
-        :return:
-        """
-        config = self.config.realm_raid
-        self.medal_grid = ImageGrid([self.I_MEDAL_5, self.I_MEDAL_4, self.I_MEDAL_3, self.I_MEDAL_3_2, self.I_MEDAL_3_3,
-                                     self.I_MEDAL_2, self.I_MEDAL_1, self.I_MEDAL_0])
-        self.ui_get_current_page()
-        self.ui_goto(page_realm_raid)
-
-        # 点击突破
-        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_then_click(self.I_UNLOCK_2, interval=1):
-                    continue
-                if self.appear(self.I_LOCK_2, threshold=0.9):
-                    break
-                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_then_click(self.I_LOCK_2, interval=1):
-                    continue
-                if self.appear(self.I_UNLOCK_2, threshold=0.9):
-                    break
-                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.ui_current = page_realm_raid
-        self.ui_goto(page_main)
-
-        self.set_next_run(task='RealmRaid', success=True)
-        raise TaskEnd
-
+        self.run_2()
 
 
     def is_ticket(self) -> bool:
     def is_ticket(self) -> bool:
         """
         """
@@ -99,7 +34,7 @@ class ScriptTask(GeneralBattle, GameUi, RealmRaidAssets):
         self.wait_until_appear(self.I_BACK_RED)
         self.wait_until_appear(self.I_BACK_RED)
         self.screenshot()
         self.screenshot()
         cu, res, total = self.O_NUMBER.ocr(self.device.image)
         cu, res, total = self.O_NUMBER.ocr(self.device.image)
-        if cu == 0 and cu+res == total:
+        if cu == 0 and cu + res == total:
             logger.warning(f'Execute round failed, no ticket')
             logger.warning(f'Execute round failed, no ticket')
             return False
             return False
         return True
         return True
@@ -179,3 +114,335 @@ class ScriptTask(GeneralBattle, GameUi, RealmRaidAssets):
             self.wait_until_appear(self.I_BACK_RED)
             self.wait_until_appear(self.I_BACK_RED)
 
 
         return True
         return True
+
+    # ------------------------------------------------------------------------------------------------------------------
+    def run_2(self):
+        con = self.config.realm_raid
+        self.ui_get_current_page()
+        self.ui_goto(page_realm_raid)
+
+        # 有呱太活动的时候第一次进入还会 出现一个弹窗
+        self.screenshot()
+        if self.appear(self.I_FROG_RAID):
+            logger.info(f'Click {self.I_FROG_RAID.name}')
+            while 1:
+                self.screenshot()
+                if not self.appear(self.I_FROG_RAID):
+                    break
+                if self.appear_then_click(self.I_FROG_RAID, interval=1):
+                    continue
+        # 判断是不是锁定阵容
+        self.ensure_lock(con.general_battle_config.lock_team_enable)
+        # 判断是否是呱太活动
+        frog = self.is_frog(True)
+        if frog:
+            logger.info(f'Frog raid')
+
+
+        # 开始循环
+        success = True
+        last_battle = True  # 记录上一次战斗的结果
+        while 1:
+            self.screenshot()
+
+            # 检查票数
+            if not self.check_ticket(con.raid_config.number_base):
+                break
+            # 挑战次数
+            if self.current_count >= con.raid_config.number_attack:
+                logger.info(f'Current count {self.current_count}, max count {con.raid_config.number_attack}')
+                break
+            # 检查是否每三次领一个奖励
+            if self.reward_detect_click(False):
+                continue
+            # 刷新 >> 如果勾选了三次刷新并且到达了三次,就刷新
+            if con.raid_config.three_refresh and self.appear(self.I_RR_THREE, threshold=0.8):
+                logger.info('Three refresh')
+                if self.check_refresh():
+                    continue
+                else:
+                    success = False
+                    break
+            # 刷新 >> 如果上一轮的失败并且勾选了失败刷新,就刷新
+            if not last_battle and con.raid_config.when_attack_fail == WhenAttackFail.REFRESH:
+                logger.info('Battle lost and then refresh')
+                if self.check_refresh():
+                    continue
+                else:
+                    success = False
+                    break
+            # ----------------------------------------开始进攻
+            medal, index = self.find_one(False)
+            if not medal and not index:
+                # 已经没有可以挑战的了,只能刷新
+                if con.raid_config.when_attack_fail == WhenAttackFail.CONTINUE:
+                    logger.info('No one can attack and then refresh')
+                    if self.check_refresh():
+                        continue
+                    else:
+                        success = False
+                        break
+                else:
+                    logger.info('No one can attack, break')
+                    success = False
+                    break
+            # 判断是不是左上角第一个
+            lock_before = con.general_battle_config.lock_team_enable
+            if index == 1:
+                logger.info('Now is the first one')
+                if con.raid_config.exit_four:
+                    logger.info('Exit four enable')
+                    self.fire(index)
+                    self.run_general_battle_back(con.general_battle_config)
+                    self.fire(index)
+                    self.run_general_battle_back(con.general_battle_config)
+                    self.fire(index)
+                    self.run_general_battle_back(con.general_battle_config)
+                    self.fire(index)
+                    self.run_general_battle_back(con.general_battle_config)
+            elif self.check_medal_is_frog(frog, medal, index):
+                # 如果挑战的这只是呱太的话,就要把锁定改为不锁定
+                con.general_battle_config.lock_team_enable = False
+            self.fire(index)
+            last_battle = self.run_general_battle(con.general_battle_config)
+            if lock_before:
+                con.general_battle_config.lock_team_enable = lock_before
+
+        self.ui_current = page_realm_raid
+        self.ui_goto(page_main)
+        self.set_next_run(task='RealmRaid', success=success, finish=True)
+        raise TaskEnd
+
+
+
+
+
+
+
+
+    # ----------------------------------------------------------------------------------------------------------------------
+    # 2023.7.21 改版个人突破
+
+    def ensure_lock(self, lock_team_enable: bool):
+        """
+        确保锁定阵容
+        :param lock_team_enable:
+        :return:
+        """
+        if lock_team_enable:
+            while 1:
+                self.screenshot()
+                if self.appear_then_click(self.I_UNLOCK, interval=1):
+                    continue
+                if self.appear_then_click(self.I_UNLOCK_2, interval=1):
+                    continue
+                if self.appear(self.I_LOCK_2, threshold=0.9):
+                    break
+                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_then_click(self.I_LOCK_2, interval=1):
+                    continue
+                if self.appear(self.I_UNLOCK_2, threshold=0.9):
+                    break
+                if self.appear(self.I_UNLOCK, threshold=0.9):
+                    break
+            logger.info(f'Click {self.I_LOCK.name}')
+
+    def is_frog(self, screenshot: bool=True) -> bool:
+        """
+        判断是不是呱太活动
+        :return:
+        """
+        if screenshot:
+            self.screenshot()
+        if self.appear(self.I_FROG_MEDAL):
+            return True
+        return False
+
+    def check_ticket(self, base: int=0) -> bool:
+        """
+        检查是不是有票, 检查这个票是否大于等于基准
+        :param base:
+        :return:
+        """
+        if base < 0 or base > 30:
+            logger.warning(f'It is not a valid base {base}')
+            base = 0
+        self.wait_until_appear(self.I_BACK_RED)
+        self.screenshot()
+        cu, res, total = self.O_NUMBER.ocr(self.device.image)
+        if cu == 0 and cu + res == total:
+            logger.warning(f'Execute raid failed, no ticket')
+            return False
+        elif cu + res == total and cu < base:
+            logger.warning(f'Execute raid failed, ticket is not enough')
+            return False
+        return True
+
+    @cached_property
+    def order_medal(self) -> ImageGrid:
+        order_attack = self.config.realm_raid.raid_config.order_attack
+        support_number = [0, 1, 2, 3, 4, 5]
+        match = {
+            0: self.I_MEDAL_0,
+            1: self.I_MEDAL_1,
+            2: self.I_MEDAL_2,
+            3: self.I_MEDAL_3,
+            4: self.I_MEDAL_4,
+            5: self.I_MEDAL_5,
+        }
+        order = order_attack.replace(' ', '').replace('\n', '')
+        order = re.split(r'>', order)
+        order = [int(i) for i in order]
+        order = [i for i in order if i in support_number]
+
+        images = []
+        for i in order:
+            images.append(match[i])
+        return ImageGrid(images)
+
+    @cached_property
+    def partition(self) -> list[RuleClick]:
+        return [self.C_PARTITION_1, self.C_PARTITION_2, self.C_PARTITION_3, self.C_PARTITION_4, self.C_PARTITION_5,
+                self.C_PARTITION_6, self.C_PARTITION_7, self.C_PARTITION_8, self.C_PARTITION_9]
+
+    def find_one(self, screenshot: bool=True) -> tuple:
+        """
+        找到一个可以打的,并且检查一下是不是这一个的是第几个的
+        我们约定次序是:从左到右 上到下
+        1 2 3
+        4 5 9
+        7 8 9
+        :return: 返回的第一个参数是一个RuleImage, 第二个参数是位置信息
+        如果没有找到,返回None, None
+        """
+        if screenshot:
+            self.screenshot()
+        target = self.order_medal.find_anyone(self.device.image)
+        if target:
+            center = target.front_center()
+            for i, click in enumerate(self.partition):
+                x1, x2, y1, y2 = click.roi_front[0], click.roi_front[0] + click.roi_front[2], \
+                                 click.roi_front[1], click.roi_front[1] + click.roi_front[3]
+                if x1 < center[0] < x2 and y1 < center[1] < y2:
+                    logger.info(f'Find one medal [{target}], order is {i + 1}')
+                    return target, i + 1
+
+        return None, None
+
+    def check_medal_is_frog(self, is_activity: False, target: RuleImage, order: int) -> bool:
+        """
+        检查这个是不是呱太,为此之前你还需要判断是不是 处于呱太活动的
+        :param target:
+        :param is_activity: 如果不是呱太活动,那么就不需要检查了
+        :param order:
+        :return:
+        """
+        if not is_activity:
+            return False
+        # 好像呱太的位置是只有 789这三个
+        if order < 7:
+            return False
+        # 有时候四星可能和五星的混一起
+        if target != self.I_MEDAL_5 and target != self.I_MEDAL_4:
+            return False
+        match_ocr = {
+            1: self.O_FROG_1,
+            2: self.O_FROG_2,
+            3: self.O_FROG_3,
+            4: self.O_FROG_4,
+            5: self.O_FROG_5,
+            6: self.O_FROG_6,
+            7: self.O_FROG_7,
+            8: self.O_FROG_8,
+            9: self.O_FROG_9,
+        }
+        target_ocr = match_ocr[order]
+        self.screenshot()
+        if target_ocr.ocr(self.device.image) == 20:
+            logger.info(f'Find frog medal [{target}]')
+            return True
+        return False
+
+    def reward_detect_click(self, screenshot: bool=True) -> bool:
+        """
+        检测是否出现 每三次就有奖励的界面, 有就领取
+        :return:
+        """
+        if screenshot:
+            self.screenshot()
+        if self.appear(self.I_SOUL_RAID):
+            self.screenshot()
+            # 稳定一次的截图时间
+            # 再次判断是否出现的
+            if not self.appear(self.I_SOUL_RAID):
+                return False
+            while 1:
+                self.screenshot()
+                if not self.appear(self.I_SOUL_RAID, threshold=0.7):
+                    return True
+                if self.appear_then_click(self.I_SOUL_RAID, interval=1.5):
+                    continue
+
+    def check_refresh(self, screenshot: bool=True) -> bool:
+        """
+        检查是否出现了刷新的按钮
+        如果可以刷新就刷新,返回True
+        如果在CD中,就返回False
+        :return:
+        """
+        if screenshot:
+            self.screenshot()
+        if not self.appear(self.I_FRESH):
+            logger.info(f'No find refresh button and it is in CD')
+            return False
+        while 1:
+            self.screenshot()
+            if self.appear(self.I_FRESH_ENSURE):
+                break
+            if self.appear_then_click(self.I_FRESH, interval=1):
+                continue
+        while 1:
+            self.screenshot()
+            if not self.appear(self.I_FRESH_ENSURE):
+                return True
+            if self.appear_then_click(self.I_FRESH_ENSURE, interval=1):
+                continue
+
+    def fire(self, order: int):
+        """
+        挑战
+        :param order:  第几个
+        :return:
+        """
+        click = self.partition[order - 1]
+        self.wait_until_appear(self.I_RR_PERSON)
+        while 1:
+            self.screenshot()
+            if not self.appear(self.I_RR_PERSON, threshold=0.8):
+                break
+            if self.appear_then_click(self.I_FIRE, interval=1):
+                continue
+            if self.click(click, interval=1.8):
+                continue
+        logger.info(f'Click fire {order} success')
+
+
+if __name__ == "__main__":
+    from module.config.config import Config
+    from module.device.device import Device
+    config = Config('oas1')
+    device = Device(config)
+    t = ScriptTask(config, device)
+
+    t.run_2()
+
+    # print(t.find_one())
+    # target, order = t.find_one()
+    # print(t.check_medal_is_frog(True, target, order))

+ 4 - 0
tasks/Restart/assets.py

@@ -50,6 +50,8 @@ class RestartAssets:
 	I_LOGIN_8 = RuleImage(roi_front=(178,572,53,60), roi_back=(19,547,223,105), threshold=0.8, method="Template matching", file="./tasks/Restart/login/login_login_8.png")
 	I_LOGIN_8 = RuleImage(roi_front=(178,572,53,60), roi_back=(19,547,223,105), threshold=0.8, method="Template matching", file="./tasks/Restart/login/login_login_8.png")
 	# 登录时候不观看CG视频 
 	# 登录时候不观看CG视频 
 	I_WATCH_VIDEO_CANCEL = RuleImage(roi_front=(466,396,130,61), roi_back=(466,396,130,61), threshold=0.8, method="Template matching", file="./tasks/Restart/login/login_watch_video_cancel.png")
 	I_WATCH_VIDEO_CANCEL = RuleImage(roi_front=(466,396,130,61), roi_back=(466,396,130,61), threshold=0.8, method="Template matching", file="./tasks/Restart/login/login_watch_video_cancel.png")
+	# 指定角色进入游戏,默认第一个 
+	I_LOGIN_SPECIFIC_SERVE = RuleImage(roi_front=(24,33,52,47), roi_back=(24,33,52,47), threshold=0.8, method="Template matching", file="./tasks/Restart/login/login_login_specific_serve.png")
 
 
 
 
 	# Ocr Rule Assets
 	# Ocr Rule Assets
@@ -59,5 +61,7 @@ class RestartAssets:
 	O_LOGIN_ENTER_GAME = RuleOcr(roi=(550,567,176,56), area=(558,574,154,49), mode="Single", method="Default", keyword="进入游戏", name="login_enter_game")
 	O_LOGIN_ENTER_GAME = RuleOcr(roi=(550,567,176,56), area=(558,574,154,49), mode="Single", method="Default", keyword="进入游戏", name="login_enter_game")
 	# 点击屏幕跳过 
 	# 点击屏幕跳过 
 	O_LOGIN_SKIP_1 = RuleOcr(roi=(1046,35,130,37), area=(1046,35,130,37), mode="Single", method="Default", keyword="点击屏幕跳过", name="login_skip_1")
 	O_LOGIN_SKIP_1 = RuleOcr(roi=(1046,35,130,37), area=(1046,35,130,37), mode="Single", method="Default", keyword="点击屏幕跳过", name="login_skip_1")
+	# 登录指定角色,默认第一个 
+	O_LOGIN_SPECIFIC_SERVE = RuleOcr(roi=(524,600,242,53), area=(516,75,662,585), mode="Single", method="Default", keyword="点击屏幕进入游戏", name="login_specific_serve")
 
 
 
 

+ 5 - 4
tasks/Restart/login.py

@@ -33,8 +33,6 @@ class LoginHandler(BaseTask, RestartAssets):
 
 
             self.screenshot()
             self.screenshot()
 
 
-
-
             # 确认进入庭院
             # 确认进入庭院
             if self.appear_then_click(self.I_LOGIN_SCROOLL_CLOSE, interval=2):
             if self.appear_then_click(self.I_LOGIN_SCROOLL_CLOSE, interval=2):
                 logger.info('Open scroll')
                 logger.info('Open scroll')
@@ -71,7 +69,10 @@ class LoginHandler(BaseTask, RestartAssets):
             if self.appear_then_click(self.I_LOGIN_YELLOW_CLOSE, interval=0.6):
             if self.appear_then_click(self.I_LOGIN_YELLOW_CLOSE, interval=0.6):
                 logger.info('Close yellow close')
                 logger.info('Close yellow close')
                 continue
                 continue
-
+            # 点击屏幕进入游戏
+            if self.appear(self.I_LOGIN_SPECIFIC_SERVE, interval=0.6) and self.ocr_appear_click(self.O_LOGIN_SPECIFIC_SERVE, interval=0.6):
+                logger.info('login specific user')
+                continue
             # 点击’进入游戏‘
             # 点击’进入游戏‘
             if not self.appear(self.I_LOGIN_8):
             if not self.appear(self.I_LOGIN_8):
                 continue
                 continue
@@ -141,7 +142,7 @@ class LoginHandler(BaseTask, RestartAssets):
                 timer_harvest.reset()
                 timer_harvest.reset()
                 continue
                 continue
             # 邮件
             # 邮件
-            if self.appear_then_click(self.I_HARVEST_MAIL, interval=1):
+            if self.appear_then_click(self.I_HARVEST_MAIL, interval=1.5):
                 timer_harvest.reset()
                 timer_harvest.reset()
                 continue
                 continue
             if self.appear(self.I_HARVEST_MAIL_TITLE, interval=0.2):
             if self.appear(self.I_HARVEST_MAIL_TITLE, interval=0.2):

+ 9 - 0
tasks/Restart/login/image.json

@@ -52,5 +52,14 @@
     "method": "Template matching",
     "method": "Template matching",
     "threshold": 0.8,
     "threshold": 0.8,
     "description": "登录时候不观看CG视频"
     "description": "登录时候不观看CG视频"
+  },
+  {
+    "itemName": "login_specific_serve",
+    "imageName": "login_login_specific_serve.png",
+    "roiFront": "24,33,52,47",
+    "roiBack": "24,33,52,47",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "指定角色进入游戏,默认第一个"
   }
   }
 ]
 ]

BIN
tasks/Restart/login/login_login_specific_serve.png


+ 9 - 0
tasks/Restart/login/ocr.json

@@ -25,5 +25,14 @@
     "method": "Default",
     "method": "Default",
     "keyword": "点击屏幕跳过",
     "keyword": "点击屏幕跳过",
     "description": "点击屏幕跳过"
     "description": "点击屏幕跳过"
+  },
+  {
+    "itemName": "login_specific_serve",
+    "roiFront": "524,600,242,53",
+    "roiBack": "516,75,662,585",
+    "mode": "Single",
+    "method": "Default",
+    "keyword": "点击屏幕进入游戏",
+    "description": "登录指定角色,默认第一个"
   }
   }
 ]
 ]

+ 8 - 4
tasks/base_task.py

@@ -26,7 +26,6 @@ from tasks.GlobalGame.config_emergency import FriendInvitation, WhenNetworkAbnor
 from module.exception import GameStuckError, ScriptError
 from module.exception import GameStuckError, ScriptError
 
 
 
 
-
 class BaseTask(GlobalGameAssets):
 class BaseTask(GlobalGameAssets):
     config: Config = None
     config: Config = None
     device: Device = None
     device: Device = None
@@ -242,7 +241,7 @@ class BaseTask(GlobalGameAssets):
                 target._match_init = True
                 target._match_init = True
 
 
             if timeout.reached():
             if timeout.reached():
-                logger.warning(f'wait_until_stable({target}) timeout')
+                logger.warning(f'Wait_until_stable({target}) timeout')
                 break
                 break
 
 
     def swipe(self, swipe: RuleSwipe, interval: float = None) -> None:
     def swipe(self, swipe: RuleSwipe, interval: float = None) -> None:
@@ -414,7 +413,7 @@ class BaseTask(GlobalGameAssets):
                 sleep(1)  # 等待滑动完成, 还没想好如何优化
                 sleep(1)  # 等待滑动完成, 还没想好如何优化
 
 
     def set_next_run(self, task: str, finish: bool = False,
     def set_next_run(self, task: str, finish: bool = False,
-                     success: bool=None, server: bool=True, target: timedelta=None) -> None:
+                     success: bool=None, server: bool=True, target: datetime=None) -> None:
         """
         """
         设置下次运行时间  当然这个也是可以重写的
         设置下次运行时间  当然这个也是可以重写的
         :param target: 可以自定义的下次运行时间
         :param target: 可以自定义的下次运行时间
@@ -451,10 +450,15 @@ class BaseTask(GlobalGameAssets):
 
 
             if self.ui_reward_appear_click():
             if self.ui_reward_appear_click():
                 while 1:
                 while 1:
+                    self.screenshot()
                     # 等待动画结束
                     # 等待动画结束
-                    if not self.appear(self.I_UI_REWARD):
+                    if not self.appear(self.I_UI_REWARD, threshold=0.6):
                         logger.info('Get reward success')
                         logger.info('Get reward success')
                         break
                         break
+
+                    # 一直点击
+                    if self.ui_reward_appear_click():
+                        continue
                 break
                 break
 
 
             if self.appear_then_click(click_image, interval=0.8):
             if self.appear_then_click(click_image, interval=0.8):