| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336 |
- # This Python file uses the following encoding: utf-8
- # @author runhey
- # github https://github.com/runhey
- from datetime import datetime, timedelta
- from module.exception import TaskEnd
- from module.base.timer import Timer
- from module.logger import logger
- from tasks.GameUi.game_ui import GameUi
- from tasks.GameUi.page import page_soul_zones, page_shikigami_records
- from tasks.Component.GeneralBattle.general_battle import GeneralBattle
- 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
- from tasks.GameUi.page import page_main, page_soul_zones, page_shikigami_records
- from time import sleep
- class ScriptTask(
- GameUi, GeneralBattle, GeneralRoom, GeneralInvite, SwitchSoul, EternitySeaAssets
- ):
- @property
- def task_name(self):
- return "EternitySea"
- def _two_teams_switch_sous(self, config):
- if config.enable:
- self.goto_page(page_shikigami_records)
- self.run_switch_soul(config.switch_group_team)
- if config.enable_switch_by_name:
- self.goto_page(page_shikigami_records)
- self.run_switch_soul_by_name(config.group_name, config.team_name)
- def _prepare_eternity_sea(self):
- self.goto_page(page_soul_zones)
- self._enter_eternity_sea()
- layer = self._task_config.eternity_sea_config.layer
- self.check_layer(layer)
- self.check_lock(self._task_config.general_battle_config.lock_team_enable)
- def run(self) -> None:
- self._two_teams_switch_sous(self._task_config.switch_soul_config_1)
- self._two_teams_switch_sous(self._task_config.switch_soul_config_2)
- match self._task_config.eternity_sea_config.user_status:
- case UserStatus.LEADER: success = self.run_leader()
- case UserStatus.MEMBER: success = self.run_member()
- case UserStatus.ALONE: success = self.run_alone()
- case _: logger.error('Unknown user status')
- self.goto_page(page_main)
- 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_leader(self):
- logger.info('Start run leader')
- self._prepare_eternity_sea()
- # 创建队伍
- logger.info('Create team')
- while 1:
- self.screenshot()
- if self.appear(self.I_CHECK_TEAM):
- break
- if self.appear_then_click(self.I_FORM_TEAM, interval=1):
- continue
- # 创建房间
- self.create_room()
- self.ensure_private()
- self.create_ensure()
- # 邀请队友
- success = True
- is_first = True
- # 这个时候我已经进入房间了哦
- while 1:
- self.screenshot()
- # 无论胜利与否, 都会出现是否邀请一次队友
- # 区别在于,失败的话不会出现那个勾选默认邀请的框
- if self.check_and_invite(self._task_config.invite_config.default_invite):
- 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
- # 如果没有进入房间那就不需要后面的邀请
- if not self.is_in_room():
- if self.is_room_dead():
- logger.warning('eternity_sea task failed')
- success = False
- break
- continue
- # 点击挑战
- if not is_first:
- if self.run_invite(config=self._task_config.invite_config):
- self.run_general_battle(config=self._task_config.general_battle_config)
- else:
- # 邀请失败,退出任务
- logger.warning('Invite failed and exit this eternity_sea task')
- success = False
- break
- # 第一次会邀请队友
- if is_first:
- if not self.run_invite(config=self._task_config.invite_config, is_first=True):
- logger.warning('Invite failed and exit this eternity_sea task')
- success = False
- break
- else:
- is_first = False
- self.run_general_battle(config=self._task_config.general_battle_config)
- # 战斗奖励动画可能还未结束, 先点掉残留奖励弹窗等界面稳定, 防止exit_room识别不到房间
- self._wait_room_stable()
- # 当结束或者是失败退出循环的时候只有两个UI的可能,在房间或者是在组队界面
- # 如果在房间就退出
- if self.exit_room():
- pass
- # 如果在组队界面就退出
- if self.exit_team():
- pass
- # 永生之海选层界面无HOME按钮且页面系统识别不了, 点返回箭头回到御魂副本选择界面
- self._back_to_soul_zones()
- self.goto_page(page_main)
- if not success:
- return False
- return True
- def _wait_room_stable(self) -> None:
- """
- 打完最后一局领取奖励后, 奖励弹窗/金币动画可能遮挡左下角导致房间识别失败, 等待界面稳定
- """
- logger.info('Wait room stable')
- timer = Timer(8).start()
- while not timer.reached():
- self.screenshot()
- if self.appear_then_click(self.I_REWARD, interval=1.5):
- continue
- if self.appear_then_click(self.I_REWARD_GOLD, interval=1.5):
- continue
- if not self.appear(self.I_REWARD) and not self.appear(self.I_REWARD_GOLD):
- sleep(1)
- return
- def _back_to_soul_zones(self) -> None:
- """
- 点返回箭头直到回到御魂副本选择界面(page_soul_zones可识别)
- """
- logger.info('Back to soul zones')
- timer = Timer(15).start()
- while not timer.reached():
- self.screenshot()
- if self.match_page_once(page_soul_zones):
- return
- if self.appear_then_click(self.I_UI_CONFIRM, interval=1):
- continue
- if self.appear_then_click(self.I_BACK_YELLOW, interval=1):
- continue
- if self.appear_then_click(self.I_BACK_YELLOW_SEA, interval=1):
- continue
- if self.appear_then_click(self.I_BACK_BOTTOM, interval=1):
- continue
- def run_member(self):
- logger.info('Start run member')
- self._prepare_eternity_sea()
- # 进入战斗流程
- self.device.stuck_record_add('BATTLE_STATUS_S')
- while 1:
- self.screenshot()
- #限制
- 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
- if self.check_then_accept():
- continue
- if self.is_in_room():
- self.device.stuck_record_clear()
- if self.wait_battle(wait_time=self._task_config.invite_config.wait_time):
- self.run_general_battle(config=self._task_config.general_battle_config)
- else:
- break
- # 队长秒开的时候,检测是否进入到战斗中
- elif self.check_take_over_battle(False, config=self._task_config.general_battle_config):
- continue
- while 1:
- # 有一种情况是本来要退出的,但是队长邀请了进入的战斗的加载界面
- if self.appear(self.I_GI_HOME) or self.appear(self.I_GI_EXPLORE):
- break
- # 如果可能在房间就退出
- if self.exit_room():
- pass
- # 如果还在战斗中,就退出战斗
- if self.exit_battle():
- pass
- self.goto_page(page_main)
- return True
- def run_alone(self) -> bool:
- logger.info("Start run alone")
- self.goto_page(page_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
- return True
- def is_room_dead(self) -> bool:
- # 如果在探索界面或者是出现在组队界面,那就是可能房间死了
- sleep(0.5)
- if self.appear(self.I_MATCHING) or self.appear(self.I_CHECK_EXPLORATION):
- sleep(0.5)
- if self.appear(self.I_MATCHING) or self.appear(self.I_CHECK_EXPLORATION):
- return True
- return False
- 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(self.I_FORM_TEAM, interval=1):
- return True
- if self.appear_then_click(self.I_ETERNITY_SEA, interval=1):
- continue
- #有可能点击到录像
- if self.appear_then_click(self.I_BACK_BOTTOM, interval=1):
- continue
- @property
- def _task_config(self) -> EternitySea:
- return self.config.model.eternity_sea
- def check_layer(self, layer: str) -> bool:
- """
- 检查挑战的层数, 并选中挑战的层
- :return:
- """
- pos = self.list_find(self.L_LAYER_LIST, layer)
- if pos:
- self.device.click(x=pos[0], y=pos[1])
- return True
- def check_lock(self, lock: bool = True) -> bool:
- """
- 检查是否锁定阵容, 要求在永生之海界面
- :param lock:
- :return:
- """
- logger.info('Check lock: %s', lock)
- if lock:
- while 1:
- self.screenshot()
- if self.appear(self.I_NEWETERNITYSEA_LOCK):
- return True
- if self.appear_then_click(self.I_ETERNITYSEA_UNLOCK, interval=1):
- continue
- else:
- while 1:
- self.screenshot()
- if self.appear(self.I_ETERNITYSEA_UNLOCK):
- return True
- if self.appear_then_click(self.I_NEWETERNITYSEA_LOCK, interval=1):
- continue
- if __name__ == "__main__":
- from module.config.config import Config
- from module.device.device import Device
- c = Config("oas1")
- d = Device(c)
- t = ScriptTask(c, d)
- t.screenshot()
|