Răsfoiți Sursa

Merge pull request #1270 from runhey/dev

Automated PR 2025.11.20
huangrunheng 1 an în urmă
părinte
comite
2036020807
43 a modificat fișierele cu 697 adăugiri și 129 ștergeri
  1. 3 0
      assets/i18n/en-US.json
  2. 9 0
      assets/i18n/zh-CN.json
  3. 3 3
      dev_tools/assets_test.py
  4. 0 1
      module/device/method/windows.py
  5. 2 2
      module/gui/qml/Component/ResizableRectangle.qml
  6. 10 0
      module/server/home_router.py
  7. 18 2
      module/server/i18n.py
  8. 0 1
      tasks/Component/RightActivity/right_activity.py
  9. 1 1
      tasks/Dokan/assets.py
  10. 2 0
      tasks/GlobalGame/assets.py
  11. 9 0
      tasks/GlobalGame/ui/image.json
  12. BIN
      tasks/GlobalGame/ui/ui_ui_gotit_small.png
  13. 3 3
      tasks/Hyakkiyakou/config.py
  14. 44 1
      tasks/MetaDemon/assets.py
  15. 146 5
      tasks/MetaDemon/config.py
  16. 155 0
      tasks/MetaDemon/md/image_2025.json
  17. BIN
      tasks/MetaDemon/md/md_battle_demon.png
  18. BIN
      tasks/MetaDemon/md/md_boss_convene.png
  19. BIN
      tasks/MetaDemon/md/md_boss_empty.png
  20. BIN
      tasks/MetaDemon/md/md_boss_empty_1.png
  21. BIN
      tasks/MetaDemon/md/md_boss_empty_2.png
  22. BIN
      tasks/MetaDemon/md/md_crafting_1.png
  23. BIN
      tasks/MetaDemon/md/md_crafting_card_star_1.png
  24. BIN
      tasks/MetaDemon/md/md_crafting_empty.png
  25. BIN
      tasks/MetaDemon/md/md_crafting_empty_new.png
  26. BIN
      tasks/MetaDemon/md/md_crafting_start.png
  27. BIN
      tasks/MetaDemon/md/md_enter2.png
  28. BIN
      tasks/MetaDemon/md/md_enter_ensure.png
  29. BIN
      tasks/MetaDemon/md/md_find_demon.png
  30. BIN
      tasks/MetaDemon/md/md_right_enter.png
  31. BIN
      tasks/MetaDemon/md/md_star56_hp_threshold_f.png
  32. BIN
      tasks/MetaDemon/md/md_star56_hp_threshold_t.png
  33. BIN
      tasks/MetaDemon/md/md_star56_pos_1.png
  34. 29 2
      tasks/MetaDemon/md/ocr.json
  35. 213 72
      tasks/MetaDemon/script_task.py
  36. 4 2
      tasks/Restart/assets.py
  37. BIN
      tasks/Restart/harvest/harvest_harvest_mail_all.png
  38. BIN
      tasks/Restart/harvest/harvest_mail_red_point.png
  39. BIN
      tasks/Restart/harvest/harvest_read_all_mail.png
  40. 12 3
      tasks/Restart/harvest/image.json
  41. 27 28
      tasks/Restart/login.py
  42. 5 1
      tasks/TrueOrochi/script_task.py
  43. 2 2
      tasks/Utils/post_diagnotor.py

+ 3 - 0
assets/i18n/en-US.json

@@ -0,0 +1,3 @@
+{
+
+}

+ 9 - 0
assets/i18n/zh-CN.json

@@ -0,0 +1,9 @@
+{
+  "boss_limit_time": "单局Boss限制时间",
+  "kirin_battle_config": "麒麟战斗配置",
+  "netherworld_battle_config": "阴界之门战斗配置",
+  "hya_onmyoji": "切换阴阳师",
+  "hya_onmyoji_help": ""
+}
+
+

+ 3 - 3
dev_tools/assets_test.py

@@ -34,10 +34,10 @@ def detect_ocr(file: str, target: RuleOcr):
 
 
 # 图片文件路径 可以是相对路径
-IMAGE_FILE = r"C:\Users\Ryland\Desktop\QQ20251014-103056.png"
+IMAGE_FILE = r"C:\Users\Ryland\Desktop\ScreenShot_2025-11-20_210804_069.png"
 if __name__ == '__main__':
-    from tasks.KekkaiActivation.script_task import ScriptTask
-    targe = ScriptTask.I_UI_CONFIRM_SAMLL
+    from tasks.MetaDemon.script_task import ScriptTask
+    targe = ScriptTask.I_BOSS_EMPTY_2
     print(detect_image(IMAGE_FILE, targe))
 
     # ocr demo

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

@@ -5,7 +5,6 @@ from module.device.env import IS_WINDOWS
 
 if IS_WINDOWS:
     from module.device.method.windows_impl import Window
-    print("dd")
 
 else:
     class Window:

+ 2 - 2
module/gui/qml/Component/ResizableRectangle.qml

