Ver código fonte

Merge branch 'dev' of https://github.com/roarhill/oas into dev

jackyhwei 2 anos atrás
pai
commit
dc934a2526
88 arquivos alterados com 2523 adições e 67 exclusões
  1. 1 1
      .gitignore
  2. 2 0
      README.md
  3. 2 1
      config/template.json
  4. 5 5
      dev_tools/assets_test.py
  5. 1 1
      module/config/config_manual.py
  6. 2 1
      module/config/config_menu.py
  7. 2 0
      module/config/config_model.py
  8. 4 4
      module/daemon/benchmark.py
  9. 2 0
      module/device/device.py
  10. 540 0
      module/device/method/nemu_ipc.py
  11. 11 7
      module/device/method/window.py
  12. 7 2
      module/device/screenshot.py
  13. 2 1
      requirements-in.txt
  14. 1 0
      requirements.txt
  15. 2 2
      tasks/Component/GeneralInvite/assets.py
  16. 3 3
      tasks/Component/GeneralInvite/gi/image.json
  17. 3 2
      tasks/GlobalGame/assets.py
  18. 3 1
      tasks/Hyakkiyakou/.gitignore
  19. 14 0
      tasks/Hyakkiyakou/README.md
  20. 165 0
      tasks/Hyakkiyakou/agent/agent.py
  21. 121 0
      tasks/Hyakkiyakou/agent/focus.py
  22. 5 0
      tasks/Hyakkiyakou/agent/utils.py
  23. 125 3
      tasks/Hyakkiyakou/assets.py
  24. 63 0
      tasks/Hyakkiyakou/config.py
  25. 217 0
      tasks/Hyakkiyakou/debugger.py
  26. 42 6
      tasks/Hyakkiyakou/hya/click.json
  27. BIN
      tasks/Hyakkiyakou/hya/hya_bean0.png
  28. BIN
      tasks/Hyakkiyakou/hya/hya_bean05.png
  29. BIN
      tasks/Hyakkiyakou/hya/hya_bean1.png
  30. BIN
      tasks/Hyakkiyakou/hya/hya_bean10.png
  31. BIN
      tasks/Hyakkiyakou/hya/hya_bean2.png
  32. BIN
      tasks/Hyakkiyakou/hya/hya_bean3.png
  33. BIN
      tasks/Hyakkiyakou/hya/hya_bean4.png
  34. BIN
      tasks/Hyakkiyakou/hya/hya_bean5.png
  35. BIN
      tasks/Hyakkiyakou/hya/hya_bean6.png
  36. BIN
      tasks/Hyakkiyakou/hya/hya_bean7.png
  37. BIN
      tasks/Hyakkiyakou/hya/hya_bean8.png
  38. BIN
      tasks/Hyakkiyakou/hya/hya_bean9.png
  39. BIN
      tasks/Hyakkiyakou/hya/hya_friend_remote_1.png
  40. BIN
      tasks/Hyakkiyakou/hya/hya_friend_remote_2.png
  41. BIN
      tasks/Hyakkiyakou/hya/hya_friend_same_1.png
  42. BIN
      tasks/Hyakkiyakou/hya/hya_friend_same_2.png
  43. BIN
      tasks/Hyakkiyakou/hya/hya_hclose_red.png
  44. BIN
      tasks/Hyakkiyakou/hya/hya_htitle.png
  45. BIN
      tasks/Hyakkiyakou/hya/hya_hya_state_buff02.png
  46. BIN
      tasks/Hyakkiyakou/hya/hya_hya_state_buff03.png
  47. BIN
      tasks/Hyakkiyakou/hya/hya_hya_state_buff05.png
  48. BIN
      tasks/Hyakkiyakou/hya/hya_hya_state_buff06.png
  49. BIN
      tasks/Hyakkiyakou/hya/hya_hya_state_buff07.png
  50. BIN
      tasks/Hyakkiyakou/hya/hya_resf_0.png
  51. BIN
      tasks/Hyakkiyakou/hya/hya_resf_1.png
  52. BIN
      tasks/Hyakkiyakou/hya/hya_resf_2.png
  53. BIN
      tasks/Hyakkiyakou/hya/hya_resf_3.png
  54. BIN
      tasks/Hyakkiyakou/hya/hya_resf_4.png
  55. BIN
      tasks/Hyakkiyakou/hya/hya_resf_5.png
  56. BIN
      tasks/Hyakkiyakou/hya/hya_resf_6.png
  57. BIN
      tasks/Hyakkiyakou/hya/hya_resf_7.png
  58. BIN
      tasks/Hyakkiyakou/hya/hya_resf_8.png
  59. BIN
      tasks/Hyakkiyakou/hya/hya_resf_9.png
  60. BIN
      tasks/Hyakkiyakou/hya/hya_resr_0.png
  61. BIN
      tasks/Hyakkiyakou/hya/hya_resr_1.png
  62. BIN
      tasks/Hyakkiyakou/hya/hya_resr_2.png
  63. BIN
      tasks/Hyakkiyakou/hya/hya_resr_3.png
  64. BIN
      tasks/Hyakkiyakou/hya/hya_resr_4.png
  65. BIN
      tasks/Hyakkiyakou/hya/hya_resr_5.png
  66. BIN
      tasks/Hyakkiyakou/hya/hya_resr_6.png
  67. BIN
      tasks/Hyakkiyakou/hya/hya_resr_7.png
  68. BIN
      tasks/Hyakkiyakou/hya/hya_resr_8.png
  69. BIN
      tasks/Hyakkiyakou/hya/hya_resr_9.png
  70. 18 0
      tasks/Hyakkiyakou/hya/image1.json
  71. 47 0
      tasks/Hyakkiyakou/hya/image2.json
  72. 182 0
      tasks/Hyakkiyakou/hya/image3.json
  73. 110 0
      tasks/Hyakkiyakou/hya/image4.json
  74. 38 0
      tasks/Hyakkiyakou/hya/image5.json
  75. 11 0
      tasks/Hyakkiyakou/hya/ocr.json
  76. 16 0
      tasks/Hyakkiyakou/hya/swipe.json
  77. 8 6
      tasks/Hyakkiyakou/prepare/get_images.py
  78. 245 0
      tasks/Hyakkiyakou/script_task.py
  79. 58 0
      tasks/Hyakkiyakou/slave/hya_color.py
  80. 55 0
      tasks/Hyakkiyakou/slave/hya_device.py
  81. 342 0
      tasks/Hyakkiyakou/slave/hya_slave.py
  82. 13 0
      tasks/RichMan/assets.py
  83. 2 2
      tasks/RichMan/script_task.py
  84. 12 2
      tasks/RichMan/shrine/ocr.json
  85. 4 1
      tasks/Script/config_device.py
  86. 5 5
      tasks/WantedQuests/assets.py
  87. 10 10
      tasks/WantedQuests/invite/image.json
  88. 2 1
      tasks/WantedQuests/script_task.py

+ 1 - 1
.gitignore

@@ -33,7 +33,7 @@ module/config/argument/setting.json
 !dev_tools/Spyxx/spyxx_amd64.exe
 !dev_tools/ViewWizard2/ViewWizard2.exe
 !dev_tools/ViewWizard3/ViewWizard.exe
-hya
+./hya
 
 
 

+ 2 - 0
README.md

@@ -53,6 +53,8 @@ This project is licensed under the GNU General Public License v3.0.
 
 ## 声明 Announcement
 本软件开源、免费,仅供学习交流使用。开发者团队拥有本项目的最终解释权。使用本软件产生的所有问题与本项目与开发者团队无关。
+OAS is a free open source software, if you paid for OAS from any channel, please refund.
+OAS 是一款免费开源软件,如果你在任何渠道付费购买了OAS,请退款。
 
 ## 关于 Alas
 OAS 基于碧蓝航线脚本 [AzurLaneAutoScript](https://github.com/LmeSzinc/AzurLaneAutoScript) 开发,考虑到星穹铁道脚本 [StarRailCopilot](https://github.com/LmeSzinc/StarRailCopilot) 中所提及的问题,

+ 2 - 1
config/template.json

@@ -4,6 +4,7 @@
     "device": {
       "serial": "auto",
       "handle": "",
+      "emulatorinfo_path": "",
       "package_name": "auto",
       "screenshot_method": "auto",
       "control_method": "minitouch",
@@ -889,4 +890,4 @@
       "netherworld_group_team": "-1,-1"
     }
   }
-}
+}

+ 5 - 5
dev_tools/assets_test.py

@@ -34,13 +34,13 @@ def detect_ocr(file: str, target: RuleOcr):
 
 
 # 图片文件路径 可以是相对路径
-IMAGE_FILE = r"C:\Users\Ryland\Desktop\QQ截图20240407130042.png"
+IMAGE_FILE = r"C:\Users\萌萌哒\Desktop\341978692-fdceb33c-eec1-4965-a2b9-8f75cd54d5e2.png"
 if __name__ == '__main__':
-    from tasks.KekkaiActivation.assets import KekkaiActivationAssets
-    from tasks.GameUi.assets import GameUiAssets
-
-    targe = GameUiAssets.I_MAIN_GOTO_TEAM
+    from tasks.RyouToppa.assets import RyouToppaAssets
+    targe = RyouToppaAssets.I_RYOU_TOPPA
     print(detect_image(IMAGE_FILE, targe))
+
+    # ocr demo
     # from tasks.KekkaiActivation.assets import KekkaiActivationAssets
     # target = KekkaiActivationAssets.O_CARD_ALL_TIME
     # print(detect_ocr(IMAGE_FILE, target))

+ 1 - 1
module/config/config_manual.py

@@ -17,7 +17,7 @@ class ConfigManual:
         > BondlingFairyland > EvoZone > GoryouRealm
         > TrueOrochi > RichMan
         > CollectiveMissions
-        > Pets > TalismanPass > SoulsTidy > Delegation
+        > Pets > TalismanPass > SoulsTidy > Delegation > Hyakkiyakou
         > Secret > WeeklyTrifles > MysteryShop > Duel > MetaDemon > FrogBoss
         """
 

+ 2 - 1
module/config/config_menu.py

@@ -25,7 +25,8 @@ class ConfigMenu:
                                    'TalismanPass', 'DemonEncounter', 'Pets', 'SoulsTidy', 'Delegation', 'WantedQuests',
                                    'Tako']
         # 很肝的任务
-        self.menu["Liver Emperor Exclusive"] = ['BondlingFairyland', 'EvoZone', 'GoryouRealm', 'Exploration',]
+        self.menu["Liver Emperor Exclusive"] = ['BondlingFairyland', 'EvoZone', 'GoryouRealm', 'Exploration',
+                                                'Hyakkiyakou']
         # 阴阳寮
         self.menu["Guild"] = ['KekkaiUtilize', 'KekkaiActivation', 'RealmRaid', 'RyouToppa', 'Dokan', 'CollectiveMissions',
                               'Hunt']

+ 2 - 0
module/config/config_model.py

@@ -55,6 +55,7 @@ from tasks.FrogBoss.config import FrogBoss
 from tasks.BondlingFairyland.config import BondlingFairyland
 from tasks.EvoZone.config import EvoZone
 from tasks.GoryouRealm.config import GoryouRealm
+from tasks.Hyakkiyakou.config import Hyakkiyakou
 # ----------------------------------------------------------------------------------------------------------------------
 
 # 每周任务---------------------------------------------------------------------------------------------------------------
@@ -107,6 +108,7 @@ class ConfigModel(ConfigBase):
     bondling_fairyland: BondlingFairyland = Field(default_factory=BondlingFairyland)
     evo_zone: EvoZone = Field(default_factory=EvoZone)
     goryou_realm: GoryouRealm = Field(default_factory=GoryouRealm)
+    hyakkiyakou: Hyakkiyakou = Field(default_factory=Hyakkiyakou)
 
     # 这些是每周任务
     true_orochi: TrueOrochi = Field(default_factory=TrueOrochi)

+ 4 - 4
module/daemon/benchmark.py

@@ -216,7 +216,7 @@ class Benchmark(DaemonBase):
         Returns:
             str: The fastest screenshot method on current device.
         """
-        screenshot = ['ADB', 'ADB_nc', 'uiautomator2', 'DroidCast_raw', 'DroidCast', 'window_background']
+        screenshot = ['ADB', 'ADB_nc', 'uiautomator2', 'DroidCast_raw', 'DroidCast', 'window_background', 'nemu_ipc']
 
         def remove(*args):
             return [l for l in screenshot if l not in args]
@@ -242,6 +242,6 @@ if __name__ == '__main__':
     config = Config('oas1')
     device = Device(config)
     b = Benchmark(config=config, device=device)
-    # print(b.run_simple_screenshot_benchmark())
-    screenshot, click = b.get_test_methods()
-    b.benchmark(set(), click)
+    print(b.run_simple_screenshot_benchmark())
+    # screenshot, click = b.get_test_methods()
+    # b.benchmark(set(), click)

+ 2 - 0
module/device/device.py

@@ -99,6 +99,8 @@ class Device(Screenshot, Control, AppControl, EmulatorManager):
         # self.config.script.device.screenshot_method = 'scrcpy'
         if self.config.script.device.screenshot_method == 'scrcpy':
             self._scrcpy_server_stop()
