Jelajahi Sumber

Merge branch 'runhey:dev' into dev

TripleEarth 3 tahun lalu
induk
melakukan
4dd57de615

+ 4 - 5
module/config/config.py

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

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

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

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

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

+ 21 - 8
module/logger.py

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

+ 2 - 0
module/ocr/base_ocr.py

@@ -17,6 +17,7 @@ from module.exception import ScriptError
 from module.logger import logger
 
 
+
 class OcrMode(Enum):
     FULL = 1  # str: "Full"
     SINGLE = 2  # str: "Single"
@@ -142,6 +143,7 @@ class BaseCor:
                     text=f'[{result}]')
         return result
 
+
     def detect_and_ocr(self, image) -> list[BoxedResult]:
         """
         注意:这里使用了预处理和后处理

+ 1 - 1
module/ocr/models.py

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

+ 11 - 2
script.py

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

+ 46 - 15
tasks/Component/GeneralBattle/general_battle.py

@@ -36,20 +36,6 @@ class GeneralBattle(BaseTask, GeneralBattleAssets):
             if self.current_count == 1:
                 self.switch_preset_team(config.preset_enable, config.preset_group, config.preset_team)
 
-            # 检测是否已经在战斗中
-            if self.is_in_battle():
-                while 1:
-                    self.screenshot()
-                    if self.appear_then_click(self.I_PREPARE_HIGHLIGHT, interval=1.5):
-                        continue
-                    if not self.appear(self.I_BUFF):
-                        break
-                win = self.battle_wait(config.random_click_swipt_enable)
-                if win:
-                    return True
-                else:
-                    return False
-
             # 点击准备按钮
             self.wait_until_appear(self.I_PREPARE_HIGHLIGHT)
             while 1:
@@ -64,7 +50,9 @@ class GeneralBattle(BaseTask, GeneralBattleAssets):
             time.sleep(0.1)
 
         # 绿标
-        self.green_mark(config.green_enable, config.green_mark)
+        self.wait_until_disappear(self.I_BUFF)
+        if self.is_in_battle(False):
+            self.green_mark(config.green_enable, config.green_mark)
 
         win = self.battle_wait(config.random_click_swipt_enable)
         if win:
@@ -370,6 +358,49 @@ class GeneralBattle(BaseTask, GeneralBattleAssets):
         else:
             return False
 
+    def is_in_prepare(self, is_screenshot: bool = True) -> bool:
+        """
+        判断是否在准备中
+        :return:
+        """
+        if is_screenshot:
+            self.screenshot()
+        if self.appear(self.I_BUFF):
+            return True
+        elif self.appear(self.I_PREPARE_HIGHLIGHT):
+            return True
+        elif self.appear(self.I_PREPARE_DARK):
+            return True
+        elif self.appear(self.I_PRESET):
+            return True
+        else:
+            return False
+
+    def check_take_over_battle(self, is_screenshot: bool, config: GeneralBattleConfig) -> bool or None:
+        """
+        中途接入战斗,并且接管
+        :return:  赢了返回True, 输了返回False, 不是在战斗中返回None
+        """
+        if is_screenshot:
+            self.screenshot()
+        if not self.is_in_battle():
+            return None
+
+        if self.is_in_prepare(False):
+            while 1:
+                self.screenshot()
+                if self.appear_then_click(self.I_PREPARE_HIGHLIGHT, interval=1.5):
+                    continue
+                if not self.appear(self.I_BUFF):
+                    break
+
+            # 被接管的战斗,只有准备阶段才可以点绿标。
+            # 因为如果是战斗中,无法保证点击的时候是否出现动画
+            self.wait_until_disappear(self.I_BUFF)
+            self.green_mark(config.green_enable, config.green_mark)
+
+        return self.battle_wait(config.random_click_swipt_enable)
+
 
 
 

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

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

+ 18 - 1
tasks/Component/config_base.py

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

+ 6 - 4
tasks/GameUi/game_ui.py

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

+ 1 - 1
tasks/KekkaiActivation/script_task.py

@@ -117,7 +117,7 @@ class ScriptTask(KU, KekkaiActivationAssets):
                 logger.info('Card is selected but not using')
                 while 1:
                     self.screenshot()
-                    if self.appear(self.I_A_INVITE):
+                    if self.appear(self.I_A_INVITE, threshold=0.7):
                         logger.info('Card is activated')
                         break
                     if self.appear_then_click(self.I_UI_CONFIRM, interval=0.6):

+ 6 - 2
tasks/KekkaiUtilize/assets.py

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

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

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

TEMPAT SAMPAH
tasks/KekkaiUtilize/realm/realm_box_exp_max.png


+ 18 - 8
tasks/KekkaiUtilize/script_task.py

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

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

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

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

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

TEMPAT SAMPAH
tasks/KekkaiUtilize/utilize/utilize_u_fish_3.png


TEMPAT SAMPAH
tasks/KekkaiUtilize/utilize/utilize_u_moon_6.png


TEMPAT SAMPAH
tasks/KekkaiUtilize/utilize/utilize_u_taiko_6.png


+ 7 - 0
tasks/Orochi/assets.py

@@ -25,6 +25,8 @@ class OrochiAssets:
 	I_SHI_RECORDS = RuleImage(roi_front=(821,638,48,45), roi_back=(821,638,48,45), threshold=0.8, method="Template matching", file="./tasks/Orochi/o/o_shi_records.png")
 	# description 
 	I_OROCHI_MATCHING = RuleImage(roi_front=(62,568,44,114), roi_back=(62,568,44,114), threshold=0.8, method="Template matching", file="./tasks/Orochi/o/o_orochi_matching.png")
+	# 小小宠物,发现宝藏 
+	I_PET_PRESENT = RuleImage(roi_front=(873,184,62,147), roi_back=(873,184,62,147), threshold=0.8, method="Template matching", file="./tasks/Orochi/o/o_pet_present.png")
 
 
 	# List Rule Assets
@@ -33,3 +35,8 @@ class OrochiAssets:
 					 array=["壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖", "拾", "悲", "神"])
 
 
+	# Ocr Rule Assets
+	# Ocr-description 
+	O_O_TEST_OCR = RuleOcr(roi=(126,136,360,491), area=(126,136,360,491), mode="Full", method="Default", keyword="", name="o_test_ocr")
+
+

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

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

TEMPAT SAMPAH
tasks/Orochi/o/o_pet_present.png


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

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

+ 27 - 4
tasks/Orochi/script_task.py

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

+ 4 - 0
tasks/Restart/assets.py

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

+ 5 - 4
tasks/Restart/login.py

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

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

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

TEMPAT SAMPAH
tasks/Restart/login/login_login_specific_serve.png


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

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

+ 8 - 4
tasks/base_task.py

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