@@ -3,8 +3,8 @@ import QtQuick.Window 2.15
 
 Item {
     id:rect
-    property int minimumWidth: 20
-    property int minimumHeight: 20
+    property int minimumWidth: 5
+    property int minimumHeight: 5
     property int mouseRegion: 5
     property var resizeTarget: rect
     anchors.fill: resizeTarget

+ 10 - 0
module/server/home_router.py

@@ -84,3 +84,13 @@ async def chinese_translate(data: dict = Body(...)):
     except Exception as e:
         logger.error(e)
     return True
+
+
+@home_app.get('/additional_translate')
+async def additional_translate() -> dict:
+    try:
+        data = I18n.load_additions()
+        return data
+    except Exception as e:
+        logger.error(e)
+    return {}

+ 18 - 2
module/server/i18n.py

@@ -2,7 +2,22 @@ import json
 from pathlib import Path
 
 
-class I18n:
+class Addition:
+    @classmethod
+    def load_additions(cls) -> dict:
+        result = {}
+        files: str = ['en-US', 'zh-CN']
+        for file in files:
+            file_path = Path.cwd() / 'assets' / 'i18n' / f'{file}.json'
+            result[file] = {}
+            if not file_path.exists():
+                continue
+            with open(str(file_path), 'r', encoding='utf-8') as f:
+                result[file] = json.load(f)
+        return result
+
+
+class I18n(Addition):
     file_zh_cn = Path.cwd() / 'module' / 'config' / 'i18n' / 'zh-CN.json'
 
     @classmethod
@@ -24,5 +39,6 @@ class I18n:
         with open(str(I18n.file_zh_cn), 'r', encoding='utf-8') as f:
             return json.load(f)
 
+
 if __name__ == '__main__':
-    print(I18n.load_zh_cn())
+    print(I18n.load_zh_cn())

+ 0 - 1
tasks/Component/RightActivity/right_activity.py

@@ -24,4 +24,3 @@ class RightActivity(GameUi, RightActivityAssets):
     def right_close(self):
         self.ui_click(self.I_RA_OPEN, self.I_RA_CLOSE, interval=2)
 
-

+ 1 - 1
tasks/Dokan/assets.py

@@ -34,7 +34,7 @@ class DokanAssets:
 
 
 	# List Rule Assets
-	# 前往按钮列表
+	# 前往按钮列表 
 	L_GOTO_CHEERING = RuleList(folder="./tasks/Dokan/res", direction="vertical", mode="ocr", roi_back=(950,172,54,324), size=(53, 62), 
 					 array=["前往"])
 

+ 2 - 0
tasks/GlobalGame/assets.py

@@ -61,5 +61,7 @@ class GlobalGameAssets:
 	I_UI_UNCHECK = RuleImage(roi_front=(567,343,33,36), roi_back=(497,303,216,100), threshold=0.8, method="Template matching", file="./tasks/GlobalGame/ui/ui_ui_uncheck.png")
 	# 勾选 
 	I_UI_CHECK = RuleImage(roi_front=(564,341,40,38), roi_back=(512,329,164,78), threshold=0.8, method="Template matching", file="./tasks/GlobalGame/ui/ui_ui_check.png")
+	# 知道了 
+	I_UI_GOTIT_SMALL = RuleImage(roi_front=(678,396,127,60), roi_back=(622,371,242,100), threshold=0.8, method="Template matching", file="./tasks/GlobalGame/ui/ui_ui_gotit_small.png")
 
 

+ 9 - 0
tasks/GlobalGame/ui/image.json

@@ -97,5 +97,14 @@
     "method": "Template matching",
     "threshold": 0.8,
     "description": "勾选"
+  },
+  {
+    "itemName": "ui_gotit_small",
+    "imageName": "ui_ui_gotit_small.png",
+    "roiFront": "678,396,127,60",
+    "roiBack": "622,371,242,100",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "知道了"
   }
 ]

BIN
tasks/GlobalGame/ui/ui_ui_gotit_small.png


+ 3 - 3
tasks/Hyakkiyakou/config.py

@@ -10,14 +10,17 @@ class ModelPrecision(str, Enum):
     FP32 = 'FP32'
     INT8 = 'INT8'
 
+
 class InferenceEngine(str, Enum):
     ONNXRUNTIME = 'Onnxruntime'
     TENSORRT = 'TensorRT'
 
+
 class ScreenshotMethod(str, Enum):
     WINDOW_BACKGROUND = 'window_background'
     NEMU_IPC = 'nemu_ipc'
 
+
 class ControlMethod(str, Enum):
     MINITOUCH = 'minitouch'
     WINDOW_MESSAGE = 'window_message'
@@ -71,7 +74,6 @@ class DebugConfig(ConfigBase):
 
     hide_fields = dynamic_hide('continuous_learning')
 
-
     @field_validator('continuous_learning', mode='after')
     @classmethod
     def false_continuous_learning(cls, v):
@@ -85,5 +87,3 @@ class Hyakkiyakou(ConfigBase):
     hyakkiyakou_config: HyakkiyakouConfig = Field(default_factory=HyakkiyakouConfig)
     hyakkiyakou_models: HyakkiyakouModels = Field(default_factory=HyakkiyakouModels)
     debug_config: DebugConfig = Field(default_factory=DebugConfig)
-
-

+ 44 - 1
tasks/MetaDemon/assets.py

@@ -47,12 +47,55 @@ class MetaDemonAssets:
 	I_RED_BACK = RuleImage(roi_front=(925,181,47,48), roi_back=(925,181,47,48), threshold=0.8, method="Template matching", file="./tasks/MetaDemon/md/md_red_back.png")
 
 
+	# Image Rule Assets
+	# 右侧进去 
+	I_RIGHT_ENTER = RuleImage(roi_front=(1183,314,46,42), roi_back=(1150,131,100,360), threshold=0.75, method="Template matching", file="./tasks/MetaDemon/md/md_right_enter.png")
+	# description 
+	I_ENTER2 = RuleImage(roi_front=(461,265,44,156), roi_back=(428,220,100,258), threshold=0.8, method="Template matching", file="./tasks/MetaDemon/md/md_enter2.png")
+	# 寻找鬼王 
+	I_FIND_DEMON = RuleImage(roi_front=(1140,582,86,81), roi_back=(1102,546,132,133), threshold=0.8, method="Template matching", file="./tasks/MetaDemon/md/md_find_demon.png")
+	# 点击战斗 
+	I_BATTLE_DEMON = RuleImage(roi_front=(1131,573,100,100), roi_back=(1085,536,165,161), threshold=0.7, method="Template matching", file="./tasks/MetaDemon/md/md_battle_demon.png")
+	# description 
+	I_BOSS_EMPTY = RuleImage(roi_front=(44,134,88,85), roi_back=(44,134,88,85), threshold=0.7, method="Template matching", file="./tasks/MetaDemon/md/md_boss_empty.png")
+	# 集结 
+	I_BOSS_CONVENE = RuleImage(roi_front=(247,146,47,52), roi_back=(228,127,88,85), threshold=0.7, method="Template matching", file="./tasks/MetaDemon/md/md_boss_convene.png")
+	# description 
+	I_BOSS_EMPTY_1 = RuleImage(roi_front=(46,372,87,90), roi_back=(46,372,87,90), threshold=0.5, method="Template matching", file="./tasks/MetaDemon/md/md_boss_empty_1.png")
+	# description 
+	I_BOSS_EMPTY_2 = RuleImage(roi_front=(46,501,88,88), roi_back=(46,501,88,88), threshold=0.5, method="Template matching", file="./tasks/MetaDemon/md/md_boss_empty_2.png")
+	# 合成 
+	I_CRAFTING_1 = RuleImage(roi_front=(1202,222,36,45), roi_back=(1167,199,100,100), threshold=0.8, method="Template matching", file="./tasks/MetaDemon/md/md_crafting_1.png")
+	# 空 
+	I_CRAFTING_EMPTY = RuleImage(roi_front=(939,460,75,81), roi_back=(922,447,108,111), threshold=0.8, method="Template matching", file="./tasks/MetaDemon/md/md_crafting_empty.png")
+	# 一星卡片 
+	I_CRAFTING_CARD_STAR_1 = RuleImage(roi_front=(217,156,87,92), roi_back=(191,127,140,137), threshold=0.8, method="Template matching", file="./tasks/MetaDemon/md/md_crafting_card_star_1.png")
+	# 开始合成 
+	I_CRAFTING_START = RuleImage(roi_front=(889,561,140,39), roi_back=(840,521,231,100), threshold=0.75, method="Template matching", file="./tasks/MetaDemon/md/md_crafting_start.png")
+	# description 
+	I_CRAFTING_EMPTY_NEW = RuleImage(roi_front=(787,307,100,100), roi_back=(772,299,128,117), threshold=0.8, method="Template matching", file="./tasks/MetaDemon/md/md_crafting_empty_new.png")
+	# description 
+	I_STAR56_POS_1 = RuleImage(roi_front=(100,205,8,11), roi_back=(100,205,8,11), threshold=0.8, method="Template matching", file="./tasks/MetaDemon/md/md_star56_pos_1.png")
+	# 血量高于阈值 
+	I_STAR56_HP_THRESHOLD_T = RuleImage(roi_front=(630,518,58,18), roi_back=(630,518,58,18), threshold=0.8, method="Template matching", file="./tasks/MetaDemon/md/md_star56_hp_threshold_t.png")
+	# 血量小于阈值 
+	I_STAR56_HP_THRESHOLD_F = RuleImage(roi_front=(659,517,26,19), roi_back=(659,517,26,19), threshold=0.8, method="Template matching", file="./tasks/MetaDemon/md/md_star56_hp_threshold_f.png")
+	# description 
+	I_ENTER_ENSURE = RuleImage(roi_front=(541,578,186,48), roi_back=(443,555,370,100), threshold=0.8, method="Template matching", file="./tasks/MetaDemon/md/md_enter_ensure.png")
+
+
 	# Ocr Rule Assets
 	# Ocr-description 
