Quellcode durchsuchen

feat: Compatible mumu12 window and perf RealmRaid

runhey vor 3 Jahren
Ursprung
Commit
ddc451637d

+ 1 - 1
module/device/control.py

@@ -72,7 +72,7 @@ class Control(Minitouch, Adb, Scrcpy, Window):
             self.handle_control_check(control_name)
         x, y = ensure_int(x, y)
         logger.info(
-            'Click %s ' % (point2str(x, y))
+            'Click %s , name: %s' % (point2str(x, y), control_name)
         )
         method = self.click_methods.get(
             self.config.script.device.control_method,

+ 23 - 4
module/device/handle.py

@@ -78,7 +78,8 @@ class WindowNode(NodeMixin):
 
 
 class Handle:
-    emulator_list = ['MuMu',
+    emulator_list = ['MuMu12',
+                     'MuMu',
                      '雷电',
                      '夜神',
                      '蓝叠',
@@ -186,13 +187,31 @@ class Handle:
         if windows is None:
             logger.error("handle_auto not get all wnidow")
 
+        emu_list = []
         for window_title in windows:
             for item in Handle.emulator_list:
                 if window_title.find(item) != -1:
-                    logger.info(f'handle auto seclect to find {window_title} and use it as root_title')
-                    return window_title
+                    emu_list.append(window_title)
 
-        return None
+        if not len(emu_list):
+            logger.error('Can not find emulator handle, please check your emulator is running')
+            return None
+
+        emulator_title = ''
+        # 测试mumu12的时候发现 获取的全部的窗体标题有这样的: 'MuMuPlayer', 'MuMuPlayer', 'MuMuPlayer', 'MuMu模拟器12'
+        # 事实上 我们只需要最后一个 'MuMu模拟器12',其他的不重要
+        if 'MuMu模拟器12' in emu_list and 'MuMuPlayer' in emu_list:
+            emulator_title = 'MuMu模拟器12'
+
+        if len(emu_list) > 1 and emulator_title == '':
+            logger.warning(f'Find more than one emulator handle, oas will use the first one {emu_list[0]}')
+            emulator_title = emu_list[0]
+
+        if len(emu_list) == 1:
+            emulator_title = emu_list[0]
+
+        logger.info(f'Handle auto seclect to find {emulator_title} and use it as root_title')
+        return emulator_title
 
     @staticmethod
     def handle_tree(hwnd, node: WindowNode, level: int =0) -> None:

+ 21 - 10
module/device/method/window.py

@@ -111,6 +111,26 @@ class Window(Handle):
         elif self.emulator_family == 'bluestacks_family':
             pass
 
+    @cached_property
+    def mumu_head_height(self):
+        """
+        不同mumu模拟器的头部高度不同
+        :return:
+        """
+        father_win_Rect = GetWindowRect(self.control_handle_list[0])
+        father_height: int = father_win_Rect[3] - father_win_Rect[1]  # 下y - 上y 计算高度
+        children_win_Rect = GetWindowRect(self.control_handle_list[1])
+        children_height: int = children_win_Rect[3] - children_win_Rect[1]  # 下y - 上y 计算高度
+        height = father_height - children_height
+        if int(height * self.window_scale_rate) == 37:
+            # 说明是mumu模拟器 不做处理
+            pass
+        if int(height * self.window_scale_rate) == 45:
+            # 说明是mumu12模拟器 不做处理
+            pass
+        logger.info(f"Mumu emulator head height: {height}")
+        return height
+
     def click_window_message(self, x: int, y: int):
         """
 
@@ -118,25 +138,16 @@ class Window(Handle):
         :param y:
         :return:
         """
-        # if x >= 1280:
-        #     x = 1280
-        # if x <= 0:
-        #     x = 0
-        # if y >= 720:
-        #     y = 720
-        # if y <= 0:
-        #     y = 0
         # 我不知道为什么的使用的pywin32==306的版本会导致获取的图片的是(1024, 576)
         # 所有我在点击的时候会除以这个缩放比例
         # 但是后面发现又不是影响的很奇怪
 
         x = int(x / self.window_scale_rate)
         y = int(y / self.window_scale_rate)
-        mumu_head_height = int(36/self.window_scale_rate)
         # print(f"我点击的x:{x}, y:{y}")
         emulator_type = len(self.control_handle_list)
         if emulator_type == 2:  # mumu模拟器
-            SendMessage(self.control_handle_list[0], WM_LBUTTONDOWN, 0, MAKELONG(x, y+mumu_head_height))  # 模拟鼠标按下 先是父窗口 上面的框高度是57
+            SendMessage(self.control_handle_list[0], WM_LBUTTONDOWN, 0, MAKELONG(x, y+self.mumu_head_height))  # 模拟鼠标按下 先是父窗口 上面的框高度是57
             time.sleep((random.randint(100, 200)) / 1000.0)  # 点击弹起改为随机,时间100ms-200ms
             SendMessage(self.control_handle_list[1], WM_LBUTTONUP, 0, MAKELONG(x, y))  # 模拟鼠标弹起 后是子窗口
         elif emulator_type > 2:  # 夜神模拟器

+ 5 - 2
module/gui/qml/Component/Overview.qml

@@ -50,13 +50,15 @@ Item {
                         showSuccess("Restart"+" "+configName)
                         process_manager.restart(configName)
                         setStatus(MainEvent.RunStatus.Free)
+                        textLog.text = ''
+                        textLog.currentLine = 0
                     }
                 }
                 FluToggleButton{
                     id: startStart
                     Layout.alignment: Qt.AlignVCenter | Qt.AlignRight
                     Layout.rightMargin: 16
-                    text: {if(overStatus.runStatus === MainEvent.RunStatus.Stop){return "Stop"}
+                    text: {if(overStatus.runStatus === MainEvent.RunStatus.Run){return "Stop"}
                            else{return "Start"}}
                     selected: {if(overStatus.runStatus === MainEvent.RunStatus.Free){return true}
                                 else{return false}}
@@ -65,6 +67,7 @@ Item {
                                else{return false}
                     }
                     onClicked: {
+                        console.debug(overStatus.runStatus)
                         if(overStatus.runStatus === MainEvent.RunStatus.Free){
                             //如果这个时候初始化好了但是还没有运行脚本
                             setStatus(MainEvent.RunStatus.Run)
@@ -73,7 +76,7 @@ Item {
                         }
                         if(overStatus.runStatus === MainEvent.RunStatus.Run){
                             // 如果这个时候运行中
-                            setStatus(MainEvent.RunStatus.Emtpy)
+                            setStatus(MainEvent.RunStatus.Empty)
                             process_manager.stop_script(root.configName)
                             return
                         }

+ 2 - 2
script.py

@@ -271,7 +271,7 @@ class Script:
             if task.next_run > datetime.now():
                 logger.info(f'Wait until {task.next_run} for task `{task.command}`')
                 # self.is_first_task = False
-                method = self.config.optimization.when_task_queue_empty
+                method = self.config.script.optimization.when_task_queue_empty
                 if method == 'close_game':
                     logger.info('Close game during wait')
                     self.device.app_stop()
@@ -443,6 +443,6 @@ class Script:
 
 if __name__ == "__main__":
     script = Script("oas1")
-    print(script.get_next_task())
+    # print(script.get_next_task())
     script.run("AreaBoss")
     # script.run('RealmRaid')

+ 4 - 0
tasks/RealmRaid/assets.py

@@ -40,6 +40,10 @@ class RealmRaidAssets:
 	I_SOUL_RAID = RuleImage(roi_front=(577,502,100,100), roi_back=(577,502,100,100), threshold=0.8, method="Template matching", file="./tasks/RealmRaid/res/res_soul_raid.png")
 	# 刷新确认 
 	I_FRESH_ENSURE = RuleImage(roi_front=(672,403,173,59), roi_back=(672,403,173,59), threshold=0.8, method="Template matching", file="./tasks/RealmRaid/res/res_fresh_ensure.png")
+	# 没有锁图片,适配呱太入侵 
+	I_UNLOCK_2 = RuleImage(roi_front=(1002,643,30,41), roi_back=(1002,643,30,41), threshold=0.9, method="Template matching", file="./tasks/RealmRaid/res/res_unlock_2.png")
+	# 以锁图片,适配呱太 
+	I_LOCK_2 = RuleImage(roi_front=(1002,645,34,38), roi_back=(1002,645,34,38), threshold=0.9, method="Template matching", file="./tasks/RealmRaid/res/res_lock_2.png")
 
 
 	# Ocr Rule Assets

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

@@ -133,5 +133,23 @@
     "method": "Template matching",
     "threshold": 0.8,
     "description": "刷新确认"
+  },
+  {
+    "itemName": "unlock_2",
+    "imageName": "res_unlock_2.png",
+    "roiFront": "1002,643,30,41",
+    "roiBack": "1002,643,30,41",
+    "method": "Template matching",
+    "threshold": 0.9,
+    "description": "没有锁图片,适配呱太入侵"
+  },
+  {
+    "itemName": "lock_2",
+    "imageName": "res_lock_2.png",
+    "roiFront": "1002,645,34,38",
+    "roiBack": "1002,645,34,38",
+    "method": "Template matching",
+    "threshold": 0.9,
+    "description": "以锁图片,适配呱太"
   }
 ]

BIN
tasks/RealmRaid/res/res_lock_2.png


BIN
tasks/RealmRaid/res/res_unlock_2.png


+ 8 - 0
tasks/RealmRaid/script_task.py

@@ -36,6 +36,10 @@ class ScriptTask(GeneralBattle, GameUi, RealmRaidAssets):
                 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}')
@@ -44,6 +48,10 @@ class ScriptTask(GeneralBattle, GameUi, RealmRaidAssets):
                 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}')

+ 11 - 0
tasks/Utils/assets.py

@@ -0,0 +1,11 @@
+from module.atom.image import RuleImage
+from module.atom.click import RuleClick
+from module.atom.long_click import RuleLongClick
+from module.atom.swipe import RuleSwipe
+from module.atom.ocr import RuleOcr
+
+# This file was automatically generated by module/dev_tools/assets_extract.py.
+# Don't modify it manually.
+class UtilsAssets: 
+	pass
+