فهرست منبع

perf(frame): Optimize combat process and Fix mumu background click

runhey 3 سال پیش
والد
کامیت
57fbac41e7
6فایلهای تغییر یافته به همراه47 افزوده شده و 9 حذف شده
  1. 19 0
      admin_test.py
  2. 2 2
      module/device/control.py
  3. 6 0
      module/device/device.py
  4. 1 0
      module/device/method/window.py
  5. 13 7
      tasks/Component/GeneralBattle/general_battle.py
  6. 6 0
      tasks/base_task.py

+ 19 - 0
admin_test.py

@@ -0,0 +1,19 @@
+# This Python file uses the following encoding: utf-8
+# @author runhey
+# github https://github.com/runhey
+
+
+
+from module.gui.utils import check_admin
+
+
+
+if __name__ == "__main__":
+    # 检查是不是以管理员身份运行,脚本启动的其他进程会继承权限
+    # 但是貌似有问题的这个函数
+    check_admin()
+
+
+
+
+

+ 2 - 2
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 , name: %s' % (point2str(x, y), control_name)
+            'Click %s @ %s' % (point2str(x, y), control_name)
         )
         method = self.click_methods.get(
             self.config.script.device.control_method,
@@ -142,7 +142,7 @@ class Control(Minitouch, Adb, Scrcpy, Window):
             duration = 0.8
         duration = ensure_time(duration)
         logger.info(
-            'Click %s @ %s' % (point2str(x, y), duration)
+            'Click %s @ %s %s' % (point2str(x, y), control_name, duration)
         )
         method = self.long_click_methods.get(
             self.config.script.emulator.control_method,

+ 6 - 0
module/device/device.py

@@ -104,6 +104,12 @@ class Device(Screenshot, Control, AppControl, EmulatorManager):
             self._scrcpy_server_stop()
 
     def stuck_record_add(self, button):
+        """
+        当你要设置这个时候检测为长时间的时候,你需要在这里添加
+        如果取消后,需要在`stuck_record_clear`中清除
+        :param button:
+        :return:
+        """
         self.detect_record.add(str(button))
 
     def stuck_record_clear(self):

+ 1 - 0
module/device/method/window.py

@@ -147,6 +147,7 @@ class Window(Handle):
         # 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_ACTIVATE, WA_ACTIVE, 0)  # 激活窗口
             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))  # 模拟鼠标弹起 后是子窗口

+ 13 - 7
tasks/Component/GeneralBattle/general_battle.py

@@ -57,7 +57,7 @@ class GeneralBattle(BaseTask, GeneralBattleAssets):
                 self.device.click(x, y)
 
                 # 选择预设的队伍
-                logger.info("select preset team")
+                logger.info("Select preset team")
                 time.sleep(0.5)
                 match config.preset_team:
                     case 1: x, y = self.C_PRESET_TEAM_1.coord()
@@ -68,7 +68,7 @@ class GeneralBattle(BaseTask, GeneralBattleAssets):
                 self.device.click(x, y)
 
                 # 点击预设确认
-                logger.info("click preset ensure")
+                logger.info("Click preset ensure")
                 while 1:
                     self.screenshot()
                     if self.appear_then_click(self.I_PRESET_ENSURE, threshold=0.8):
@@ -78,8 +78,8 @@ class GeneralBattle(BaseTask, GeneralBattleAssets):
 
             # 点击buff按钮
             if config.buff_enable:
-                logger.info("buff is enable")
-                logger.info("click buff button")
+                logger.info("Buff is enable")
+                logger.info("Click buff button")
                 while 1:
                     self.screenshot()
                     if self.appear_then_click(self.I_BUFF, interval=1.5):
@@ -119,8 +119,12 @@ class GeneralBattle(BaseTask, GeneralBattleAssets):
             # 点击绿标
             self.device.click(x, y)
 
+        # 有的时候是长战斗,需要在设置stuck检测为长战斗
+        # 但是无需取消设置,因为如果有点击或者滑动的话 handle_control_check会自行取消掉
+        self.device.stuck_record_add('BATTLE_STATUS_S')
+
         # 战斗过程 随机点击和滑动 防封
-        logger.info("battle process")
+        logger.hr("Battle process", 2)
         win: bool = False
         while 1:
             self.screenshot()
@@ -152,9 +156,11 @@ class GeneralBattle(BaseTask, GeneralBattleAssets):
                             self.swipe(self.S_BATTLE_RANDOM_LEFT, interval=20)
                         case 2:
                             self.swipe(self.S_BATTLE_RANDOM_RIGHT, interval=20)
+                    # 重新设置为长战斗
+                    self.device.stuck_record_add('BATTLE_STATUS_S')
 
         # 再次确认战斗结果
-        logger.info("reconfirm the results of the battle")
+        logger.info("Reconfirm the results of the battle")
         while 1:
             self.screenshot()
             if win:
@@ -171,7 +177,7 @@ class GeneralBattle(BaseTask, GeneralBattleAssets):
                     return False
         # 最后保证能点击 获得奖励
         self.wait_until_appear(self.I_REWARD)
-        logger.info("get reward")
+        logger.info("Get reward")
         while 1:
             self.screenshot()
             # 如果出现领奖励

+ 6 - 0
tasks/base_task.py

@@ -58,9 +58,11 @@ class BaseTask(GlobalGameAssets):
         if self.friend_timer and self.friend_timer.reached():
             self.friend_timer.reset()
             invite = self.appear(self.I_ACCEPT)
+            logger.info(f"Find friend invitation")
             # 如果是全部接受
             if invite and self.config.global_game.emergency.friend_invitation == FriendInvitation.ACCEPT:
                 # 如果是接受邀请
+                logger.info(f"Accept friend invitation")
                 while 1:
                     if self.appear_then_click(self.I_ACCEPT):
                         continue
@@ -68,6 +70,7 @@ class BaseTask(GlobalGameAssets):
                         break
             # 如果是全部拒绝
             elif invite and self.config.global_game.emergency.friend_invitation == FriendInvitation.REJECT:
+                logger.info(f"Reject friend invitation")
                 while 1:
                     if self.appear_then_click(self.I_REJECT):
                         continue
@@ -75,6 +78,7 @@ class BaseTask(GlobalGameAssets):
                         break
             # 最后一个是仅仅接受勾协
             elif invite and self.config.global_game.emergency.friend_invitation == FriendInvitation.ONLY_JADE:
+                logger.info(f"Accept jade invitation")
                 while 1:
                     if self.appear_then_click(self.I_ACCEPT):
                         continue
@@ -82,10 +86,12 @@ class BaseTask(GlobalGameAssets):
                         break
             # 判断网络异常
             if self.appear(self.I_NETWORK_ABNORMAL):
+                logger.warning(f"Network abnormal")
                 raise GameStuckError
 
             # 判断网络错误
             if self.appear(self.I_NETWORK_ERROR):
+                logger.warning(f"Network error")
                 raise GameStuckError
 
         return self.device.image