-	O_MD_EXHAUSTION = RuleOcr(roi=(1096,18,89,31), area=(1096,18,89,31), mode="DigitCounter", method="Default", keyword="", name="md_exhaustion")
+	O_MD_EXHAUSTION = RuleOcr(roi=(1114,24,94,31), area=(1114,24,94,31), mode="DigitCounter", method="Default", keyword="", name="md_exhaustion")
 	# Ocr-description 
 	O_MD_TICKET = RuleOcr(roi=(923,18,82,30), area=(923,18,82,30), mode="DigitCounter", method="Default", keyword="", name="md_ticket")
 	# Ocr-description 
 	O_MD_COUNT_INFO = RuleOcr(roi=(94,314,161,37), area=(94,314,161,37), mode="Single", method="Default", keyword="击败奖励结算中", name="md_count_info")
+	# 一星卡 
+	O_CRAFTING_CARD_1 = RuleOcr(roi=(303,158,161,33), area=(303,158,161,33), mode="Single", method="Default", keyword="一星梦告铃鼓", name="crafting_card_1")
+	# 式神全名 
+	O_MD_FULL_NAME = RuleOcr(roi=(479,116,100,217), area=(479,116,100,217), mode="Full", method="Default", keyword="", name="md_full_name")
+	# 判断别人是否给鬼王 
+	O_BOSS_EMPTY_1 = RuleOcr(roi=(141,400,94,32), area=(141,400,94,32), mode="Single", method="Default", keyword="剩余时间", name="boss_empty_1")
 
 

+ 146 - 5
tasks/MetaDemon/config.py

@@ -1,25 +1,166 @@
 # This Python file uses the following encoding: utf-8
 # @author runhey
 # github https://github.com/runhey
-from tasks.Component.config_base import ConfigBase, TimeDelta, DateTime, Time
-from pydantic import BaseModel, ValidationError, validator, Field
+
+from pydantic import BaseModel, ValidationError, validator, Field, field_validator
+from pydantic import Field, BaseModel, model_validator, model_serializer, ValidationError
 from enum import Enum
+from typing import Any, Dict
+
+from module.logger import logger
 from tasks.Component.config_scheduler import Scheduler
 from tasks.Component.SwitchSoul.switch_soul_config import SwitchSoulConfig
+from tasks.Component.config_base import ConfigBase, dynamic_hide
+
+
+class DefaultStrategy(ConfigBase):
+    # 1 是高于阈值选这个阵容 2是低于这个阈值选这个阵容
+    md_preset_group_team_default_1: str = Field(default='1,1', description='md_preset_group_team_default_1_help')
+    md_preset_group_team_default_2: str = Field(default='1,1', description='md_preset_group_team_default_2_help')
+
+    # fff = dynamic_hide('md_match_names')
+
 
-# 鬼王的难度为: 易、中、高、难、极 五个 对应英文:easy、medium、hard、difficult、extreme
+class Strategy(ConfigBase):
+    # 匹配的式神中文名字
+    md_match_names: str = Field(default='御撰津')
+    # 选哪一个预设组
+    md_preset_group_team_1: str = Field(default='1,1')
+    md_preset_group_team_2: str = Field(default='1,1')
+
+    def is_valid(self):
+        return self.md_match_names != "" and self.md_match_names is not None
+
+    @classmethod
+    def parse_names(cls, names: str) -> list[str]:
+        names = names.replace(',', ',').replace(' ', '')
+        try:
+            return names.split(',')
+        except Exception as e:
+            logger.error(f'parse_names error: {e}')
+            raise e
+
+    @classmethod
+    def parse_group_team(cls, team: str) -> list[int]:
+        team = team.replace(',', ',').replace(' ', '')
+        team = ''.join([c for c in team if c.isdigit() or c == ','])
+        try:
+            result = [int(i) for i in team.split(',')]
+            if len(result) != 2:
+                raise Exception('group team length is not 2')
+            if result[0] < 0 and result[1] < 0:
+                raise Exception('group team is not valid')
+            # group 不能小于1 和大于 7
+            if result[0] < 1 or result[0] > 7:
+                raise Exception('group is not valid')
+            # team 不能小于1 和大于 5
+            if result[1] < 1 or result[1] > 5:
+                raise Exception('team is not valid')
+            return result
+        except Exception as e:
+            logger.error(f'group team string: {team}')
+            logger.error(f'parse_team error: {e}')
+            raise e
+
+    @classmethod
+    def parse_all(cls, data: list['Strategy']) -> dict[str, list[int]]:
+        result = {}
+        for item in data:
+            value = item.parse_group_team(item.md_preset_group_team_1) \
+                    + item.parse_group_team(item.md_preset_group_team_2)
+            for name in cls.parse_names(item.md_match_names):
+                result[name] = value
+        return result
 
 
 class MetaDemonConfig(ConfigBase):
