Просмотр исходного кода

Merge pull request #163 from xbj110825/dev

feat: 支持单刷永生之海
huangrunheng 2 лет назад
Родитель
Сommit
c66e5ac0c6

+ 1 - 1
tasks/Component/GeneralBattle/general_battle.py

@@ -20,7 +20,7 @@ class GeneralBattle(GeneralBuff, GeneralBattleAssets):
     使用这个通用的战斗必须要求这个任务的config有config_general_battle
     """
 
-    def run_general_battle(self, config: dict=None, buff: BuffClass or list[BuffClass]=None) -> bool:
+    def run_general_battle(self, config: GeneralBattleConfig=None, buff: BuffClass or list[BuffClass]=None) -> bool:
         """
         运行脚本
         :return:

+ 10 - 1
tasks/EternitySea/assets.py

@@ -8,5 +8,14 @@ from module.atom.list import RuleList
 # This file was automatically generated by ./dev_tools/assets_extract.py.
 # Don't modify it manually.
 class EternitySeaAssets: 
-	pass
+
+
+	# Image Rule Assets
+	# 选择永生之海 
+	I_ETERNITY_SEA = RuleImage(roi_front=(1150,101,127,416), roi_back=(0,0,1279,719), threshold=0.8, method="Template matching", file="./tasks/EternitySea/res/es_eternity_sea.png")
+	# 组队 
+	I_FORM_TEAM = RuleImage(roi_front=(939,594,96,90), roi_back=(939,594,96,90), threshold=0.8, method="Template matching", file="./tasks/EternitySea/res/es_form_team.png")
+	# 挑战 
+	I_ETERNITY_SEA_FIRE = RuleImage(roi_front=(1108,592,96,93), roi_back=(1108,592,96,93), threshold=0.8, method="Template matching", file="./tasks/EternitySea/res/es_eternity_sea_fire.png")
+
 

+ 2 - 0
tasks/EternitySea/config.py

@@ -7,6 +7,7 @@ from datetime import datetime, time
 
 from tasks.Component.config_scheduler import Scheduler
 from tasks.Component.config_base import ConfigBase, Time
+from tasks.Component.GeneralBattle.config_general_battle import GeneralBattleConfig
 from tasks.Orochi.config import UserStatus
 
 
@@ -29,4 +30,5 @@ class EternitySeaConfig(ConfigBase):
 class EternitySea(ConfigBase):
     scheduler: Scheduler = Field(default_factory=Scheduler)
     eternity_sea_config: EternitySeaConfig = Field(default_factory=EternitySeaConfig)
+    general_battle_config: GeneralBattleConfig = Field(default_factory=GeneralBattleConfig)
 

BIN
tasks/EternitySea/res/es_eternity_sea.png


BIN
tasks/EternitySea/res/es_eternity_sea_fire.png


BIN
tasks/EternitySea/res/es_form_team.png


+ 29 - 0
tasks/EternitySea/res/image.json

@@ -0,0 +1,29 @@
+[
+    {
+        "itemName": "eternity_sea",
+        "imageName": "es_eternity_sea.png",
+        "roiFront": "1150,101,127,416",
+        "roiBack": "0,0,1279,719",
+        "method": "Template matching",
+        "threshold": 0.8,
+        "description": "选择永生之海"
+    },
+    {
+        "itemName": "form_team",
+        "imageName": "es_form_team.png",
+        "roiFront": "939,594,96,90",
+        "roiBack": "939,594,96,90",
+        "method": "Template matching",
+        "threshold": 0.8,
+        "description": "组队"
+    },
+    {
+        "itemName": "eternity_sea_fire",
+        "imageName": "es_eternity_sea_fire.png",
+        "roiFront": "1108,592,96,93",
+        "roiBack": "1108,592,96,93",
+        "method": "Template matching",
+        "threshold": 0.8,
+        "description": "挑战"
+    }
+]

+ 97 - 13
tasks/EternitySea/script_task.py

@@ -1,38 +1,122 @@
 # This Python file uses the following encoding: utf-8
 # @author runhey
 # github https://github.com/runhey
-from cached_property import cached_property
+from datetime import datetime, timedelta
 
 from module.exception import TaskEnd
 from module.logger import logger
-from module.base.timer import Timer
 
-from tasks.GameUi.game_ui import GameUi
-from tasks.GameUi.page import page_main, page_soul_zones, page_shikigami_records
+from tasks.GameUi.game_ui import GameUi, Page
+from tasks.GameUi.page import page_soul_zones
 from tasks.Component.GeneralBattle.general_battle import GeneralBattle
