瀏覽代碼

feat(tasks): Update MetaDemon 2

ryland 1 年之前
父節點
當前提交
7e2049cf43

+ 3 - 1
assets/i18n/zh-CN.json

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

+ 2 - 2
dev_tools/assets_test.py

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

+ 7 - 3
tasks/MetaDemon/assets.py

@@ -57,11 +57,13 @@ class MetaDemonAssets:
 	# 点击战斗 
 	# 点击战斗 
 	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")
 	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 
 	# description 
-	I_BOSS_EMPTY = RuleImage(roi_front=(44,134,88,85), roi_back=(44,134,88,85), threshold=0.8, method="Template matching", file="./tasks/MetaDemon/md/md_boss_empty.png")
+	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 
 	# description 
-	I_BOSS_EMPTY_1 = RuleImage(roi_front=(46,372,87,90), roi_back=(46,372,87,90), threshold=0.8, method="Template matching", file="./tasks/MetaDemon/md/md_boss_empty_1.png")
+	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 
 	# description 
-	I_BOSS_EMPTY_2 = RuleImage(roi_front=(46,501,88,88), roi_back=(46,501,88,88), threshold=0.8, method="Template matching", file="./tasks/MetaDemon/md/md_boss_empty_2.png")
+	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_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")
 	# 空 
 	# 空 
@@ -93,5 +95,7 @@ class MetaDemonAssets:
 	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_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_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")
 
 
 
 

+ 1 - 4
tasks/MetaDemon/config.py

@@ -66,7 +66,7 @@ class Strategy(ConfigBase):
     def parse_all(cls, data: list['Strategy']) -> dict[str, list[int]]:
     def parse_all(cls, data: list['Strategy']) -> dict[str, list[int]]:
         result = {}
         result = {}
         for item in data:
         for item in data:
-            value = item.parse_group_team(item.md_preset_group_team_1)\
+            value = item.parse_group_team(item.md_preset_group_team_1) \
                     + item.parse_group_team(item.md_preset_group_team_2)
                     + item.parse_group_team(item.md_preset_group_team_2)
             for name in cls.parse_names(item.md_match_names):
             for name in cls.parse_names(item.md_match_names):
                 result[name] = value
                 result[name] = value
@@ -80,7 +80,6 @@ class MetaDemonConfig(ConfigBase):
     md_strategy_count: int = Field(default=0, ge=0, description='md_strategy_count_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')
     md_use_strategy: bool = Field(default=False, description='md_use_strategy_help')
 
 
-
     @field_validator('auto_tea', mode='after')
     @field_validator('auto_tea', mode='after')
     @classmethod
     @classmethod
     def to_false(cls, v):
     def to_false(cls, v):
@@ -94,7 +93,6 @@ class MetaDemonConfig(ConfigBase):
         return v
         return v
 
 
 
 
-
 class MetaDemon(ConfigBase):
 class MetaDemon(ConfigBase):
     scheduler: Scheduler = Field(default_factory=Scheduler)
     scheduler: Scheduler = Field(default_factory=Scheduler)
     switch_soul: SwitchSoulConfig = Field(default_factory=SwitchSoulConfig)
     switch_soul: SwitchSoulConfig = Field(default_factory=SwitchSoulConfig)
@@ -166,4 +164,3 @@ class MetaDemon(ConfigBase):
 if __name__ == '__main__':
 if __name__ == '__main__':
     ff = MetaDemon()
     ff = MetaDemon()
     ff.model_dump()
     ff.model_dump()
-

+ 12 - 3
tasks/MetaDemon/md/image_2025.json

@@ -41,16 +41,25 @@
     "roiFront": "44,134,88,85",
     "roiFront": "44,134,88,85",
     "roiBack": "44,134,88,85",
     "roiBack": "44,134,88,85",
     "method": "Template matching",
     "method": "Template matching",
-    "threshold": 0.8,
+    "threshold": 0.7,
     "description": "description"
     "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",
     "itemName": "boss_empty_1",
     "imageName": "md_boss_empty_1.png",
     "imageName": "md_boss_empty_1.png",
     "roiFront": "46,372,87,90",
     "roiFront": "46,372,87,90",
     "roiBack": "46,372,87,90",
     "roiBack": "46,372,87,90",
     "method": "Template matching",
     "method": "Template matching",
-    "threshold": 0.8,
+    "threshold": 0.5,
     "description": "description"
     "description": "description"
   },
   },
   {
   {
@@ -59,7 +68,7 @@
     "roiFront": "46,501,88,88",
     "roiFront": "46,501,88,88",
     "roiBack": "46,501,88,88",
     "roiBack": "46,501,88,88",
     "method": "Template matching",
     "method": "Template matching",
-    "threshold": 0.8,
+    "threshold": 0.5,
     "description": "description"
     "description": "description"
   },
   },
   {
   {

二進制
tasks/MetaDemon/md/md_boss_convene.png


+ 9 - 0
tasks/MetaDemon/md/ocr.json

@@ -43,5 +43,14 @@
     "method": "Default",
     "method": "Default",
     "keyword": "",
     "keyword": "",
     "description": "式神全名"
     "description": "式神全名"
+  },
+  {
+    "itemName": "boss_empty_1",
+    "roiFront": "141,400,94,32",
+    "roiBack": "141,400,94,32",
+    "mode": "Single",
+    "method": "Default",
+    "keyword": "剩余时间",
+    "description": "判断别人是否给鬼王"
   }
   }
 ]
 ]

+ 22 - 9
tasks/MetaDemon/script_task.py