+    meta_crafting_card: bool = Field(default=True, description='craft_essence_help')
     auto_tea: bool = Field(default=False, description='auto_tea_help')
-    extreme_notify: bool = Field(default=False, description='extreme_notify_help')
+    # extreme_notify: bool = Field(default=False, description='extreme_notify_help')
+    md_strategy_count: int = Field(default=0, ge=0, description='md_strategy_count_help')
+    md_use_strategy: bool = Field(default=False, description='md_use_strategy_help')
+
+    @field_validator('auto_tea', mode='after')
+    @classmethod
+    def to_false(cls, v):
+        return False
+
+    @field_validator('md_strategy_count', mode='after')
+    @classmethod
+    def validator_strategy_count(cls, v):
+        if v < 0:
+            return 0
+        return v
 
 
 class MetaDemon(ConfigBase):
     scheduler: Scheduler = Field(default_factory=Scheduler)
-    meta_demon_config: MetaDemonConfig = Field(default_factory=MetaDemonConfig)
     switch_soul: SwitchSoulConfig = Field(default_factory=SwitchSoulConfig)
+    meta_demon_config: MetaDemonConfig = Field(default_factory=MetaDemonConfig)
+    md_default_strategy: DefaultStrategy = Field(default_factory=DefaultStrategy)
+    md_strategies: list[Strategy] = None
+
+    @model_validator(mode='before')
+    @classmethod
+    def validator_all(cls, v: dict) -> Any:
+        strategy_count = v.get('meta_demon_config', {}).get('md_strategy_count', 1)
+
+        def validator_list(list_name, data, item_type=None, list_size=1):
+            if list_name not in data:
+                data[list_name] = []
+
+            remove_keys = []
+            for key, value in data.items():
+                if list_name == key or list_name not in key:
+                    continue
+                try:
+                    item = item_type(**value)
+                    if item.is_valid():
+                        data[list_name].append(item)
+                    remove_keys.append(key)
+                except ValidationError as e:
+                    pass
+                except TypeError as e:
+                    pass
+
+            for key in remove_keys:
+                del data[key]
+
+            if item_type is not None:
+                current_list = data[list_name]
+                current_length = len(current_list)
+                if current_length < list_size:
+                    num_to_add = list_size - current_length
+                    new_elements = [item_type() for _ in range(num_to_add)]
+                    data[list_name].extend(new_elements)
+                elif current_length > list_size:
+                    data[list_name] = data[list_name][:list_size]
+
+        validator_list('md_strategies', v, Strategy, strategy_count)
+
+        return v
+
+    @model_serializer()
+    def serializer_model(self, value: Any) -> Dict[str, Any]:
+        properties = self.__dict__
+        data = {}
 
+        def v_dump(v):
+            try:
+                return v.model_dump()
+            except AttributeError as e:
+                logger.error(e)
+                return v
 
+        for key, value in properties.items():
+            if isinstance(value, list):
+                for index, v in enumerate(value):
+                    data[f'{key}_{index + 1}'] = v_dump(v)
+            else:
+                data[key] = v_dump(value)
+        return data
 
 
+if __name__ == '__main__':
+    ff = MetaDemon()
+    ff.model_dump()

+ 155 - 0
tasks/MetaDemon/md/image_2025.json

@@ -0,0 +1,155 @@
+[
+  {
+    "itemName": "right_enter",
+    "imageName": "md_right_enter.png",
+    "roiFront": "1183,314,46,42",
+    "roiBack": "1150,131,100,360",
+    "method": "Template matching",
+    "threshold": 0.75,
+    "description": "右侧进去"
+  },
+  {
+    "itemName": "enter2",
+    "imageName": "md_enter2.png",
+    "roiFront": "461,265,44,156",
+    "roiBack": "428,220,100,258",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "find_demon",
+    "imageName": "md_find_demon.png",
+    "roiFront": "1140,582,86,81",
+    "roiBack": "1102,546,132,133",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "寻找鬼王"
+  },
+  {
+    "itemName": "battle_demon",
+    "imageName": "md_battle_demon.png",
+    "roiFront": "1131,573,100,100",
+    "roiBack": "1085,536,165,161",
+    "method": "Template matching",
+    "threshold": 0.7,
+    "description": "点击战斗"
+  },
+  {
+    "itemName": "boss_empty",
+    "imageName": "md_boss_empty.png",
+    "roiFront": "44,134,88,85",
+    "roiBack": "44,134,88,85",
+    "method": "Template matching",
+    "threshold": 0.7,
+    "description": "description"
+  },
+  {
+    "itemName": "boss_convene",
+    "imageName": "md_boss_convene.png",
+    "roiFront": "247,146,47,52",
+    "roiBack": "228,127,88,85",
+    "method": "Template matching",
+    "threshold": 0.7,
+    "description": "集结"
+  },
+  {
+    "itemName": "boss_empty_1",
+    "imageName": "md_boss_empty_1.png",
+    "roiFront": "46,372,87,90",
+    "roiBack": "46,372,87,90",
+    "method": "Template matching",
+    "threshold": 0.5,
+    "description": "description"
+  },
+  {
+    "itemName": "boss_empty_2",
+    "imageName": "md_boss_empty_2.png",
+    "roiFront": "46,501,88,88",
+    "roiBack": "46,501,88,88",
+    "method": "Template matching",
+    "threshold": 0.5,
+    "description": "description"
+  },
+  {
+    "itemName": "crafting_1",
+    "imageName": "md_crafting_1.png",
+    "roiFront": "1202,222,36,45",
+    "roiBack": "1167,199,100,100",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "合成"
+  },
+  {
+    "itemName": "crafting_empty",
+    "imageName": "md_crafting_empty.png",
+    "roiFront": "939,460,75,81",
+    "roiBack": "922,447,108,111",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "空"
+  },
+  {
+    "itemName": "crafting_card_star_1",
+    "imageName": "md_crafting_card_star_1.png",
+    "roiFront": "217,156,87,92",
+    "roiBack": "191,127,140,137",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "一星卡片"
+  },
+  {
+    "itemName": "crafting_start",
+    "imageName": "md_crafting_start.png",
+    "roiFront": "889,561,140,39",
+    "roiBack": "840,521,231,100",
+    "method": "Template matching",
+    "threshold": 0.75,
+    "description": "开始合成"
+  },
+  {
+    "itemName": "crafting_empty_new",
+    "imageName": "md_crafting_empty_new.png",
+    "roiFront": "787,307,100,100",
+    "roiBack": "772,299,128,117",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "star56_pos_1",
+    "imageName": "md_star56_pos_1.png",
+    "roiFront": "100,205,8,11",
+    "roiBack": "100,205,8,11",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "star56_hp_threshold_t",
+    "imageName": "md_star56_hp_threshold_t.png",
+    "roiFront": "630,518,58,18",
+    "roiBack": "630,518,58,18",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "血量高于阈值"
+  },
+  {
+    "itemName": "star56_hp_threshold_f",
+    "imageName": "md_star56_hp_threshold_f.png",
+    "roiFront": "659,517,26,19",
+    "roiBack": "659,517,26,19",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "血量小于阈值"
+  },
+  {
+    "itemName": "enter_ensure",
+    "imageName": "md_enter_ensure.png",
+    "roiFront": "541,578,186,48",
+    "roiBack": "443,555,370,100",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  }
+]