+        if self.config.Emulator_ScreenshotMethod == 'nemu_ipc':
+            self.nemu_ipc_release()
 
     def stuck_record_add(self, button):
         """

+ 540 - 0
module/device/method/nemu_ipc.py

@@ -0,0 +1,540 @@
+import asyncio
+import ctypes
+import os
+import sys
+from functools import partial, wraps
+
+import cv2
+import numpy as np
+
+from module.base.decorator import cached_property, del_cached_property, has_cached_property
+from module.base.utils import ensure_time
+from module.device.method.minitouch import insert_swipe, random_rectangle_point
+from module.device.method.utils import RETRY_TRIES, retry_sleep
+from module.exception import RequestHumanTakeover
+from module.logger import logger
+
+
+class NemuIpcIncompatible(Exception):
+    pass
+
+
+class NemuIpcError(Exception):
+    pass
+
+
+class CaptureStd:
+    """
+    Capture stdout and stderr from both python and C library
+    https://stackoverflow.com/questions/5081657/how-do-i-prevent-a-c-shared-library-to-print-on-stdout-in-python/17954769
+
+    ```
+    with CaptureStd() as capture:
+        # String wasn't printed
+        print('whatever')
+    # But captured in ``capture.stdout``
+    print(f'Got stdout: "{capture.stdout}"')
+    print(f'Got stderr: "{capture.stderr}"')
+    ```
+    """
+
+    def __init__(self):
+        self.stdout = b''
+        self.stderr = b''
+
+    def _redirect_stdout(self, to):
+        sys.stdout.close()
+        os.dup2(to, self.fdout)
+        sys.stdout = os.fdopen(self.fdout, 'w')
+
+    def _redirect_stderr(self, to):
+        sys.stderr.close()
+        os.dup2(to, self.fderr)
+        sys.stderr = os.fdopen(self.fderr, 'w')
+
+    def __enter__(self):
+        self.fdout = sys.stdout.fileno()
+        self.fderr = sys.stderr.fileno()
+        self.reader_out, self.writer_out = os.pipe()
+        self.reader_err, self.writer_err = os.pipe()
+        self.old_stdout = os.dup(self.fdout)
+        self.old_stderr = os.dup(self.fderr)
+
+        file_out = os.fdopen(self.writer_out, 'w')
+        file_err = os.fdopen(self.writer_err, 'w')
+        self._redirect_stdout(to=file_out.fileno())
+        self._redirect_stderr(to=file_err.fileno())
+        return self
+
+    def __exit__(self, exc_type, exc_val, exc_tb):
+        self._redirect_stdout(to=self.old_stdout)
+        self._redirect_stderr(to=self.old_stderr)
+        os.close(self.old_stdout)
+        os.close(self.old_stderr)
+
+        self.stdout = self.recvall(self.reader_out)
+        self.stderr = self.recvall(self.reader_err)
+        os.close(self.reader_out)
+        os.close(self.reader_err)
+
+    @staticmethod
+    def recvall(reader, length=1024) -> bytes:
+        fragments = []
+        while 1:
+            chunk = os.read(reader, length)
+            if chunk:
+                fragments.append(chunk)
+            else:
+                break
+        output = b''.join(fragments)
+        return output
+
+
+class CaptureNemuIpc(CaptureStd):
+    instance = None
+
+    def is_capturing(self):
+        """
+        Only capture at the topmost wrapper to avoid nested capturing
+        If a capture is ongoing, this instance does nothing
+        """
+        cls = self.__class__
+        return isinstance(cls.instance, cls) and cls.instance != self
+
+    def __enter__(self):
+        if self.is_capturing():
+            return self
+
+        super().__enter__()
+        CaptureNemuIpc.instance = self
+        return self
+
+    def __exit__(self, exc_type, exc_val, exc_tb):
+        if self.is_capturing():
+            return
+
+        CaptureNemuIpc.instance = None
+        super().__exit__(exc_type, exc_val, exc_tb)
+
+        self.check_stdout()
+        self.check_stderr()
+
+    def check_stdout(self):
+        if not self.stdout:
+            return
+        logger.info(f'NemuIpc stdout: {self.stdout}')
+
+    def check_stderr(self):
+        if not self.stderr:
+            return
+        logger.error(f'NemuIpc stderr: {self.stderr}')
+
+        # Calling an old MuMu12 player
+        # Tested on 3.4.0
+        # b'nemu_capture_display rpc error: 1783\r\n'
+        # Tested on 3.7.3
+        # b'nemu_capture_display rpc error: 1745\r\n'
+        if b'error: 1783' in self.stderr or b'error: 1745' in self.stderr:
+            raise NemuIpcIncompatible(
+                f'NemuIpc requires MuMu12 version >= 3.8.13, please check your version')
+        # contact_id incorrect
+        # b'nemu_capture_display cannot find rpc connection\r\n'
+        if b'cannot find rpc connection' in self.stderr:
+            raise NemuIpcError(self.stderr)
+        # Emulator died
+        # b'nemu_capture_display rpc error: 1722\r\n'
+        # MuMuVMMSVC.exe died
+        # b'nemu_capture_display rpc error: 1726\r\n'
+        # No idea how to handle yet
+        if b'error: 1722' in self.stderr or b'error: 1726' in self.stderr:
+            raise NemuIpcError('Emulator instance is probably dead')
+
+
+def retry(func):
+    @wraps(func)
+    def retry_wrapper(self, *args, **kwargs):
+        """
+        Args:
+            self (NemuIpcImpl):
+        """
+        init = None
+        for _ in range(RETRY_TRIES):
+            try:
+                if callable(init):
+                    retry_sleep(_)
+                    init()
+                return func(self, *args, **kwargs)
+            # Can't handle
+            except RequestHumanTakeover:
+                break
+            # Can't handle
+            except NemuIpcIncompatible as e:
+                logger.error(e)
+                break
+            # Function call timeout
+            except asyncio.TimeoutError:
+                logger.warning(f'Func {func.__name__}() call timeout, retrying: {_}')
+
+                def init():
+                    self.reconnect()
+            # NemuIpcError
+            except NemuIpcError as e:
+                logger.error(e)
+
+                def init():
+                    self.reconnect()
+            # Unknown, probably a trucked image
+            except Exception as e:
+                logger.exception(e)
+
+                def init():
+                    pass
+
+        logger.critical(f'Retry {func.__name__}() failed')
+        raise RequestHumanTakeover
+
+    return retry_wrapper
+
+
+class NemuIpcImpl:
+    def __init__(self, nemu_folder: str, instance_id: int, display_id: int = 0):
+        """
+        Args:
+            nemu_folder: Installation path of MuMu12, e.g. E:/ProgramFiles/MuMuPlayer-12.0
+            instance_id: Emulator instance ID, starting from 0
+            display_id: Always 0 if keep app alive was disabled
+        """
+        self.nemu_folder: str = nemu_folder
+        self.instance_id: int = instance_id
+        self.display_id: int = display_id
+
+        ipc_dll = os.path.abspath(os.path.join(nemu_folder, './shell/sdk/external_renderer_ipc.dll'))
+        logger.info(
+            f'NemuIpcImpl init, '
+            f'nemu_folder={nemu_folder}, '
+            f'ipc_dll={ipc_dll}, '
+            f'instance_id={instance_id}, '
+            f'display_id={display_id}'
+        )
+
+        try:
+            self.lib = ctypes.CDLL(ipc_dll)
+        except OSError as e:
+            logger.error(e)
+            # OSError: [WinError 126] 找不到指定的模块。
+            if not os.path.exists(ipc_dll):
+                raise NemuIpcIncompatible(
+                    f'ipc_dll={ipc_dll} does not exist, '
+                    f'NemuIpc requires MuMu12 version >= 3.8.13, please check your version')
+            else:
+                raise NemuIpcIncompatible(
+                    f'ipc_dll={ipc_dll} exists, but cannot be loaded')
+        self.connect_id: int = 0
+        self.width = 0
+        self.height = 0
+
+    def connect(self):
+        if self.connect_id > 0:
+            return
+
+        connect_id = self.ev_run_sync(
+            self.lib.nemu_connect,
+            self.nemu_folder, self.instance_id
+        )
+        if connect_id == 0:
+            raise NemuIpcError(
+                'Connection failed, please check if nemu_folder is correct and emulator is running'
+            )
+
+        self.connect_id = connect_id
+        # logger.info(f'NemuIpc connected: {self.connect_id}')
+
+    def disconnect(self):
+        if self.connect_id == 0:
+            return
+
+        self.ev_run_sync(
+            self.lib.nemu_disconnect,
+            self.connect_id
+        )
+
+        # logger.info(f'NemuIpc disconnected: {self.connect_id}')
+        self.connect_id = 0
+
+    def reconnect(self):
+        self.disconnect()
+        self.connect()
+
+    def __enter__(self):
+        self.connect()
+        return self
+
+    def __exit__(self, exc_type, exc_val, exc_tb):
+        self.disconnect()
+
+    @cached_property
+    def _ev(self):
+        return asyncio.new_event_loop()
+
+    async def ev_run_async(self, func, *args, **kwargs):
+        """
+        Args:
+            func: Sync function to call
+            *args:
+            **kwargs:
+
+        Raises:
+            asyncio.TimeoutError: If function call timeout
+        """
+        func_wrapped = partial(func, *args, **kwargs)
+        # Increased timeout for slow PCs
+        # Default screenshot interval is 0.2s, so a 0.15s timeout would have a fast retry without extra time costs
+        result = await asyncio.wait_for(self._ev.run_in_executor(None, func_wrapped), timeout=0.15)
+        return result
+
+    def ev_run_sync(self, func, *args, **kwargs):
+        """
+        Args:
+            func: Sync function to call
+            *args:
+            **kwargs:
+
+        Raises:
+            asyncio.TimeoutError: If function call timeout
+            NemuIpcIncompatible:
+            NemuIpcError
+        """
+        result = self._ev.run_until_complete(self.ev_run_async(func, *args, **kwargs))
+
+        err = False
+        if func.__name__ == 'nemu_connect':
+            if result == 0:
+                err = True
+        else:
+            if result > 0:
+                err = True
+        # Get to actual error message printed in std
+        if err:
+            logger.warning(f'Failed to call {func.__name__}, result={result}')
+            with CaptureNemuIpc():
+                result = self._ev.run_until_complete(self.ev_run_async(func, *args, **kwargs))
+
+        return result
+
+    def get_resolution(self):
+        """
+        Get emulator resolution, `self.width` and `self.height` will be set
+        """
+        if self.connect_id == 0:
+            self.connect()
+
+        width_ptr = ctypes.pointer(ctypes.c_int(0))
+        height_ptr = ctypes.pointer(ctypes.c_int(0))
+        nullptr = ctypes.POINTER(ctypes.c_int)()
+
+        ret = self.ev_run_sync(
+            self.lib.nemu_capture_display,
+            self.connect_id, self.display_id, 0, width_ptr, height_ptr, nullptr
+        )
+        if ret > 0:
+            raise NemuIpcError('nemu_capture_display failed during get_resolution()')
+        self.width = width_ptr.contents.value
+        self.height = height_ptr.contents.value
+
+    @retry
+    def screenshot(self):
+        """
+        Returns:
+            np.ndarray: Image array in RGBA color space
+                Note that image is upside down
+        """
+        if self.connect_id == 0:
+            self.connect()
+
+        self.get_resolution()
+
+        width_ptr = ctypes.pointer(ctypes.c_int(self.width))
+        height_ptr = ctypes.pointer(ctypes.c_int(self.height))
+        length = self.width * self.height * 4
+        pixels_pointer = ctypes.pointer((ctypes.c_ubyte * length)())
+
+        ret = self.ev_run_sync(
+            self.lib.nemu_capture_display,
+            self.connect_id, self.display_id, length, width_ptr, height_ptr, pixels_pointer
+        )
+        if ret > 0:
+            raise NemuIpcError('nemu_capture_display failed during screenshot()')
+
+        # image = np.ctypeslib.as_array(pixels_pointer, shape=(self.height, self.width, 4))
+        image = np.ctypeslib.as_array(pixels_pointer.contents).reshape((self.height, self.width, 4))
+        return image
+
+    def convert_xy(self, x, y):
+        """
+        Convert classic ADB coordinates to Nemu's
+        `self.height` must be updated before calling this method
+
+        Returns:
+            int, int
+        """
+        x, y = int(x), int(y)
+        x, y = self.height - y, x
+        return x, y
+
+    @retry
+    def down(self, x, y):
+        """
+        Contact down, continuous contact down will be considered as swipe
+        """
+        if self.connect_id == 0:
+            self.connect()
+        if self.height == 0:
+            self.get_resolution()
+
+        x, y = self.convert_xy(x, y)
+
+        ret = self.ev_run_sync(
+            self.lib.nemu_input_event_touch_down,
+            self.connect_id, self.display_id, x, y
+        )
+        if ret > 0:
+            raise NemuIpcError('nemu_input_event_touch_down failed')
+
+    @retry
+    def up(self):
+        """
+        Contact up
+        """
+        if self.connect_id == 0:
+            self.connect()
+
+        ret = self.ev_run_sync(
+            self.lib.nemu_input_event_touch_up,
+            self.connect_id, self.display_id
+        )
+        if ret > 0:
+            raise NemuIpcError('nemu_input_event_touch_up failed')
+
+
+def serial_to_id(serial: str):
+    """
+    Predict instance ID from serial
+    E.g.
+        "127.0.0.1:16384" -> 0
+        "127.0.0.1:16416" -> 1
+
+    Returns:
+        int: instance_id, or None if failed to predict
+    """
+    try:
+        port = int(serial.split(':')[1])
+    except (IndexError, ValueError):
+        return None
+    index, offset = divmod(port - 16384, 32)
+    if 0 <= index < 32 and offset in [0, 1, 2]:
+        return index
+    else:
+        return None
+
+
+class NemuIpc():
+    @cached_property
+    def nemu_ipc(self) -> NemuIpcImpl:
+        """
+        Initialize a nemu ipc implementation
+        """
+        # Try existing settings first
+        if self.config.script.device.emulatorinfo_path:
+            folder = os.path.abspath(os.path.join(self.config.script.device.emulatorinfo_path, '../../'))
+            index = serial_to_id(self.serial)
+            if index is not None:
+                try:
+                    return NemuIpcImpl(
+                        nemu_folder=folder,
+                        instance_id=index,
+                        display_id=0
+                    ).__enter__()
+                except (NemuIpcIncompatible, NemuIpcError) as e:
+                    logger.error(e)
+                    logger.error('Emulator info incorrect')
+
+        # Search emulator instance
+        # with E:\ProgramFiles\MuMuPlayer-12.0\shell\MuMuPlayer.exe
+        # installation path is E:\ProgramFiles\MuMuPlayer-12.0
+        if self.emulator_instance is None:
+            logger.error('Unable to use NemuIpc because emulator instance not found')
+            raise RequestHumanTakeover
+        try:
+            return NemuIpcImpl(
+                nemu_folder=self.emulator_instance.emulator.abspath('../'),
+                instance_id=self.emulator_instance.MuMuPlayer12_id,
+                display_id=0
+            ).__enter__()
+        except (NemuIpcIncompatible, NemuIpcError) as e:
+            logger.error(e)
+            logger.error('Unable to initialize NemuIpc')
+            raise RequestHumanTakeover
+
+    def nemu_ipc_available(self) -> bool:
+        if not self.is_mumu_family:
+            return False
+        if self.nemud_app_keep_alive == '':
+            return False
+        try:
+            _ = self.nemu_ipc
+        except RequestHumanTakeover:
+            return False
+        return True
+
+    def nemu_ipc_release(self):
+        if has_cached_property(self, 'nemu_ipc'):
+            self.nemu_ipc.disconnect()
+        del_cached_property(self, 'nemu_ipc')
+        logger.info('nemu_ipc released')
+
+    def screenshot_nemu_ipc(self):
+        image = self.nemu_ipc.screenshot()
+
+        image = cv2.cvtColor(image, cv2.COLOR_BGRA2BGR)
+        cv2.flip(image, 0, dst=image)
+        return image
+
+    def click_nemu_ipc(self, x, y):
+        down = ensure_time((0.010, 0.020))
+        self.nemu_ipc.down(x, y)
+        self.sleep(down)
+        self.nemu_ipc.up()
+        self.sleep(0.050 - down)
+
+    def long_click_nemu_ipc(self, x, y, duration=1.0):
+        self.nemu_ipc.down(x, y)
+        self.sleep(duration)
+        self.nemu_ipc.up()
+        self.sleep(0.050)
+
+    def swipe_nemu_ipc(self, p1, p2):
+        points = insert_swipe(p0=p1, p3=p2)
+
+        for point in points:
+            self.nemu_ipc.down(*point)
+            self.sleep(0.010)
+
+        self.nemu_ipc.up()
+        self.sleep(0.050)
+
+    def drag_nemu_ipc(self, p1, p2, point_random=(-10, -10, 10, 10)):
+        p1 = np.array(p1) - random_rectangle_point(point_random)
+        p2 = np.array(p2) - random_rectangle_point(point_random)
+        points = insert_swipe(p0=p1, p3=p2, speed=20)
+
+        for point in points:
+            self.nemu_ipc.down(*point)
+            self.sleep(0.010)
+
+        self.nemu_ipc.down(*p2)
+        self.sleep(0.140)
+        self.nemu_ipc.down(*p2)
+        self.sleep(0.140)
+
+        self.nemu_ipc.up()
+        self.sleep(0.050)

+ 11 - 7
module/device/method/window.py

@@ -130,11 +130,12 @@ class Window(Handle):
         logger.info(f"Mumu emulator head height: {height}")
         return height
 
-    def click_window_message(self, x: int, y: int):
+    def click_window_message(self, x: int, y: int, fast: bool = False):
         """
 
         :param x:
         :param y:
