Kaynağa Gözat

Merge pull request #817 from yEs1do/feat(DyeTrials_ljxun)

添加灵染试炼任务 @ljxun
huangrunheng 1 yıl önce
ebeveyn
işleme
f19de7871f

+ 1 - 1
module/config/config_manual.py

@@ -18,7 +18,7 @@ class ConfigManual:
         > TrueOrochi > RichMan
         > CollectiveMissions
         > Pets > TalismanPass > Delegation > Hyakkiyakou
-        > Secret > WeeklyTrifles > MysteryShop > Duel > MetaDemon > FrogBoss > FloatParade > Quiz > KittyShop
+        > Secret > WeeklyTrifles > MysteryShop > Duel > MetaDemon > FrogBoss > FloatParade > Quiz > KittyShop > DyeTrials
         """
 
     DEVICE_OVER_HTTP = False

+ 1 - 1
module/config/config_menu.py

@@ -40,7 +40,7 @@ class ConfigMenu:
         # 每周任务
         self.menu["Weekly Task"] = ['TrueOrochi', 'RichMan', 'Secret', 'WeeklyTrifles', 'MysteryShop', 'Duel']
         # 活动的任务
-        self.menu["Activity Task"] = ['ActivityShikigami', 'MetaDemon', 'FrogBoss', 'FloatParade', 'Quiz', 'KittyShop']
+        self.menu["Activity Task"] = ['ActivityShikigami', 'MetaDemon', 'FrogBoss', 'FloatParade', 'Quiz', 'KittyShop', 'DyeTrials']
         # 开发工具
         self.menu["Tools"] = ['Image Rule', 'Ocr Rule', 'Click Rule', 'Long Click Rule', 'Swipe Rule', 'List Rule']
 

+ 2 - 0
module/config/config_model.py

@@ -56,6 +56,7 @@ from tasks.FrogBoss.config import FrogBoss
 from tasks.FloatParade.config import FloatParade
 from tasks.Quiz.config import Quiz
 from tasks.KittyShop.config import KittyShop
+from tasks.DyeTrials.config import DyeTrials
 # ----------------------------------------------------------------------------------------------------------------------
 
 # 肝帝专属---------------------------------------------------------------------------------------------------------------
@@ -117,6 +118,7 @@ class ConfigModel(ConfigBase):
     float_parade: FloatParade = Field(default_factory=FloatParade)
     quiz: Quiz = Field(default_factory=Quiz)
     kitty_shop: KittyShop = Field(default_factory=KittyShop)
+    dye_trials: DyeTrials = Field(default_factory=DyeTrials)
 
     # 这些是肝帝专属
     bondling_fairyland: BondlingFairyland = Field(default_factory=BondlingFairyland)

+ 30 - 0
tasks/DyeTrials/assets.py

@@ -0,0 +1,30 @@
+from module.atom.image import RuleImage
+from module.atom.click import RuleClick
+from module.atom.long_click import RuleLongClick
+from module.atom.swipe import RuleSwipe
+from module.atom.ocr import RuleOcr
+from module.atom.list import RuleList
+
+# This file was automatically generated by ./dev_tools/assets_extract.py.
+# Don't modify it manually.
+class DyeTrialsAssets: 
+
+
+	# Image Rule Assets
+	# 从庭院进入灵染试炼活动 
+	I_FP_ACCESS = RuleImage(roi_front=(1192,317,36,34), roi_back=(1000,101,261,472), threshold=0.8, method="Template matching", file="./tasks/DyeTrials/fp/fp_fp_access.png")
+	# 寻找切换按钮 
+	I_TOGGLE_BUTTON = RuleImage(roi_front=(1202,466,22,21), roi_back=(1090,127,176,377), threshold=0.7, method="Template matching", file="./tasks/DyeTrials/fp/fp_toggle_button.png")
+	# 进入灵染试炼战斗界面 
+	I_FP_ACCESS_1 = RuleImage(roi_front=(264,339,26,95), roi_back=(129,202,329,380), threshold=0.7, method="Template matching", file="./tasks/DyeTrials/fp/fp_fp_access_1.png")
+	# 挑战 
+	I_FP_CHALLENGE = RuleImage(roi_front=(1159,598,60,29), roi_back=(1159,598,60,29), threshold=0.8, method="Template matching", file="./tasks/DyeTrials/fp/fp_fp_challenge.png")
+	# description 
+	I_BATTLE_SUCCESS = RuleImage(roi_front=(435,147,100,100), roi_back=(435,147,100,100), threshold=0.8, method="Template matching", file="./tasks/DyeTrials/fp/battle_success.png")
+
+
+	# Ocr Rule Assets
+	# 战斗次数 
+	O_BATTLE_NUM = RuleOcr(roi=(1144,408,100,21), area=(1144,408,100,21), mode="DigitCounter", method="Default", keyword="", name="battle_num")
+
+

+ 13 - 0
tasks/DyeTrials/config.py

@@ -0,0 +1,13 @@
+# This Python file uses the following encoding: utf-8
+# @author runhey
+# github https://github.com/runhey
+from pydantic import Field
+
+from tasks.Component.SwitchSoul.switch_soul_config import SwitchSoulConfig
+from tasks.Component.config_base import ConfigBase
+from tasks.Component.config_scheduler import Scheduler
+
+
+class DyeTrials(ConfigBase):
+    scheduler: Scheduler = Field(default_factory=Scheduler)
+    switch_soul_config: SwitchSoulConfig = Field(default_factory=SwitchSoulConfig)

BIN
tasks/DyeTrials/fp/battle_success.png


BIN
tasks/DyeTrials/fp/fp_fp_access.png


BIN
tasks/DyeTrials/fp/fp_fp_access_1.png


BIN
tasks/DyeTrials/fp/fp_fp_challenge.png


BIN
tasks/DyeTrials/fp/fp_toggle_button.png


+ 48 - 0
tasks/DyeTrials/fp/image.json

@@ -0,0 +1,48 @@
+[
+  {
+    "itemName": "fp_access",
+    "imageName": "fp_fp_access.png",
+    "roiFront": "1192,317,36,34",
+    "roiBack": "1000,101,261,472",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "从庭院进入灵染试炼活动"
+  },
+  {
+    "itemName": "toggle_button",
+    "imageName": "fp_toggle_button.png",
+    "roiFront": "1202,466,22,21",
+    "roiBack": "1090,127,176,377",
+    "method": "Template matching",
+    "threshold": 0.7,
+    "description": "寻找切换按钮"
+  },
+  {
+    "itemName": "fp_access_1",
+    "imageName": "fp_fp_access_1.png",
+    "roiFront": "264,339,26,95",
+    "roiBack": "129,202,329,380",
+    "method": "Template matching",
+    "threshold": 0.7,
+    "description": "进入灵染试炼战斗界面"
+  },
+  {
+    "itemName": "fp_challenge",
+    "imageName": "fp_fp_challenge.png",
+    "roiFront": "1159,598,60,29",
+    "roiBack": "1159,598,60,29",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "挑战"
+  },
+  {
+    "itemName": "battle_success",
+    "imageName": "battle_success.png",
+    "roiFront": "435,147,100,100",
+    "roiBack": "435,147,100,100",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  }
+]
+

+ 11 - 0
tasks/DyeTrials/fp/ocr.json

@@ -0,0 +1,11 @@
+[
+  {
+    "itemName": "battle_num",
+    "roiFront": "1144,408,100,21",
+    "roiBack": "1144,408,100,21",
+    "mode": "DigitCounter",
+    "method": "Default",
+    "keyword": "",
+    "description": "战斗次数"
+  }
+]

+ 101 - 0
tasks/DyeTrials/script_task.py

@@ -0,0 +1,101 @@
+# This Python file uses the following encoding: utf-8
+# @author runhey
+# github https://github.com/runhey
+import time
+
+from module.base.timer import Timer
+from module.exception import TaskEnd
+from module.logger import logger
+from tasks.Component.GeneralBattle.general_battle import GeneralBattle
+from tasks.Component.SwitchSoul.switch_soul import SwitchSoul
+from tasks.DyeTrials.assets import DyeTrialsAssets
+from tasks.GameUi.game_ui import GameUi
+from tasks.GameUi.page import page_main, page_shikigami_records
+from tasks.Restart.assets import RestartAssets
+
+""" 灵染 试炼 """
+
+
+class ScriptTask(GeneralBattle, GameUi, SwitchSoul, DyeTrialsAssets):
+
+    def run(self):
+
+        cfg = self.config.dye_trials
+
+        # 自动换御魂
+        if cfg.switch_soul_config.enable:
+            self.ui_get_current_page()
+            self.ui_goto(page_shikigami_records)
+            self.run_switch_soul(cfg.switch_soul_config.switch_group_team)
+        if cfg.switch_soul_config.enable_switch_by_name:
+            self.ui_get_current_page()
+            self.ui_goto(page_shikigami_records)
+            self.run_switch_soul_by_name(cfg.switch_soul_config.group_name, cfg.switch_soul_config.team_name)
+
+        self.ui_get_current_page()
+        self.ui_goto(page_main)
+
+        self.get_all()
+
+        self.ui_get_current_page()
+        self.ui_goto(page_main)
+
+        self.set_next_run(task='DyeTrials', success=True, finish=True)
+        raise TaskEnd('DyeTrials')
+
+    def get_all(self):
+        while 1:
+            self.screenshot()
+            if self.appear(self.I_FP_CHALLENGE):
+                break
+            if self.appear_then_click(self.I_FP_ACCESS, interval=0.8):
+                continue
+            if self.appear_then_click(self.I_FP_ACCESS_1, interval=1.5):
+                continue
+            if self.appear_then_click(self.I_TOGGLE_BUTTON, interval=3):
+                continue
+        logger.info('Enter DyeTrials')
+        boss_timer = Timer(60)
+        boss_timer.start()
+        battle_num = 0
+        while 1:
+            self.screenshot()
+            time.sleep(0.1)
+            if boss_timer.reached():
+                self.config.notifier.push(title='超鬼王', message='识别超时退出')
+                break
+            # 获得奖励
+            if self.ui_reward_appear_click():
+                boss_timer.reset()
+            if self.appear_then_click(RestartAssets.I_HARVEST_CHAT_CLOSE):
+                boss_timer.reset()
+                continue
+            if self.appear(self.I_FP_CHALLENGE, interval=1):
+                cu, res, total = self.O_BATTLE_NUM.ocr(image=self.device.image)
+                if cu == total == 50 and cu + res == total:
+                    break
+                if battle_num >= 50:
+                    logger.info(f'Battle {battle_num}, enough battle, break')
+                    break
+                self.ui_click_until_disappear(self.I_FP_CHALLENGE)
+                battle_num += 1
+                logger.info(f'Battle num [{battle_num}]')
+                self.device.stuck_record_clear()
+                self.device.stuck_record_add('BATTLE_STATUS_S')
+                boss_timer.reset()
+                continue
+            if self.appear_then_click(self.I_BATTLE_SUCCESS, interval=1):
+                boss_timer.reset()
+                continue
+
+
+if __name__ == '__main__':
+    from module.config.config import Config
+    from module.device.device import Device
+
+    c = Config('DU')
+    d = Device(c)
+    t = ScriptTask(c, d)
+    t.screenshot()
+
+    t.run()