BIN
tasks/MetaDemon/md/md_battle_demon.png


BIN
tasks/MetaDemon/md/md_boss_convene.png


BIN
tasks/MetaDemon/md/md_boss_empty.png


BIN
tasks/MetaDemon/md/md_boss_empty_1.png


BIN
tasks/MetaDemon/md/md_boss_empty_2.png


BIN
tasks/MetaDemon/md/md_crafting_1.png


BIN
tasks/MetaDemon/md/md_crafting_card_star_1.png


BIN
tasks/MetaDemon/md/md_crafting_empty.png


BIN
tasks/MetaDemon/md/md_crafting_empty_new.png


BIN
tasks/MetaDemon/md/md_crafting_start.png


BIN
tasks/MetaDemon/md/md_enter2.png


BIN
tasks/MetaDemon/md/md_enter_ensure.png


BIN
tasks/MetaDemon/md/md_find_demon.png


BIN
tasks/MetaDemon/md/md_right_enter.png


BIN
tasks/MetaDemon/md/md_star56_hp_threshold_f.png


BIN
tasks/MetaDemon/md/md_star56_hp_threshold_t.png


BIN
tasks/MetaDemon/md/md_star56_pos_1.png


+ 29 - 2
tasks/MetaDemon/md/ocr.json

@@ -1,8 +1,8 @@
 [
   {
     "itemName": "md_exhaustion",
-    "roiFront": "1096,18,89,31",
-    "roiBack": "1096,18,89,31",
+    "roiFront": "1114,24,94,31",
+    "roiBack": "1114,24,94,31",
     "mode": "DigitCounter",
     "method": "Default",
     "keyword": "",
@@ -25,5 +25,32 @@
     "method": "Default",
     "keyword": "击败奖励结算中",
     "description": "Ocr-description"
+  },
+  {
+    "itemName": "crafting_card_1",
+    "roiFront": "303,158,161,33",
+    "roiBack": "303,158,161,33",
+    "mode": "Single",
+    "method": "Default",
+    "keyword": "一星梦告铃鼓",
+    "description": "一星卡"
+  },
+  {
+    "itemName": "md_full_name",
+    "roiFront": "479,116,100,217",
+    "roiBack": "479,116,100,217",
+    "mode": "Full",
+    "method": "Default",
+    "keyword": "",
+    "description": "式神全名"
+  },
+  {
+    "itemName": "boss_empty_1",
+    "roiFront": "141,400,94,32",
+    "roiBack": "141,400,94,32",
+    "mode": "Single",
+    "method": "Default",
+    "keyword": "剩余时间",
+    "description": "判断别人是否给鬼王"
   }
 ]

+ 213 - 72
tasks/MetaDemon/script_task.py

@@ -5,29 +5,73 @@ from cached_property import cached_property
 from datetime import datetime
 from time import sleep
 
-from tasks.Component.config_base import ConfigBase, TimeDelta, DateTime, Time
+
+from module.base.timer import Timer
+from module.logger import logger
+from module.exception import TaskEnd
+
+
+from tasks.Component.RightActivity.right_activity import RightActivity
 from tasks.Component.GeneralBattle.general_battle import GeneralBattle
 from tasks.Component.GeneralBattle.config_general_battle import GeneralBattleConfig
 from tasks.Component.SwitchSoul.switch_soul import SwitchSoul
 from tasks.GameUi.game_ui import GameUi
 from tasks.GameUi.page import page_main, page_shikigami_records
-from tasks.MetaDemon.config import MetaDemon
+from tasks.MetaDemon.config import MetaDemon, DefaultStrategy, Strategy
 from tasks.MetaDemon.assets import MetaDemonAssets
-
-from module.logger import logger
-from module.exception import TaskEnd
 from tasks.Restart.assets import RestartAssets
 from tasks.ActivityShikigami.assets import ActivityShikigamiAssets
-from module.base.timer import Timer
 
-"""超鬼王"""
 
 
-class ScriptTask(GeneralBattle, SwitchSoul, GameUi, MetaDemonAssets):
+class Star56(GameUi, MetaDemonAssets):
 
-    def run(self):
+    @cached_property
+    def cached_strategies(self) -> dict[str, list[int]]:
+        return Strategy.parse_all(self.config.meta_demon.md_strategies)
+
+    @cached_property
+    def cached_default_group_team(self) -> list[int]:
+        return Strategy.parse_group_team(self.config.meta_demon.md_default_strategy.md_preset_group_team_default_1) \
+            + Strategy.parse_group_team(self.config.meta_demon.md_default_strategy.md_preset_group_team_default_2)
+
+    def is_star56(self):
+        if not self.appear(self.I_STAR56_POS_1):
+            return True
+        return False
+
+    def hp_threshold_low(self, image):
+        """
+        @param image:
+        @return: 血量小于阈值返回True
+        """
+        return self.appear(self.I_STAR56_HP_THRESHOLD_F) and not self.appear(self.I_STAR56_HP_THRESHOLD_T)
+
+    @classmethod
+    def strategy2group_team(cls, strategies: dict[str, list[int]], detect_name: str) -> list[int] | None:
+        """
+        先是默认的完全匹配,然后是1个字符不同,最后是2个字符不同
+        @param strategies:
+        @param detect_name:
+        @return:
+        """
+        for i in range(2):
+            for key_name in strategies:
+                if len(key_name) != len(detect_name):
+                    continue
+                diff_count = sum(1 for c1, c2 in zip(key_name, detect_name) if c1 != c2)
+                if diff_count <= i < len(detect_name):
+                    return strategies[key_name]
+        return None
+
+    def get_group_team(self, detect_name: str) -> list[int]:
+        tmp = self.strategy2group_team(self.cached_strategies, detect_name)
+        return tmp if tmp else self.cached_default_group_team
 
 
+class ScriptTask(RightActivity, GeneralBattle, SwitchSoul, Star56):
+
+    def run(self):
         if self.config.meta_demon.switch_soul.enable:
             self.ui_get_current_page()
             self.ui_goto(page_shikigami_records)