-from tasks.Component.GeneralBattle.config_general_battle import GeneralBattleConfig
 from tasks.Component.GeneralRoom.general_room import GeneralRoom
 from tasks.Component.GeneralInvite.general_invite import GeneralInvite
 from tasks.Component.SwitchSoul.switch_soul import SwitchSoul
 from tasks.EternitySea.assets import EternitySeaAssets
+from tasks.Orochi.config import UserStatus
+from tasks.EternitySea.config import EternitySea
+from module.exception import RequestHumanTakeover
 
-class ScriptTask(GameUi, GeneralBattle, GeneralRoom, GeneralInvite, SwitchSoul, EternitySeaAssets):
 
-    def run(self):
-        con = self.config.eternity_sea.eternity_sea_config
+class ScriptTask(
+    GameUi, GeneralBattle, GeneralRoom, GeneralInvite, SwitchSoul, EternitySeaAssets
+):
+    @property
+    def task_name(self):
+        return "EternitySea"
+
+    def run(self) -> None:
+        match self._task_config.eternity_sea_config.user_status:
+            case UserStatus.ALONE:
+                success = self.run_alone()
+            case _:
+                logger.critical(
+                    f"UserStatus {self._task_config.eternity_sea_config.user_status} not support"
+                )
+                raise RequestHumanTakeover
+
+        if success:
+            self.set_next_run(self.task_name, finish=True, success=True)
+        else:
+            self.set_next_run(self.task_name, finish=False, success=False)
+
+        raise TaskEnd(self.task_name)
+
+    def run_alone(self) -> bool:
+        logger.info("Start run alone")
+        self._navigate_to_soul_zones()
+        self._enter_eternity_sea()
+
+        if self._task_config.general_battle_config.lock_team_enable == False:
+            logger.critical(f"Only supports lock team mode")
+            raise RequestHumanTakeover
+
+        while 1:
+            self.screenshot()
+
+            if not self._is_in_eternity_sea():
+                continue
+
+            if self.current_count >= self._task_config.eternity_sea_config.limit_count:
+                logger.info("EternitySea count limit out")
+                break
+            if datetime.now() - self.start_time >= self._limit_time:
+                logger.info("EternitySea time limit out")
+                break
+
+            # 点击挑战
+            while 1:
+                self.screenshot()
+                if self.appear_then_click(self.I_ETERNITY_SEA_FIRE, interval=1):
+                    pass
+
+                if not self.appear(self.I_ETERNITY_SEA_FIRE):
+                    self.run_general_battle(
+                        config=self._task_config.general_battle_config
+                    )
+                    break
+
+    def _is_in_eternity_sea(self) -> bool:
+        self.screenshot()
+        return self.appear(self.I_ETERNITY_SEA_FIRE)
+
+    @property
+    def _limit_time(self) -> timedelta:
+        limit_time = self._task_config.eternity_sea_config.limit_time
+        return timedelta(
+            hours=limit_time.hour, minutes=limit_time.minute, seconds=limit_time.second
+        )
+
+    def _enter_eternity_sea(self) -> None:
+        logger.info("Enter eternity_sea")
+        while True:
+            self.screenshot()
+            if self.appear_then_click(self.I_ETERNITY_SEA, interval=1):
+                break
+
+        while True:
+            self.screenshot()
+            if self.appear(self.I_FORM_TEAM):
+                return
+
+    def _navigate_to_soul_zones(self) -> None:
         self.ui_get_current_page()
         self.ui_goto(page_soul_zones)
 
-        self.set_next_run(task='EternitySea', success=True, finish=False)
-        raise TaskEnd('EternitySea')
-
+    def _navigate_to_game_page(self, destination: Page) -> None:
+        self.ui_get_current_page()
+        self.ui_goto(destination)
 
+    @property
+    def _task_config(self) -> EternitySea:
+        return self.config.model.eternity_sea
 
 
-if __name__ == '__main__':
+if __name__ == "__main__":
     from module.config.config import Config
     from module.device.device import Device
-    c = Config('oas1')
+
+    c = Config("oas1")
     d = Device(c)
     t = ScriptTask(c, d)
     t.screenshot()

+ 1 - 1
tasks/GameUi/game_ui.py

@@ -158,7 +158,7 @@ class GameUi(BaseTask, GameUiAssets):
         """
         pass
 
-    def ui_goto(self, destination, confirm_wait=0, skip_first_screenshot=True):
+    def ui_goto(self, destination: Page, confirm_wait=0, skip_first_screenshot=True):
         """
         Args:
             destination (Page):