+        :param fast:
         :return:
         """
         # 我不知道为什么的使用的pywin32==306的版本会导致获取的图片的是(1024, 576)
@@ -143,7 +144,10 @@ class Window(Handle):
 
         x = int(x / self.window_scale_rate)
         y = int(y / self.window_scale_rate)
-        # print(f"我点击的x:{x}, y:{y}")
+        if fast:
+            press_time: float = (random.randint(10, 40)) / 1000.0
+        else:
+            press_time: float = (random.randint(100, 200)) / 1000.0
         emulator_type = len(self.control_handle_list)
         if emulator_type == 2:  # mumu模拟器
             SendMessage(self.control_handle_list[0], WM_ACTIVATE, WA_ACTIVE, 0)  # 激活窗口
@@ -151,20 +155,20 @@ class Window(Handle):
             # SendMessage(self.control_handle_list[0], WM_LBUTTONDOWN, 0, MAKELONG(x, y+self.mumu_head_height))  # 模拟鼠标按下 先是父窗口 上面的框高度是57
             # mumu12模拟器 V3.5.16 之后后可以用下面的方式
             SendMessage(self.control_handle_list[1], WM_LBUTTONDOWN, 0, MAKELONG(x, y))
-            time.sleep((random.randint(100, 200)) / 1000.0)  # 点击弹起改为随机,时间100ms-200ms
+            time.sleep(press_time)
             SendMessage(self.control_handle_list[1], WM_LBUTTONUP, 0, MAKELONG(x, y))  # 模拟鼠标弹起 后是子窗口
         elif emulator_type > 2:  # 夜神模拟器
             SendMessage(self.control_handle_list[0], WM_LBUTTONDOWN, 0, MAKELONG(x, y))  # 模拟鼠标按下 先是父窗口 上面的框高度是57
             SendMessage(self.control_handle_list[1], WM_LBUTTONDOWN, 0, MAKELONG(x, y))
             SendMessage(self.control_handle_list[2], WM_LBUTTONDOWN, 0, MAKELONG(x, y))
             SendMessage(self.control_handle_list[3], WM_LBUTTONDOWN, 0, MAKELONG(x, y))
-            time.sleep((random.randint(100, 200)) / 1000.0)  # 点击弹起改为随机,时间100ms-200ms
+            time.sleep(press_time)
             SendMessage(self.control_handle_list[3], WM_LBUTTONUP, 0, MAKELONG(x, y))  # 模拟鼠标弹起 后是子窗口
         elif emulator_type == 1:  # 雷电模拟器
             clickPos = MAKELONG(x, y)
-            SendMessage(self.control_handle_list[0], WM_LBUTTONDOWN, 0, clickPos)  # 模拟鼠标按下
-            time.sleep((random.randint(100, 300)) / 1000.0)  # 点击弹起改为随机,时间100ms-200ms
-            SendMessage(self.control_handle_list[0], WM_LBUTTONUP, 0, clickPos)  # 模拟鼠标弹起
+            SendMessage(self.control_handle_list[0], WM_LBUTTONDOWN, 0, clickPos)
+            time.sleep(press_time)
+            SendMessage(self.control_handle_list[0], WM_LBUTTONUP, 0, clickPos)
 
     def long_click_window_message(self, x: int, y: int, duration: float):
         """

+ 7 - 2
module/device/screenshot.py

@@ -15,11 +15,12 @@ from module.device.method.adb import Adb
 from module.device.method.window import Window
 from module.device.method.droidcast import DroidCast
 from module.device.method.scrcpy import Scrcpy
+from module.device.method.nemu_ipc import NemuIpc
 from module.exception import RequestHumanTakeover, ScriptError
 from module.logger import logger
 
 
-class Screenshot(Adb, DroidCast, Scrcpy, Window):
+class Screenshot(Adb, DroidCast, Scrcpy, Window, NemuIpc):
     _screen_size_checked = False
     _screen_black_checked = False
     _minicap_uninstalled = False
@@ -42,7 +43,8 @@ class Screenshot(Adb, DroidCast, Scrcpy, Window):
             'DroidCast': self.screenshot_droidcast,
             'DroidCast_raw': self.screenshot_droidcast_raw,
             'scrcpy': self.screenshot_scrcpy,
-            'window_background': self.screenshot_window_background
+            'window_background': self.screenshot_window_background,
+            'nemu_ipc': self.screenshot_nemu_ipc
         }
 
     def screenshot(self):
@@ -158,6 +160,9 @@ class Screenshot(Adb, DroidCast, Scrcpy, Window):
             if interval != origin:
                 logger.warning(f'Optimization.ScreenshotInterval {origin} is revised to {interval}')
                 self.config.script.optimization.screenshot_interval = interval
+            # Allow nemu_ipc to have a lower default
+            if self.config.Emulator_ScreenshotMethod == 'nemu_ipc':
+                interval = limit_in(origin, 0.1, 0.2)
         elif interval == 'combat':
             origin = self.config.script.optimization.combat_screenshot_interval
             interval = limit_in(origin, 0.3, 1.0)

+ 2 - 1
requirements-in.txt

@@ -18,4 +18,5 @@ ppocr-onnx==0.0.3.9
 onepush==1.2.0
 paho-mqtt==1.6.1
 fastapi==0.104.1
-uvicorn==0.23.2
+uvicorn==0.23.2
+oashya

+ 1 - 0
requirements.txt

@@ -39,6 +39,7 @@ mdurl==0.1.2              # via markdown-it-py
 mpmath==1.3.0             # via sympy
 msgpack==1.0.7            # via zerorpc
 numpy==1.24.3             # via -r requirements-in.txt, onnxruntime, opencv-python, ppocr-onnx, shapely
+oashya==0.0.7             # via -r requirements-in.txt
 onepush==1.2.0            # via -r requirements-in.txt
 onnxruntime==1.16.3       # via ppocr-onnx
 opencv-python==4.7.0.72   # via -r requirements-in.txt, ppocr-onnx

+ 2 - 2
tasks/Component/GeneralInvite/assets.py

@@ -46,9 +46,9 @@ class GeneralInviteAssets:
 	# 左上角退出 
 	I_BACK_YELLOW = RuleImage(roi_front=(19,13,58,55), roi_back=(19,13,58,55), threshold=0.8, method="Template matching", file="./tasks/Component/GeneralInvite/gi/gi_back_yellow.png")
 	# 点击邀请 
-	I_INVITE_ENSURE = RuleImage(roi_front=(712,544,132,60), roi_back=(712,544,132,60), threshold=0.8, method="Template matching", file="./tasks/Component/GeneralInvite/gi/gi_invite_ensure.png")
+	I_INVITE_ENSURE = RuleImage(roi_front=(500,541,132,60), roi_back=(478,523,378,92), threshold=0.8, method="Template matching", file="./tasks/Component/GeneralInvite/gi/gi_invite_ensure.png")
 	# 判断是否点中好友了 
-	I_SELECTED = RuleImage(roi_front=(895,373,33,32), roi_back=(541,157,407,350), threshold=0.8, method="Template matching", file="./tasks/Component/GeneralInvite/gi/gi_selected.png")
+	I_SELECTED = RuleImage(roi_front=(895,373,33,32), roi_back=(380,157,568,350), threshold=0.8, method="Template matching", file="./tasks/Component/GeneralInvite/gi/gi_selected.png")
 	# 用来判断当前的列表是哪儿的 
 	I_FLAG_1_ON = RuleImage(roi_front=(354,126,62,21), roi_back=(354,126,62,21), threshold=0.8, method="Template matching", file="./tasks/Component/GeneralInvite/gi/gi_flag_1_on.png")
 	# description 

+ 3 - 3
tasks/Component/GeneralInvite/gi/image.json