@@ -38,96 +82,192 @@ class ScriptTask(GeneralBattle, SwitchSoul, GameUi, MetaDemonAssets):
             self.ui_goto(page_shikigami_records)
             self.run_switch_soul_by_name(self.config.meta_demon.switch_soul.group_name,
                                          self.config.meta_demon.switch_soul.team_name)
-        self.ui_get_current_page()
-        self.ui_goto(page_main)
 
-        boss_timer = Timer(200)
-        boss_timer.start()
+        self.enter(self.I_RIGHT_ENTER)
         while 1:
             self.screenshot()
-            sleep(0.1)
-            if boss_timer.reached():
-                self.config.notifier.push(title='超鬼王', message='识别超时退出')
-                break
-            if self.appear(self.I_BACK_CHECK):
-                self.click(self.I_RED_BACK, interval=1.5)
+            if self.appear(self.I_FIND_DEMON) or self.appear(self.I_BATTLE_DEMON):
                 break
-            if self.appear_then_click(RestartAssets.I_HARVEST_CHAT_CLOSE):
-                boss_timer.reset()
+
+            if self.ui_reward_appear_click():
                 continue
-            if self.appear_then_click(ActivityShikigamiAssets.I_SHI, interval=1):
-                boss_timer.reset()
+            if self.appear_then_click(self.I_UI_BACK_RED, interval=1.5):
                 continue
-            if self.appear_then_click(self.I_A2):
-                boss_timer.reset()
+            if self.appear_then_click(self.I_ENTER_ENSURE, interval=1):
                 continue
-            if self.appear_then_click(self.I_A3, interval=1):
-                boss_timer.reset()
+            if self.appear_then_click(self.I_ENTER2, interval=1):
                 continue
-            if self.appear_then_click(self.I_A4, interval=1):
-                boss_timer.reset()
+        if self.config.meta_demon.meta_demon_config.meta_crafting_card:
+            self.crafting()
+
+        boss_timer = Timer(180)
+        boss_timer.start()
+        first_battle_for_easy_boss = True
+        while 1:
+            battle_processing = False
+            is_hard_boss = False  # 五星或者六星
+            self.screenshot()
+            if not (self.appear(self.I_FIND_DEMON) or self.appear(self.I_BATTLE_DEMON)):
                 continue
-            if self.appear_then_click(self.I_A5, interval=1):
-                self.device.stuck_record_clear()
-                self.device.stuck_record_add('BATTLE_STATUS_S')
+
+            # 先看自己有没有鬼王要打
+            if not self.appear(self.I_BOSS_EMPTY) and self.appear(self.I_BOSS_CONVENE):
+                logger.info('Try to battle boss from self')
+                self.click(self.I_BOSS_EMPTY, interval=1.5)
+                battle_processing = True
+                if self.is_star56():
+                    is_hard_boss = True
+            # 看别人的是否给我共享鬼王
+            if not battle_processing:
+                if not self.appear(self.I_BOSS_EMPTY_1) and self.ocr_appear(self.O_BOSS_EMPTY_1):
+                    logger.info('Try to battle boss 1 from others')
+                    self.click(self.I_BOSS_EMPTY_1, interval=1.5)
+                    self.ui_click(self.I_BOSS_EMPTY_1, stop=self.I_BATTLE_DEMON, interval=1.5)
+                    battle_processing = True
+                    is_hard_boss = True
+                elif not self.appear(self.I_BOSS_EMPTY_2):
+                    logger.info('Try to battle boss 2 from others')
+                    self.click(self.I_BOSS_EMPTY_2, interval=1.5)
+                    self.ui_click(self.I_BOSS_EMPTY_1, stop=self.I_BATTLE_DEMON, interval=1.5)
+                    battle_processing = True
+                    is_hard_boss = True
+            # 是否喝茶 疲劳满了就不打了
+            current_exhaustion = self.current_exhaustion()
+            if current_exhaustion > 99:
+                if self.config.meta_demon.meta_demon_config.auto_tea:
+                    logger.info('Exhaustion is full, buy tea')
+                    boss_timer.reset()
+                    self.buy_tea()
+                else:
+                    logger.info('Exhaustion is full, exit')
+                    break
+            # 超时结束
+            if boss_timer.reached():
+                logger.info('Time out, exit')
+                break
+            # 5/6星特殊处理 + 使用自定义策略组
+            target_group_team = [None, None]
+            if is_hard_boss:
+                logger.info('Hard boss')
+                if self.config.meta_demon.meta_demon_config.md_use_strategy:
+                    detect_full_name = self.O_MD_FULL_NAME.ocr_single(self.device.image)
+                    logger.info(f'detect_full_name: {detect_full_name}')
+                    if not detect_full_name:
+                        detect_full_name = ''
+                    group_team = self.get_group_team(detect_full_name)
+                    if self.hp_threshold_low(self.device.image):
+                        logger.info('Hp threshold low')
+                        target_group_team = group_team[2:4]
+                    else:
+                        logger.info('Hp threshold high')
+                        target_group_team = group_team[0:2]
+            else:
+                if self.config.meta_demon.meta_demon_config.md_use_strategy and first_battle_for_easy_boss:
+                    logger.info('Normal boss first battle use default group team')
+                    target_group_team = self.cached_default_group_team
+            if battle_processing and self.appear(self.I_BATTLE_DEMON):
+                logger.info(f'preset group team: {target_group_team}')
+                self.battle_boss(target_group_team[0], target_group_team[1])
+                if first_battle_for_easy_boss:
+                    first_battle_for_easy_boss = False
+                if is_hard_boss:
+                    first_battle_for_easy_boss = True
                 boss_timer.reset()
                 continue
-            if self.appear_then_click(self.I_A6, interval=1):
+
+            # 自己召唤鬼王
+            if current_exhaustion < 90 and self.find_demon():
                 boss_timer.reset()
                 continue
 
-        config: MetaDemon = self.config.model.meta_demon
-        # 主循环
-        while 1:
-            self.screenshot()
-            if self.appear(self.I_CHECK_MAIN):
-                logger.info('Exit MetaDemon')
-                break
-            if self.appear_then_click(self.I_UI_BACK_YELLOW, interval=1):
-                continue
+        # 退出
+        self.ui_click(self.I_UI_BACK_YELLOW, self.I_CHECK_MAIN, interval=1.4)
+        logger.info('Exit MetaDemon')
         self.set_next_run(task="MetaDemon", success=True)
         raise TaskEnd
 