@@ -60,7 +60,7 @@ class Star56(GameUi, MetaDemonAssets):
                 if len(key_name) != len(detect_name):
                 if len(key_name) != len(detect_name):
                     continue
                     continue
                 diff_count = sum(1 for c1, c2 in zip(key_name, detect_name) if c1 != c2)
                 diff_count = sum(1 for c1, c2 in zip(key_name, detect_name) if c1 != c2)
-                if diff_count <= i:
+                if diff_count <= i < len(detect_name):
                     return strategies[key_name]
                     return strategies[key_name]
         return None
         return None
 
 
@@ -102,7 +102,7 @@ class ScriptTask(RightActivity, GeneralBattle, SwitchSoul, Star56):
 
 
         boss_timer = Timer(180)
         boss_timer = Timer(180)
         boss_timer.start()
         boss_timer.start()
-        first_battle = True
+        first_battle_for_easy_boss = True
         while 1:
         while 1:
             battle_processing = False
             battle_processing = False
             is_hard_boss = False  # 五星或者六星
             is_hard_boss = False  # 五星或者六星
@@ -111,21 +111,26 @@ class ScriptTask(RightActivity, GeneralBattle, SwitchSoul, Star56):
                 continue
                 continue
 
 
             # 先看自己有没有鬼王要打
             # 先看自己有没有鬼王要打
-            if not self.appear(self.I_BOSS_EMPTY):
+            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)
                 self.click(self.I_BOSS_EMPTY, interval=1.5)
                 battle_processing = True
                 battle_processing = True
                 if self.is_star56():
                 if self.is_star56():
                     is_hard_boss = True
                     is_hard_boss = True
             # 看别人的是否给我共享鬼王
             # 看别人的是否给我共享鬼王
             if not battle_processing:
             if not battle_processing:
-                if not self.appear(self.I_BOSS_EMPTY_1):
+                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')
                     logger.info('Try to battle boss 1 from others')
                     self.click(self.I_BOSS_EMPTY_1, interval=1.5)
                     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
                     battle_processing = True
+                    is_hard_boss = True
                 elif not self.appear(self.I_BOSS_EMPTY_2):
                 elif not self.appear(self.I_BOSS_EMPTY_2):
                     logger.info('Try to battle boss 2 from others')
                     logger.info('Try to battle boss 2 from others')
                     self.click(self.I_BOSS_EMPTY_2, interval=1.5)
                     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
                     battle_processing = True
+                    is_hard_boss = True
             # 是否喝茶 疲劳满了就不打了
             # 是否喝茶 疲劳满了就不打了
             current_exhaustion = self.current_exhaustion()
             current_exhaustion = self.current_exhaustion()
             if current_exhaustion > 99:
             if current_exhaustion > 99:
@@ -157,19 +162,21 @@ class ScriptTask(RightActivity, GeneralBattle, SwitchSoul, Star56):
                         logger.info('Hp threshold high')
                         logger.info('Hp threshold high')
                         target_group_team = group_team[0:2]
                         target_group_team = group_team[0:2]
             else:
             else:
-                if self.config.meta_demon.meta_demon_config.md_use_strategy and first_battle:
+                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')
                     logger.info('Normal boss first battle use default group team')
                     target_group_team = self.cached_default_group_team
                     target_group_team = self.cached_default_group_team
             if battle_processing and self.appear(self.I_BATTLE_DEMON):
             if battle_processing and self.appear(self.I_BATTLE_DEMON):
                 logger.info(f'preset group team: {target_group_team}')
                 logger.info(f'preset group team: {target_group_team}')
                 self.battle_boss(target_group_team[0], target_group_team[1])
                 self.battle_boss(target_group_team[0], target_group_team[1])
-                if first_battle:
-                    first_battle = False
+                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()
                 boss_timer.reset()
                 continue
                 continue
 
 
             # 自己召唤鬼王
             # 自己召唤鬼王
-            if self.find_demon():
+            if current_exhaustion < 90 and self.find_demon():
                 boss_timer.reset()
                 boss_timer.reset()
                 continue
                 continue
 
 
@@ -215,6 +222,7 @@ class ScriptTask(RightActivity, GeneralBattle, SwitchSoul, Star56):
                 continue
                 continue
         logger.info('Finish star crafting')
         logger.info('Finish star crafting')
         self.ui_click_until_disappear(self.I_UI_BACK_RED, interval=1)
         self.ui_click_until_disappear(self.I_UI_BACK_RED, interval=1)
+        sleep(0.5)
 
 
     def find_demon(self) -> bool:
     def find_demon(self) -> bool:
         """
         """
@@ -231,7 +239,12 @@ class ScriptTask(RightActivity, GeneralBattle, SwitchSoul, Star56):
         self.screenshot()
         self.screenshot()
         if self.is_star56():
         if self.is_star56():
             logger.info('Star 5 or 6 demon found')
             logger.info('Star 5 or 6 demon found')
-            detect_full_name = self.O_MD_FULL_NAME.ocr_single(self.device.image)
+            while 1:
+                sleep(0.4)
+                self.screenshot()
+                detect_full_name = self.O_MD_FULL_NAME.ocr_single(self.device.image)
+                if detect_full_name:
+                    break
             logger.info(f'召唤到高星鬼王: {detect_full_name}')
             logger.info(f'召唤到高星鬼王: {detect_full_name}')
             self.config.notifier.push(content=f'召唤到高星鬼王: {detect_full_name}', title='超鬼王')
             self.config.notifier.push(content=f'召唤到高星鬼王: {detect_full_name}', title='超鬼王')
         return True
         return True