فهرست منبع

fix(Hyakkiyakou): Detects if the screenshot image is all black

ryland 2 سال پیش
والد
کامیت
6fc5a19278
2فایلهای تغییر یافته به همراه24 افزوده شده و 10 حذف شده
  1. 2 2
      tasks/Dokan/script_task.py
  2. 22 8
      tasks/Hyakkiyakou/slave/hya_device.py

+ 2 - 2
tasks/Dokan/script_task.py

@@ -291,9 +291,9 @@ class ScriptTask(GeneralBattle, GameUi, SwitchSoul, DokanAssets):
             return False
 
     def dokan_choose_attack_priority(self, attack_priority: int) -> bool:
-        ''' 选择优先攻击
+        """ 选择优先攻击
         : return 
-        '''
+        """
         logger.hr('Try to choose attack priority')
         max_try = 5
 

+ 22 - 8
tasks/Hyakkiyakou/slave/hya_device.py

@@ -1,11 +1,20 @@
 import timeit
+import numpy as np
 
 from module.base.timer import Timer
 from module.logger import logger
 from module.base.utils import point2str
+from module.exception import RequestHumanTakeover
 from tasks.base_task import BaseTask
 
 
+def image_black(img) -> bool:
+    for y, x in [(0, 0), (719, 1279), (719, 0), (0, 1279)]:
+        if np.all(img[y, x] != 0):
+            return False
+    return True
+
+
 class HyaDevice(BaseTask):
     """
     这个类主要是是优化截屏点击速度
@@ -20,6 +29,9 @@ class HyaDevice(BaseTask):
         self.hya_screenshot_interval.wait()
         self.hya_screenshot_interval.reset()
         self.device.image = self.device.screenshot_window_background()
+        if image_black(self.device.image):
+            logger.error('Screenshot image is black, try again')
+            raise RequestHumanTakeover('Screenshot image is black, try again')
         return self.device.image
 
     def fast_click(self, x: int, y: int) -> None:
@@ -37,7 +49,6 @@ class HyaDevice(BaseTask):
         self.hya_screenshot_interval = Timer(interval / 1000.)
 
 
-
 if __name__ == '__main__':
     from module.config.config import Config
     from module.device.device import Device
@@ -46,10 +57,13 @@ if __name__ == '__main__':
     d = Device(c)
     hd = HyaDevice(c, d)
 
-    def screenshot():
-        global hd
-        # hd.fast_screenshot()
-        hd.fast_click(420, 370)
-        hd.fast_click(750, 400)
-    execution_time = timeit.timeit(screenshot, number=50)
-    print(f"执行总的时间: {execution_time * 1000} ms")
+    # def screenshot():
+    #     global hd
+    #     # hd.fast_screenshot()
+    #     hd.fast_click(420, 370)
+    #     hd.fast_click(750, 400)
+    # execution_time = timeit.timeit(screenshot, number=50)
+    # print(f"执行总的时间: {execution_time * 1000} ms")
+
+    hd.fast_screenshot()
+