-    @cached_property
-    def battle_config(self):
-        config = GeneralBattleConfig()
-        config.lock_team_enable = False
-        return config
-
-    def ensure_ticket(self, screenshot: bool = False) -> bool:
-        if screenshot:
-            self.screenshot()
-        cu, res, total = self.O_MD_TICKET.ocr(self.device.image)
-        if cu <= 0:
-            return False
-        return True
-
-    def check_exhaustion(self, screenshot: bool = False) -> bool:
-        # EXHAUSTION
-        if screenshot:
-            self.screenshot()
-        cu, res, total = self.O_MD_EXHAUSTION.ocr(self.device.image)
-        if cu >= 100:
-            return False
-        return True
-
     def current_exhaustion(self) -> int:
         self.screenshot()
         cu, res, total = self.O_MD_EXHAUSTION.ocr(self.device.image)
         return int(cu)
 
-    def click_fire(self):
+    def buy_tea(self):
+        pass
+
+    def crafting(self):
+        """
+        把一星合成二星
+        @return:
+        """
+        logger.info('Star crafting 1 star to 2 star')
+        self.ui_click(self.I_CRAFTING_1, self.I_CRAFTING_START, interval=1.5)
+        timer = Timer(3).start()
+        count = 0
+        while 1:
+            self.screenshot()
+            if self.ui_reward_appear_click():
+                timer.reset()
+                continue
+            if timer.reached() or count > 3:
+                break
+            if not self.ocr_appear(self.O_CRAFTING_CARD_1):
+                break
+            if self.appear(self.I_CRAFTING_EMPTY) or self.appear(self.I_CRAFTING_EMPTY_NEW):
+                if self.appear_then_click(self.I_CRAFTING_CARD_STAR_1, interval=1):
+                    continue
+            else:
+                self.appear_then_click(self.I_CRAFTING_START, interval=3)
+                count += 1
+                timer.reset()
+                continue
+        logger.info('Finish star crafting')
+        self.ui_click_until_disappear(self.I_UI_BACK_RED, interval=1)
+        sleep(0.5)
+
+    def find_demon(self) -> bool:
+        """
+        召唤鬼王
+        @return:
+        """
+        logger.info('Find demon')
         while 1:
             self.screenshot()
-            if not self.appear(self.I_MD_FIRE):
+            if self.appear(self.I_BATTLE_DEMON) and not self.appear(self.I_BOSS_EMPTY):
+                break
+            if self.appear_then_click(self.I_FIND_DEMON, interval=3.5):
+                continue
+        self.screenshot()
+        if self.is_star56():
+            logger.info('Star 5 or 6 demon found')
+            while 1:
+                sleep(0.4)
                 self.screenshot()
-                if not self.appear(self.I_MD_FIRE):
+                detect_full_name = self.O_MD_FULL_NAME.ocr_single(self.device.image)
+                if detect_full_name:
                     break
-            if self.appear_then_click(self.I_MD_FIRE, interval=2):
-                continue
+            logger.info(f'召唤到高星鬼王: {detect_full_name}')
+            self.config.notifier.push(content=f'召唤到高星鬼王: {detect_full_name}', title='超鬼王')
+        return True
 
-    def buy_tea(self):
-        pass
+    def battle_boss(self, group: int = None, team: int = None) -> bool:
+        logger.info('Battle boss')
+        self.ui_click_until_disappear(self.I_BATTLE_DEMON, interval=1.8)
+        battle_config = GeneralBattleConfig()
+        battle_config.lock_team_enable = False
+        if group is None and team is None:
+            battle_config.preset_enable = False
+            success = self.run_general_battle(battle_config)
+            return True if success else False
+        # 针对5/6星的挑战
+        else:
+            battle_config.preset_enable = True
+            battle_config.preset_group = group
+            battle_config.preset_team = team
+            tmp_battle_count = self.current_count
+            self.current_count = 0
+            success = self.run_general_battle(battle_config)
+            self.current_count = tmp_battle_count + 1
+            return True if success else False
 
     def battle_wait(self, random_click_swipt_enable: bool) -> bool:
         # 重写
@@ -158,3 +298,4 @@ if __name__ == '__main__':
     t = ScriptTask(c, d)
 
     t.run()
+

+ 4 - 2
tasks/Restart/assets.py

@@ -22,7 +22,7 @@ class RestartAssets:
 	# 邮件小图标 
 	I_HARVEST_MAIL = RuleImage(roi_front=(337,505,37,25), roi_back=(38,465,880,89), threshold=0.8, method="Template matching", file="./tasks/Restart/harvest/harvest_harvest_mail.png")
 	# 全部收取 
-	I_HARVEST_MAIL_ALL = RuleImage(roi_front=(69,589,64,57), roi_back=(28,572,115,123), threshold=0.8, method="Template matching", file="./tasks/Restart/harvest/harvest_harvest_mail_all.png")
+	I_HARVEST_MAIL_ALL = RuleImage(roi_front=(69,579,80,67), roi_back=(28,551,142,144), threshold=0.8, method="Template matching", file="./tasks/Restart/harvest/harvest_harvest_mail_all.png")
 	# 有些邮件需要点击一次 
 	I_HARVEST_MAIL_OPEN = RuleImage(roi_front=(163,367,45,48), roi_back=(139,86,100,487), threshold=0.9, method="Template matching", file="./tasks/Restart/harvest/harvest_harvest_mail_open.png")
 	# 确认收取邮件 
@@ -64,7 +64,9 @@ class RestartAssets:
 	# 特殊邮件打开状态 
 	I_SPECIAL_MAIL_OPEN = RuleImage(roi_front=(1201,380,55,110), roi_back=(1190,348,79,162), threshold=0.8, method="Template matching", file="./tasks/Restart/harvest/harvest_special_mail_open.png")
 	# 一键已读所有邮件 
-	I_READ_ALL_MAIL = RuleImage(roi_front=(155,603,166,44), roi_back=(149,588,182,72), threshold=0.8, method="Template matching", file="./tasks/Restart/harvest/harvest_read_all_mail.png")
+	I_READ_ALL_MAIL = RuleImage(roi_front=(180,605,130,35), roi_back=(149,588,182,72), threshold=0.8, method="Template matching", file="./tasks/Restart/harvest/harvest_read_all_mail.png")
+	# 邮件红点 
+	I_MAIL_RED_POINT = RuleImage(roi_front=(1229,200,16,21), roi_back=(1159,189,100,317), threshold=0.8, method="Template matching", file="./tasks/Restart/harvest/harvest_mail_red_point.png")
 
 
 	# Click Rule Assets