@@ -155,8 +155,8 @@
   {
     "itemName": "invite_ensure",
     "imageName": "gi_invite_ensure.png",
-    "roiFront": "712,544,132,60",
-    "roiBack": "712,544,132,60",
+    "roiFront": "500,541,132,60",
+    "roiBack": "478,523,378,92",
     "method": "Template matching",
     "threshold": 0.8,
     "description": "点击邀请"
@@ -165,7 +165,7 @@
     "itemName": "selected",
     "imageName": "gi_selected.png",
     "roiFront": "895,373,33,32",
-    "roiBack": "541,157,407,350",
+    "roiBack": "380,157,568,350",
     "method": "Template matching",
     "threshold": 0.8,
     "description": "判断是否点中好友了"

+ 3 - 2
tasks/GlobalGame/assets.py

@@ -9,6 +9,7 @@ from module.atom.list import RuleList
 # Don't modify it manually.
 class GlobalGameAssets: 
 
+
 	# Image Rule Assets
 	# 接受 
 	I_G_ACCEPT = RuleImage(roi_front=(830,407,56,46), roi_back=(798,369,117,110), threshold=0.8, method="Template matching", file="./tasks/GlobalGame/gg/gg_g_accept.png")
@@ -16,9 +17,9 @@ class GlobalGameAssets:
 	I_G_REJECT = RuleImage(roi_front=(832,508,53,51), roi_back=(808,480,108,101), threshold=0.8, method="Template matching", file="./tasks/GlobalGame/gg/gg_g_reject.png")
 	# 勾玉 
 	I_G_JADE = RuleImage(roi_front=(661,466,43,46), roi_back=(661,466,43,46), threshold=0.8, method="Template matching", file="./tasks/GlobalGame/gg/gg_g_jade.png")
-	# 猫粮
+	# 猫粮 
 	I_G_CAT_FOOD = RuleImage(roi_front=(565,463,59,65), roi_back=(565,463,59,65), threshold=0.8, method="Template matching", file="./tasks/GlobalGame/gg/gg_g_cat_food.png")
-	# 狗粮
+	# 狗粮 
 	I_G_DOG_FOOD = RuleImage(roi_front=(565,464,60,63), roi_back=(565,464,60,63), threshold=0.8, method="Template matching", file="./tasks/GlobalGame/gg/gg_g_dog_food.png")
 	# 忽略 
 	I_G_IGNORE = RuleImage(roi_front=(773,116,21,21), roi_back=(759,102,48,48), threshold=0.8, method="Template matching", file="./tasks/GlobalGame/gg/gg_g_ignore.png")

+ 3 - 1
tasks/Hyakkiyakou/.gitignore

@@ -1,3 +1,5 @@
 
 /utils/exp_gen.py
-/temp
+/temp
+/agent/tagent.py
+/agent/tfocus.py

+ 14 - 0
tasks/Hyakkiyakou/README.md

@@ -0,0 +1,14 @@
+
+
+
+- agent: 砸豆子的决策模型
+- slave: 针对百鬼对接模拟器的接口
+- debugger.py: 辅助
+---
+
+detector: 检测器
+
+tracker: 跟踪器
+
+
+

+ 165 - 0
tasks/Hyakkiyakou/agent/agent.py

@@ -0,0 +1,165 @@
+import cv2
+import time
+import copy
+import numpy as np
+
+from datetime import datetime
+from pathlib import Path
+from numpy import uint8, fromfile
+from cached_property import cached_property
+
+from oashya.tracker import Tracker
+from oashya.labels import CLASSINDEX as CI
+from oashya.labels import id2label, id2name
+from module.logger import logger
+from tasks.Hyakkiyakou.agent.focus import Focus
+from tasks.Hyakkiyakou.debugger import Debugger
+
+
+def generate_gaussian_patch(size=(300, 300), mean=0, std_dev=60):
+    x = np.linspace(-150, 150, size[1])
+    y = np.linspace(-150, 150, size[0])
+    x, y = np.meshgrid(x, y)
+    z = np.exp(-(((x - mean) ** 2 + (y - mean) ** 2) / (2 * std_dev ** 2)))
+    return z
+
+
+def embed_patch_in_canvas(canvas, patch, position=(0, 0), patch_size=(300, 300)):
+    canvas_height, canvas_width = 720, 1280
+    patch_height, patch_width = patch_size
+    pos_x, pos_y = position
+    pos_x = max(0, min(pos_x, canvas_width))
+    pos_y = max(0, min(pos_y, canvas_width))
+
+    x1 = pos_x - patch_width // 2
+    y1 = pos_y - patch_height // 2
+    x2 = pos_x + patch_width // 2
+    y2 = pos_y + patch_height // 2
+    x1 = max(0, x1)
+    y1 = max(0, y1)
+    x2 = min(canvas_width, x2)
+    y2 = min(canvas_height, y2)
+    embed_w = x2 - x1
+    embed_h = y2 - y1
+    if embed_w <= 0 or embed_h <= 0:
+        logger.warning(f'Cannot embed patch in canvas: ({position})')
+        return canvas
+    if embed_w < patch_width or embed_h < patch_height:
+        _patch = patch[:embed_h, :embed_w]
+    else:
+        _patch = patch
+    # Embed the patch in the canvas
+    canvas[y1:y2, x1:x2] += _patch
+    return canvas
+
+
+class Agent:
+    GAUSSIAN = generate_gaussian_patch()
+    OBSERVE_THRESHOLD = 0.6
+    # --------------------------------------------------------------------------------
+
+    def __init__(self, strategy: dict = None):
+        self.z = np.zeros((720, 1280), dtype=np.float32)
+        self.focus: Focus = None
+        # 
+        strategy: dict = strategy if strategy is not None else {
+            # 'weights': [1., 1., 1., 0.6, 0.3, 0.3],
+            'priorities': [],
+            'invite_friend': False,
+            'auto_bean': False
+        }
+        self.strategy = strategy
+        self.weights: list[float] = strategy.get('weights', [1., 1., 0.7, 0.3, 0., 0.])
+        self.priorities: list[int] = strategy.get('priorities', [])
+        self.invite_friend: bool = strategy.get('invite_friend', False)
+        self.auto_bean: bool = strategy.get('auto_bean', False)
+        #
+        self.last_throw_time = datetime.now()
+        self.dbg_throw: int = 0
+        self.dbg_throw_n: int = 0
+
+    @classmethod
+    def gamma(cls, tracks: list[tuple],
+              weights: list[float],
+              priorities: list[int] = []) -> np.ndarray:
+        """
+        @param tracks:
+        @param weights: sp, ssr, sr, r, n, g
+        @param priorities:
+        @return:
+        """
+        z = np.zeros((720, 1280), dtype=np.float32)
+        for _id, _class, _conf, _cx, _cy, _w, _h, _v in tracks:
+            weight = 1.
+            mu = 0.8 + (_cx * 0.2) / 1280
+            match _class:
+                case _ if CI.MIN_G <= _class <= CI.MAX_G: weight = weights[5]
+                case _ if CI.MIN_N <= _class <= CI.MAX_N: weight = weights[4]
+                case _ if _class != CI.R_008 and _class != CI.R_007 and (CI.MIN_R <= _class <= CI.MAX_R):
+                    weight = weights[3]  # 不要童男童女
+                case _ if CI.MIN_SR <= _class <= CI.MAX_SR: weight = weights[2]
+                case _ if CI.MIN_SSR <= _class <= CI.MAX_SSR: weight = 1.5 * weights[1]
+                case _ if CI.MIN_SP <= _class <= CI.MAX_SP: weight = 1.5 * weights[0]
+                case CI.BUFF_005:  # freeze
+                    weight = -1.
+                    _cy += 100
+                case _: continue
+            for priority in priorities:  # 我的代码在你之上
+                if priority == _class:
+                    weight = 1.7
+                    break
+            if weight == 0.:
+                continue
+            z = embed_patch_in_canvas(canvas=z, patch=(mu * weight) * Agent.GAUSSIAN, position=(_cx, _cy))
+        return z
+
+    @classmethod
+    def argmax_gamma(cls, z: np.ndarray, tracks: list[tuple]) -> Focus:
+        max_y, max_x = np.unravel_index(np.argmax(z), z.shape)
+        max_variance = 2000
+        max_index = -1
+        for index, track in enumerate(tracks):
+            _id, _class, _conf, _cx, _cy, _w, _h, _v = track
+            variance = (max_x - _cx)**2 + (max_y - _cy)**2
+            if variance < max_variance:
+                max_index = index
+                max_variance = variance
+        return Focus(inputs=tracks[max_index])
+
+    def decision(self, tracks: list[tuple], state: list) -> list:
+        not_decision = [-1, -1, False, -1]
+        if not tracks:
+            return not_decision
+        # Cache the time interval for scattering beans
+        new_time = datetime.now()
+        delta_time = 1000 * (new_time - self.last_throw_time).total_seconds()  # ms
+        self.check_observe(tracks=tracks)
+        if self.focus is None:
+            return not_decision
+        result = self.focus.decision(tracks=tracks, strategy=self.strategy, state=[delta_time] + state)
+        if result[2]:
+            self.last_throw_time = new_time
+            self.dbg_throw += 1
+        else:
+            self.dbg_throw_n += 1
+        return result
+
+    def check_observe(self, tracks: list[tuple]):
+        z = Agent.gamma(tracks=tracks, weights=self.weights, priorities=self.priorities)
+        focus = Agent.argmax_gamma(z=z, tracks=tracks)
+        omega = focus.omega(z)
+        if omega < self.OBSERVE_THRESHOLD:
+            if self.focus is not None:
+                logger.info(f'Focus disappear')
+            self.focus = None
+            return
+        if self.focus is None or self.focus != focus:
+            logger.info(f'Focus changed, now: {id2name(focus._class)}')
+            self.focus = focus
+            self.focus.set_omega(omega)
+        elif self.focus == focus:
+            self.focus.update(focus)
+            self.focus.set_omega(omega)
+        # if Debugger.info_enable:
+        #     self.focus.show()
+

+ 121 - 0
tasks/Hyakkiyakou/agent/focus.py

@@ -0,0 +1,121 @@
+import numpy as np
+
+from rich.table import Table
+from rich.text import Text
+from cached_property import cached_property
+
+from module.logger import logger
+
+from oashya.labels import id2label, id2name
+from oashya.labels import CLASSINDEX as CI
+
+
+class Focus:
+    def __init__(self, inputs: list[tuple]):
+        self._id: int = inputs[0]
+        self._class: int = inputs[1]
+        self._conf: int = inputs[2]
+        self._cx: int = inputs[3]
+        self._cy: int = inputs[4]
+        self._w: int = inputs[5]
+        self._h: int = inputs[6]
+        self._v: float = inputs[7]
+        # -----------------------
+        self._omega: float = 0.
+        self._omega_buff: float = 0.
+
+    def __eq__(self, o):
+        return self._id == o._id or o._class == self._class
+
+    def __str__(self):
+        return f"""
+id: {self._id}
+class: {self._class}
+label: {id2label(self._class)}
+name: {id2name(self._class)}
+conf: {self._conf}
+xywh: ({self._cx}, {self._cy}, {self._w}, {self._h})
+velocity: {self._v}"""
+
+    def omega(self, z):
+        __omega = z[self._cy, self._cx]
+        self._omega = __omega
+        return __omega
+
+    def set_omega(self, value):
+        self._omega = value
+
+    def show(self):
+        table = Table(show_lines=True)
+        table.add_column('Property', header_style="bright_cyan", style="cyan", no_wrap=True)
+        table.add_column("Value", style="green")
+        table.add_column('Property', header_style="bright_cyan", style="cyan", no_wrap=True)
+        table.add_column("Value", style="green")
+        table.add_row('id', str(self._id), 'conf', str(self._conf))
+        table.add_row('class', str(self._class), 'xywh', f'({self._cx}, {self._cy}, {self._w}, {self._h})')
+        table.add_row('label', id2label(self._class), 'velocity', str(self._v))
+        table.add_row('name', f'{id2name(self._class)}', 'omega', str(self._omega))
+        logger.print(table, justify='center')
+
+    def update(self, focus):
+        self._id = focus._id
+        self._class = focus._class
+        self._conf = focus._conf
+        self._cx = focus._cx
+        self._cy = focus._cy
+        self._w = focus._w
+        self._h = focus._h
+        self._v = focus._v
+
+    def decision(self, tracks, strategy, state) -> list:
+
+        buff_omega, buff_cx, buff_cy, buff_v, buff_class = self.omega_buff(tracks, strategy['invite_friend'])
+        if self._omega > buff_omega:
+            buffed = False
+            target_x = self._cx + self._v * 100 - (self._w // 2)
+            target_y = self._cy - 40
+        else:
+            buffed = True
+            target_x = buff_cx + buff_v * 100
+            target_y = buff_cy - 40  # top left corner
+
+        _r = self.r(vector=state, omega=self._omega, omega_buff=self._omega_buff)
+        throw = True if _r > 0 else False
+        # x, y, throw, number
+        return [target_x, target_y, throw, 10]
+
+    def omega_buff(self, tracks, invite_friend: bool) -> float:
+        max_omega = 0.
+        max_cx = 0
+        max_cy = 0
+        max_v = 0
+        max_class = 0
+
+        for _id, _class, _conf, _cx, _cy, _w, _h, _v in tracks:
+            _current_omega = 0.
+            match _class:
+                case CI.BUFF_004: _current_omega = 2.2
+                case CI.BUFF_006: _current_omega = 2.0
+                case CI.BUFF_007: _current_omega = 2.0 if invite_friend and _cx <= 1000 else 0
+                case CI.BUFF_002: _current_omega = 2.0 if self._omega >= 1.5 else 0
+                case CI.BUFF_003: _current_omega = 2.0 if self._omega >= 1.5 else 0
+                case CI.BUFF_003: _current_omega = 2.0 if self._omega >= 1.5 and _cx <= 640 else 0
+                case _: pass
+            if _current_omega > max_omega:
+                max_omega = _current_omega
+                max_cx = _cx
+                max_cy = _cy
+                max_v = _v
+                max_class = _class
+        return max_omega, max_cx, max_cy, max_v, max_class
+            
+    @classmethod
+    def r(cls, vector: list, omega: float, omega_buff: float) -> float:
+        _omega = max(omega, omega_buff)
+        tau = - 140 / (max(101, vector[0]) - 100)
+        upsilon = (vector[1] / 250 - vector[2] / 35)
+        upsilon = 100 * (upsilon**2 if upsilon > 0 else - upsilon**2)
+        result = _omega + tau + upsilon - 0.6
+        # print(f"total: {result:.4f} | {_omega:.4f} | {tau:.4f} | {upsilon:.4f}")
+        return result
+

+ 5 - 0
tasks/Hyakkiyakou/agent/utils.py

@@ -0,0 +1,5 @@
+
+
+
+
+

+ 125 - 3
tasks/Hyakkiyakou/assets.py

@@ -12,11 +12,23 @@ class HyakkiyakouAssets:
 
 	# Click Rule Assets
 	# description 
-	C_HSELECT_1 = RuleClick(roi_front=(158,209,225,405), roi_back=(158,209,225,405), name="hselect_1")
+	C_HSELECT_1 = RuleClick(roi_front=(200,318,115,273), roi_back=(200,318,115,273), name="hselect_1")
 	# description 
-	C_HSELECT_2 = RuleClick(roi_front=(531,225,202,363), roi_back=(531,225,202,363), name="hselect_2")
+	C_HSELECT_2 = RuleClick(roi_front=(570,307,142,285), roi_back=(570,307,142,285), name="hselect_2")
 	# description 
-	C_HSELECT_3 = RuleClick(roi_front=(875,210,219,394), roi_back=(875,210,219,394), name="hselect_3")
+	C_HSELECT_3 = RuleClick(roi_front=(934,298,115,306), roi_back=(934,298,115,306), name="hselect_3")
+	# description 
+	C_FRIEND_1 = RuleClick(roi_front=(446,227,181,67), roi_back=(446,227,181,67), name="friend_1")
+	# description 
+	C_FRIEND_2 = RuleClick(roi_front=(718,229,178,64), roi_back=(718,229,178,64), name="friend_2")
+	# description 
+	C_FRIEND_3 = RuleClick(roi_front=(445,310,183,66), roi_back=(445,310,183,66), name="friend_3")
+	# description 
+	C_FRIEND_4 = RuleClick(roi_front=(712,311,184,62), roi_back=(712,311,184,62), name="friend_4")
+	# description 
+	C_FRIEND_5 = RuleClick(roi_front=(449,394,178,61), roi_back=(449,394,178,61), name="friend_5")
+	# description 
+	C_FRIEND_6 = RuleClick(roi_front=(714,397,182,62), roi_back=(714,397,182,62), name="friend_6")
 
 
 	# Image Rule Assets
@@ -32,6 +44,116 @@ class HyakkiyakouAssets:
 	I_HEND = RuleImage(roi_front=(81,164,86,299), roi_back=(81,164,86,299), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_hend.png")
 	# 冰冻 
 	I_HFREEZE = RuleImage(roi_front=(1092,665,187,54), roi_back=(1092,665,187,54), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_hfreeze.png")
+	# description 
+	I_HTITLE = RuleImage(roi_front=(578,21,134,48), roi_back=(578,21,134,48), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_htitle.png")
+	# description 
+	I_HCLOSE_RED = RuleImage(roi_front=(1056,177,54,54), roi_back=(1056,177,54,54), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_hclose_red.png")
+
+
+	# Image Rule Assets
+	# 左边概率up 
+	I_HYA_STATE_BUFF06 = RuleImage(roi_front=(331,7,126,41), roi_back=(137,1,342,66), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_hya_state_buff06.png")
+	# 冰冻 
+	I_HYA_STATE_BUFF05 = RuleImage(roi_front=(158,5,127,45), roi_back=(147,0,322,62), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_hya_state_buff05.png")
+	# 左边好友up 
+	I_HYA_STATE_BUFF07 = RuleImage(roi_front=(157,7,127,43), roi_back=(143,0,347,80), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_hya_state_buff07.png")
+	# 左边减速 
+	I_HYA_STATE_BUFF02 = RuleImage(roi_front=(157,6,128,39), roi_back=(146,1,348,55), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_hya_state_buff02.png")
+	# 左边砸豆加速 
+	I_HYA_STATE_BUFF03 = RuleImage(roi_front=(326,4,129,44), roi_back=(143,3,326,59), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_hya_state_buff03.png")
+
+
+	# Image Rule Assets
+	# description 
+	I_RESF_0 = RuleImage(roi_front=(615,13,30,46), roi_back=(606,11,43,51), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_resf_0.png")
+	# description 
+	I_RESF_1 = RuleImage(roi_front=(617,13,31,46), roi_back=(610,11,42,50), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_resf_1.png")
+	# description 
+	I_RESF_2 = RuleImage(roi_front=(611,14,33,47), roi_back=(602,10,47,57), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_resf_2.png")
+	# description 
+	I_RESF_3 = RuleImage(roi_front=(619,14,28,45), roi_back=(610,12,40,49), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_resf_3.png")
+	# description 
+	I_RESF_4 = RuleImage(roi_front=(611,14,37,47), roi_back=(608,14,43,47), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_resf_4.png")
+	# description 
+	I_RESF_5 = RuleImage(roi_front=(612,10,35,48), roi_back=(612,10,35,48), threshold=0.9, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_resf_5.png")
+	# description 
+	I_RESF_6 = RuleImage(roi_front=(616,10,29,49), roi_back=(616,10,29,49), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_resf_6.png")
+	# description 
+	I_RESF_7 = RuleImage(roi_front=(611,14,38,44), roi_back=(611,14,38,44), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_resf_7.png")
+	# description 
+	I_RESF_8 = RuleImage(roi_front=(615,10,32,50), roi_back=(615,10,32,50), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_resf_8.png")
+	# description 
+	I_RESF_9 = RuleImage(roi_front=(612,12,38,49), roi_back=(612,12,38,49), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_resf_9.png")
+	# description 
+	I_RESR_0 = RuleImage(roi_front=(636,11,34,47), roi_back=(636,11,34,47), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_resr_0.png")
+	# description 
+	I_RESR_1 = RuleImage(roi_front=(638,13,29,48), roi_back=(638,13,29,48), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_resr_1.png")
+	# description 
+	I_RESR_2 = RuleImage(roi_front=(639,15,30,39), roi_back=(639,15,30,39), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_resr_2.png")
+	# description 
+	I_RESR_3 = RuleImage(roi_front=(639,14,30,41), roi_back=(639,14,30,41), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_resr_3.png")
+	# description 
+	I_RESR_4 = RuleImage(roi_front=(636,13,32,46), roi_back=(636,13,32,46), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_resr_4.png")
+	# description 
+	I_RESR_5 = RuleImage(roi_front=(639,13,31,46), roi_back=(639,13,31,46), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_resr_5.png")
+	# description 
+	I_RESR_6 = RuleImage(roi_front=(638,12,32,44), roi_back=(638,12,32,44), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_resr_6.png")
+	# description 
+	I_RESR_7 = RuleImage(roi_front=(638,15,34,42), roi_back=(638,15,34,42), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_resr_7.png")
+	# description 
+	I_RESR_8 = RuleImage(roi_front=(638,13,33,47), roi_back=(638,13,33,47), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_resr_8.png")
+	# description 
+	I_RESR_9 = RuleImage(roi_front=(638,12,32,47), roi_back=(638,12,32,47), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_resr_9.png")
+
+
+	# Image Rule Assets
+	# description 
+	I_BEAN0 = RuleImage(roi_front=(150,648,13,22), roi_back=(0,0,100,100), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_bean0.png")
+	# description 
+	I_BEAN1 = RuleImage(roi_front=(134,648,11,22), roi_back=(0,0,100,100), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_bean1.png")
+	# description 
+	I_BEAN2 = RuleImage(roi_front=(134,649,14,21), roi_back=(0,0,100,100), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_bean2.png")
+	# description 
+	I_BEAN3 = RuleImage(roi_front=(134,649,14,21), roi_back=(0,0,100,100), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_bean3.png")
+	# description 
+	I_BEAN4 = RuleImage(roi_front=(135,647,13,23), roi_back=(0,0,100,100), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_bean4.png")
+	# description 
+	I_BEAN5 = RuleImage(roi_front=(135,649,13,22), roi_back=(0,0,100,100), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_bean5.png")
+	# description 
+	I_BEAN6 = RuleImage(roi_front=(132,649,15,21), roi_back=(0,0,100,100), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_bean6.png")
+	# description 
+	I_BEAN7 = RuleImage(roi_front=(133,648,15,22), roi_back=(0,0,100,100), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_bean7.png")
+	# description 
+	I_BEAN8 = RuleImage(roi_front=(132,646,14,23), roi_back=(0,0,100,100), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_bean8.png")
+	# description 
+	I_BEAN9 = RuleImage(roi_front=(133,649,15,21), roi_back=(0,0,100,100), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_bean9.png")
+	# description 
+	I_BEAN05 = RuleImage(roi_front=(387,640,32,35), roi_back=(371,631,86,52), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_bean05.png")
+	# description 
+	I_BEAN10 = RuleImage(roi_front=(560,640,32,35), roi_back=(531,634,72,47), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_bean10.png")
+
+
+	# Image Rule Assets
+	# description 
+	I_FRIEND_SAME_1 = RuleImage(roi_front=(375,122,106,62), roi_back=(375,122,106,62), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_friend_same_1.png")
+	# description 
+	I_FRIEND_REMOTE_1 = RuleImage(roi_front=(498,125,106,56), roi_back=(498,125,106,56), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_friend_remote_1.png")
+	# description 
+	I_FRIEND_SAME_2 = RuleImage(roi_front=(377,126,100,60), roi_back=(377,126,100,60), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_friend_same_2.png")
+	# description 
+	I_FRIEND_REMOTE_2 = RuleImage(roi_front=(504,127,100,56), roi_back=(504,127,100,56), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_friend_remote_2.png")
+
+
+	# Ocr Rule Assets
+	# 最坏的情况下来判断豆子的数量 
+	O_BEAN_NUMBER = RuleOcr(roi=(119,645,45,29), area=(119,645,45,29), mode="Digit", method="Default", keyword="", name="bean_number")
+
+
+	# Swipe Rule Assets
+	# description 
+	S_BEAN_05TO10 = RuleSwipe(roi_front=(390,648,21,22), roi_back=(577,647,21,23), mode="default", name="bean_05to10")
+	# description 
+	S_BEAN_10TO05 = RuleSwipe(roi_front=(565,647,24,24), roi_back=(390,647,22,22), mode="default", name="bean_10to05")
 
 
 	# Click Rule Assets

+ 63 - 0
tasks/Hyakkiyakou/config.py

@@ -0,0 +1,63 @@
+from pydantic import BaseModel, Field
+from enum import Enum
+
+from tasks.Component.config_scheduler import Scheduler
+from tasks.Component.config_base import ConfigBase, Time
+
+
+class ModelPrecision(str, Enum):
+    FP32 = 'FP32'
+    INT8 = 'INT8'
+
+class InferenceEngine(str, Enum):
+    ONNXRUNTIME = 'Onnxruntime'
+    TENSORRT = 'TensorRT'
+
+
+class HyakkiyakouConfig(ConfigBase):
+    hya_limit_time: Time = Field(default=Time(minute=20), description='hya_limit_time_help')
+    hya_limit_count: int = Field(default=10, description='hya_limit_count_help')
+    hya_invite_friend: bool = Field(default=False, description='hya_invite_friend_help')
+    # 自动调整豆子数量
+    hya_auto_bean: bool = Field(default=False, description='hya_auto_bean_help')
+    hya_priorities: str = Field(default='', description='hya_priorities_help')
+    hya_sp: float = Field(default=1., description='hya_sp_help')
+    hya_ssr: float = Field(default=1., description='hya_ssr_help')
+    hya_sr: float = Field(default=0.7, description='hya_sr_help')
+    hya_r: float = Field(default=0.3, description='hya_r_help')
+    hya_n: float = Field(default=0.0, description='hya_n_help')
+    # 呱太和N卡不是一个东西
+    hya_g: float = Field(default=0.0, description='hya_g_help')
+
+
+class HyakkiyakouModels(ConfigBase):
+    # 置信度阈值
+    conf_threshold: float = Field(default=0.6, description='conf_threshold_help')
+    # nms阈值
+    iou_threshold: float = Field(default=0.7, description='iou_threshold_help')
+    # 模型的推理精度 目前全部是fp32
+    model_precision: ModelPrecision = Field(default=ModelPrecision.FP32, description='model_precision_help')
+    # 推理引擎 目前全部是onnxruntime
+    inference_engine: InferenceEngine = Field(default=InferenceEngine.ONNXRUNTIME, description='inference_engine_help')
+
+
+class DebugConfig(ConfigBase):
+    # 运行期间现实每一张的跟踪结果
+    hya_show: bool = Field(default=False, description='hya_show_help')
+    # 输出更多调试信息, 给使用者显示的
+    hya_info: bool = Field(default=False, description='hya_info_help')
+    # 保存图片,拿去回喂给模型
+    continuous_learning: bool = Field(default=False, description='continuous_learning_help')
+    # 保存每一张票的结果
+    hya_save_result: bool = Field(default=False, description='hya_save_result_help')
+    # 单独的设定截屏间隔, 单位ms
+    hya_interval: float = Field(default=300, description='hya_interval_help')
+
+
+class Hyakkiyakou(ConfigBase):
+    scheduler: Scheduler = Field(default_factory=Scheduler)
+    hyakkiyakou_config: HyakkiyakouConfig = Field(default_factory=HyakkiyakouConfig)
+    hyakkiyakou_models: HyakkiyakouModels = Field(default_factory=HyakkiyakouModels)
+    debug_config: DebugConfig = Field(default_factory=DebugConfig)
+
+

+ 217 - 0
tasks/Hyakkiyakou/debugger.py

@@ -0,0 +1,217 @@
+import cv2
+import copy
+import shutil
+import time
+import numpy as np
+
+from datetime import datetime
+from cached_property import cached_property
+from pathlib import Path
+from numpy import uint8, fromfile
+from rich.table import Table
+from threading import Event, Lock, Thread
+from oashya.labels import id2label, CLASSIFY, CLASSINDEX, id2name
+from oashya.utils import draw_tracks
+from oashya.tracker import Tracker
+
+from tasks.base_task import BaseTask
+from module.logger import logger
+from tasks.Hyakkiyakou.agent.focus import Focus
+
+
+def test_track(show: bool = False):
+    tracker = Tracker()
+    # --------------------------------
+    #
+    folder_save = Path('./tasks/Hyakkiyakou/temp/save')
+    shutil.rmtree(folder_save, ignore_errors=True)
+    folder_save.mkdir(parents=True, exist_ok=True)
+    folder_image = Path('./tasks/Hyakkiyakou/temp/20240621T221325')
+    #
+    start_time = datetime.now()
+    for index, file in enumerate(folder_image.iterdir()):
+        print(f'{index}-----------------------------------------------------------------------------------------------')
+        if file.suffix != '.png':
+            continue
+        image = cv2.imdecode(fromfile(str(file), dtype=uint8), -1)
+        image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
+        results = tracker(image=image, response=[0, 0, False, 10])
+        print(results)
+        save_file = folder_save / f'{file.stem}.png'
+        draw_image = draw_tracks(image, results)
+        if show:
+            cv2.imshow('OAS Tracker', draw_image)
+            cv2.waitKey(500)
+            print('Press any key to continue')
+        else:
+            cv2.imwrite(str(save_file), draw_image)
+        # if index >= 14:
+        #     raise
+    end_time = datetime.now()
+    print(f'平均时间: {(end_time - start_time) / len([folder_image.iterdir()])}')
+
+
+def show_track(sync_image, sync_lock, stop_event):
+    # global glob_image
+    while True:
+        if stop_event.is_set():
+            logger.info('OAS Track Debugger stopped')
+            cv2.destroyAllWindows()
+            break
+        sync_lock.acquire()
+        if Debugger.sync_image is None:
+            logger.info('OAS Track Debugger not started')
+            time.sleep(1)
+            sync_lock.release()
+            continue
+        cv2.imshow('OAS Tracker', Debugger.sync_image)
+        sync_lock.release()
+        cv2.waitKey(100)
+
+
+class Debugger:
+    info_enable: bool = False
+    sync_image = None
+    sync_lock = Lock()
+    stop_event = Event()
+    sync_thread = Thread(target=show_track, daemon=True, name='OAS Track Debugger',
+                         args=(sync_image, sync_lock, stop_event))
+    # sync_event = Event()  # reserved for future use
+    # -------------------------------------------------------------------------
+
+    def __init__(self, 
+                 info_enable: bool = False, 
+                 continuous_learning: bool = False,
+                 hya_save_result: bool = False):
+        self._reset_thread_env()
+        Debugger.info_enable = info_enable
+        self.images_cache: dict = {}
+        self.continuous_learning = continuous_learning
+        self.hya_save_result = hya_save_result
+        if continuous_learning:
+            logger.info('Continuous Learning Mode Enabled')
+            save_time = datetime.now().strftime('%Y%m%dT%H')
+            self.hya_save_folder: Path = Path(f'./log/hya/{save_time}')
+            self.hya_save_folder.mkdir(parents=True, exist_ok=True)
+        if hya_save_result:
+            logger.info('Hyakkiyakou Save Result Mode Enabled')
+            save_time = datetime.now().strftime('%Y%m%dT%H')
+            self.hya_save_result_folder: Path = Path(f'./log/hyakkiyakou/{save_time}')
+            self.hya_save_result_folder.mkdir(parents=True, exist_ok=True)
+
+    @cached_property
+    def save_class(self) -> list[int]:
+        """
+        需要保存的类别
+        @return:
+        """
+        sp = [i for i in range(CLASSINDEX.MIN_SP, CLASSINDEX.MAX_SP + 1)]
+        ssr = [i for i in range(CLASSINDEX.MIN_SSR, CLASSINDEX.MAX_SSR + 1)]
+        g = [i for i in range(CLASSINDEX.MIN_G, CLASSINDEX.MAX_G + 1)]
+        return sp + ssr + g
+
+    def _reset_thread_env(self):
+        logger.info('Reset Debugger Thread Environment')
+        Debugger.sync_image = None
+        self.sync_lock = Lock()
+        self.stop_event = Event()
+        self.sync_thread = Thread(target=show_track, daemon=True, name='OAS Track Debugger',
+                                  args=(Debugger.sync_image, self.sync_lock, self.stop_event))
+
+    def show(self, results):
+        image = draw_tracks(self.device.image, results)
+        cv2.imshow('OAS Tracker', image)
+
+    def show_start(self):
+        logger.info('OAS Track Debugger show image start')
+        Debugger.sync_image = np.zeros((720, 1280, 3), dtype=np.uint8)
+        self.sync_thread.start()
+
+    def show_sync(self, image=None):
+        self.sync_lock.acquire()
+        if image is not None:
+            # deepcopy
+            Debugger.sync_image = copy.deepcopy(image)
+            # logger.info('OAS Track Debugger synced image')
+        self.sync_lock.release()
+
+    def show_stop(self):
+        logger.info('OAS Track Debugger show image stop')
+        self.stop_event.set()
+        self.sync_thread.join()
+
+    def check_class(self, _class: int) -> bool:
+        return _class in self.save_class
+
+    def deal_learning(self, image, tracks: list):
+        save_flag: bool = False
+        for _id, _class, _conf, _cx, _cy, _w, _h, _v in tracks:
+            if self.check_class(_class):
+                save_flag = True
+                break
+        if not save_flag:
+            return
+        time_now_image_name = f'hya_{int(time.time() * 1000)}'
+        self.images_cache[time_now_image_name] = image
+
+    def save_images(self):
+        if not self.images_cache:
+            self.images_cache: dict = {}
+            return
+        logger.info('OAS Track Debugger save images to train model')
+        for image_name, image in self.images_cache.items():
+            image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
+            cv2.imwrite(str(self.hya_save_folder / f'{image_name}.png'), image)
+        self.images_cache.clear()
+
+    def save_result(self, image):
+        if not self.hya_save_result:
+            return
+        _now_name = f'hya_{int(time.time() * 1000)}.png'
+        image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
+        cv2.imwrite(str(self.hya_save_result_folder / _now_name), image)
+
+    @classmethod
+    def show_info(cls, tracker, f: Focus):
+        table = Table(show_lines=True)
+        table.add_column('Property', header_style="bright_cyan", style="cyan", no_wrap=True)
+        table.add_column("Value", style="green")
+        table.add_column('Property', header_style="bright_cyan", style="cyan", no_wrap=True)
+        table.add_column("Value", style="green")
+        if f is not None:
+            try:
+                table.add_row('id', str(f._id), 'conf', f'{f._conf:.2f}')
+                table.add_row('class', str(f._class), 'xywh', f'({f._cx}, {f._cy}, {f._w}, {f._h})')
+                table.add_row('label', id2label(f._class), 'velocity', f'{f._v:.2f}')
+                table.add_row('name', f'{id2name(f._class)}', 'omega', str(f._omega))
+            except Exception as e:
+                pass
+        table.add_row('detect cost', f'{(tracker.detect_time.total_seconds() * 1000):.2f}ms',
+                    'track cost', f'{(tracker.track_time.total_seconds() * 1000):.2f}ms')
+        logger.print(table, justify='center')
+
+
+def test_debugger():
+    debugger = Debugger(info_enable=False, continuous_learning=True)
+    debugger.show_start()
+    folder_image = Path('./tasks/Hyakkiyakou/temp/20240621T221325')
+    for index, file in enumerate(folder_image.iterdir()):
+        print(f'{index}-----------------------------------------------------------------------------------------------')
+        if file.suffix != '.png':
+            continue
+        image = cv2.imdecode(fromfile(str(file), dtype=uint8), -1)
+        image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
+        debugger.show_sync(image)
+        tracks = [[1, 190, 0.9, 0, 0, 0, 0, 0]]
+        debugger.deal_learning(image=image, tracks=tracks)
+        time.sleep(0.5)
+        if index >= 19:
+            break
+    debugger.show_stop()
+    debugger.save_images()
+
+
+if __name__ == '__main__':
+    # test_track()
+    test_debugger()
+    pass

+ 42 - 6
tasks/Hyakkiyakou/hya/click.json

@@ -1,20 +1,56 @@
 [
   {
     "itemName": "hselect_1",
-    "roiFront": "158,209,225,405",
-    "roiBack": "158,209,225,405",
+    "roiFront": "200,318,115,273",
+    "roiBack": "200,318,115,273",
     "description": "description"
   },
   {
     "itemName": "hselect_2",
-    "roiFront": "531,225,202,363",
-    "roiBack": "531,225,202,363",
+    "roiFront": "570,307,142,285",
+    "roiBack": "570,307,142,285",
     "description": "description"
   },
   {
     "itemName": "hselect_3",
-    "roiFront": "875,210,219,394",
-    "roiBack": "875,210,219,394",
+    "roiFront": "934,298,115,306",
+    "roiBack": "934,298,115,306",
+    "description": "description"
+  },
+  {
+    "itemName": "friend_1",
+    "roiFront": "446,227,181,67",
+    "roiBack": "446,227,181,67",
+    "description": "description"
+  },
+  {
+    "itemName": "friend_2",
+    "roiFront": "718,229,178,64",
+    "roiBack": "718,229,178,64",
+    "description": "description"
+  },
+  {
+    "itemName": "friend_3",
+    "roiFront": "445,310,183,66",
+    "roiBack": "445,310,183,66",
+    "description": "description"
+  },
+  {
+    "itemName": "friend_4",
+    "roiFront": "712,311,184,62",
+    "roiBack": "712,311,184,62",
+    "description": "description"
+  },
+  {
+    "itemName": "friend_5",
+    "roiFront": "449,394,178,61",
+    "roiBack": "449,394,178,61",
+    "description": "description"
+  },
+  {
+    "itemName": "friend_6",
+    "roiFront": "714,397,182,62",
+    "roiBack": "714,397,182,62",
     "description": "description"
   }
 ]

BIN
tasks/Hyakkiyakou/hya/hya_bean0.png


BIN
tasks/Hyakkiyakou/hya/hya_bean05.png


BIN
tasks/Hyakkiyakou/hya/hya_bean1.png


BIN
tasks/Hyakkiyakou/hya/hya_bean10.png


BIN
tasks/Hyakkiyakou/hya/hya_bean2.png


BIN
tasks/Hyakkiyakou/hya/hya_bean3.png


BIN
tasks/Hyakkiyakou/hya/hya_bean4.png


BIN
tasks/Hyakkiyakou/hya/hya_bean5.png


BIN
tasks/Hyakkiyakou/hya/hya_bean6.png


BIN
tasks/Hyakkiyakou/hya/hya_bean7.png


BIN
tasks/Hyakkiyakou/hya/hya_bean8.png


BIN
tasks/Hyakkiyakou/hya/hya_bean9.png


BIN
tasks/Hyakkiyakou/hya/hya_friend_remote_1.png


BIN
tasks/Hyakkiyakou/hya/hya_friend_remote_2.png


BIN
tasks/Hyakkiyakou/hya/hya_friend_same_1.png


BIN
tasks/Hyakkiyakou/hya/hya_friend_same_2.png


BIN
tasks/Hyakkiyakou/hya/hya_hclose_red.png


BIN
tasks/Hyakkiyakou/hya/hya_htitle.png


BIN
tasks/Hyakkiyakou/hya/hya_hya_state_buff02.png


BIN
tasks/Hyakkiyakou/hya/hya_hya_state_buff03.png


BIN
tasks/Hyakkiyakou/hya/hya_hya_state_buff05.png


BIN
tasks/Hyakkiyakou/hya/hya_hya_state_buff06.png


BIN
tasks/Hyakkiyakou/hya/hya_hya_state_buff07.png


BIN
tasks/Hyakkiyakou/hya/hya_resf_0.png


BIN
tasks/Hyakkiyakou/hya/hya_resf_1.png


BIN
tasks/Hyakkiyakou/hya/hya_resf_2.png


BIN
tasks/Hyakkiyakou/hya/hya_resf_3.png


BIN
tasks/Hyakkiyakou/hya/hya_resf_4.png


BIN
tasks/Hyakkiyakou/hya/hya_resf_5.png


BIN
tasks/Hyakkiyakou/hya/hya_resf_6.png


BIN
tasks/Hyakkiyakou/hya/hya_resf_7.png


BIN
tasks/Hyakkiyakou/hya/hya_resf_8.png


BIN
tasks/Hyakkiyakou/hya/hya_resf_9.png


BIN
tasks/Hyakkiyakou/hya/hya_resr_0.png


BIN
tasks/Hyakkiyakou/hya/hya_resr_1.png


BIN
tasks/Hyakkiyakou/hya/hya_resr_2.png


BIN
tasks/Hyakkiyakou/hya/hya_resr_3.png


BIN
tasks/Hyakkiyakou/hya/hya_resr_4.png


BIN
tasks/Hyakkiyakou/hya/hya_resr_5.png


BIN
tasks/Hyakkiyakou/hya/hya_resr_6.png


BIN
tasks/Hyakkiyakou/hya/hya_resr_7.png


BIN
tasks/Hyakkiyakou/hya/hya_resr_8.png


BIN
tasks/Hyakkiyakou/hya/hya_resr_9.png


+ 18 - 0
tasks/Hyakkiyakou/hya/image1.json

@@ -52,5 +52,23 @@
     "method": "Template matching",
     "threshold": 0.8,
     "description": "冰冻"
+  },
+  {
+    "itemName": "htitle",
+    "imageName": "hya_htitle.png",
+    "roiFront": "578,21,134,48",
+    "roiBack": "578,21,134,48",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "hclose_red",
+    "imageName": "hya_hclose_red.png",
+    "roiFront": "1056,177,54,54",
+    "roiBack": "1056,177,54,54",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
   }
 ]

+ 47 - 0
tasks/Hyakkiyakou/hya/image2.json

@@ -0,0 +1,47 @@
+[
+  {
+    "itemName": "hya_state_buff06",
+    "imageName": "hya_hya_state_buff06.png",
+    "roiFront": "331,7,126,41",
+    "roiBack": "137,1,342,66",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "左边概率up"
+  },
+  {
+    "itemName": "hya_state_buff05",
+    "imageName": "hya_hya_state_buff05.png",
+    "roiFront": "158,5,127,45",
+    "roiBack": "147,0,322,62",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "冰冻"
+  },
+  {
+    "itemName": "hya_state_buff07",
+    "imageName": "hya_hya_state_buff07.png",
+    "roiFront": "157,7,127,43",
+    "roiBack": "143,0,347,80",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "左边好友up"
+  },
+  {
+    "itemName": "hya_state_buff02",
+    "imageName": "hya_hya_state_buff02.png",
+    "roiFront": "157,6,128,39",
+    "roiBack": "146,1,348,55",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "左边减速"
+  },
+  {
+    "itemName": "hya_state_buff03",
+    "imageName": "hya_hya_state_buff03.png",
+    "roiFront": "326,4,129,44",
+    "roiBack": "143,3,326,59",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "左边砸豆加速"
+  }
+]

+ 182 - 0
tasks/Hyakkiyakou/hya/image3.json

@@ -0,0 +1,182 @@
+[
+  {
+    "itemName": "resf_0",
+    "imageName": "hya_resf_0.png",
+    "roiFront": "615,13,30,46",
+    "roiBack": "606,11,43,51",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "resf_1",
+    "imageName": "hya_resf_1.png",
+    "roiFront": "617,13,31,46",
+    "roiBack": "610,11,42,50",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "resf_2",
+    "imageName": "hya_resf_2.png",
+    "roiFront": "611,14,33,47",
+    "roiBack": "602,10,47,57",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "resf_3",
+    "imageName": "hya_resf_3.png",
+    "roiFront": "619,14,28,45",
+    "roiBack": "610,12,40,49",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "resf_4",
+    "imageName": "hya_resf_4.png",
+    "roiFront": "611,14,37,47",
+    "roiBack": "608,14,43,47",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "resf_5",
+    "imageName": "hya_resf_5.png",
+    "roiFront": "612,10,35,48",
+    "roiBack": "612,10,35,48",
+    "method": "Template matching",
+    "threshold": 0.9,
+    "description": "description"
+  },
+  {
+    "itemName": "resf_6",
+    "imageName": "hya_resf_6.png",
+    "roiFront": "616,10,29,49",
+    "roiBack": "616,10,29,49",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "resf_7",
+    "imageName": "hya_resf_7.png",
+    "roiFront": "611,14,38,44",
+    "roiBack": "611,14,38,44",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "resf_8",
+    "imageName": "hya_resf_8.png",
+    "roiFront": "615,10,32,50",
+    "roiBack": "615,10,32,50",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "resf_9",
+    "imageName": "hya_resf_9.png",
+    "roiFront": "612,12,38,49",
+    "roiBack": "612,12,38,49",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "resr_0",
+    "imageName": "hya_resr_0.png",
+    "roiFront": "636,11,34,47",
+    "roiBack": "636,11,34,47",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "resr_1",
+    "imageName": "hya_resr_1.png",
+    "roiFront": "638,13,29,48",
+    "roiBack": "638,13,29,48",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "resr_2",
+    "imageName": "hya_resr_2.png",
+    "roiFront": "639,15,30,39",
+    "roiBack": "639,15,30,39",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "resr_3",
+    "imageName": "hya_resr_3.png",
+    "roiFront": "639,14,30,41",
+    "roiBack": "639,14,30,41",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "resr_4",
+    "imageName": "hya_resr_4.png",
+    "roiFront": "636,13,32,46",
+    "roiBack": "636,13,32,46",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "resr_5",
+    "imageName": "hya_resr_5.png",
+    "roiFront": "639,13,31,46",
+    "roiBack": "639,13,31,46",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "resr_6",
+    "imageName": "hya_resr_6.png",
+    "roiFront": "638,12,32,44",
+    "roiBack": "638,12,32,44",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "resr_7",
+    "imageName": "hya_resr_7.png",
+    "roiFront": "638,15,34,42",
+    "roiBack": "638,15,34,42",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "resr_8",
+    "imageName": "hya_resr_8.png",
+    "roiFront": "638,13,33,47",
+    "roiBack": "638,13,33,47",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "resr_9",
+    "imageName": "hya_resr_9.png",
+    "roiFront": "638,12,32,47",
+    "roiBack": "638,12,32,47",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  }
+]

+ 110 - 0
tasks/Hyakkiyakou/hya/image4.json

@@ -0,0 +1,110 @@
+[
+  {
+    "itemName": "bean0",
+    "imageName": "hya_bean0.png",
+    "roiFront": "150,648,13,22",
+    "roiBack": "0,0,100,100",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "bean1",
+    "imageName": "hya_bean1.png",
+    "roiFront": "134,648,11,22",
+    "roiBack": "0,0,100,100",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "bean2",
+    "imageName": "hya_bean2.png",
+    "roiFront": "134,649,14,21",
+    "roiBack": "0,0,100,100",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "bean3",
+    "imageName": "hya_bean3.png",
+    "roiFront": "134,649,14,21",
+    "roiBack": "0,0,100,100",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "bean4",
+    "imageName": "hya_bean4.png",
+    "roiFront": "135,647,13,23",
+    "roiBack": "0,0,100,100",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "bean5",
+    "imageName": "hya_bean5.png",
+    "roiFront": "135,649,13,22",
+    "roiBack": "0,0,100,100",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "bean6",
+    "imageName": "hya_bean6.png",
+    "roiFront": "132,649,15,21",
+    "roiBack": "0,0,100,100",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "bean7",
+    "imageName": "hya_bean7.png",
+    "roiFront": "133,648,15,22",
+    "roiBack": "0,0,100,100",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "bean8",
+    "imageName": "hya_bean8.png",
+    "roiFront": "132,646,14,23",
+    "roiBack": "0,0,100,100",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "bean9",
+    "imageName": "hya_bean9.png",
+    "roiFront": "133,649,15,21",
+    "roiBack": "0,0,100,100",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "bean05",
+    "imageName": "hya_bean05.png",
+    "roiFront": "387,640,32,35",
+    "roiBack": "371,631,86,52",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "bean10",
+    "imageName": "hya_bean10.png",
+    "roiFront": "560,640,32,35",
+    "roiBack": "531,634,72,47",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  }
+]

+ 38 - 0
tasks/Hyakkiyakou/hya/image5.json

@@ -0,0 +1,38 @@
+[
+  {
+    "itemName": "friend_same_1",
+    "imageName": "hya_friend_same_1.png",
+    "roiFront": "375,122,106,62",
+    "roiBack": "375,122,106,62",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "friend_remote_1",
+    "imageName": "hya_friend_remote_1.png",
+    "roiFront": "498,125,106,56",
+    "roiBack": "498,125,106,56",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "friend_same_2",
+    "imageName": "hya_friend_same_2.png",
+    "roiFront": "377,126,100,60",
+    "roiBack": "377,126,100,60",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "friend_remote_2",
+    "imageName": "hya_friend_remote_2.png",
+    "roiFront": "504,127,100,56",
+    "roiBack": "504,127,100,56",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  }
+]

+ 11 - 0
tasks/Hyakkiyakou/hya/ocr.json

@@ -0,0 +1,11 @@
+[
+  {
+    "itemName": "bean_number",
+    "roiFront": "119,645,45,29",
+    "roiBack": "119,645,45,29",
+    "mode": "Digit",
+    "method": "Default",
+    "keyword": "",
+    "description": "最坏的情况下来判断豆子的数量"
+  }
+]

+ 16 - 0
tasks/Hyakkiyakou/hya/swipe.json

@@ -0,0 +1,16 @@
+[
+  {
+    "itemName": "bean_05to10",
+    "roiFront": "390,648,21,22",
+    "roiBack": "577,647,21,23",
+    "mode": "default",
+    "description": "description"
+  },
+  {
+    "itemName": "bean_10to05",
+    "roiFront": "565,647,24,24",
+    "roiBack": "390,647,22,22",
+    "mode": "default",
+    "description": "description"
+  }
+]

+ 8 - 6
tasks/Hyakkiyakou/prepare/get_images.py

@@ -25,7 +25,7 @@ class GenerateImages(GameUi, HyakkiyakouAssets):
     def run(self):
         self.ui_get_current_page()
         self.ui_goto(page_hyakkiyakou)
-        for i in range(40):
+        for i in range(1):
             self.save_one()
 
     def save_one(self):
@@ -49,7 +49,7 @@ class GenerateImages(GameUi, HyakkiyakouAssets):
                 self.click(click_button, interval=1)
         self.device.stuck_record_add('BATTLE_STATUS_S')
         # 保存图片
-        save_img_timer = Timer(0.2)
+        save_img_timer = Timer(0.35)
         save_img_timer.start()
         while 1:
             self.screenshot()
@@ -58,8 +58,8 @@ class GenerateImages(GameUi, HyakkiyakouAssets):
                 break
             if not self.appear(self.I_CHECK_RUN):
                 continue
-            if self.appear(self.I_HFREEZE):
-                continue
+            # if self.appear(self.I_HFREEZE):
+            #     continue
             if save_img_timer.reached():
                 save_img_timer.reset()
                 self.save_image()
@@ -73,8 +73,10 @@ class GenerateImages(GameUi, HyakkiyakouAssets):
         # 时间戳毫秒级别
         time_now1 = int(time.time() * 1000)
         time_now2 = time_now1 + 1
-        cv2.imwrite(str(self.save_folder / f'{time_now1}.png'), img1)
-        cv2.imwrite(str(self.save_folder / f'{time_now2}.png'), img2)
+        image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
+        # cv2.imwrite(str(self.save_folder / f'{time_now1}.png'), img1)
+        # cv2.imwrite(str(self.save_folder / f'{time_now2}.png'), img2)
+        cv2.imwrite(str(self.save_folder / f'all{time_now1}.png'), image)
 
 
 if __name__ == '__main__':

+ 245 - 0
tasks/Hyakkiyakou/script_task.py

@@ -0,0 +1,245 @@
+# This Python file uses the following encoding: utf-8
+# @author runhey
+# github https://github.com/runhey
+import time
+
+import cv2
+import numpy as np
+
+from datetime import datetime, timedelta
+from numpy import uint8, fromfile
+from random import choice
+from cached_property import cached_property
+# Use cmd to install: ./toolkit/python.exe -m pip install -i https://pypi.org/simple/ oashya --trusted-host pypi.org
+# update oashya:  ./toolkit/python.exe -m pip install --upgrade oashya
+from oashya.tracker import Tracker
+from oashya.labels import label2id
+from oashya.utils import draw_tracks
+
+from module.exception import TaskEnd
+from module.logger import logger
+from module.exception import RequestHumanTakeover
+from tasks.GameUi.game_ui import GameUi
+from tasks.GameUi.page import page_hyakkiyakou
+from tasks.Hyakkiyakou.config import Hyakkiyakou as HyakkiyakouConfig
+from tasks.Hyakkiyakou.config import InferenceEngine, ModelPrecision
+from tasks.Hyakkiyakou.assets import HyakkiyakouAssets
+from tasks.Hyakkiyakou.agent.agent import Agent
+from tasks.Hyakkiyakou.slave.hya_slave import HyaSlave
+from tasks.Hyakkiyakou.debugger import Debugger
+
+
+def plot_save(image, boxes):
+    color_palette = np.random.uniform(0, 255, size=(226, 3))
+    for box in boxes:
+        _cls = box[0]
+        _scores = box[1]
+        _x, _y, _w, _h = box[2]
+        x1 = int(_x - _w / 2)
+        y1 = int(_y - _h / 2)
+        x2 = int(_x + _w / 2)
+        y2 = int(_y + _h / 2)
+        cv2.rectangle(image, (x1, y1), (x2, y2), color_palette[_cls], 2)
+        #
+        cv2.putText(image, f'{_cls} {_scores:.2f}', (x1, y1 - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, color_palette[_cls],
+                    2)
+    save_file = './tasks/Hyakkiyakou/temp/image.png'
+    cv2.imwrite(save_file, image)
+
+
+class ScriptTask(GameUi, HyaSlave):
+
+    @property
+    def _config(self):
+        return self.config.hyakkiyakou
+
+    @cached_property
+    def tracker(self) -> Tracker:
+        hyakkiyakou_models = self._config.hyakkiyakou_models
+        conf = hyakkiyakou_models.conf_threshold
+        nms = hyakkiyakou_models.iou_threshold
+        if conf < 0.2 or conf > 1:
+            raise RequestHumanTakeover('conf_threshold should be in [0.2, 1]')
+        if nms < 0.2 or nms > 1:
+            raise RequestHumanTakeover('iou_threshold should be in [0.2, 1]')
+        inf_en = 'onnxruntime' if hyakkiyakou_models.inference_engine == InferenceEngine.ONNXRUNTIME else 'tensorrt'
+        precision = 'fp32' if hyakkiyakou_models.model_precision == ModelPrecision.FP32 else 'int8'
+        # 这个坑后面在补
+        if inf_en == 'tensorrt' or precision == 'int8':
+            raise RequestHumanTakeover('Only support onnxruntime')
+        debug_info: bool = self._config.debug_config.hya_info
+        args = {
+            'conf_threshold': conf,
+            'iou_threshold': nms,
+            'precision': precision,
+            'inference_engine': inf_en,
+            'debug': debug_info,
+        }
+        return Tracker(args=args)
+
+    @cached_property
+    def agent(self) -> Agent:
+        hya_config = self._config.hyakkiyakou_config
+        sp = hya_config.hya_sp
+        ssr = hya_config.hya_ssr
+        sr = hya_config.hya_sr
+        r = hya_config.hya_r
+        n = hya_config.hya_n
+        g = hya_config.hya_g
+        weights: list = [sp, ssr, sr, r, n, g]
+        str_priorities: str = hya_config.hya_priorities
+        if str_priorities == '':
+            priorities = []
+        else:
+            str_priorities = str_priorities.replace(' ', '').replace(',', ',')
+            try:
+                priorities = [label2id(s) for s in str_priorities.split(',')]
+            except Exception as e:
+                logger.error(f'Priority error: {str_priorities}')
+                logger.error(e)
+                raise RequestHumanTakeover
+        strategy: dict = {
+            'weights': weights,
+            'priorities': priorities,
+            'invite_friend': hya_config.hya_invite_friend,
+            'auto_bean': hya_config.hya_auto_bean
+        }
+        return Agent(strategy=strategy)
+
+    @cached_property
+    def debugger(self) -> Debugger:
+        debug_config = self._config.debug_config
+        hya_interval = debug_config.hya_interval
+        hya_save_result = debug_config.hya_save_result
+        if hya_interval <= 100 or hya_interval >= 1000:
+            raise RequestHumanTakeover('screenshot_interval must be between 1000 and 10000')
+        self.set_fast_screenshot_interval(hya_interval)
+        return Debugger(info_enable=debug_config.hya_info, 
+                        continuous_learning=debug_config.continuous_learning,
+                        hya_save_result=hya_save_result)
+
+    def run(self):
+        hya_count: int = 0
+        self.limit_count: int = self._config.hyakkiyakou_config.hya_limit_count
+        limit_time = self._config.hyakkiyakou_config.hya_limit_time
+        self.limit_time: timedelta = timedelta(hours=limit_time.hour, minutes=limit_time.minute,
+                                               seconds=limit_time.second)
+        self.ui_get_current_page()
+        self.ui_goto(page_hyakkiyakou)
+
+
+        while 1:
+            if hya_count >= self.limit_count:
+                logger.info('Hyakkiyakou count limit out')
+                break
+            if datetime.now() - self.start_time >= self.limit_time:
+                logger.info('Hyakkiyakou time limit out')
+                break
+                
+
+            self.one()
+            hya_count += 1
+
+        while 1:
+            self.screenshot()
+
+            if not self.appear(self.I_HACCESS):
+                continue
+            if self.appear(self.I_HCLOSE_RED):
+                break
+        self.ui_click_until_disappear(self.I_HCLOSE_RED)
+        self.set_next_run(task='Hyakkiyakou', success=True, finish=False)
+        raise TaskEnd
+
+    def one(self):
+        self.reset_state()
+        if not self.appear(self.I_HACCESS):
+            logger.warning('Page Error')
+        if self._config.hyakkiyakou_config.hya_invite_friend:
+            self.invite_friend(True)
+        # start
+        self.ui_click(self.I_HACCESS, self.I_HSTART, interval=2)
+        self.wait_until_appear(self.I_HTITLE)
+        # 随机选一个
+        click_button = choice([self.C_HSELECT_1, self.C_HSELECT_2, self.C_HSELECT_3])
+        while 1:
+            self.screenshot()
+            if not self.appear(self.I_HTITLE):
+                break
+            if self.appear_then_click(self.I_HSTART, interval=2):
+                continue
+            if not self.appear(self.I_HSELECTED):
+                self.click(click_button, interval=2)
+        self.device.stuck_record_add('BATTLE_STATUS_S')
+        # 正式开始
+        logger.hr('Start Hyakkiyakou')
+        init_bean_flag: bool = False
+        last_action = [0, 0, False, 10]
+        if self._config.debug_config.hya_show:
+            self.debugger.show_start()
+        while 1:
+            self.fast_screenshot()
+            if self.appear(self.I_HEND):
+                break
+            if not self.appear(self.I_CHECK_RUN):
+                continue
+            if not init_bean_flag:
+                init_bean_flag = True
+                self.bean_05to10()
+                time.sleep(0.5)
+            if not self.appear(self.I_HFREEZE):
+                # --------------------------------------------------------
+                self.slave_state = self.update_state()
+                tracks = self.tracker(image=self.device.image, response=last_action)
+                last_action = self.agent.decision(tracks=tracks, state=self.slave_state)
+                self.do_action(last_action, state=self.slave_state)
+            else:
+                # TODO freeze state
+                tracks = []
+            # debug
+            if self._config.debug_config.hya_show:
+                draw_image = draw_tracks(self.device.image, tracks=tracks)
+                self.debugger.show_sync(image=draw_image)
+            if self._config.debug_config.continuous_learning:
+                self.debugger.deal_learning(image=self.device.image, tracks=tracks)
+            if self._config.debug_config.hya_info:
+                self.debugger.show_info(tracker=self.tracker, f=self.agent.focus)
+
+        logger.info('Hyakkiyakou End')
+        if self._config.debug_config.hya_show:
+            self.debugger.show_stop()
+        if self._config.debug_config.hya_save_result:
+            # 走个动画
+            time.sleep(1.5)
+            self.debugger.save_result(self.device.image)
+        self.ui_click(self.I_HEND, self.I_HACCESS)
+        self.debugger.save_images()
+        del self.debugger
+        # you maybe update oashya
+        self.tracker.clear_tracks()
+
+    def do_action(self, action: list, state):
+        x, y, throw, bean = action
+        if not throw:
+            return
+        if state[0] <= 0:
+            return
+        self.fast_click(x=x, y=y)
+
+
+if __name__ == '__main__':
+    from module.config.config import Config
+    from module.device.device import Device
+
+    c = Config('oas1')
+    d = Device(c)
+
+    t = ScriptTask(c, d)
+    t.run()
+
+    # from tasks.Hyakkiyakou.agent.tagent import test_observe, test_state
+    # test_state()
+    # from debugger import test_track
+    # test_track(show=False)
+    pass
+

+ 58 - 0
tasks/Hyakkiyakou/slave/hya_color.py

@@ -0,0 +1,58 @@
+# This Python file uses the following encoding: utf-8
+# @author runhey
+# github https://github.com/runhey
+import cv2
+from cached_property import cached_property
+
+from tasks.base_task import BaseTask
+
+
+class HyaColor(BaseTask):
+    BUFF_STATE_POS0: tuple[int] = (190, 42, 57, 37, 46)
+    BUFF_STATE_POS1: tuple[int] = (370, 35, 58, 39, 53)
+    BUFF_STATE_POS2: tuple[int] = (905, 35, 46, 29, 37)
+    BUFF_STATE_POS3: tuple[int] = (1060, 33, 53, 33, 39)
+
+    BEAN_NUM10: tuple[int] = (550, 657, 44, 32, 43)
+    BEAN_NUM05: tuple[int] = (400, 657, 44, 32, 43)
+
+    @cached_property
+    def buff_colors(self) -> list[tuple[int]]:
+        return [self.BUFF_STATE_POS0,
+                self.BUFF_STATE_POS1,
+                self.BUFF_STATE_POS2,
+                self.BUFF_STATE_POS3]
+
+    def show_point_color(self, x: int, y: int):
+        color = self.device.image[y, x]
+        print(f"({x}, {y}) color: {color}")
+        return color
+
+    def match_color(self, package: tuple, offset: int=5) -> bool:
+        x, y, r, g, b = package
+        img_r, img_g, img_b = self.device.image[y, x]
+        if abs(img_r - r) > offset:
+            return False
+        if abs(img_g - g) > offset:
+            return False
+        if abs(img_b - b) > offset:
+            return False
+        return True
+
+
+
+if __name__ == "__main__":
+    import timeit
+    from module.config.config import Config
+    from module.device.device import Device
+
+    c = Config('oas1')
+    d = Device(c)
+    hd = HyaColor(c, d)
+    img = cv2.imread(r'E:\Project\OnmyojiAutoScript\tasks\Hyakkiyakou\temp\20240615T144058\all1718433698934.png')
+    img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
+    hd.device.image = img
+
+    # print(hd.show_point_color(400, 657))
+    # print(hd.match_color(hd.BUFF_STATE_POS1))
+

+ 55 - 0
tasks/Hyakkiyakou/slave/hya_device.py

@@ -0,0 +1,55 @@
+import timeit
+
+from module.base.timer import Timer
+from module.logger import logger
+from module.base.utils import point2str
+from tasks.base_task import BaseTask
+
+
+class HyaDevice(BaseTask):
+    """
+    这个类主要是是优化截屏点击速度
+    1. 使用特别的method
+    2. 扔掉中间的冗余校验
+    3. 考虑JIT加速
+    我宣布世界上最好的 Linux 系统是 Windows
+    """
+    hya_screenshot_interval = Timer(0.2)  # 300ms
+
+    def fast_screenshot(self):
+        self.hya_screenshot_interval.wait()
+        self.hya_screenshot_interval.reset()
+        self.device.image = self.device.screenshot_window_background()
+        return self.device.image
+
+    def fast_click(self, x: int, y: int) -> None:
+        logger.info(
+            'Click %s @ %s' % (point2str(x, y), 'Click')
+        )
+        self.device.click_window_message(x=x, y=y, fast=True)
+
+    def set_fast_screenshot_interval(self, interval: float):
+        """
+
+        @param interval: ms
+        @return:
+        """
+        self.hya_screenshot_interval = Timer(interval / 1000.)
+
+
+
+if __name__ == '__main__':
+    from module.config.config import Config
+    from module.device.device import Device
+
+    c = Config('oas1')
+    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")

+ 342 - 0
tasks/Hyakkiyakou/slave/hya_slave.py

@@ -0,0 +1,342 @@
+import cv2
+
+from cached_property import cached_property
+from pathlib import Path
+from enum import Enum
+
+from module.logger import logger
+from module.base.timer import Timer
+from module.atom.image import RuleImage
+from module.exception import RequestHumanTakeover
+from tasks.Hyakkiyakou.slave.hya_device import HyaDevice
+from tasks.Hyakkiyakou.slave.hya_color import HyaColor
+from tasks.Hyakkiyakou.assets import HyakkiyakouAssets
+
+
+class HyaBuff(int, Enum):
+    BUFF_STATE0 = -1  # None
+    BUFF_STATE2 = 0  # 式神减速
+    BUFF_STATE3 = 1  # 砸豆加速
+    BUFF_STATE5 = 2  # 式神冰冻
+    BUFF_STATE6 = 3  # 概率UP
+    BUFF_STATE7 = 4  # 好友UP
+
+    @classmethod
+    def from_index(cls, index: int):
+        for member in cls:
+            if member.value == index:
+                return member
+        raise ValueError(f"No HyaBuff member with value {index}")
+
+
+
+class HyaSlave(HyaDevice, HyaColor, HyakkiyakouAssets):
+    """
+    主要是用来跟游戏进行交互的
+    """
+    # x, y, w, h
+    HUNDRED0HUNDRED: list[int] = [117, 647, 18, 25]
+    DECADE0HUNDRED: list[int] = [131, 647, 18, 25]
+    UNIT0HUNDRED: list[int] = [146, 647, 18, 25]
+    DECADE0DECADE: list[int] = [126, 647, 18, 25]
+    UNIT0DECADE: list[int] = [140, 647, 18, 25]
+    UNIT0: list[int] = [132, 647, 18, 25]
+    # buff
+    BUFF_ROI1: list[int] = [150, 1, 150, 50]
+    BUFF_ROI2: list[int] = [320, 1, 140, 50]
+    BUFF_ROI3: list[int] = [840, 1, 150, 50]
+    BUFF_ROI4: list[int] = [1100, 1, 140, 50]
+
+    # 剩余豆子数量, 剩余式神数量, 一次砸豆子的数量, 第一个格子, 第二个格子, 第三个格子, 第四个格子
+    slave_state: tuple = [250, 36, 10,
+                          HyaBuff.BUFF_STATE0, HyaBuff.BUFF_STATE0, HyaBuff.BUFF_STATE0, HyaBuff.BUFF_STATE0]
+
+    @cached_property
+    def res_r(self) -> list[RuleImage]:
+        return [
+            self.I_RESR_0,
+            self.I_RESR_1,
+            self.I_RESR_2,
+            self.I_RESR_3,
+            self.I_RESR_4,
+            self.I_RESR_5,
+            self.I_RESR_6,
+            self.I_RESR_7,
+            self.I_RESR_8,
+            self.I_RESR_9,
+        ]
+
+    @cached_property
+    def res_f(self) -> list[RuleImage]:
+        return [
+            self.I_RESF_0,
+            self.I_RESF_1,
+            self.I_RESF_2,
+            self.I_RESF_3,
+            self.I_RESF_4,
+            self.I_RESF_5,
+            self.I_RESF_6,
+            self.I_RESF_7,
+            self.I_RESF_8,
+            self.I_RESF_9,
+        ]
+
+    @cached_property
+    def bean(self) -> list[RuleImage]:
+        return [
+            self.I_BEAN0,
+            self.I_BEAN1,
+            self.I_BEAN2,
+            self.I_BEAN3,
+            self.I_BEAN4,
+            self.I_BEAN5,
+            self.I_BEAN6,
+            self.I_BEAN7,
+            self.I_BEAN8,
+            self.I_BEAN9,
+        ]
+
+    @cached_property
+    def buff_state_rois(self) -> list[list[int]]:
+        return [
+            self.BUFF_ROI1,
+            self.BUFF_ROI2,
+            self.BUFF_ROI3,
+            self.BUFF_ROI4
+        ]
+
+    @cached_property
+    def buff_state_images(self) -> list[RuleImage]:
+        return [
+            self.I_HYA_STATE_BUFF02,  # 式神减速
+            self.I_HYA_STATE_BUFF03,  # 砸豆加速
+            self.I_HYA_STATE_BUFF05,  # 冰冻
+            self.I_HYA_STATE_BUFF06,  # 概率up
+            self.I_HYA_STATE_BUFF07,  # 好友UP
+        ]
+
+    def predict_res(self, current: int) -> int:
+        for i in range(current, current-5, -1):
+            unit = i % 10
+            unit_img = self.res_r[unit] if i >= 10 else self.res_f[unit]
+            if not self.appear(unit_img):
+                continue
+            if i < 10:
+                return i
+            decade = i // 10
+            decade_img = self.res_f[decade]
+            if not self.appear(decade_img):
+                continue
+            return i
+        logger.warning(f'Cannot predict result, current: {current}')
+        return current
+
+    def predict_bean(self, current: int):
+        possible_beans: list[int] = [current, current - 10, current - 20]
+        for bean in possible_beans:
+            if bean >= 100:
+                decade = bean // 10 % 10
+                decade_img = self.bean[decade]
+                decade_img.roi_back = self.DECADE0HUNDRED
+                if not self.appear(decade_img):
+                    continue
+                hundred = bean // 100
+                hundred_img = self.bean[hundred]
+                hundred_img.roi_back = self.HUNDRED0HUNDRED
+                if not self.appear(hundred_img):
+                    continue
+                return bean
+
+            elif bean >= 10:
+                decade = bean // 10
+                decade_img = self.bean[decade]
+                decade_img.roi_back = self.DECADE0DECADE
+                if not self.appear(decade_img):
+                    continue
+                unit = bean % 10
+                unit_img = self.bean[unit]
+                unit_img.roi_back = self.UNIT0DECADE
+                if self.appear(unit_img):
+                    return bean
+                for i in range(10):
+                    unit_img = self.bean[i]
+                    unit_img.roi_back = self.UNIT0DECADE
+                    if self.appear(unit_img):
+                        return max(0, (bean // 10) * 10 + i)
+            else:
+                unit = bean % 10
+                unit_img = self.bean[unit]
+                unit_img.roi_back = self.UNIT0
+                if self.appear(unit_img):
+                    return bean
+                for i in range(10):
+                    unit_img = self.bean[i]
+                    unit_img.roi_back = self.UNIT0
+                    if self.appear(unit_img):
+                        return max(0, i)
+        # 最坏的情况下用ocr
+        num = self.O_BEAN_NUMBER.ocr(self.device.image)
+        if isinstance(num, int) and num >= 0:
+            return num
+
+        logger.warning(f'Cannot predict bean, current: {current}')
+        return current
+
+    def predict_buff_state(self, pos: int, current: HyaBuff = None) -> HyaBuff:
+        color = self.buff_colors[pos]
+        if self.match_color(color):
+            return HyaBuff.BUFF_STATE0
+        roi = self.buff_state_rois[pos]
+        if current is not None and current != HyaBuff.BUFF_STATE0:
+            current_image = self.buff_state_images[current]
+            current_image.roi_back = roi
+            if self.appear(current_image):
+                return current
+        for i, img in enumerate(self.buff_state_images):
+            img.roi_back = roi
+            if self.appear(img):
+                # int to HyaBuff
+                return HyaBuff.from_index(i)
+        return HyaBuff.BUFF_STATE0
+
+    def recognize_bean_05(self) -> bool:
+        return self.appear(self.I_BEAN05)
+
+    def recognize_bean_10(self) -> bool:
+        return self.appear(self.I_BEAN10)
+
+    def bean_05to10(self):
+        self.swipe(self.S_BEAN_05TO10)
+
+    def bean_10to05(self):
+        self.swipe(self.S_BEAN_10TO05)
+
+    # main process
+    # ------------------------------------------------------------------------------------------------------------------
+
+    def invite_friend(self, same: bool = True):
+        logger.hr('Invite friend', 2)
+        while 1:
+            self.screenshot()
+            if self.appear(self.I_FRIEND_SAME_1) or self.appear(self.I_FRIEND_SAME_2):
+                break
+            if self.appear_then_click(self.I_HINVITE, interval=4):
+                continue
+        if not self._invite_friend(True):
+            if not self._invite_friend(False):
+                raise RequestHumanTakeover('Invite friend failed')
+
+
+
+    def _invite_friend(self, same: bool = True) -> bool:
+        if not same:
+            logger.info('Invite different server friend')
+            self.ui_click(self.I_FRIEND_REMOTE_1, self.I_FRIEND_REMOTE_2)
+        invite_timer = Timer(8)
+        invite_timer.start()
+        while 1:
+            self.screenshot()
+            if not self.appear(self.I_HINVITE):
+                break
+            if self.click(self.C_FRIEND_1, interval=2):
+                continue
+            if self.click(self.C_FRIEND_2, interval=3):
+                continue
+            if invite_timer.reached():
+                logger.warning('Invite friend timeout, It may be no friend available')
+                return False
+        logger.info('Invite friend done')
+        return True
+
+    def update_state(self):
+        res_bean = self.predict_bean(self.slave_state[0])
+        res_shi = self.predict_res(self.slave_state[1])
+        num_bean = 5 if self.recognize_bean_05() else 10
+        buff_0 = self.predict_buff_state(pos=0, current=self.slave_state[3])
+        buff_1 = self.predict_buff_state(pos=1, current=self.slave_state[4])
+        buff_2 = self.predict_buff_state(pos=2, current=self.slave_state[5])
+        buff_3 = self.predict_buff_state(pos=3, current=self.slave_state[6])
+        self.slave_state = [
+            res_bean, res_shi, num_bean, buff_0, buff_1, buff_2, buff_3
+        ]
+        return self.slave_state
+
+    def reset_state(self):
+        self.slave_state = [250, 36, 10,
+                          HyaBuff.BUFF_STATE0, HyaBuff.BUFF_STATE0, HyaBuff.BUFF_STATE0, HyaBuff.BUFF_STATE0]
+def covert_rgb():
+    images_folders: Path = Path(r'E:\Project\OnmyojiAutoScript\tasks\Hyakkiyakou\temp\20240614T214216')
+    save_folders = images_folders.parent / 'save14'
+    save_folders.mkdir(parents=True, exist_ok=True)
+    for file in images_folders.iterdir():
+        if file.suffix != '.png':
+            continue
+        img = cv2.imread(str(file))
+        img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
+        cv2.imwrite(str(save_folders / file.name), img)
+
+def test_predict_res():
+    import timeit
+    from module.config.config import Config
+    from module.device.device import Device
+
+    c = Config('oas1')
+    d = Device(c)
+    hd = HyaSlave(c, d)
+    img = cv2.imread('D:/Project/OnmyojiAutoScript/tasks/Hyakkiyakou/temp/20240621T221325/all1718979259551.png')
+    img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
+    hd.device.image = img
+    print(hd.predict_res(2))
+
+    # def do_test():
+    #     hd.predict_res(18)
+    # execution_time = timeit.timeit(do_test, number=100)
+    # print(f"执行总的时间: {execution_time * 1000} ms")
+    # total time is 36.2ms on my computer /cpu:AMD Ryzen 5 3550H with Radeon Vega Mobile
+    # 0.362ms per predict_res
+
+def test_predict_bean():
+    import timeit
+    from module.config.config import Config
+    from module.device.device import Device
+
+    c = Config('oas1')
+    d = Device(c)
+    hd = HyaSlave(c, d)
+    img = cv2.imread('./tasks/Hyakkiyakou/temp/20240621T221325/all1718979269677.png')
+    img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
+    hd.device.image = img
+    print(hd.predict_bean(15))
+    # def do_test():
+    #     hd.predict_bean(180)
+    # execution_time = timeit.timeit(do_test, number=100)
+    # print(f"执行总的时间: {execution_time * 1000} ms")
+    # total time is 17.9ms on my computer in 100 times
+
+def test_predict_buff():
+    import timeit
+    from module.config.config import Config
+    from module.device.device import Device
+
+    c = Config('oas1')
+    d = Device(c)
+    hd = HyaSlave(c, d)
+    img = cv2.imread(r'E:\Project\OnmyojiAutoScript\tasks\Hyakkiyakou\temp\save14\all1718372600237.png')
+    img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
+    hd.device.image = img
+    print(hd.predict_buff_state(1))
+
+
+if __name__ == '__main__':
+    from module.config.config import Config
+    from module.device.device import Device
+
+    c = Config('oas1')
+    d = Device(c)
+    hd = HyaSlave(c, d)
+    # hd.invite_friend(False)
+
+    # test_predict_res()
+    test_predict_bean()
+    # test_predict_buff()
+

+ 13 - 0
tasks/RichMan/assets.py

@@ -337,6 +337,19 @@ class RichManAssets:
 	I_CENTER2 = RuleImage(roi_front=(76,590,79,75), roi_back=(65,575,100,100), threshold=0.8, method="Template matching", file="./tasks/RichMan/shrine/shrine_center2.png")
 
 
+	# Ocr Rule Assets
+	# Ocr-description 
+	O_S_TOTAL = RuleOcr(roi=(1134,11,112,36), area=(1134,11,112,36), mode="Digit", method="Default", keyword="", name="s_total")
+	# 已兑换 
+	O_S_BLACK = RuleOcr(roi=(582,179,84,48), area=(582,179,84,48), mode="Single", method="Default", keyword="", name="s_black")
+	# Ocr-description 
+	O_S_WHITE_FIVE = RuleOcr(roi=(774,174,69,44), area=(774,174,69,44), mode="Single", method="Default", keyword="", name="s_white_five")
+	# Ocr-description 
+	O_S_WHITE_FOUR = RuleOcr(roi=(952,168,74,60), area=(952,168,74,60), mode="Single", method="Default", keyword="", name="s_white_four")
+	# 买两个四星蛋 
+	O_S_FOUR_NUMBER = RuleOcr(roi=(581,414,46,45), area=(581,414,46,45), mode="Digit", method="Default", keyword="2", name="s_four_number")
+
+
 	# Image Rule Assets
 	# 千物宝库 
 	I_TT_ENTER = RuleImage(roi_front=(1140,585,73,76), roi_back=(1140,585,73,76), threshold=0.8, method="Template matching", file="./tasks/RichMan/tt/tt_tt_enter.png")

+ 2 - 2
tasks/RichMan/script_task.py

@@ -48,8 +48,8 @@ if __name__ == '__main__':
     d = Device(c)
     t = ScriptTask(c, d)
 
-    # t.run()
-    t.execute_mall()
+    t.run()
+    # t.execute_mall()
 
 
 

+ 12 - 2
tasks/RichMan/shrine/ocr.json

@@ -1,37 +1,47 @@
 [
   {
     "itemName": "s_total",
-    "roiFront": "1164,11,74,36",
-    "roiBack": "1164,11,74,36",
+    "roiFront": "1134,11,112,36",
+    "roiBack": "1134,11,112,36",
+    "mode": "Digit",
     "method": "Default",
+    "keyword": "",
     "description": "Ocr-description"
   },
   {
     "itemName": "s_black",
     "roiFront": "582,179,84,48",
     "roiBack": "582,179,84,48",
+    "mode": "Single",
     "method": "Default",
+    "keyword": "",
     "description": "已兑换"
   },
   {
     "itemName": "s_white_five",
     "roiFront": "774,174,69,44",
     "roiBack": "774,174,69,44",
+    "mode": "Single",
     "method": "Default",
+    "keyword": "",
     "description": "Ocr-description"
   },
   {
     "itemName": "s_white_four",
     "roiFront": "952,168,74,60",
     "roiBack": "952,168,74,60",
+    "mode": "Single",
     "method": "Default",
+    "keyword": "",
     "description": "Ocr-description"
   },
   {
     "itemName": "s_four_number",
     "roiFront": "581,414,46,45",
     "roiBack": "581,414,46,45",
+    "mode": "Digit",
     "method": "Default",
+    "keyword": "2",
     "description": "买两个四星蛋"
   }
 ]

+ 4 - 1
tasks/Script/config_device.py

@@ -22,6 +22,7 @@ class ScreenshotMethod(str, Enum):
     DROIDCAST_RAW = 'DroidCast_raw'
     SCRCPY = 'scrcpy'
     WINDOW_BACKGROUND = 'window_background'
+    NEMU_IPC = 'nemu_ipc'
 
 class ControlMethod(str, Enum):
     ADB = 'adb'
@@ -29,12 +30,14 @@ class ControlMethod(str, Enum):
     MINITOUCH = 'minitouch'
     WINDOW_MESSAGE = 'window_message'
 
-
 class Device(BaseModel):
     serial: str = Field(default="auto",
                         description='serial_help')
     handle: str = Field(default='',
                         description='handle_help')
+    emulatorinfo_path: str = Field(default='',
+                        description='emulatorinfo_path_help')
+    # 举例, E:\ProgramFiles\MuMuPlayer-12.0\shell\MuMuPlayer.exe
     package_name: PackageName = Field(title='Package Name',
                                       default=PackageName.AUTO,
                                       description='package_name_help')

+ 5 - 5
tasks/WantedQuests/assets.py

@@ -65,15 +65,15 @@ class WantedQuestsAssets:
 	# description 
 	I_WQ_INVITE_3 = RuleImage(roi_front=(754,366,39,42), roi_back=(728,339,100,100), threshold=0.8, method="Template matching", file="./tasks/WantedQuests/invite/invite_wq_invite_3.png")
 	# description 
-	I_WQ_FIREND_1 = RuleImage(roi_front=(449,191,172,70), roi_back=(449,191,172,70), threshold=0.8, method="Template matching", file="./tasks/WantedQuests/invite/invite_wq_firend_1.png")
+	I_WQ_FIREND_1 = RuleImage(roi_front=(245,190,175,70), roi_back=(245,190,175,70), threshold=0.8, method="Template matching", file="./tasks/WantedQuests/invite/invite_wq_firend_1.png")
 	# description 
-	I_WQ_FIREND_2 = RuleImage(roi_front=(743,192,172,69), roi_back=(743,192,172,69), threshold=0.8, method="Template matching", file="./tasks/WantedQuests/invite/invite_wq_firend_2.png")
+	I_WQ_FIREND_2 = RuleImage(roi_front=(537,190,175,70), roi_back=(537,190,175,70), threshold=0.8, method="Template matching", file="./tasks/WantedQuests/invite/invite_wq_firend_2.png")
 	# description 
-	I_WQ_FIREND_3 = RuleImage(roi_front=(453,281,175,71), roi_back=(453,281,175,71), threshold=0.8, method="Template matching", file="./tasks/WantedQuests/invite/invite_wq_firend_3.png")
+	I_WQ_FIREND_3 = RuleImage(roi_front=(245,286,175,70), roi_back=(245,286,175,70), threshold=0.8, method="Template matching", file="./tasks/WantedQuests/invite/invite_wq_firend_3.png")
 	# description 
-	I_WQ_FIREND_4 = RuleImage(roi_front=(743,280,171,76), roi_back=(743,280,171,76), threshold=0.8, method="Template matching", file="./tasks/WantedQuests/invite/invite_wq_firend_4.png")
+	I_WQ_FIREND_4 = RuleImage(roi_front=(537,286,175,70), roi_back=(537,286,175,70), threshold=0.8, method="Template matching", file="./tasks/WantedQuests/invite/invite_wq_firend_4.png")
 	# description 
-	I_WQ_FIREND_5 = RuleImage(roi_front=(479,376,148,56), roi_back=(479,376,148,56), threshold=0.8, method="Template matching", file="./tasks/WantedQuests/invite/invite_wq_firend_5.png")
+	I_WQ_FIREND_5 = RuleImage(roi_front=(245,382,175,70), roi_back=(245,382,175,70), threshold=0.8, method="Template matching", file="./tasks/WantedQuests/invite/invite_wq_firend_5.png")
 
 
 	# Image Rule Assets

+ 10 - 10
tasks/WantedQuests/invite/image.json

@@ -29,8 +29,8 @@
   {
     "itemName": "wq_firend_1",
     "imageName": "invite_wq_firend_1.png",
-    "roiFront": "449,191,172,70",
-    "roiBack": "449,191,172,70",
+    "roiFront": "245,190,175,70",
+    "roiBack": "245,190,175,70",
     "method": "Template matching",
     "threshold": 0.8,
     "description": "description"
@@ -38,8 +38,8 @@
   {
     "itemName": "wq_firend_2",
     "imageName": "invite_wq_firend_2.png",
-    "roiFront": "743,192,172,69",
-    "roiBack": "743,192,172,69",
+    "roiFront": "537,190,175,70",
+    "roiBack": "537,190,175,70",
     "method": "Template matching",
     "threshold": 0.8,
     "description": "description"
@@ -47,8 +47,8 @@
   {
     "itemName": "wq_firend_3",
     "imageName": "invite_wq_firend_3.png",
-    "roiFront": "453,281,175,71",
-    "roiBack": "453,281,175,71",
+    "roiFront": "245,286,175,70",
+    "roiBack": "245,286,175,70",
     "method": "Template matching",
     "threshold": 0.8,
     "description": "description"
@@ -56,8 +56,8 @@
   {
     "itemName": "wq_firend_4",
     "imageName": "invite_wq_firend_4.png",
-    "roiFront": "743,280,171,76",
-    "roiBack": "743,280,171,76",
+    "roiFront": "537,286,175,70",
+    "roiBack": "537,286,175,70",
     "method": "Template matching",
     "threshold": 0.8,
     "description": "description"
@@ -65,8 +65,8 @@
   {
     "itemName": "wq_firend_5",
     "imageName": "invite_wq_firend_5.png",
-    "roiFront": "479,376,148,56",
-    "roiBack": "479,376,148,56",
+    "roiFront": "245,382,175,70",
+    "roiBack": "245,382,175,70",
     "method": "Template matching",
     "threshold": 0.8,
     "description": "description"

+ 2 - 1
tasks/WantedQuests/script_task.py

@@ -294,7 +294,8 @@ if __name__ == '__main__':
     t = ScriptTask(c, d)
     t.screenshot()
 
-    t.run()
+    # t.run()
+    t.invite_five()
     # print(t.appear(t.I_WQ_CHECK_TASK))