BIN
tasks/Restart/harvest/harvest_harvest_mail_all.png


BIN
tasks/Restart/harvest/harvest_mail_red_point.png


BIN
tasks/Restart/harvest/harvest_read_all_mail.png


+ 12 - 3
tasks/Restart/harvest/image.json

@@ -47,8 +47,8 @@
   {
     "itemName": "harvest_mail_all",
     "imageName": "harvest_harvest_mail_all.png",
-    "roiFront": "69,589,64,57",
-    "roiBack": "28,572,115,123",
+    "roiFront": "69,579,80,67",
+    "roiBack": "28,551,142,144",
     "method": "Template matching",
     "threshold": 0.8,
     "description": "全部收取"
@@ -236,10 +236,19 @@
   {
     "itemName": "read_all_mail",
     "imageName": "harvest_read_all_mail.png",
-    "roiFront": "155,603,166,44",
+    "roiFront": "180,605,130,35",
     "roiBack": "149,588,182,72",
     "method": "Template matching",
     "threshold": 0.8,
     "description": "一键已读所有邮件"
+  },
+  {
+    "itemName": "mail_red_point",
+    "imageName": "harvest_mail_red_point.png",
+    "roiFront": "1229,200,16,21",
+    "roiBack": "1159,189,100,317",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "邮件红点"
   }
 ]

+ 27 - 28
tasks/Restart/login.py

@@ -270,36 +270,35 @@ class LoginHandler(BaseTask, RestartAssets):
         self.character = character
         self.O_LOGIN_SPECIFIC_SERVE.keyword = character
 
-    def harvest_mail(self, ) -> bool:
-        if ((self.appear(self.I_HARVEST_MAIL) or self.appear(self.I_HARVEST_MAIL_COPY))
-                and not self.appear(self.I_LOGIN_RED_CLOSE)):
-            self.click(self.I_HARVEST_MAIL, interval=2)
-            self.wait_until_appear(self.I_READ_ALL_MAIL, wait_time=2)
-        else:
-            return False
-        logger.info('Harvest system mail')
-        self.click(self.I_SYSTEM_MAIL_CLOSE)
-        self.wait_until_appear(self.I_SYSTEM_MAIL_OPEN, wait_time=2)
-        self.exec_harvest_mail()
-        logger.info('Harvest special mail')
-        self.click(self.I_SPECIAL_MAIL_CLOSE)
-        self.wait_until_appear(self.I_SPECIAL_MAIL_OPEN, wait_time=2)
-        self.exec_harvest_mail()
-        return True
-
-    def exec_harvest_mail(self):
+    def harvest_mail(self) -> bool:
+        if not self.appear(self.I_HARVEST_MAIL) and \
+                not self.appear(self.I_HARVEST_MAIL_COPY):
+            if not self.appear(self.I_READ_ALL_MAIL):
+                return False
+        logger.info('Harvest mail')
+        while 1:
+            self.screenshot()
+            if self.appear(self.I_READ_ALL_MAIL):
+                break
+            if self.appear_then_click(self.I_HARVEST_MAIL, interval=1.5):
+                continue
+            if self.appear_then_click(self.I_HARVEST_MAIL_COPY, interval=1.5):
+                continue
         timeout_timer = Timer(3).start()
-        while not timeout_timer.reached():
+        logger.info('Exec harvest mail')
+        while 1:
             self.screenshot()
+            if timeout_timer.reached():
+                break
+            if self.appear_then_click(self.I_HARVEST_MAIL_CONFIRM, interval=0.8):
+                break
+
             if self.appear_then_click(self.I_READ_ALL_MAIL, interval=1.5):
                 continue
-            if self.appear(self.I_HARVEST_MAIL_CONFIRM):
-                self.click(self.I_HARVEST_MAIL_CONFIRM, interval=2)
-                self.wait_until_disappear(self.I_HARVEST_MAIL_CONFIRM)
-                break
-            if self.appear(self.I_HARVEST_MAIL_ALL, threshold=0.9):
-                time.sleep(random.uniform(0.3, 0.5))
-                self.click(self.I_HARVEST_MAIL_ALL, interval=2)
-                self.wait_until_appear(self.I_HARVEST_MAIL_CONFIRM, wait_time=1)
-                timeout_timer.reset()
+            if self.appear_then_click(self.I_HARVEST_MAIL_ALL, interval=1.5):
                 continue
+            if self.appear_then_click(self.I_MAIL_RED_POINT, interval=4):
+                continue
+        self.ui_click_until_disappear(self.I_LOGIN_RED_CLOSE)
+        return True
+

+ 5 - 1
tasks/TrueOrochi/script_task.py

@@ -5,7 +5,7 @@ from time import sleep
 from datetime import datetime, time
 
 from module.logger import logger
-from module.exception import TaskEnd
+from module.exception import TaskEnd, GameStuckError
 from module.base.timer import Timer
 
 from tasks.GameUi.game_ui import GameUi
@@ -135,6 +135,7 @@ class ScriptTask(OrochiScriptTask, TrueOrochiAssets):
         logger.info("Start battle process")
         check_timer = Timer(280)
         check_timer.start()
+        check_count = 0
         while 1:
             self.screenshot()
             if self.appear(self.I_GREED_GHOST):
@@ -155,6 +156,9 @@ class ScriptTask(OrochiScriptTask, TrueOrochiAssets):
             if self.appear_then_click(self.I_ST_FRAME, interval=1):
                 continue
             if check_timer.reached():
+                if check_count > 3:
+                    raise GameStuckError
+                check_count += 1
                 logger.warning('Battle timeout')
                 check_timer.reset()
                 self.device.stuck_record_clear()

+ 2 - 2
tasks/Utils/post_diagnotor.py

@@ -16,8 +16,8 @@ class AnalyzeType(str, Enum):
 
 class PostDiagnotor(GlobalGameAssets, SoulsTidyAssets):
     def handle(self, e: Exception, command: str, image: np.ndarray) -> AnalyzeType:
-        if self.I_UI_CONFIRM_SAMLL.match(image) and \
-                self.I_ST_SOUL_OVERFLOW.match(image):
+        if self.I_ST_SOUL_OVERFLOW.match(image) and \
+                (self.I_UI_CONFIRM_SAMLL.match(image) or self.I_UI_GOTIT_SMALL.match(image)):
             logger.warning(f"Detect soul overflow, command: {command}")
             return AnalyzeType.SoulOverflow